Added write and read to buffer to Chunk

This commit is contained in:
2025-01-27 01:01:46 -05:00
parent b24f1e9039
commit 69b2cbc32b

View File

@@ -13,6 +13,7 @@
#include <J3ML/Geometry/QuadTree.hpp>
#include "Tile.hpp"
#include "Data.hpp"
#include "Serialization.hpp"
#include <filesystem>
#include <fstream>
@@ -67,6 +68,31 @@ namespace CaveGame::Core
[[nodiscard]] std::array<TileID, ChunkSize * ChunkSize> DataContiguous() const;
void write(Buffer& buf) {
write_f32(buf, cell.x);
write_f32(buf, cell.y);
for (int x = 0; x < ChunkSize; x++) {
for (int y = 0; y < ChunkSize; y++) {
write_u8(buf, (uint8_t)GetTile(x, y));
}
}
}
void read(Buffer& buf)
{
cell.x = read_f32(buf);
cell.y = read_f32(buf);
for (int x = 0; x < ChunkSize; x++)
{
for (int y = 0; y < ChunkSize; y++)
{
SetTile(x, y, (TileID) read_u8(buf));
}
}
}
void SetData(char* buffer);
[[nodiscard]] static constexpr std::size_t BufferSizeBytes();