Changeset - r26932:8648ca7bcbfc
[Not reviewed]
master
0 3 0
Rubidium - 17 months ago 2023-01-21 16:32:28
rubidium@openttd.org
Codechange: hide Tile(Extended) into the Tile structure
3 files changed with 47 insertions and 59 deletions:
0 comments (0 inline, 0 general)
src/map.cpp
Show inline comments
 
@@ -27,8 +27,8 @@ extern "C" _CRTIMP void __cdecl _assert(
 
/* static */ uint Map::size;      ///< The number of tiles on the map
 
/* static */ uint Map::tile_mask; ///< _map_size - 1 (to mask the mapsize)
 

	
 
TileBase *_m = nullptr;          ///< Tiles of the map
 
TileExtended *_me = nullptr; ///< Extended Tiles of the map
 
/* static */ Tile::TileBase *Tile::base_tiles = nullptr;         ///< Base tiles of the map
 
/* static */ Tile::TileExtended *Tile::extended_tiles = nullptr; ///< Extended tiles of the map
 

	
 

	
 
/**
 
@@ -56,11 +56,11 @@ TileExtended *_me = nullptr; ///< Extend
 
	Map::size = size_x * size_y;
 
	Map::tile_mask = Map::size - 1;
 

	
 
	free(_m);
 
	free(_me);
 
	free(Tile::base_tiles);
 
	free(Tile::extended_tiles);
 

	
 
	_m = CallocT<TileBase>(Map::size);
 
	_me = CallocT<TileExtended>(Map::size);
 
	Tile::base_tiles = CallocT<Tile::TileBase>(Map::size);
 
	Tile::extended_tiles = CallocT<Tile::TileExtended>(Map::size);
 
}
 

	
 

	
src/map_func.h
Show inline comments
 
@@ -16,22 +16,6 @@
 
#include "direction_func.h"
 

	
 
/**
 
 * Pointer to the tile-array.
 
 *
 
 * This variable points to the tile-array which contains the tiles of
 
 * the map.
 
 */
 
extern TileBase *_m;
 

	
 
/**
 
 * Pointer to the extended tile-array.
 
 *
 
 * This variable points to the extended tile-array which contains the tiles
 
 * of the map.
 
 */
 
extern TileExtended *_me;
 

	
 
/**
 
 * Wrapper class to abstract away the way the tiles are stored. It is
 
 * intended to be used to access the "map" data of a single tile.
 
 *
 
@@ -40,6 +24,36 @@ extern TileExtended *_me;
 
 */
 
class Tile {
 
private:
 
	friend struct Map;
 
	/**
 
	 * Data that is stored per tile. Also used TileExtended for this.
 
	 * Look at docs/landscape.html for the exact meaning of the members.
 
	 */
 
	struct TileBase {
 
		byte   type;   ///< The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
 
		byte   height; ///< The height of the northern corner.
 
		uint16 m2;     ///< Primarily used for indices to towns, industries and stations
 
		byte   m1;     ///< Primarily used for ownership information
 
		byte   m3;     ///< General purpose
 
		byte   m4;     ///< General purpose
 
		byte   m5;     ///< General purpose
 
	};
 

	
 
	static_assert(sizeof(TileBase) == 8);
 

	
 
	/**
 
	 * Data that is stored per tile. Also used TileBase for this.
 
	 * Look at docs/landscape.html for the exact meaning of the members.
 
	 */
 
	struct TileExtended {
 
		byte m6;   ///< General purpose
 
		byte m7;   ///< Primarily used for newgrf support
 
		uint16 m8; ///< General purpose
 
	};
 

	
 
	static TileBase *base_tiles;         ///< Pointer to the tile-array.
 
	static TileExtended *extended_tiles; ///< Pointer to the extended tile-array.
 

	
 
	TileIndex tile; ///< The tile to access the map data for.
 

	
 
public:
 
@@ -74,7 +88,7 @@ public:
 
	 */
 
	debug_inline byte &type()
 
	{
 
		return _m[tile].type;
 
		return base_tiles[tile].type;
 
	}
 

	
 
	/**
 
@@ -86,7 +100,7 @@ public:
 
	 */
 
	debug_inline byte &height()
 
	{
 
		return _m[tile].height;
 
		return base_tiles[tile].height;
 
	}
 

	
 
	/**
 
@@ -98,7 +112,7 @@ public:
 
	 */
 
	debug_inline byte &m1()
 
	{
 
		return _m[tile].m1;
 
		return base_tiles[tile].m1;
 
	}
 

	
 
	/**
 
@@ -110,7 +124,7 @@ public:
 
	 */
 
	debug_inline uint16 &m2()
 
	{
 
		return _m[tile].m2;
 
		return base_tiles[tile].m2;
 
	}
 

	
 
	/**
 
@@ -122,7 +136,7 @@ public:
 
	 */
 
	debug_inline byte &m3()
 
	{
 
		return _m[tile].m3;
 
		return base_tiles[tile].m3;
 
	}
 

	
 
	/**
 
@@ -134,7 +148,7 @@ public:
 
	 */
 
	debug_inline byte &m4()
 
	{
 
		return _m[tile].m4;
 
		return base_tiles[tile].m4;
 
	}
 

	
 
	/**
 
@@ -146,7 +160,7 @@ public:
 
	 */
 
	debug_inline byte &m5()
 
	{
 
		return _m[tile].m5;
 
		return base_tiles[tile].m5;
 
	}
 

	
 
	/**
 
@@ -158,7 +172,7 @@ public:
 
	 */
 
	debug_inline byte &m6()
 
	{
 
		return _me[tile].m6;
 
		return extended_tiles[tile].m6;
 
	}
 

	
 
	/**
 
@@ -170,7 +184,7 @@ public:
 
	 */
 
	debug_inline byte &m7()
 
	{
 
		return _me[tile].m7;
 
		return extended_tiles[tile].m7;
 
	}
 

	
 
	/**
 
@@ -182,7 +196,7 @@ public:
 
	 */
 
	debug_inline uint16 &m8()
 
	{
 
		return _me[tile].m8;
 
		return extended_tiles[tile].m8;
 
	}
 
};
 

	
 
@@ -339,7 +353,7 @@ public:
 
	 */
 
	static bool IsInitialized()
 
	{
 
		return _m != nullptr;
 
		return Tile::base_tiles != nullptr;
 
	}
 

	
 
	/**
src/map_type.h
Show inline comments
 
@@ -11,32 +11,6 @@
 
#define MAP_TYPE_H
 

	
 
/**
 
 * Data that is stored per tile. Also used TileExtended for this.
 
 * Look at docs/landscape.html for the exact meaning of the members.
 
 */
 
struct TileBase {
 
	byte   type;        ///< The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
 
	byte   height;      ///< The height of the northern corner.
 
	uint16 m2;          ///< Primarily used for indices to towns, industries and stations
 
	byte   m1;          ///< Primarily used for ownership information
 
	byte   m3;          ///< General purpose
 
	byte   m4;          ///< General purpose
 
	byte   m5;          ///< General purpose
 
};
 

	
 
static_assert(sizeof(TileBase) == 8);
 

	
 
/**
 
 * Data that is stored per tile. Also used TileBase for this.
 
 * Look at docs/landscape.html for the exact meaning of the members.
 
 */
 
struct TileExtended {
 
	byte m6;   ///< General purpose
 
	byte m7;   ///< Primarily used for newgrf support
 
	uint16 m8; ///< General purpose
 
};
 

	
 
/**
 
 * An offset value between two tiles.
 
 *
 
 * This value is used for the difference between
0 comments (0 inline, 0 general)