Lodestone.Level
Loading...
Searching...
No Matches
ChunkContainer.h
Go to the documentation of this file.
1//
2// Created by DexrnZacAttack on 11/9/25 using zPc-i2.
3//
4#ifndef LODESTONE_CHUNKCONTAINER_H
5#define LODESTONE_CHUNKCONTAINER_H
6#include <iostream>
7#include <memory>
8
13
18 public:
19 ~ChunkContainer() override = default;
20 ChunkContainer() = default;
23
24 std::string toString() const override {
25 return std::format("ChunkContainer[chunks={}, bounds={}]", m_chunks.size(), getChunkBounds().toString());
26 };
27
29
35 bool hasChunk(const coords::ChunkCoordinates &coords) const;
36
43 bool hasChunk(const int x, const int z) const {
44 return hasChunk({x, z});
45 };
46
53 Chunk *createChunk(const coords::ChunkCoordinates &coords, int height = 256);
54
62 Chunk *createChunk(const int x, const int z, const int height = 256) {
63 return createChunk({x, z}, height);
64 };
65
66 void addChunk(std::unique_ptr<Chunk> chunk);
67
68 void addChunk(const coords::ChunkCoordinates &coords, std::unique_ptr<Chunk> chunk);
69
70 void addChunk(const int x, const int z, std::unique_ptr<Chunk> chunk) {
71 addChunk({x, z}, std::move(chunk));
72 }
73
74 Chunk *getChunk(const coords::ChunkCoordinates &coords);
75
76 Chunk *getChunk(const int x, const int z) { return getChunk({x, z}); };
77
81
82 Chunk *getChunkCreate(const coords::ChunkCoordinates &coords, int height = 256);
83
84 Chunk *getChunkCreate(const int x, const int z, const int height = 256) {
85 return getChunkCreate({x, z}, height);
86 };
87
88 Chunk *getChunkFromBlockCoordsCreate(const int blockX, const int blockZ, const int height = 256) {
90 };
91
92 const Chunk *getChunk(const coords::ChunkCoordinates &coords) const;
93
94 const Chunk *getChunk(const int x, const int z) const {
95 return getChunk({x, z});
96 };
97
98 const Chunk *getChunkFromBlockCoords(const signed_size_t blockX, const signed_size_t blockZ) const {
100 };
101
102 std::unique_ptr<Chunk> detachChunk(const coords::ChunkCoordinates &coords,
103 bool shouldInvalidateCoords = true);
104
105 std::unique_ptr<Chunk>
106 detachChunk(const int x, const int z,
107 const bool shouldInvalidateCoords = true) {
108 return detachChunk({x, z}, shouldInvalidateCoords);
109 };
110
111 void removeChunk(const coords::ChunkCoordinates &coords);
112
113 void removeChunk(const int x, const int z) { removeChunk({x, z}); };
114
115 void merge(std::unique_ptr<ChunkContainer> rhs);
116
120
124
125 // todo replace with inbuilt bounds that gets updated
126 types::Bounds3i getChunkBounds() const;
127
130
131 protected:
133 };
134} // namespace lodestone::level::chunk
135
136#endif // LODESTONE_CHUNKCONTAINER_H
long signed int signed_size_t
#define LODESTONE_API
gtl::flat_hash_map< T... > map_t
ChunkContainer(ChunkContainer &&)=default
types::Bounds3i getChunkBounds() const
Definition ChunkContainer.cpp:131
bool hasChunk(const coords::ChunkCoordinates &coords) const
Returns true if chunk at coords exist.
Definition ChunkContainer.cpp:15
Chunk * createChunk(const int x, const int z, const int height=256)
Creates a chunk at the given coordinates with the given height.
Definition ChunkContainer.h:62
ChunkContainer & operator=(const ChunkContainer &)=delete
std::unique_ptr< Chunk > detachChunk(const coords::ChunkCoordinates &coords, bool shouldInvalidateCoords=true)
Definition ChunkContainer.cpp:98
Chunk * getChunk(const coords::ChunkCoordinates &coords)
Definition ChunkContainer.cpp:74
std::unique_ptr< Chunk > detachChunk(const int x, const int z, const bool shouldInvalidateCoords=true)
Definition ChunkContainer.h:106
Chunk * getChunk(const int x, const int z)
Definition ChunkContainer.h:76
Chunk * getChunkCreate(const coords::ChunkCoordinates &coords, int height=256)
Definition ChunkContainer.cpp:81
ChunkContainer & operator=(ChunkContainer &&)=default
Chunk * getChunkCreate(const int x, const int z, const int height=256)
Definition ChunkContainer.h:84
Chunk * getChunkFromBlockCoordsCreate(const int blockX, const int blockZ, const int height=256)
Definition ChunkContainer.h:88
virtual bool isChunkInBounds(const coords::ChunkCoordinates &coords)=0
bool hasChunk(const int x, const int z) const
Returns true if chunk at coords exist.
Definition ChunkContainer.h:43
Chunk * getChunkFromBlockCoords(const signed_size_t blockX, const signed_size_t blockZ)
Definition ChunkContainer.h:78
std::string toString() const override
Definition ChunkContainer.h:24
map_t< coords::ChunkCoordinates, std::unique_ptr< Chunk > > m_chunks
Definition ChunkContainer.h:132
void addChunk(std::unique_ptr< Chunk > chunk)
Definition ChunkContainer.cpp:40
void removeChunk(const int x, const int z)
Definition ChunkContainer.h:113
const Chunk * getChunkFromBlockCoords(const signed_size_t blockX, const signed_size_t blockZ) const
Definition ChunkContainer.h:98
map_t< coords::ChunkCoordinates, std::unique_ptr< Chunk > > & getChunks()
Definition ChunkContainer.h:117
ChunkContainer(const ChunkContainer &)=delete
Chunk * createChunk(const coords::ChunkCoordinates &coords, int height=256)
Creates a chunk at the given coordinates with the given height.
Definition ChunkContainer.cpp:19
const Chunk * getChunk(const int x, const int z) const
Definition ChunkContainer.h:94
const map_t< coords::ChunkCoordinates, std::unique_ptr< Chunk > > & getChunks() const
Definition ChunkContainer.h:121
void addChunk(const int x, const int z, std::unique_ptr< Chunk > chunk)
Definition ChunkContainer.h:70
Definition Chunk.h:26
Definition ChunkCoordinates.h:16
static constexpr ChunkCoordinates fromBlockCoordinates(const signed_size_t blockX, const signed_size_t blockZ)
Definition ChunkCoordinates.h:30
Definition Chunk.cpp:10
Definition ChunkCoordinates.cpp:10
Bounds3< int > Bounds3i
Definition Bounds3.h:94