fix fragment:place lights

This commit is contained in:
MihailRis 2025-12-19 19:25:58 +03:00
parent 024f9670eb
commit 7a513949e9
3 changed files with 14 additions and 3 deletions

View file

@ -30,7 +30,7 @@ static int l_place(lua::State* L) {
auto offset = tovec3(L, 2);
int rotation = tointeger(L, 3);
fragment->getFragment(rotation)->place(
*scripting::level->chunks, offset
*scripting::controller, offset
);
}
return 0;

View file

@ -11,6 +11,8 @@
#include "voxels/GlobalChunks.hpp"
#include "voxels/VoxelsVolume.hpp"
#include "voxels/blocks_agent.hpp"
#include "logic/LevelController.hpp"
#include "lighting/Lighting.hpp"
#include "world/Level.hpp"
#include "core_defs.hpp"
@ -171,8 +173,12 @@ void VoxelFragment::prepare(const Content& content) {
}
void VoxelFragment::place(
GlobalChunks& chunks, const glm::ivec3& offset
LevelController& controller, const glm::ivec3& offset
) {
auto& level = *controller.getLevel();
auto& chunks = *level.chunks;
auto lighting = controller.getChunksController()->lighting.get();
const auto& defs = level.content.getIndices()->blocks;
auto& structVoxels = getRuntimeVoxels();
for (int y = 0; y < size.y; y++) {
int sy = y + offset.y;
@ -189,6 +195,10 @@ void VoxelFragment::place(
blocks_agent::set(
chunks, sx, sy, sz, structVoxel.id, structVoxel.state
);
if (lighting) {
const auto& def = defs.require(structVoxel.id);
lighting->onBlockSet(sx, sy, sz, def.rt.id);
}
}
}
}

View file

@ -12,6 +12,7 @@ inline constexpr int STRUCTURE_FORMAT_VERSION = 1;
class Level;
class Content;
class GlobalChunks;
class LevelController;
class VoxelFragment : public Serializable {
glm::ivec3 size;
@ -45,7 +46,7 @@ public:
/// @brief Place fragment to the world
/// @param offset target location
void place(GlobalChunks& chunks, const glm::ivec3& offset);
void place(LevelController& controller, const glm::ivec3& offset);
/// @brief Create structure copy rotated 90 deg. clockwise
std::unique_ptr<VoxelFragment> rotated(const Content& content) const;