From 30bc490292a87f6da6f21474c2c5fad105a71c5d Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 11 Sep 2022 00:12:23 +0300 Subject: [PATCH] Codechange: Don't store tree counter in the map array (cherry picked from commit 6c3f351d5a4b0d19a1a265f04f44c70c24c19cd2) See: https://github.com/OpenTTD/OpenTTD/pull/10018 --- docs/landscape.html | 2 -- src/tree_cmd.cpp | 16 ++++++---------- src/tree_map.h | 44 -------------------------------------------- 3 files changed, 6 insertions(+), 56 deletions(-) diff --git a/docs/landscape.html b/docs/landscape.html index fe8f37e70f..78763f9d17 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -840,8 +840,6 @@
  • m2 bits 5..4: ground density
  • -
  • m2 bits 3..0: update counter, incremented on every periodic processing.
    - on wraparound the growth status is updated (or, if it's 3, a random action is taken)
  • m3 bits 7..0: type of trees: diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index a110578a52..cd1a5b1567 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -248,9 +248,6 @@ static void PlaceTree(TileIndex tile, uint32 r) if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) { SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3); } - - /* Set the counter to a random start value */ - SetTreeCounter(tile, (TreeGround)GB(r, 24, 4)); } } @@ -914,10 +911,13 @@ static void TileLoop_Trees(TileIndex tile) AmbientSoundEffect(tile); - uint treeCounter = GetTreeCounter(tile); + /* _tick_counter is incremented by 256 between each call, so ignore lower 8 bits. + * Also, we add tile % 31 to spread the updates evenly over the map, + * where 31 is just some prime number that looks ok. */ + uint32 cycle = (uint32)tile % 31 + (_tick_counter >> 8); /* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */ - if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { + if ((cycle & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { uint density = GetTreeDensity(tile); if (density < 3) { SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1); @@ -925,11 +925,7 @@ static void TileLoop_Trees(TileIndex tile) } } - if (GetTreeCounter(tile) < 15) { - AddTreeCounter(tile, 1); - return; - } - SetTreeCounter(tile, 0); + if ((cycle & 15) < 15) return; if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return; diff --git a/src/tree_map.h b/src/tree_map.h index affc82bb95..5d2c34f44e 100644 --- a/src/tree_map.h +++ b/src/tree_map.h @@ -215,50 +215,6 @@ static inline void SetTreeGrowth(TileIndex t, uint g) SB(_m[t].m5, 0, 3, g); } -/** - * Get the tick counter of a tree tile. - * - * Returns the saved tick counter of a given tile. - * - * @param t The tile to get the counter value from - * @pre Tile must be of type MP_TREES - */ -static inline uint GetTreeCounter(TileIndex t) -{ - assert_tile(IsTileType(t, MP_TREES), t); - return GB(_m[t].m2, 0, 4); -} - -/** - * Add a value on the tick counter of a tree-tile - * - * This function adds a value on the tick counter of a tree-tile. - * - * @param t The tile to add the value on - * @param a The value to add on the tick counter - * @pre Tile must be of type MP_TREES - */ -static inline void AddTreeCounter(TileIndex t, int a) -{ - assert_tile(IsTileType(t, MP_TREES), t); // XXX incomplete - _m[t].m2 += a; -} - -/** - * Set the tick counter for a tree-tile - * - * This function sets directly the tick counter for a tree-tile. - * - * @param t The tile to set the tick counter - * @param c The new tick counter value - * @pre Tile must be of type MP_TREES - */ -static inline void SetTreeCounter(TileIndex t, uint c) -{ - assert_tile(IsTileType(t, MP_TREES), t); // XXX incomplete - SB(_m[t].m2, 0, 4, c); -} - /** * Make a tree-tile. *