Changeset - r26924:37373e5f7e00
[Not reviewed]
master
0 5 0
dP - 20 months ago 2023-02-26 21:39:44
dp@dpointer.org
Codechange: Don't store tree counter in the map array (#10018)
5 files changed with 18 insertions and 59 deletions:
0 comments (0 inline, 0 general)
docs/landscape.html
Show inline comments
 
@@ -807,8 +807,6 @@
 
      </table>
 
     </li>
 
     <li>m2 bits 5..4: ground density</li>
 
     <li>m2 bits 3..0: update counter, incremented on every periodic processing.<br>
 
          on wraparound the growth status is updated (or, if it's <tt>3</tt>, a random action is taken)</li>
 
     <li>m3 bits 7..0: type of trees:
 
      <table>
 
       <tr>
regression/regression/result.txt
Show inline comments
 
@@ -588,7 +588,7 @@ ERROR: IsEnd() is invalid as Begin() is 
 
  SetName():            false
 
  GetLastErrorString(): ERR_NAME_IS_NOT_UNIQUE
 
  GetName():                         Regression
 
  GetPresidentName():                E. McAlpine
 
  GetPresidentName():                J. Green
 
  SetPresidentName():                true
 
  GetPresidentName():                Regression AI
 
  GetBankBalance():                  100000
src/saveload/afterload.cpp
Show inline comments
 
@@ -2334,8 +2334,7 @@ bool AfterLoadGame()
 
			if (IsTileType(t, MP_TREES)) {
 
				uint density = GB(_m[t].m2, 6, 2);
 
				uint ground = GB(_m[t].m2, 4, 2);
 
				uint counter = GB(_m[t].m2, 0, 4);
 
				_m[t].m2 = ground << 6 | density << 4 | counter;
 
				_m[t].m2 = ground << 6 | density << 4;
 
			}
 
		}
 
	}
 
@@ -3190,6 +3189,15 @@ bool AfterLoadGame()
 
			}
 
		}
 

	
 
		if (IsSavegameVersionBeforeOrAt(SLV_MULTITRACK_LEVEL_CROSSINGS)) {
 
			/* Reset unused tree counters to reduce the savegame size. */
 
			for (TileIndex t = 0; t < map_size; t++) {
 
				if (IsTileType(t, MP_TREES)) {
 
					SB(_m[t].m2, 0, 4, 0);
 
				}
 
			}
 
		}
 

	
 
		/* Refresh all level crossings to bar adjacent crossing tiles, if needed. */
 
		for (TileIndex tile = 0; tile < Map::Size(); tile++) {
 
			if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile, false);
src/tree_cmd.cpp
Show inline comments
 
@@ -174,9 +174,6 @@ static void PlaceTree(TileIndex tile, ui
 
		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));
 
	}
 
}
 

	
 
@@ -710,10 +707,14 @@ static void TileLoop_Trees(TileIndex til
 

	
 
	AmbientSoundEffect(tile);
 

	
 
	uint treeCounter = GetTreeCounter(tile);
 
	/* _tick_counter is incremented by 256 between each call, so ignore lower 8 bits.
 
	 * Also, we use a simple hash to spread the updates evenly over the map.
 
	 * 11 and 9 are just some co-prime numbers for better spread.
 
	 */
 
	uint32 cycle = 11 * TileX(tile) + 9 * TileY(tile) + (_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);
 
@@ -723,11 +724,7 @@ static void TileLoop_Trees(TileIndex til
 

	
 
	if (_settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
 

	
 
	if (GetTreeCounter(tile) < 15) {
 
		AddTreeCounter(tile, 1);
 
		return;
 
	}
 
	SetTreeCounter(tile, 0);
 
	if ((cycle & 15) != 15) return;
 

	
 
	switch (GetTreeGrowth(tile)) {
 
		case 3: // regular sized tree
src/tree_map.h
Show inline comments
 
@@ -216,50 +216,6 @@ static inline void SetTreeGrowth(TileInd
 
}
 

	
 
/**
 
 * 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(IsTileType(t, MP_TREES));
 
	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(IsTileType(t, MP_TREES)); // 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(IsTileType(t, MP_TREES)); // XXX incomplete
 
	SB(_m[t].m2, 0, 4, c);
 
}
 

	
 
/**
 
 * Make a tree-tile.
 
 *
 
 * This functions change the tile to a tile with trees and all information which belongs to it.
0 comments (0 inline, 0 general)