From e713412a6d286c493d562bc58339bc834794c611 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 14 Dec 2024 18:58:51 +0300 Subject: [PATCH] rename ChunksStorage to GlobalChunks --- src/frontend/debug_panel.cpp | 2 +- src/frontend/hud.cpp | 2 +- src/logic/ChunksController.cpp | 2 +- src/logic/scripting/lua/libs/libblock.cpp | 2 +- src/logic/scripting/lua/libs/libworld.cpp | 2 +- .../{ChunksStorage.cpp => GlobalChunks.cpp} | 26 +++++++++---------- .../{ChunksStorage.hpp => GlobalChunks.hpp} | 6 ++--- src/world/Level.cpp | 4 +-- src/world/Level.hpp | 4 +-- src/world/World.cpp | 2 +- src/world/generator/VoxelFragment.cpp | 2 +- 11 files changed, 27 insertions(+), 27 deletions(-) rename src/voxels/{ChunksStorage.cpp => GlobalChunks.cpp} (86%) rename src/voxels/{ChunksStorage.hpp => GlobalChunks.hpp} (90%) diff --git a/src/frontend/debug_panel.cpp b/src/frontend/debug_panel.cpp index f78fc6a8..3470cdb1 100644 --- a/src/frontend/debug_panel.cpp +++ b/src/frontend/debug_panel.cpp @@ -21,7 +21,7 @@ #include "voxels/Block.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "world/Level.hpp" #include "world/World.hpp" diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 55449ad9..1a2d8315 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -40,7 +40,7 @@ #include "voxels/Block.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "window/Camera.hpp" #include "window/Events.hpp" #include "window/input.hpp" diff --git a/src/logic/ChunksController.cpp b/src/logic/ChunksController.cpp index f61a2755..0d8d97b4 100644 --- a/src/logic/ChunksController.cpp +++ b/src/logic/ChunksController.cpp @@ -14,7 +14,7 @@ #include "voxels/Block.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "world/Level.hpp" #include "world/World.hpp" #include "world/generator/WorldGenerator.hpp" diff --git a/src/logic/scripting/lua/libs/libblock.cpp b/src/logic/scripting/lua/libs/libblock.cpp index c8499e71..dbd87489 100644 --- a/src/logic/scripting/lua/libs/libblock.cpp +++ b/src/logic/scripting/lua/libs/libblock.cpp @@ -7,7 +7,7 @@ #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" #include "voxels/voxel.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "world/Level.hpp" #include "maths/voxmaths.hpp" #include "data/StructLayout.hpp" diff --git a/src/logic/scripting/lua/libs/libworld.cpp b/src/logic/scripting/lua/libs/libworld.cpp index 747c68a4..68004777 100644 --- a/src/logic/scripting/lua/libs/libworld.cpp +++ b/src/logic/scripting/lua/libs/libworld.cpp @@ -13,7 +13,7 @@ #include "lighting/Lighting.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "world/Level.hpp" #include "world/World.hpp" diff --git a/src/voxels/ChunksStorage.cpp b/src/voxels/GlobalChunks.cpp similarity index 86% rename from src/voxels/ChunksStorage.cpp rename to src/voxels/GlobalChunks.cpp index 8a872eea..379ca328 100644 --- a/src/voxels/ChunksStorage.cpp +++ b/src/voxels/GlobalChunks.cpp @@ -1,4 +1,4 @@ -#include "ChunksStorage.hpp" +#include "GlobalChunks.hpp" #include @@ -28,10 +28,10 @@ inline long long keyfrom(int x, int z) { static debug::Logger logger("chunks-storage"); -ChunksStorage::ChunksStorage(Level* level) : level(level) { +GlobalChunks::GlobalChunks(Level* level) : level(level) { } -std::shared_ptr ChunksStorage::fetch(int x, int z) { +std::shared_ptr GlobalChunks::fetch(int x, int z) { const auto& found = chunksMap.find(keyfrom(x, z)); if (found == chunksMap.end()) { return nullptr; @@ -63,11 +63,11 @@ static void check_voxels(const ContentIndices& indices, Chunk& chunk) { } } -void ChunksStorage::erase(int x, int z) { +void GlobalChunks::erase(int x, int z) { chunksMap.erase(keyfrom(x, z)); } -std::shared_ptr ChunksStorage::create(int x, int z) { +std::shared_ptr GlobalChunks::create(int x, int z) { const auto& found = chunksMap.find(keyfrom(x, z)); if (found != chunksMap.end()) { return found->second; @@ -120,19 +120,19 @@ std::shared_ptr ChunksStorage::create(int x, int z) { return chunk; } -void ChunksStorage::pinChunk(std::shared_ptr chunk) { +void GlobalChunks::pinChunk(std::shared_ptr chunk) { pinnedChunks[{chunk->x, chunk->z}] = std::move(chunk); } -void ChunksStorage::unpinChunk(int x, int z) { +void GlobalChunks::unpinChunk(int x, int z) { pinnedChunks.erase({x, z}); } -size_t ChunksStorage::size() const { +size_t GlobalChunks::size() const { return chunksMap.size(); } -voxel* ChunksStorage::get(int x, int y, int z) const { +voxel* GlobalChunks::get(int x, int y, int z) const { if (y < 0 || y >= CHUNK_H) { return nullptr; } @@ -150,7 +150,7 @@ voxel* ChunksStorage::get(int x, int y, int z) const { return &chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx]; } -void ChunksStorage::incref(Chunk* chunk) { +void GlobalChunks::incref(Chunk* chunk) { auto key = reinterpret_cast(chunk); const auto& found = refCounters.find(key); if (found == refCounters.end()) { @@ -160,7 +160,7 @@ void ChunksStorage::incref(Chunk* chunk) { found->second++; } -void ChunksStorage::decref(Chunk* chunk) { +void GlobalChunks::decref(Chunk* chunk) { auto key = reinterpret_cast(chunk); const auto& found = refCounters.find(key); if (found == refCounters.end()) { @@ -180,7 +180,7 @@ void ChunksStorage::decref(Chunk* chunk) { } } -void ChunksStorage::save(Chunk* chunk) { +void GlobalChunks::save(Chunk* chunk) { if (chunk == nullptr) { return; } @@ -204,7 +204,7 @@ void ChunksStorage::save(Chunk* chunk) { ); } -void ChunksStorage::saveAll() { +void GlobalChunks::saveAll() { for (const auto& [_, chunk] : chunksMap) { save(chunk.get()); } diff --git a/src/voxels/ChunksStorage.hpp b/src/voxels/GlobalChunks.hpp similarity index 90% rename from src/voxels/ChunksStorage.hpp rename to src/voxels/GlobalChunks.hpp index 9d8d0332..b21e15e6 100644 --- a/src/voxels/ChunksStorage.hpp +++ b/src/voxels/GlobalChunks.hpp @@ -12,14 +12,14 @@ class Chunk; class Level; -class ChunksStorage { +class GlobalChunks { Level* level; std::unordered_map> chunksMap; std::unordered_map> pinnedChunks; std::unordered_map refCounters; public: - ChunksStorage(Level* level); - ~ChunksStorage() = default; + GlobalChunks(Level* level); + ~GlobalChunks() = default; std::shared_ptr fetch(int x, int z); std::shared_ptr create(int x, int z); diff --git a/src/world/Level.cpp b/src/world/Level.cpp index a89dc2e6..99f47d86 100644 --- a/src/world/Level.cpp +++ b/src/world/Level.cpp @@ -13,7 +13,7 @@ #include "settings.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "window/Camera.hpp" #include "LevelEvents.hpp" #include "World.hpp" @@ -25,7 +25,7 @@ Level::Level( ) : world(std::move(worldPtr)), content(content), - chunksStorage(std::make_unique(this)), + chunksStorage(std::make_unique(this)), physics(std::make_unique(glm::vec3(0, -22.6f, 0))), events(std::make_unique()), entities(std::make_unique(this)), diff --git a/src/world/Level.hpp b/src/world/Level.hpp index 1f3ef183..63274672 100644 --- a/src/world/Level.hpp +++ b/src/world/Level.hpp @@ -15,7 +15,7 @@ class Inventories; class LevelEvents; class Lighting; class PhysicsSolver; -class ChunksStorage; +class GlobalChunks; class Camera; class Players; struct EngineSettings; @@ -27,7 +27,7 @@ public: const Content* const content; std::unique_ptr chunks; - std::unique_ptr chunksStorage; + std::unique_ptr chunksStorage; std::unique_ptr inventories; std::unique_ptr physics; diff --git a/src/world/World.cpp b/src/world/World.cpp index 0067964c..eb8c33bf 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -15,7 +15,7 @@ #include "settings.hpp" #include "voxels/Chunk.hpp" #include "voxels/Chunks.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "world/generator/WorldGenerator.hpp" #include "world/generator/GeneratorDef.hpp" #include "Level.hpp" diff --git a/src/world/generator/VoxelFragment.cpp b/src/world/generator/VoxelFragment.cpp index f36824b0..2d7ab923 100644 --- a/src/world/generator/VoxelFragment.cpp +++ b/src/world/generator/VoxelFragment.cpp @@ -8,7 +8,7 @@ #include "content/Content.hpp" #include "voxels/Chunks.hpp" #include "voxels/Block.hpp" -#include "voxels/ChunksStorage.hpp" +#include "voxels/GlobalChunks.hpp" #include "voxels/VoxelsVolume.hpp" #include "world/Level.hpp" #include "core_defs.hpp"