Browse Source

changed voxel data to use atomics

testing
totallyfake 1 year ago
parent
commit
1c5e4cf289
3 changed files with 8 additions and 7 deletions
  1. 3
    1
      include/chunk.h
  2. 5
    5
      src/chunk.cpp
  3. 0
    1
      src/game.cpp

+ 3
- 1
include/chunk.h View File

@@ -3,6 +3,7 @@
#include "voxelutils.h"
#include "chunkrenderer.h"
#include "graphics/chunkmesh.h"
#include "util/mobileatomic.h"

#include <glm/glm.hpp>

@@ -35,7 +36,8 @@ protected:
void setQueuedForMeshRebuild(const bool& rebuild = true);
bool isQueuedForMeshRebuild();

std::array<unsigned, 4096> voxels;
std::array<util::MobileAtomic<unsigned>, 4096> mData;
//std::array<unsigned, 4096> voxels;
World& mLinkedWorld;
glm::ivec3 mPos;
std::atomic<bool> mLoaded;

+ 5
- 5
src/chunk.cpp View File

@@ -31,10 +31,10 @@ Chunk::Chunk(World& world) :
renderer.linkedChunk = this;

//fill voxels with 0
for (unsigned i = 0; i < 4096; i++) {
voxels[i] = 0;
for (unsigned i = 0; i < mData.size(); i++) {
mData[i].store(0);
}
mLoaded = true;
mLoaded.store(true);
}

bool Chunk::isLoaded() {
@@ -60,7 +60,7 @@ void Chunk::setVoxelType(const int& x, const int& y, const int& z, const unsigne
std::cout << "CHUNK ACCESS ERROR (set voxel): Out of range, doing nothing\n";
return;
}
voxels[index] = type;
mData[index].store(type, std::memory_order_release);

if (!update) return;
mLinkedWorld.queueChunkUpdate(mPos);
@@ -72,7 +72,7 @@ unsigned Chunk::getVoxelType(const unsigned& x, const unsigned& y, const unsigne
std::cout << "CHUNK ACCESS ERROR (get voxel): Out of range, returning type 0\n";
return 0;
}
return voxels[index];
return mData[index].load(std::memory_order_consume);
}

glm::ivec3 Chunk::getWorldCoords(const int& x, const int& y, const int& z) {

+ 0
- 1
src/game.cpp View File

@@ -115,7 +115,6 @@ void Game::loop() {

activeScene->update(dTime);

//glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glDepthFunc(GL_GREATER);
glClearDepth(0.0f);

Loading…
Cancel
Save