From 3c27bb9350e5469f9bb8da862fec3e9e6f4749a8 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 12 Feb 2022 18:19:33 -0500 Subject: [PATCH] Fix VM light update issue (#590) --- mesecons/util.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mesecons/util.lua b/mesecons/util.lua index 5215e8c..80afd09 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -326,6 +326,9 @@ end -- Nil if no VM-based transaction is in progress. local vm_cache = nil +-- Whether the current transaction will need a light update afterward. +local vm_update_light = false + -- Starts a VoxelManipulator-based transaction. -- -- During a VM transaction, calls to vm_get_node and vm_swap_node operate on a @@ -334,6 +337,7 @@ local vm_cache = nil -- vm_abort. function mesecon.vm_begin() vm_cache = {} + vm_update_light = false end -- Finishes a VoxelManipulator-based transaction, freeing the VMs and map data @@ -343,7 +347,7 @@ function mesecon.vm_commit() if tbl.dirty then local vm = tbl.vm vm:set_data(tbl.data) - vm:write_to_map(tbl.update_light) + vm:write_to_map(vm_update_light) vm:update_map() end end @@ -364,7 +368,7 @@ local function vm_get_or_create_entry(pos) local vm = minetest.get_voxel_manip(pos, pos) local min_pos, max_pos = vm:get_emerged_area() local va = VoxelArea:new{MinEdge = min_pos, MaxEdge = max_pos} - tbl = {vm = vm, va = va, data = vm:get_data(), param1 = vm:get_light_data(), param2 = vm:get_param2_data(), dirty = false, update_light = false} + tbl = {vm = vm, va = va, data = vm:get_data(), param1 = vm:get_light_data(), param2 = vm:get_param2_data(), dirty = false} vm_cache[hash] = tbl end return tbl @@ -391,8 +395,11 @@ end -- -- The swap will necessitate a light update unless update_light equals false. function mesecon.vm_swap_node(pos, name, update_light) + -- If one node needs a light update, all VMs should use light updates to + -- prevent newly calculated light from being overwritten by other VMs. + vm_update_light = vm_update_light or update_light ~= false + local tbl = vm_get_or_create_entry(pos) - tbl.update_light = update_light ~= false or tbl.update_light local index = tbl.va:indexp(pos) tbl.data[index] = minetest.get_content_id(name) tbl.dirty = true