- Introduced `IndustryTypeCountCaches` struct to represent the cache of industry counts for a specific industry type.
This cache includes a KD-Tree for spatial indexing and a new `IndustryTownCache` struct to represent the cache of industries for a specific town.
- Modified `Industry::counts` to use `IndustryTypeCountCaches` struct.
- Added `industry_kdtree.h` and `industry_kdtree.cpp` for KD-Tree operations and to avoid circular dependencies.
- Introduced `RebuildIndustryKdtree` function to rebuild the KD-Tree for each industry type by iterating over all industries and categorizing them by type.
- Updated `IncIndustryTypeCount` and `DecIndustryTypeCount` methods to manage KD-Tree insertions and removals directly within the `Industry` class.
- Updated `CountTownIndustriesOfTypeMatchingCondition` to use the new data structures for performance.
- Updated `ResetIndustryCounts` to clear the vector of `IndustryTownCache` entries.
- Modified `GetIndustryTypeCount` to count industries of a type via KD-Tree for better performance.
- Modified `CheckIfFarEnoughFromConflictingIndustry` to utilize KD-Tree for faster conflict checks.
- Simplified `DoCreateNewIndustry` and `Industry::~Industry` by directly integrating KD-Tree updates.
- Modified `GetClosestIndustry` to use `FindNearest` and `FindNearestExcept` for faster checking.
- Modified `FindNearestRecursive` to handle an optional parameter to exclude a specific element from the search.
- Added `FindNearestExcept` function to find the nearest element excluding a specified element.
- Improved Doxygen comments for `FindNearest`, `FindNearestExcept`, and `FindContained` functions.
- Ensured that Doxygen comments now include parameter descriptions and return values for better documentation and clarity.
- Modified `Industry::counts` to use a vector of pairs to store pairs of `TownID` and vectors of `IndustryID`.
- Modified `IncIndustryTypeCount` and `DecIndustryTypeCount` to manage industry counts at the town level.
- Introduced `ProcessIndustries` as a helper function to process and count industries based on a provided condition.
- Introduced `CountTownIndustriesOfTypeMatchingCondition` to count industries for a specific type within a town or across all towns.
- Modified `GetIndustryTypeCount` function to utilize the new counting mechanism.
- Updated `ResetIndustryCounts` to clear the vector of industry counts for each industry type.
- Updated `DoCreateNewIndustry` and save/load functions to use the new `IncIndustryTypeCount` method.
- Updated `Industry::~Industry` to use the new `DecIndustryTypeCount` method.
- Modified `FindTownForIndustry` to use the new `HasTownIndustryOfType` method for better performance.
- Modified `GetCountAndDistanceOfClosestInstance` to use `CountTownIndustriesOfTypeMatchingCondition` for more efficient counting.
Kdtree uses a function pointer and incorrectly calls it a functor. The function pointer needs to be passed on instantiaton.
Instead, use an actual functor. This simplifies instantiation.
Ship and RoadVehicle path caches use a std::deque, which is quite memory hungry, especially for RoadVehicle which has two.
std::deque was used to be able to push/pop from either end.
Change to use a single std::vector each, which is now push/popped from the back.
IndustrySpec and IndustryTileSpec cargo label lists are only used for original industries. Original industries can only have up to 2 inputs and 3 outputs. Therefore having space for 16 input/outputs slots is unnecessary
This saves 216 bytes per industry type, and 164 bytes per industry tile type.
* After double-clicking on a location button to follow a vehicle, show that state by drawing the location button in a lowered state.
* Allow cancelling the follow state by clicking on the location button again.