update ChunksStorage

This commit is contained in:
MihailRis
2024-12-11 16:30:19 +03:00
parent 91fa2838d6
commit 436bfd24ba
6 changed files with 46 additions and 44 deletions
+4 -7
View File
@@ -1,11 +1,9 @@
#pragma once
#include <mutex>
#include <memory>
#include <unordered_map>
#include "typedefs.hpp"
#include "voxel.hpp"
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
@@ -14,13 +12,12 @@ class Level;
class ChunksStorage {
Level* level;
std::unordered_map<glm::ivec2, std::shared_ptr<Chunk>> chunksMap;
std::mutex mutex;
std::unordered_map<glm::ivec2, std::weak_ptr<Chunk>> chunksMap;
public:
ChunksStorage(Level* level);
~ChunksStorage() = default;
std::shared_ptr<Chunk> get(int x, int z) const;
void store(const std::shared_ptr<Chunk>& chunk);
void remove(int x, int y);
std::shared_ptr<Chunk> fetch(int x, int z);
std::shared_ptr<Chunk> create(int x, int z);
};