diff --git a/cmake-build-emrelease/CMakeFiles/CMakeOutput.log b/cmake-build-emrelease/CMakeFiles/CMakeOutput.log index f06d64c..61b4e77 100644 --- a/cmake-build-emrelease/CMakeFiles/CMakeOutput.log +++ b/cmake-build-emrelease/CMakeFiles/CMakeOutput.log @@ -1,30 +1,30 @@ The target system is: Emscripten - 1 - x86 The host system is: Linux - 6.1.0-5-amd64 - x86_64 Determining if the include file unistd.h exists passed with the following output: -Change Dir: /home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-R1cnjV +Change Dir: /home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-nkD9HZ -Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_8162d/fast && /usr/bin/gmake -f CMakeFiles/cmTC_8162d.dir/build.make CMakeFiles/cmTC_8162d.dir/build -gmake[1]: Entering directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-R1cnjV' -Building C object CMakeFiles/cmTC_8162d.dir/CheckIncludeFile.c.o -/usr/bin/emcc -MD -MT CMakeFiles/cmTC_8162d.dir/CheckIncludeFile.c.o -MF CMakeFiles/cmTC_8162d.dir/CheckIncludeFile.c.o.d -o CMakeFiles/cmTC_8162d.dir/CheckIncludeFile.c.o -c "/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-R1cnjV/CheckIncludeFile.c" -Linking C executable cmTC_8162d.js -/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8162d.dir/link.txt --verbose=1 -/usr/bin/emcc @CMakeFiles/cmTC_8162d.dir/objects1 -o cmTC_8162d.js -gmake[1]: Leaving directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-R1cnjV' +Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_964c5/fast && /usr/bin/gmake -f CMakeFiles/cmTC_964c5.dir/build.make CMakeFiles/cmTC_964c5.dir/build +gmake[1]: Entering directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-nkD9HZ' +Building C object CMakeFiles/cmTC_964c5.dir/CheckIncludeFile.c.o +/usr/bin/emcc -MD -MT CMakeFiles/cmTC_964c5.dir/CheckIncludeFile.c.o -MF CMakeFiles/cmTC_964c5.dir/CheckIncludeFile.c.o.d -o CMakeFiles/cmTC_964c5.dir/CheckIncludeFile.c.o -c "/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-nkD9HZ/CheckIncludeFile.c" +Linking C executable cmTC_964c5.js +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_964c5.dir/link.txt --verbose=1 +/usr/bin/emcc @CMakeFiles/cmTC_964c5.dir/objects1 -o cmTC_964c5.js +gmake[1]: Leaving directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-nkD9HZ' Determining if the include file fcntl.h exists passed with the following output: -Change Dir: /home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-fztl4Q +Change Dir: /home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-s1aY2P -Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_3ae2a/fast && /usr/bin/gmake -f CMakeFiles/cmTC_3ae2a.dir/build.make CMakeFiles/cmTC_3ae2a.dir/build -gmake[1]: Entering directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-fztl4Q' -Building C object CMakeFiles/cmTC_3ae2a.dir/CheckIncludeFile.c.o -/usr/bin/emcc -MD -MT CMakeFiles/cmTC_3ae2a.dir/CheckIncludeFile.c.o -MF CMakeFiles/cmTC_3ae2a.dir/CheckIncludeFile.c.o.d -o CMakeFiles/cmTC_3ae2a.dir/CheckIncludeFile.c.o -c "/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-fztl4Q/CheckIncludeFile.c" -Linking C executable cmTC_3ae2a.js -/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3ae2a.dir/link.txt --verbose=1 -/usr/bin/emcc @CMakeFiles/cmTC_3ae2a.dir/objects1 -o cmTC_3ae2a.js -gmake[1]: Leaving directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-fztl4Q' +Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_90857/fast && /usr/bin/gmake -f CMakeFiles/cmTC_90857.dir/build.make CMakeFiles/cmTC_90857.dir/build +gmake[1]: Entering directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-s1aY2P' +Building C object CMakeFiles/cmTC_90857.dir/CheckIncludeFile.c.o +/usr/bin/emcc -MD -MT CMakeFiles/cmTC_90857.dir/CheckIncludeFile.c.o -MF CMakeFiles/cmTC_90857.dir/CheckIncludeFile.c.o.d -o CMakeFiles/cmTC_90857.dir/CheckIncludeFile.c.o -c "/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-s1aY2P/CheckIncludeFile.c" +Linking C executable cmTC_90857.js +/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_90857.dir/link.txt --verbose=1 +/usr/bin/emcc @CMakeFiles/cmTC_90857.dir/objects1 -o cmTC_90857.js +gmake[1]: Leaving directory '/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles/CMakeScratch/TryCompile-s1aY2P' diff --git a/cmake-build-emrelease/CMakeFiles/FinalProject.dir/includes_CXX.rsp b/cmake-build-emrelease/CMakeFiles/FinalProject.dir/includes_CXX.rsp index df10e27..cf0117b 100644 --- a/cmake-build-emrelease/CMakeFiles/FinalProject.dir/includes_CXX.rsp +++ b/cmake-build-emrelease/CMakeFiles/FinalProject.dir/includes_CXX.rsp @@ -1 +1 @@ --I"/home/brett/Documents/Brock/CS 3P98/Final Project/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/BLT/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/BLT/config" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/freetype-2.13.0/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/freetype-2.13.0/include" +-I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/sparsepp/sparsepp" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/parallel-hashmap/parallel_hashmap" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/BLT/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/BLT/config" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/freetype-2.13.0/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/freetype-2.13.0/include" diff --git a/cmake-build-emrelease/CMakeFiles/FinalProject.dir/src/main.cpp.o.d b/cmake-build-emrelease/CMakeFiles/FinalProject.dir/src/main.cpp.o.d index 87ec94a..37e60ea 100644 --- a/cmake-build-emrelease/CMakeFiles/FinalProject.dir/src/main.cpp.o.d +++ b/cmake-build-emrelease/CMakeFiles/FinalProject.dir/src/main.cpp.o.d @@ -338,11 +338,28 @@ CMakeFiles/FinalProject.dir/src/main.cpp.o: \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/render/camera.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/world/chunk/world.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/world/chunk/storage.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/BLT/include/blt/std/format.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/world/chunk/typedefs.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/world/registry.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/render/textures.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/stb/stb_image.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/util/settings.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/stb/stb_image_resize.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap.h \ + /usr/share/emscripten/cache/sysroot/include/c++/v1/array \ + /usr/share/emscripten/cache/sysroot/include/c++/v1/cassert \ + /usr/share/emscripten/cache/sysroot/include/assert.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap_fwd_decl.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap_utils.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap_bits.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap_config.h \ + /usr/share/emscripten/cache/sysroot/include/c++/v1/any \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/parallel-hashmap/parallel_hashmap/phmap_base.h \ + /usr/share/emscripten/cache/sysroot/include/c++/v1/shared_mutex \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/sparsepp/sparsepp/spp.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/sparsepp/sparsepp/spp_stdint.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/sparsepp/sparsepp/spp_config.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/sparsepp/sparsepp/spp_traits.h \ + /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/libraries/sparsepp/sparsepp/spp_utils.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/util/math.h \ /home/brett/Documents/Brock/CS\ 3P98/Final\ Project/include/stb/stb_perlin.h diff --git a/cmake-build-emrelease/CMakeFiles/Makefile2 b/cmake-build-emrelease/CMakeFiles/Makefile2 index d706233..be0d208 100644 --- a/cmake-build-emrelease/CMakeFiles/Makefile2 +++ b/cmake-build-emrelease/CMakeFiles/Makefile2 @@ -116,8 +116,8 @@ libraries/freetype-2.13.0/clean: libraries/freetype-2.13.0/CMakeFiles/freetype.d # Target rules for target CMakeFiles/FinalProject.dir # All Build rule for target. -CMakeFiles/FinalProject.dir/all: libraries/freetype-2.13.0/CMakeFiles/freetype.dir/all CMakeFiles/FinalProject.dir/all: libraries/BLT/CMakeFiles/BLT.dir/all +CMakeFiles/FinalProject.dir/all: libraries/freetype-2.13.0/CMakeFiles/freetype.dir/all $(MAKE) $(MAKESILENT) -f CMakeFiles/FinalProject.dir/build.make CMakeFiles/FinalProject.dir/depend $(MAKE) $(MAKESILENT) -f CMakeFiles/FinalProject.dir/build.make CMakeFiles/FinalProject.dir/build @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir="/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/CMakeFiles" --progress-num=10,11,12,13,14,15,16,17,18,19,20,21,22 "Built target FinalProject" diff --git a/cmake-build-emrelease/libraries/BLT/CMakeFiles/BLT.dir/includes_CXX.rsp b/cmake-build-emrelease/libraries/BLT/CMakeFiles/BLT.dir/includes_CXX.rsp index 5c03c07..497e585 100644 --- a/cmake-build-emrelease/libraries/BLT/CMakeFiles/BLT.dir/includes_CXX.rsp +++ b/cmake-build-emrelease/libraries/BLT/CMakeFiles/BLT.dir/includes_CXX.rsp @@ -1 +1 @@ --I"/home/brett/Documents/Brock/CS 3P98/Final Project/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/BLT/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/BLT/config" +-I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/sparsepp/sparsepp" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/parallel-hashmap/parallel_hashmap" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/libraries/BLT/include" -I"/home/brett/Documents/Brock/CS 3P98/Final Project/cmake-build-emrelease/libraries/BLT/config" diff --git a/cmake-build-relwithdebinfo/.ninja_deps b/cmake-build-relwithdebinfo/.ninja_deps index 1108351..8a45c63 100644 Binary files a/cmake-build-relwithdebinfo/.ninja_deps and b/cmake-build-relwithdebinfo/.ninja_deps differ diff --git a/cmake-build-relwithdebinfo/.ninja_log b/cmake-build-relwithdebinfo/.ninja_log index 217a5fc..1c297f5 100644 --- a/cmake-build-relwithdebinfo/.ninja_log +++ b/cmake-build-relwithdebinfo/.ninja_log @@ -184,3 +184,16 @@ 2 1220 1678080343755903154 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 19cb330422f1ead7 2 1521 1678080344055911519 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 5a5f514ae327b7c6 1521 1655 1678080344187915200 FinalProject 9e02455301d10951 +2 1191 1678115458859390863 CMakeFiles/FinalProject.dir/src/main.cpp.o 44f0aca089894d0f +2 1420 1678115459091397186 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 19cb330422f1ead7 +2 1575 1678115459243401325 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 5a5f514ae327b7c6 +1575 1704 1678115459371404813 FinalProject 9e02455301d10951 +2 1181 1678115586658870102 CMakeFiles/FinalProject.dir/src/main.cpp.o 44f0aca089894d0f +2 1332 1678115586806874126 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 19cb330422f1ead7 +3 1557 1678115587030880222 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 5a5f514ae327b7c6 +1557 1693 1678115587166883922 FinalProject 9e02455301d10951 +2 1071 1678115738963010170 CMakeFiles/FinalProject.dir/src/main.cpp.o 44f0aca089894d0f +2 1222 1678115739115014299 CMakeFiles/FinalProject.dir/src/world/chunk/storage.cpp.o 19cb330422f1ead7 +2 1350 1678115739243017776 CMakeFiles/FinalProject.dir/src/world/registry.cpp.o 3e7542c3498b07ce +2 1467 1678115739359020927 CMakeFiles/FinalProject.dir/src/world/chunk/world.cpp.o 5a5f514ae327b7c6 +1467 1599 1678115739491024515 FinalProject 9e02455301d10951 diff --git a/cmake-build-relwithdebinfo/FinalProject b/cmake-build-relwithdebinfo/FinalProject index b26fcad..049611e 100755 Binary files a/cmake-build-relwithdebinfo/FinalProject and b/cmake-build-relwithdebinfo/FinalProject differ diff --git a/cmake-build-relwithdebinfo/Testing/Temporary/LastTest.log b/cmake-build-relwithdebinfo/Testing/Temporary/LastTest.log index 56cf379..379fe61 100644 --- a/cmake-build-relwithdebinfo/Testing/Temporary/LastTest.log +++ b/cmake-build-relwithdebinfo/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Mar 06 00:25 EST +Start testing: Mar 06 10:15 EST ---------------------------------------------------------- -End testing: Mar 06 00:25 EST +End testing: Mar 06 10:15 EST diff --git a/include/world/chunk/storage.h b/include/world/chunk/storage.h index 1ad5594..bbe5c0f 100644 --- a/include/world/chunk/storage.h +++ b/include/world/chunk/storage.h @@ -40,10 +40,11 @@ namespace fp { } [[nodiscard]] inline bool checkBlockVisibility(const block_pos& pos) const { + // blocks outside the check are always not visible to us. This requires special logic if (pos.x < 0 || pos.x >= CHUNK_SIZE || pos.y < 0 || pos.y >= CHUNK_SIZE || pos.z < 0 || pos.z >= CHUNK_SIZE) { return false; } - return fp::registry::get(get(pos)).visibility <= fp::registry::TRANSPARENT_TEXTURE; + return fp::registry::get(get(pos)).visibility >= fp::registry::TRANSPARENT_TEXTURE; } inline void set(const block_pos& pos, block_type blockID) { diff --git a/include/world/chunk/typedefs.h b/include/world/chunk/typedefs.h index 162eb4a..ee6f477 100644 --- a/include/world/chunk/typedefs.h +++ b/include/world/chunk/typedefs.h @@ -31,10 +31,8 @@ namespace fp { OKAY = 0, // chunk needs its VAO updated with the newest mesh REFRESH = 1, - // chunk needs its edges re-meshed because it was created with null neighbours - PARTIAL_MESH = 2, // chunk needs a complete re-mesh. - FULL_MESH = 3 + DIRTY = 2 }; enum chunk_update_status { diff --git a/include/world/chunk/world.h b/include/world/chunk/world.h index d41b20b..77f295a 100644 --- a/include/world/chunk/world.h +++ b/include/world/chunk/world.h @@ -92,34 +92,19 @@ namespace fp { void updateChunkMesh(); /** - * Mark the chunk as completely dirty and in need of a full check refresh + * Mark the chunk as completely dirty and in need of a full chunk refresh */ inline void markDirty() { - dirtiness = FULL_MESH; - } - - /** - * Partial mesh update has been completed, we are now waiting on the edge chunks to be - * generated before continuing to generate the chunk edge mesh - */ - inline void markPartialComplete() { - dirtiness = PARTIAL_MESH; + dirtiness = DIRTY; } /** * Full chunk mesh is now completely generated and waiting on uploading to the GPU */ - inline void markComplete() { + inline void markRefresh() { dirtiness = REFRESH; } - /** - * Mesh uploading complete, chunk meshing is now done and inactive - */ - inline void markDone() { - dirtiness = OKAY; - } - [[nodiscard]] inline block_storage*& getBlockStorage() { return storage; } @@ -167,10 +152,6 @@ namespace fp { private: std::unordered_map chunk_storage; protected: - static void generateFullMesh(mesh_storage* mesh, chunk* chunk); - - void generateEdgeMesh(mesh_storage* mesh, chunk* chunk); - void generateChunkMesh(chunk* chunk); chunk* generateChunk(const chunk_pos& pos); @@ -234,8 +215,7 @@ namespace fp { } ~world() { - BLT_PRINT_PROFILE("Chunk Mesh", blt::logging::TRACE, true); - BLT_PRINT_PROFILE("Chunk Generate", blt::logging::TRACE, true); + BLT_PRINT_PROFILE("Chunk", blt::logging::TRACE, true); for (auto& chunk : chunk_storage) delete (chunk.second); } diff --git a/src/world/chunk/world.cpp b/src/world/chunk/world.cpp index 14a0f26..7c3ee69 100644 --- a/src/world/chunk/world.cpp +++ b/src/world/chunk/world.cpp @@ -11,41 +11,6 @@ #include "stb/stb_perlin.h" #include -void fp::world::generateFullMesh(mesh_storage* mesh, fp::chunk* chunk) { - BLT_START_INTERVAL("Chunk Mesh", "Full Mesh"); - - for (int i = 0; i < CHUNK_SIZE; i++) { - for (int j = 0; j < CHUNK_SIZE; j++) { - for (int k = 0; k < CHUNK_SIZE; k++) { - auto*& storage = chunk->getBlockStorage(); - - auto& block = fp::registry::get(storage->get({i, j, k})); - - auto texture_index = fp::registry::getTextureIndex(block.textureName); - - // The main chunk mesh can handle opaque and transparent textures. (Transparency will be discarded) - if (block.visibility <= registry::TRANSPARENT_TEXTURE) { - if (!storage->checkBlockVisibility({i - 1, j, k})) - mesh->addFace(X_NEG, {i, j, k}, texture_index); - if (!storage->checkBlockVisibility({i + 1, j, k})) - mesh->addFace(X_POS, {i, j, k}, texture_index); - if (!storage->checkBlockVisibility({i, j - 1, k})) - mesh->addFace(Y_NEG, {i, j, k}, texture_index); - if (!storage->checkBlockVisibility({i, j + 1, k})) - mesh->addFace(Y_POS, {i, j, k}, texture_index); - if (!storage->checkBlockVisibility({i, j, k - 1})) - mesh->addFace(Z_NEG, {i, j, k}, texture_index); - if (!storage->checkBlockVisibility({i, j, k + 1})) - mesh->addFace(Z_POS, {i, j, k}, texture_index); - } - } - } - } - - chunk->markPartialComplete(); - BLT_END_INTERVAL("Chunk Mesh", "Full Mesh"); -} - inline void checkEdgeFaces( fp::mesh_storage* mesh, fp::chunk* chunk, fp::chunk* neighbour, fp::face face, const fp::block_pos& pos, const fp::block_pos& neighbour_pos @@ -60,22 +25,55 @@ inline void checkEdgeFaces( } } -void fp::world::generateEdgeMesh(mesh_storage* mesh, fp::chunk* chunk) { - BLT_START_INTERVAL("Chunk Mesh", "Edge Mesh"); - // don't try to regen the chunk mesh unless there is a chance all neighbours are not null +void fp::world::generateChunkMesh(chunk* chunk) { + // don't re-mesh unless requested + if (chunk->getDirtiness() != DIRTY) + return; + // don't try to re-mesh the chunk unless there is a chance all neighbours are not null if (chunk->getStatus() != chunk_update_status::NEIGHBOUR_CREATE) return; chunk_neighbours neighbours{}; getNeighbours(chunk->getPos(), neighbours); - // if none of the neighbours exist we cannot continue! for (auto* neighbour : neighbours.neighbours) { if (!neighbour) return; } + auto* mesh = new mesh_storage(); + + BLT_START_INTERVAL("Chunk", "Mesh"); + + auto*& block_storage = chunk->getBlockStorage(); + + for (int i = 0; i < CHUNK_SIZE; i++) { + for (int j = 0; j < CHUNK_SIZE; j++) { + for (int k = 0; k < CHUNK_SIZE; k++) { + auto& block = fp::registry::get(block_storage->get({i, j, k})); + + auto texture_index = fp::registry::getTextureIndex(block.textureName); + + // The main chunk mesh can handle opaque and transparent textures. (Transparency will be discarded) + if (block.visibility <= registry::TRANSPARENT_TEXTURE) { + if (block_storage->checkBlockVisibility({i - 1, j, k})) + mesh->addFace(X_NEG, {i, j, k}, texture_index); + if (block_storage->checkBlockVisibility({i + 1, j, k})) + mesh->addFace(X_POS, {i, j, k}, texture_index); + if (block_storage->checkBlockVisibility({i, j - 1, k})) + mesh->addFace(Y_NEG, {i, j, k}, texture_index); + if (block_storage->checkBlockVisibility({i, j + 1, k})) + mesh->addFace(Y_POS, {i, j, k}, texture_index); + if (block_storage->checkBlockVisibility({i, j, k - 1})) + mesh->addFace(Z_NEG, {i, j, k}, texture_index); + if (block_storage->checkBlockVisibility({i, j, k + 1})) + mesh->addFace(Z_POS, {i, j, k}, texture_index); + } + } + } + } + for (int i = 0; i < CHUNK_SIZE; i++) { for (int j = 0; j < CHUNK_SIZE; j++) { checkEdgeFaces( @@ -101,21 +99,11 @@ void fp::world::generateEdgeMesh(mesh_storage* mesh, fp::chunk* chunk) { } } + chunk->getMeshStorage() = mesh; chunk->getStatus() = NONE; - chunk->markComplete(); - BLT_END_INTERVAL("Chunk Mesh", "Edge Mesh"); -} - -void fp::world::generateChunkMesh(fp::chunk* chunk) { - if (chunk->getMeshStorage() == nullptr) - chunk->getMeshStorage() = new mesh_storage(); + chunk->markRefresh(); - if (chunk->getDirtiness() == FULL_MESH) { // full chunk mesh - generateFullMesh(chunk->getMeshStorage(), chunk); - } - if (chunk->getDirtiness() == PARTIAL_MESH) { // partial chunk mesh (had null neighbours) - generateEdgeMesh(chunk->getMeshStorage(), chunk); - } + BLT_END_INTERVAL("Chunk", "Mesh"); } std::queue chunks_to_generate{}; @@ -248,5 +236,5 @@ void fp::chunk::updateChunkMesh() { // delete the local chunk mesh memory, since we no longer need to store it. delete (mesh); mesh = nullptr; - markDone(); + dirtiness = OKAY; } diff --git a/src/world/registry.cpp b/src/world/registry.cpp index 9eddee5..f5205ad 100644 --- a/src/world/registry.cpp +++ b/src/world/registry.cpp @@ -5,13 +5,18 @@ */ #include #include +#include #include #include #include #include #include +#ifdef __EMSCRIPTEN__ std::unordered_map blocks; +#else +phmap::flat_hash_map blocks; +#endif fp::texture::palette* base_palette;