Merge pull request #741 from MihailRis/fix-fragment-place

fix fragment:place lights
This commit is contained in:
MihailRis 2025-12-19 19:49:39 +03:00 • committed by GitHub
commit c6c23c3c53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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); auto offset = tovec3(L, 2);
int rotation = tointeger(L, 3); int rotation = tointeger(L, 3);
fragment->getFragment(rotation)->place( fragment->getFragment(rotation)->place(
*scripting::level->chunks, offset *scripting::controller, offset
); );
} }
return 0; return 0;

View file

@ -11,6 +11,8 @@
#include "voxels/GlobalChunks.hpp" #include "voxels/GlobalChunks.hpp"
#include "voxels/VoxelsVolume.hpp" #include "voxels/VoxelsVolume.hpp"
#include "voxels/blocks_agent.hpp" #include "voxels/blocks_agent.hpp"
#include "logic/LevelController.hpp"
#include "lighting/Lighting.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "core_defs.hpp" #include "core_defs.hpp"
@ -171,8 +173,12 @@ void VoxelFragment::prepare(const Content& content) {
} }
void VoxelFragment::place( 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(); auto& structVoxels = getRuntimeVoxels();
for (int y = 0; y < size.y; y++) { for (int y = 0; y < size.y; y++) {
int sy = y + offset.y; int sy = y + offset.y;
@ -189,6 +195,10 @@ void VoxelFragment::place(
blocks_agent::set( blocks_agent::set(
chunks, sx, sy, sz, structVoxel.id, structVoxel.state 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 Level;
class Content; class Content;
class GlobalChunks; class GlobalChunks;
class LevelController;
class VoxelFragment : public Serializable { class VoxelFragment : public Serializable {
glm::ivec3 size; glm::ivec3 size;
@ -45,7 +46,7 @@ public:
/// @brief Place fragment to the world /// @brief Place fragment to the world
/// @param offset target location /// @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 /// @brief Create structure copy rotated 90 deg. clockwise
std::unique_ptr<VoxelFragment> rotated(const Content& content) const; std::unique_ptr<VoxelFragment> rotated(const Content& content) const;