Compare commits
No commits in common. "de39d10776ca2981a11e2499e3a6bc88dcd822d7" and "55d01e86c16d3cd589bffb3ec26ce81ecf4a42de" have entirely different histories.
de39d10776
...
55d01e86c1
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
@ -47,9 +47,3 @@ It took me a couple of days to fix the ray casting. I forgot that my mesh is off
|
|||||||
Woah! The camera doesn't just phase through placed blocks anymore! The camera can also fall into the void for eternity! So cool!
|
Woah! The camera doesn't just phase through placed blocks anymore! The camera can also fall into the void for eternity! So cool!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 0.8.0 : Data Structure Redo - 11/19/25
|
|
||||||
|
|
||||||
Final part of the blog post tutorial. Changing the data structure of the Chunk's to store voxels in a 1d array instead of a HashMap.
|
|
||||||
|
|
||||||

|
|
||||||
|
|||||||
16
src/Chunk.h
16
src/Chunk.h
@ -59,33 +59,25 @@ class Chunk {
|
|||||||
// Mutators
|
// Mutators
|
||||||
inline void set(int x, int y, int z, VoxelKind v) {
|
inline void set(int x, int y, int z, VoxelKind v) {
|
||||||
data[index(x, y, z)] = v;
|
data[index(x, y, z)] = v;
|
||||||
empty_checked = false; // Invalidate cache
|
|
||||||
}
|
}
|
||||||
inline void set(glm::ivec3 pos, VoxelKind v) {
|
inline void set(glm::ivec3 pos, VoxelKind v) {
|
||||||
// std::cout << "Setting Pos (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl;
|
// std::cout << "Setting Pos (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl;
|
||||||
data[index(pos.x, pos.y, pos.z)] = v;
|
data[index(pos.x, pos.y, pos.z)] = v;
|
||||||
empty_checked = false; // Invalidate cache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
inline bool isEmpty() const {
|
inline bool isEmpty() const {
|
||||||
if (!empty_checked) {
|
return std::all_of(data.begin(), data.end(), [](VoxelKind k){
|
||||||
is_empty = std::all_of(data.begin(), data.end(), [](VoxelKind k){
|
return k == VoxelKind::Air;
|
||||||
return k == VoxelKind::Air;
|
});
|
||||||
});
|
|
||||||
empty_checked = true;
|
|
||||||
}
|
|
||||||
return is_empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int SIZE = CHUNK_SIZE;
|
static constexpr int SIZE = CHUNK_SIZE;
|
||||||
static constexpr int TOTAL = SIZE * SIZE * SIZE;
|
static constexpr int TOTAL = SIZE * SIZE * SIZE;
|
||||||
std::array<VoxelKind, TOTAL> data;
|
std::array<VoxelKind, TOTAL + 1> data;
|
||||||
|
|
||||||
std::unique_ptr<Mesh> mesh; // Nullable mesh
|
std::unique_ptr<Mesh> mesh; // Nullable mesh
|
||||||
mutable bool is_empty = true; // Cache empty state
|
|
||||||
mutable bool empty_checked = false; // Track if we've checked
|
|
||||||
|
|
||||||
static inline constexpr int index(int x, int y, int z) noexcept {
|
static inline constexpr int index(int x, int y, int z) noexcept {
|
||||||
return x + (y * SIZE) + (z * SIZE * SIZE);
|
return x + (y * SIZE) + (z * SIZE * SIZE);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user