fixed FPS issues (turns out you shouldn't look at 32768 * 16 voxels every frame
This commit is contained in:
parent
55d01e86c1
commit
57d749f09b
12
src/Chunk.h
12
src/Chunk.h
@ -59,25 +59,33 @@ 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 {
|
||||||
return std::all_of(data.begin(), data.end(), [](VoxelKind k){
|
if (!empty_checked) {
|
||||||
|
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 + 1> data;
|
std::array<VoxelKind, TOTAL> 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);
|
||||||
|
|||||||
@ -43,7 +43,7 @@ void Mesh::init() {
|
|||||||
void Mesh::uploadData(const std::vector<float> &vboData, const std::vector<unsigned int> &eboData) {
|
void Mesh::uploadData(const std::vector<float> &vboData, const std::vector<unsigned int> &eboData) {
|
||||||
m_indexCount = eboData.size();
|
m_indexCount = eboData.size();
|
||||||
|
|
||||||
// std::cout << "Uploading mesh: " << vboData.size() << " floats, " << eboData.size() << " indices" << std::endl;
|
std::cout << "Uploading mesh: " << vboData.size() << " floats, " << eboData.size() << " indices" << std::endl;
|
||||||
|
|
||||||
// Bind VAO first, then upload buffer data
|
// Bind VAO first, then upload buffer data
|
||||||
glBindVertexArray(m_VAO);
|
glBindVertexArray(m_VAO);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user