rename ChunksStorage to GlobalChunks
This commit is contained in:
parent
323acb2573
commit
e713412a6d
@ -21,7 +21,7 @@
|
|||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "window/Camera.hpp"
|
#include "window/Camera.hpp"
|
||||||
#include "window/Events.hpp"
|
#include "window/Events.hpp"
|
||||||
#include "window/input.hpp"
|
#include "window/input.hpp"
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
#include "world/generator/WorldGenerator.hpp"
|
#include "world/generator/WorldGenerator.hpp"
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/voxel.hpp"
|
#include "voxels/voxel.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "maths/voxmaths.hpp"
|
#include "maths/voxmaths.hpp"
|
||||||
#include "data/StructLayout.hpp"
|
#include "data/StructLayout.hpp"
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#include "lighting/Lighting.hpp"
|
#include "lighting/Lighting.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "ChunksStorage.hpp"
|
#include "GlobalChunks.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -28,10 +28,10 @@ inline long long keyfrom(int x, int z) {
|
|||||||
|
|
||||||
static debug::Logger logger("chunks-storage");
|
static debug::Logger logger("chunks-storage");
|
||||||
|
|
||||||
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
GlobalChunks::GlobalChunks(Level* level) : level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Chunk> ChunksStorage::fetch(int x, int z) {
|
std::shared_ptr<Chunk> GlobalChunks::fetch(int x, int z) {
|
||||||
const auto& found = chunksMap.find(keyfrom(x, z));
|
const auto& found = chunksMap.find(keyfrom(x, z));
|
||||||
if (found == chunksMap.end()) {
|
if (found == chunksMap.end()) {
|
||||||
return nullptr;
|
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));
|
chunksMap.erase(keyfrom(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
std::shared_ptr<Chunk> GlobalChunks::create(int x, int z) {
|
||||||
const auto& found = chunksMap.find(keyfrom(x, z));
|
const auto& found = chunksMap.find(keyfrom(x, z));
|
||||||
if (found != chunksMap.end()) {
|
if (found != chunksMap.end()) {
|
||||||
return found->second;
|
return found->second;
|
||||||
@ -120,19 +120,19 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::pinChunk(std::shared_ptr<Chunk> chunk) {
|
void GlobalChunks::pinChunk(std::shared_ptr<Chunk> chunk) {
|
||||||
pinnedChunks[{chunk->x, chunk->z}] = std::move(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});
|
pinnedChunks.erase({x, z});
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ChunksStorage::size() const {
|
size_t GlobalChunks::size() const {
|
||||||
return chunksMap.size();
|
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) {
|
if (y < 0 || y >= CHUNK_H) {
|
||||||
return nullptr;
|
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];
|
return &chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::incref(Chunk* chunk) {
|
void GlobalChunks::incref(Chunk* chunk) {
|
||||||
auto key = reinterpret_cast<ptrdiff_t>(chunk);
|
auto key = reinterpret_cast<ptrdiff_t>(chunk);
|
||||||
const auto& found = refCounters.find(key);
|
const auto& found = refCounters.find(key);
|
||||||
if (found == refCounters.end()) {
|
if (found == refCounters.end()) {
|
||||||
@ -160,7 +160,7 @@ void ChunksStorage::incref(Chunk* chunk) {
|
|||||||
found->second++;
|
found->second++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::decref(Chunk* chunk) {
|
void GlobalChunks::decref(Chunk* chunk) {
|
||||||
auto key = reinterpret_cast<ptrdiff_t>(chunk);
|
auto key = reinterpret_cast<ptrdiff_t>(chunk);
|
||||||
const auto& found = refCounters.find(key);
|
const auto& found = refCounters.find(key);
|
||||||
if (found == refCounters.end()) {
|
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) {
|
if (chunk == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ void ChunksStorage::save(Chunk* chunk) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::saveAll() {
|
void GlobalChunks::saveAll() {
|
||||||
for (const auto& [_, chunk] : chunksMap) {
|
for (const auto& [_, chunk] : chunksMap) {
|
||||||
save(chunk.get());
|
save(chunk.get());
|
||||||
}
|
}
|
||||||
@ -12,14 +12,14 @@
|
|||||||
class Chunk;
|
class Chunk;
|
||||||
class Level;
|
class Level;
|
||||||
|
|
||||||
class ChunksStorage {
|
class GlobalChunks {
|
||||||
Level* level;
|
Level* level;
|
||||||
std::unordered_map<long long, std::shared_ptr<Chunk>> chunksMap;
|
std::unordered_map<long long, std::shared_ptr<Chunk>> chunksMap;
|
||||||
std::unordered_map<glm::ivec2, std::shared_ptr<Chunk>> pinnedChunks;
|
std::unordered_map<glm::ivec2, std::shared_ptr<Chunk>> pinnedChunks;
|
||||||
std::unordered_map<ptrdiff_t, int> refCounters;
|
std::unordered_map<ptrdiff_t, int> refCounters;
|
||||||
public:
|
public:
|
||||||
ChunksStorage(Level* level);
|
GlobalChunks(Level* level);
|
||||||
~ChunksStorage() = default;
|
~GlobalChunks() = default;
|
||||||
|
|
||||||
std::shared_ptr<Chunk> fetch(int x, int z);
|
std::shared_ptr<Chunk> fetch(int x, int z);
|
||||||
std::shared_ptr<Chunk> create(int x, int z);
|
std::shared_ptr<Chunk> create(int x, int z);
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "window/Camera.hpp"
|
#include "window/Camera.hpp"
|
||||||
#include "LevelEvents.hpp"
|
#include "LevelEvents.hpp"
|
||||||
#include "World.hpp"
|
#include "World.hpp"
|
||||||
@ -25,7 +25,7 @@ Level::Level(
|
|||||||
)
|
)
|
||||||
: world(std::move(worldPtr)),
|
: world(std::move(worldPtr)),
|
||||||
content(content),
|
content(content),
|
||||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
chunksStorage(std::make_unique<GlobalChunks>(this)),
|
||||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||||
events(std::make_unique<LevelEvents>()),
|
events(std::make_unique<LevelEvents>()),
|
||||||
entities(std::make_unique<Entities>(this)),
|
entities(std::make_unique<Entities>(this)),
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class Inventories;
|
|||||||
class LevelEvents;
|
class LevelEvents;
|
||||||
class Lighting;
|
class Lighting;
|
||||||
class PhysicsSolver;
|
class PhysicsSolver;
|
||||||
class ChunksStorage;
|
class GlobalChunks;
|
||||||
class Camera;
|
class Camera;
|
||||||
class Players;
|
class Players;
|
||||||
struct EngineSettings;
|
struct EngineSettings;
|
||||||
@ -27,7 +27,7 @@ public:
|
|||||||
const Content* const content;
|
const Content* const content;
|
||||||
|
|
||||||
std::unique_ptr<Chunks> chunks;
|
std::unique_ptr<Chunks> chunks;
|
||||||
std::unique_ptr<ChunksStorage> chunksStorage;
|
std::unique_ptr<GlobalChunks> chunksStorage;
|
||||||
std::unique_ptr<Inventories> inventories;
|
std::unique_ptr<Inventories> inventories;
|
||||||
|
|
||||||
std::unique_ptr<PhysicsSolver> physics;
|
std::unique_ptr<PhysicsSolver> physics;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "world/generator/WorldGenerator.hpp"
|
#include "world/generator/WorldGenerator.hpp"
|
||||||
#include "world/generator/GeneratorDef.hpp"
|
#include "world/generator/GeneratorDef.hpp"
|
||||||
#include "Level.hpp"
|
#include "Level.hpp"
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
#include "voxels/ChunksStorage.hpp"
|
#include "voxels/GlobalChunks.hpp"
|
||||||
#include "voxels/VoxelsVolume.hpp"
|
#include "voxels/VoxelsVolume.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "core_defs.hpp"
|
#include "core_defs.hpp"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user