Fix VM light update issue (#590)

This commit is contained in:
Jude Melton-Houghton 2022-02-12 18:19:33 -05:00 committed by GitHub
parent fb255d292e
commit 3c27bb9350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -326,6 +326,9 @@ end
-- Nil if no VM-based transaction is in progress. -- Nil if no VM-based transaction is in progress.
local vm_cache = nil local vm_cache = nil
-- Whether the current transaction will need a light update afterward.
local vm_update_light = false
-- Starts a VoxelManipulator-based transaction. -- Starts a VoxelManipulator-based transaction.
-- --
-- During a VM transaction, calls to vm_get_node and vm_swap_node operate on a -- 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. -- vm_abort.
function mesecon.vm_begin() function mesecon.vm_begin()
vm_cache = {} vm_cache = {}
vm_update_light = false
end end
-- Finishes a VoxelManipulator-based transaction, freeing the VMs and map data -- Finishes a VoxelManipulator-based transaction, freeing the VMs and map data
@ -343,7 +347,7 @@ function mesecon.vm_commit()
if tbl.dirty then if tbl.dirty then
local vm = tbl.vm local vm = tbl.vm
vm:set_data(tbl.data) vm:set_data(tbl.data)
vm:write_to_map(tbl.update_light) vm:write_to_map(vm_update_light)
vm:update_map() vm:update_map()
end end
end end
@ -364,7 +368,7 @@ local function vm_get_or_create_entry(pos)
local vm = minetest.get_voxel_manip(pos, pos) local vm = minetest.get_voxel_manip(pos, pos)
local min_pos, max_pos = vm:get_emerged_area() local min_pos, max_pos = vm:get_emerged_area()
local va = VoxelArea:new{MinEdge = min_pos, MaxEdge = max_pos} 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 vm_cache[hash] = tbl
end end
return tbl return tbl
@ -391,8 +395,11 @@ end
-- --
-- The swap will necessitate a light update unless update_light equals false. -- The swap will necessitate a light update unless update_light equals false.
function mesecon.vm_swap_node(pos, name, update_light) 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) local tbl = vm_get_or_create_entry(pos)
tbl.update_light = update_light ~= false or tbl.update_light
local index = tbl.va:indexp(pos) local index = tbl.va:indexp(pos)
tbl.data[index] = minetest.get_content_id(name) tbl.data[index] = minetest.get_content_id(name)
tbl.dirty = true tbl.dirty = true