mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor TilePointerIndex
This commit is contained in:
parent
c4b4595708
commit
0e57643a68
|
@ -494,6 +494,7 @@
|
|||
<ClInclude Include="world\TileElement.h" />
|
||||
<ClInclude Include="world\TileElementsView.h" />
|
||||
<ClInclude Include="world\TileInspector.h" />
|
||||
<ClInclude Include="world\TilePointerIndex.hpp" />
|
||||
<ClInclude Include="world\Wall.h" />
|
||||
<ClInclude Include="world\Water.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include "../world/SmallScenery.h"
|
||||
#include "../world/Sprite.h"
|
||||
#include "../world/Surface.h"
|
||||
#include "../world/TilePointerIndex.hpp"
|
||||
#include "../world/Wall.h"
|
||||
#include "RCT1.h"
|
||||
#include "Tables.h"
|
||||
|
@ -1535,7 +1536,8 @@ namespace RCT1
|
|||
gMapBaseZ = 7;
|
||||
|
||||
// Build tile pointer cache (needed to get the first element at a certain location)
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(RCT1_MAX_MAP_SIZE, _s4.tile_elements);
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(
|
||||
RCT1_MAX_MAP_SIZE, _s4.tile_elements, std::size(_s4.tile_elements));
|
||||
|
||||
std::vector<TileElement> tileElements;
|
||||
for (TileCoordsXY coords = { 0, 0 }; coords.y < MAXIMUM_MAP_SIZE_TECHNICAL; coords.y++)
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
#include "../world/Scenery.h"
|
||||
#include "../world/Sprite.h"
|
||||
#include "../world/Surface.h"
|
||||
#include "../world/TilePointerIndex.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
|
@ -1084,7 +1085,8 @@ public:
|
|||
void ImportTileElements()
|
||||
{
|
||||
// Build tile pointer cache (needed to get the first element at a certain location)
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(RCT2_MAXIMUM_MAP_SIZE_TECHNICAL, _s6.tile_elements);
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(
|
||||
RCT2_MAXIMUM_MAP_SIZE_TECHNICAL, _s6.tile_elements, std::size(_s6.tile_elements));
|
||||
|
||||
std::vector<TileElement> tileElements;
|
||||
bool nextElementInvisible = false;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "../scenario/Scenario.h"
|
||||
#include "../util/Util.h"
|
||||
#include "../windows/Intent.h"
|
||||
#include "../world/TilePointerIndex.hpp"
|
||||
#include "Banner.h"
|
||||
#include "Climate.h"
|
||||
#include "Footpath.h"
|
||||
|
@ -146,7 +147,7 @@ const std::vector<TileElement>& GetTileElements()
|
|||
void SetTileElements(std::vector<TileElement>&& tileElements)
|
||||
{
|
||||
_tileElements = std::move(tileElements);
|
||||
_tileIndex = TilePointerIndex<TileElement>(MAXIMUM_MAP_SIZE_TECHNICAL, _tileElements.data());
|
||||
_tileIndex = TilePointerIndex<TileElement>(MAXIMUM_MAP_SIZE_TECHNICAL, _tileElements.data(), _tileElements.size());
|
||||
_tileElementsInUse = _tileElements.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -144,43 +144,6 @@ constexpr auto SURFACE_STYLE_FLAG_RAISE_OR_LOWER_BASE_HEIGHT = 0x20;
|
|||
extern const uint8_t tile_element_lower_styles[9][32];
|
||||
extern const uint8_t tile_element_raise_styles[9][32];
|
||||
|
||||
template<typename T> class TilePointerIndex
|
||||
{
|
||||
std::vector<T*> TilePointers;
|
||||
uint16_t MapSize{};
|
||||
|
||||
public:
|
||||
TilePointerIndex() = default;
|
||||
|
||||
explicit TilePointerIndex(const uint16_t mapSize, T* tileElements)
|
||||
{
|
||||
MapSize = mapSize;
|
||||
const uint16_t MaxTileElementPointers = MapSize * MapSize;
|
||||
TilePointers.reserve(MaxTileElementPointers);
|
||||
|
||||
T* tileElement = tileElements;
|
||||
for (size_t y = 0; y < MapSize; y++)
|
||||
{
|
||||
for (size_t x = 0; x < MapSize; x++)
|
||||
{
|
||||
TilePointers.emplace_back(tileElement);
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T* GetFirstElementAt(TileCoordsXY coords)
|
||||
{
|
||||
return TilePointers[coords.x + (coords.y * MapSize)];
|
||||
}
|
||||
|
||||
void SetTile(TileCoordsXY coords, T* tileElement)
|
||||
{
|
||||
TilePointers[coords.x + (coords.y * MapSize)] = tileElement;
|
||||
}
|
||||
};
|
||||
|
||||
void ReorganiseTileElements();
|
||||
const std::vector<TileElement>& GetTileElements();
|
||||
void SetTileElements(std::vector<TileElement>&& tileElements);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
template<typename T> class TilePointerIndex
|
||||
{
|
||||
std::vector<T*> TilePointers;
|
||||
uint16_t MapSize{};
|
||||
|
||||
public:
|
||||
TilePointerIndex() = default;
|
||||
|
||||
explicit TilePointerIndex(const uint16_t mapSize, T* tileElements, size_t count)
|
||||
{
|
||||
MapSize = mapSize;
|
||||
TilePointers.reserve(MapSize * MapSize);
|
||||
|
||||
size_t index = 0;
|
||||
for (size_t y = 0; y < MapSize; y++)
|
||||
{
|
||||
for (size_t x = 0; x < MapSize; x++)
|
||||
{
|
||||
assert(index < count);
|
||||
TilePointers.emplace_back(&tileElements[index]);
|
||||
do
|
||||
{
|
||||
index++;
|
||||
} while (!tileElements[index - 1].IsLastForTile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T* GetFirstElementAt(TileCoordsXY coords)
|
||||
{
|
||||
return TilePointers[coords.x + (coords.y * MapSize)];
|
||||
}
|
||||
|
||||
void SetTile(TileCoordsXY coords, T* tileElement)
|
||||
{
|
||||
TilePointers[coords.x + (coords.y * MapSize)] = tileElement;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue