packed chunk data
This commit is contained in:
@@ -65,7 +65,7 @@ using AllTiles = std::tuple<EmptyTile, TowerTile, WalkableTile, DecorationTile>;
|
||||
|
||||
using TileFactory = sp::MessageFactory<Tile, AllTiles>;
|
||||
|
||||
class TileHandler : public sp::GenericHandler<AllTiles>{};
|
||||
class TileHandler : public sp::GenericHandler<AllTiles> {};
|
||||
|
||||
using TilePtr = std::shared_ptr<sp::SerializableMessage<TileFactory>>;
|
||||
|
||||
@@ -79,35 +79,14 @@ typedef std::uint32_t TileIndex;
|
||||
// 32 x 32 area
|
||||
struct Chunk {
|
||||
enum { ChunkWidth = 32, ChunkHeight = 32, ChunkSize = ChunkWidth * ChunkHeight };
|
||||
typedef std::array<std::uint16_t, ChunkSize> ChunkData;
|
||||
using ChunkData = std::array<std::uint16_t, ChunkSize>;
|
||||
using ChunkPackedData = std::vector<uint64_t>;
|
||||
|
||||
// stores index of tile palette
|
||||
ChunkData m_Tiles{0};
|
||||
ChunkPalette m_Palette;
|
||||
ChunkPackedData m_Data;
|
||||
|
||||
TileIndex GetTileIndex(std::uint16_t tileNumber) const {
|
||||
TileIndex chunkPaletteIndex = m_Tiles.at(tileNumber);
|
||||
if (chunkPaletteIndex == 0) // index 0 means empty tile index 1 = first tile
|
||||
return 0;
|
||||
return m_Palette.at(chunkPaletteIndex);
|
||||
}
|
||||
|
||||
// TODO: keep data packed
|
||||
/*
|
||||
std::size_t startLong = static_cast<std::size_t>((tileNumber * bitsPerTile) / BITS_IN_LONG);
|
||||
std::size_t startOffset = static_cast<std::size_t>((tileNumber * bitsPerTile) % BITS_IN_LONG);
|
||||
std::size_t endLong = static_cast<std::size_t>(((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG);
|
||||
|
||||
std::uint64_t value = static_cast<std::uint64_t>(a_Chunk->m_Tiles[tileNumber]);
|
||||
|
||||
value &= individualValueMask;
|
||||
|
||||
chunkData[startLong] |= (value << startOffset);
|
||||
|
||||
if (startLong != endLong) {
|
||||
chunkData[endLong] = (value >> (BITS_IN_LONG - startOffset));
|
||||
}
|
||||
*/
|
||||
TileIndex GetTileIndex(std::uint16_t tileNumber) const;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Chunk> ChunkPtr;
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#include <memory>
|
||||
#include <sp/common/GenericHandler.h>
|
||||
#include <sp/io/SerializableMessage.h>
|
||||
#include <sp/protocol/ConcreteMessage.h>
|
||||
#include <sp/protocol/MessageDispatcher.h>
|
||||
#include <sp/protocol/MessageFactory.h>
|
||||
#include <td/Types.h>
|
||||
#include <td/common/NonCopyable.h>
|
||||
#include <td/protocol/command/CommandData.h>
|
||||
#include <sp/io/SerializableMessage.h>
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
Reference in New Issue
Block a user