FaceDeer / dfcaverns

Replicating Dwarf Fortress' underground flora in Minetest
Other
16 stars 9 forks source link

Random light errors on the surface #22

Closed TurkeyMcMac closed 1 year ago

TurkeyMcMac commented 2 years ago

Sometimes I see light errors like this: screenshot_20220127_204010

When I regenerate the world, the errors do not appear where they previously did (they appear elsewhere.)

I don't know what causes them, but this patch seems prevent them from cropping up:

--- surface_tunnels-old.lua
+++ surface_tunnels-new.lua
@@ -15,6 +15,7 @@
    local t_start = os.clock()

    local vm, data, data_param2, area = mapgen_helper.mapgen_vm_data_param2()
+   local data_changed = false

    local eminp = {x=minp.x, y=area.MinEdge.y, z=minp.z}
    local emaxp = {x=maxp.x, y=area.MaxEdge.y, z=maxp.z}
@@ -51,9 +52,11 @@
                local index2d = mapgen_helper.index2d(minp, maxp, x, z)
                local humidity = humiditymap[index2d]
                if previous_potential_floor_y <= maxp_y and previous_potential_floor_y >= minp_y then
+                   data_changed = true
                    df_caverns.tunnel_floor(minp, maxp, area, previous_potential_floor_vi, nvals_cracks, data, data_param2, humidity > 30)
                end
                if y <= maxp_y and y >= minp_y then
+                   data_changed = true
                    df_caverns.tunnel_ceiling(minp, maxp, area, vi, nvals_cracks, data, data_param2, humidity > 30)
                end
                previous_potential_floor_vi = nil
@@ -66,16 +69,18 @@

    end

-   --send data back to voxelmanip
-   vm:set_data(data)
-   vm:set_param2_data(data_param2)
-   --calc lighting
-   vm:set_lighting({day = 0, night = 0})
-   vm:calc_lighting()
-   
-   vm:update_liquids()
-   --write it to world
-   vm:write_to_map()
+   if data_changed then
+       --send data back to voxelmanip
+       vm:set_data(data)
+       vm:set_param2_data(data_param2)
+       --calc lighting
+       vm:set_lighting({day = 0, night = 0})
+       vm:calc_lighting()
+       
+       vm:update_liquids()
+       --write it to world
+       vm:write_to_map()
+   end

    local time_taken = os.clock() - t_start -- how long this chunk took, in seconds
    mapgen_helper.record_time("df_caverns surface tunnels", time_taken)

My Minetest version is 5.5.0-dev with LuaJIT. My operating system is Ubuntu 21.10. My computer's architecture is x86_64.

FaceDeer commented 1 year ago

Sorry it took so long for me to be dragged back to the modding biz. I've added your changes, even without the lighting improvement it seems like this will be a nice efficiency improvement.