add on_chunk_present and on_chunk_remove events
This commit is contained in:
+4
-3
@@ -52,13 +52,14 @@ Level::Level(
|
||||
entities->setNextID(worldInfo.nextEntityId);
|
||||
}
|
||||
|
||||
events->listen(LevelEventType::EVT_CHUNK_SHOWN, [this](LevelEventType, Chunk* chunk) {
|
||||
events->listen(LevelEventType::CHUNK_SHOWN, [this](LevelEventType, Chunk* chunk) {
|
||||
chunks->incref(chunk);
|
||||
});
|
||||
events->listen(LevelEventType::EVT_CHUNK_HIDDEN, [this](LevelEventType, Chunk* chunk) {
|
||||
events->listen(LevelEventType::CHUNK_HIDDEN, [this](LevelEventType, Chunk* chunk) {
|
||||
chunks->decref(chunk);
|
||||
});
|
||||
chunks->setOnUnload([this](const Chunk& chunk) {
|
||||
chunks->setOnUnload([this](Chunk& chunk) {
|
||||
events->trigger(LevelEventType::CHUNK_UNLOAD, &chunk);
|
||||
AABB aabb = chunk.getAABB();
|
||||
entities->despawn(entities->getAllInside(aabb));
|
||||
});
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
|
||||
class Chunk;
|
||||
|
||||
enum LevelEventType {
|
||||
EVT_CHUNK_SHOWN,
|
||||
EVT_CHUNK_HIDDEN,
|
||||
enum class LevelEventType {
|
||||
CHUNK_SHOWN,
|
||||
CHUNK_HIDDEN,
|
||||
CHUNK_PRESENT,
|
||||
CHUNK_UNLOAD,
|
||||
};
|
||||
|
||||
using ChunkEventFunc = std::function<void(LevelEventType, Chunk*)>;
|
||||
|
||||
Reference in New Issue
Block a user