migrate blocks interaction (scripting) to global chunks storage (WIP)

This commit is contained in:
MihailRis
2024-12-13 05:54:41 +03:00
parent 53cc8d3c7b
commit e0b3425eff
16 changed files with 227 additions and 144 deletions
+8
View File
@@ -54,12 +54,20 @@ Level::Level(
entities->setNextID(worldInfo.nextEntityId);
}
events->listen(LevelEventType::EVT_CHUNK_SHOWN, [this](LevelEventType, Chunk* chunk) {
chunksStorage->incref(chunk);
});
events->listen(LevelEventType::EVT_CHUNK_HIDDEN, [this](LevelEventType, Chunk* chunk) {
chunksStorage->decref(chunk);
});
uint matrixSize =
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) *
2;
chunks = std::make_unique<Chunks>(
matrixSize, matrixSize, 0, 0, world->wfile.get(), this
);
lighting = std::make_unique<Lighting>(content, chunks.get());
inventories = std::make_unique<Inventories>(*this);
+3 -3
View File
@@ -4,14 +4,14 @@
using std::vector;
void LevelEvents::listen(lvl_event_type type, const chunk_event_func& func) {
void LevelEvents::listen(LevelEventType type, const ChunkEventFunc& func) {
auto& callbacks = chunk_callbacks[type];
callbacks.push_back(func);
}
void LevelEvents::trigger(lvl_event_type type, Chunk* chunk) {
void LevelEvents::trigger(LevelEventType type, Chunk* chunk) {
const auto& callbacks = chunk_callbacks[type];
for (const chunk_event_func& func : callbacks) {
for (const ChunkEventFunc& func : callbacks) {
func(type, chunk);
}
}
+6 -5
View File
@@ -6,16 +6,17 @@
class Chunk;
enum lvl_event_type {
enum LevelEventType {
EVT_CHUNK_SHOWN,
EVT_CHUNK_HIDDEN,
};
using chunk_event_func = std::function<void(lvl_event_type, Chunk*)>;
using ChunkEventFunc = std::function<void(LevelEventType, Chunk*)>;
class LevelEvents {
std::unordered_map<lvl_event_type, std::vector<chunk_event_func>>
std::unordered_map<LevelEventType, std::vector<ChunkEventFunc>>
chunk_callbacks;
public:
void listen(lvl_event_type type, const chunk_event_func& func);
void trigger(lvl_event_type type, Chunk* chunk);
void listen(LevelEventType type, const ChunkEventFunc& func);
void trigger(LevelEventType type, Chunk* chunk);
};
+1 -1
View File
@@ -66,7 +66,7 @@ void World::writeResources(const Content* content) {
void World::write(Level* level) {
const Content* content = level->content;
level->chunks->saveAll();
level->chunksStorage->saveAll();
info.nextEntityId = level->entities->peekNextID();
wfile->write(this, content);