OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #ifndef TILEMATRIX_TYPE_HPP
11 #define TILEMATRIX_TYPE_HPP
26 template <
typename T, u
int N>
36 uint old_w = this->
area.
w / N;
37 uint old_h = this->
area.
h / N;
41 uint grid_x = (
TileX(tile) / N) * N;
42 uint grid_y = (
TileY(tile) / N) * N;
47 T *new_data = CallocT<T>(this->
area.
w / N * this->area.h / N);
54 for (uint row = 0; row < old_h; row++) {
55 MemCpyT(&new_data[(row + offs_y) * this->
area.
w / N + offs_x], &this->data[row * old_w], old_w);
60 this->
data = new_data;
64 static const uint GRID = N;
94 uint tile_x = (
TileX(tile) / N) * N;
95 uint tile_y = (
TileY(tile) / N) * N;
98 w += std::min(extend * N, tile_x);
99 h += std::min(extend * N, tile_y);
101 tile_x -= std::min(extend * N, tile_x);
102 tile_y -= std::min(extend * N, tile_y);
104 w += std::min(extend * N,
MapSizeX() - tile_x - w);
105 h += std::min(extend * N,
MapSizeY() - tile_y - h);
130 tile -= this->area.
tile;
131 uint x =
TileX(tile) / N;
132 uint y =
TileY(tile) / N;
134 return &this->data[y * this->area.
w / N + x];
140 return *this->
Get(tile);
T & operator[](TileIndex tile)
Array access operator, see Get.
uint32 TileIndex
The index/ID of a Tile.
A simple matrix that stores one value per N*N square of the map.
const TileArea & GetArea() const
Get the total covered area.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
TileArea area
Area covered by the matrix.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static uint MapSizeX()
Get the size of the map along the X.
T * Get(TileIndex tile)
Get the value associated to a tile index.
uint16 w
The width of the area.
Represents the covered area of e.g.
static uint MapSizeY()
Get the size of the map along the Y.
uint16 h
The height of the area.
static TileArea GetAreaForTile(TileIndex tile, uint extend=0)
Get the area of the matrix square that contains a specific tile.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
void Add(TileIndex tile)
Extend the coverage area to include a tile.
TileIndex tile
The base tile of the area.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
T * data
Pointer to data array.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void AllocateStorage(TileIndex tile)
Allocates space for a new tile in the matrix.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?