-
-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codechange: Don't store tree counter in the map array #10018
Conversation
7f68f4d
to
6c3f351
Compare
(cherry picked from commit 6c3f351d5a4b0d19a1a265f04f44c70c24c19cd2) See: OpenTTD/OpenTTD#10018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly: Instead of keeping track of when each tree should grow based on a random initial counter, we randomly pick trees to grow and assume that the result is approximately the same? Trees also have a growth/density state, which is not affected.
Is that correct?
6c3f351
to
8b45c0d
Compare
8b45c0d
to
09cde6a
Compare
From a discussion on Discord:
...
... Based on my understanding of how trees currently work and how this changes that, I think this PR is a worthwhile change. If we can get the same results without bloating the savegame with unnecessary noise, we should. I imagine it would most benefit people joining network games with large maps, which is a known issue. Most network games don't have trees for this very reason. That said, if the current randomization is "kinda temporary and can be improved" let's wait for that before we merge. 😄 |
09cde6a
to
ba44fe9
Compare
It was temporary in a sense that I planned more entropy reduction patches for trees that would need a better random/hash anyway. Unfortunately, circumstances changed so I probably won't return to that work for a while. In any case, this is a fine (and simple) change on its own. Also, I improved hash a little bit so now I can't see any pattern whatsoever even on fast forward. Btw, keep in mind that tile loop adds its own randomization on top of this. |
Sure, fine by me. Except it doesn't build now. 😉 |
It isn't (and cannot be) the same result, but it might be close enough. As the usage of the map array has changed, it might be desirable to bump the savegame version and clear the existing data on existing maps, and ensure those bits are cleared when creating tree tiles, otherwise the benefits only appear for new maps. |
ba44fe9
to
cd558e0
Compare
@@ -720,11 +721,7 @@ static void TileLoop_Trees(TileIndex tile) | |||
|
|||
if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an interesting behavioural question to answer here. Should the grass grow or not?
With this setting on 'no growth and no spread', it previously disabled it for about 87.5% of the tree tiles, and it introduced an 8x speed up for the remaining 12.5% of the tiles. Since either the treeCounter & 7
is actually 7 and it triggers every time because the tree counter does not get updated, or it never triggers as (again) the tree counter does not get updated.
As it stands now the grass is now allowed to grow for 100% of the tiles. If grass should not grow like on 87.5% of the tiles previously, then this check needs to be moved up to just after AmbientSoundEffect(tile);
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it was introduced in #8415 accidentally so this fixes it. Even though non-growing grass is an interesting feature to have doing that only under the trees is a bug. Also, idk what 87.5% you're talking about, I just tested and no grass grows under trees in 13.0.
cd558e0
to
aeb88a0
Compare
aeb88a0
to
e045fa8
Compare
@@ -3190,6 +3189,15 @@ bool AfterLoadGame() | |||
} | |||
} | |||
|
|||
if (IsSavegameVersionBeforeOrAt(SLV_MULTITRACK_LEVEL_CROSSINGS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure you want this savegame version? Last is (since not long) now SLV_LINKGRAPH_EDGES
(with a wrong comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it should indeed have been SLV_LINKGRAPH_EDGES
, but given the speed the two savegame versions after SLV_MULTITRACK_LEVEL_CROSSINGS
got added to master, I doubt there are many (if any) savegames that are made between NewGRF road stops got added and this was merged. So, in the grand scheme of things it does not really matter.
I fixed the comment with #10471 by just squashing that tiny change into the same savegame version. Similarly, technically not the right thing to do, but essentially harmless.
Motivation / Problem
Trees add a lot of entropy to the map array drastically increasing the size of the save file.
According to my estimations, this change decreases the size by 10-15%.
Description
The tree counter is just used to determine each 8th or 16th call to the
TileLoop_Trees
and that can easily be done without storing it in the map array. I plan to do some follow-up tree patches but this one is so free I decided to PR it separately.Limitations
It does change the order in which tiles are processed in the tile loop so it's not a perfect replica but it's ok as the rate is still the same. Regression tests had to be updated though as the random state blew up.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.