move Lighting instance to ChunksController

This commit is contained in:
MihailRis
2024-12-17 05:13:49 +03:00
parent c5049d0e24
commit b7664b4188
14 changed files with 60 additions and 61 deletions
+7 -11
View File
@@ -104,7 +104,13 @@ static int l_set(lua::State* L) {
return 0;
}
blocks_agent::set(*level->chunksStorage, x, y, z, id, int2blockstate(state));
level->lighting->onBlockSet(x, y, z, id);
auto chunksController = controller->getChunksController();
if (chunksController == nullptr) {
return 1;
}
Lighting& lighting = *chunksController->lighting;
lighting.onBlockSet(x, y, z, id);
if (!noupdate) {
blocks->updateSides(x, y, z);
}
@@ -120,15 +126,6 @@ static int l_get(lua::State* L) {
return lua::pushinteger(L, id);
}
static int l_get_fast(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
auto vox = blocks_agent::get(*level->chunks, x, y, z);
int id = vox == nullptr ? -1 : vox->id;
return lua::pushinteger(L, id);
}
static int l_get_x(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
@@ -638,7 +635,6 @@ const luaL_Reg blocklib[] = {
{"is_solid_at", lua::wrap<l_is_solid_at>},
{"is_replaceable_at", lua::wrap<l_is_replaceable_at>},
{"set", lua::wrap<l_set>},
{"get_fast", lua::wrap<l_get_fast>},
{"get", lua::wrap<l_get>},
{"get_X", lua::wrap<l_get_x>},
{"get_Y", lua::wrap<l_get_y>},
+15 -6
View File
@@ -16,6 +16,8 @@
#include "voxels/GlobalChunks.hpp"
#include "world/Level.hpp"
#include "world/World.hpp"
#include "logic/LevelController.hpp"
#include "logic/ChunksController.hpp"
using namespace scripting;
namespace fs = std::filesystem;
@@ -203,30 +205,37 @@ static int l_set_chunk_data(lua::State* L) {
} else {
chunk->decode(buffer->data().data());
}
auto chunksController = controller->getChunksController();
if (chunksController == nullptr) {
return 1;
}
Lighting& lighting = *chunksController->lighting;
chunk->updateHeights();
level->lighting->buildSkyLight(x, y);
lighting.buildSkyLight(x, y);
chunk->flags.modified = true;
level->lighting->onChunkLoaded(x, y, true);
lighting.onChunkLoaded(x, y, true);
chunk = level->chunks->getChunk(x - 1, y);
if (chunk != nullptr) {
chunk->flags.modified = true;
level->lighting->onChunkLoaded(x - 1, y, true);
lighting.onChunkLoaded(x - 1, y, true);
}
chunk = level->chunks->getChunk(x + 1, y);
if (chunk != nullptr) {
chunk->flags.modified = true;
level->lighting->onChunkLoaded(x + 1, y, true);
lighting.onChunkLoaded(x + 1, y, true);
}
chunk = level->chunks->getChunk(x, y - 1);
if (chunk != nullptr) {
chunk->flags.modified = true;
level->lighting->onChunkLoaded(x, y - 1, true);
lighting.onChunkLoaded(x, y - 1, true);
}
chunk = level->chunks->getChunk(x, y + 1);
if (chunk != nullptr) {
chunk->flags.modified = true;
level->lighting->onChunkLoaded(x, y + 1, true);
lighting.onChunkLoaded(x, y + 1, true);
}
return 1;