rster2002 / ed-journals

Work in progress journal parsing and utilities for Elite Dangerous written in Rust.
https://crates.io/crates/ed-journals
MIT License
2 stars 2 forks source link

Optimize species spawn conditions. #20

Closed rster2002 closed 2 months ago

rster2002 commented 2 months ago

Currently it's quite inefficient to check which species matches criteria as it means allocating a Vec for every single species that exists and going though them one by one. A possible solutions could be something like this:

lazy_static! {
    static ref SPECIES_SPAWN_CONDITIONS: [(Species, Vec<SpawnCondition>); 100] = [
        (Species::AleoidaArcus, vec![
            SpawnCondition::ThinAtmosphere(AtmosphereType::CarbonDioxide),
            SpawnCondition::MaxGravity(0.27),
            SpawnCondition::MinMeanTemperature(175.0),
            SpawnCondition::MaxMeanTemperature(180.0),
        ]),
        // etc...
    ];
}

Which would just allocate everything once when it is first required and then keeps it allocated. This sacrifices memory usage for speed, but I think that it would be worth it.

Then to find matches you can just iterate over SPECIES_SPAWN_CONDITIONS and note down the species for the matches.