mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
migrate blocks interaction (scripting) to global chunks storage (WIP)
This commit is contained in:
parent
53cc8d3c7b
commit
e0b3425eff
16 changed files with 228 additions and 145 deletions
|
|
@ -1,16 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/hash.hpp>
|
||||
|
||||
#include "util/WeakPtrsMap.hpp"
|
||||
#include "voxel.hpp"
|
||||
|
||||
class Chunk;
|
||||
class Level;
|
||||
|
||||
class ChunksStorage {
|
||||
Level* level;
|
||||
std::shared_ptr<util::WeakPtrsMap<glm::ivec2, 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<ptrdiff_t, int> refCounters;
|
||||
public:
|
||||
ChunksStorage(Level* level);
|
||||
~ChunksStorage() = default;
|
||||
|
|
@ -18,5 +24,18 @@ public:
|
|||
std::shared_ptr<Chunk> fetch(int x, int z);
|
||||
std::shared_ptr<Chunk> create(int x, int z);
|
||||
|
||||
void pinChunk(std::shared_ptr<Chunk> chunk);
|
||||
void unpinChunk(int x, int z);
|
||||
|
||||
voxel* get(int x, int y, int z) const;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
void incref(Chunk* chunk);
|
||||
void decref(Chunk* chunk);
|
||||
|
||||
void erase(int x, int z);
|
||||
|
||||
void save(Chunk* chunk);
|
||||
void saveAll();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue