Codechange: Make HouseSpec list and cached building counts dynamic. #12287
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
HouseSpecs and cached building counts use fixed size arrays. These arrays are
There are also some loops that go through all 512 possible House IDs, even though by default only 110 are used.
Description
Replace HouseSpecs array with a vector, allocated as needed.
Change BuildingCounts to use vectors too -- these now require a bit of extra management to make sure they are initialized to the correct size when created.
This is based on how ObjectSpecs are dynamically allocated.
Limitations
TownCache
is now 96 bytes + vector allocation, instead of a fixed 1880 bytes, however it now needs to allocate extra memory for each town, 2 bytes for each house type and 2 bytes for each class. By default this is 220 bytes and 2 bytes (there are no classes by default).BuildingCounts
could perhaps be resized on-demand inIncreaseBuildingCount
which might reduce the (default) 220 bytes a little but means there'd be random allocations occurring.Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.