Add configurable globalstep interval (#32)

* Add configurable globalstep interval

* Add warning for high globalstep interval

* Lower maximum globalstep interval

With no accelerator tubes, 0.8 can handle item movement speeds even
with lag.
This commit is contained in:
Jude Melton-Houghton 2022-05-24 19:13:41 -04:00 committed by GitHub
parent 90425fde95
commit 7b15bdbd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 11 deletions

@ -28,6 +28,7 @@ local settings = {
drop_on_routing_fail = false, drop_on_routing_fail = false,
delete_item_on_clearobject = true, delete_item_on_clearobject = true,
use_real_entities = true, use_real_entities = true,
entity_update_interval = 0,
} }
pipeworks.toggles = {} pipeworks.toggles = {}
@ -63,10 +64,9 @@ pipeworks.toggles.finite_water = nil
for name, value in pairs(settings) do for name, value in pairs(settings) do
local setting_type = type(value) local setting_type = type(value)
if setting_type == "boolean" then if setting_type == "boolean" then
pipeworks[name] = minetest.settings:get_bool(prefix..name) pipeworks[name] = minetest.settings:get_bool(prefix..name, value)
if pipeworks[name] == nil then elseif setting_type == "number" then
pipeworks[name] = value pipeworks[name] = tonumber(minetest.settings:get(prefix..name) or value)
end
else else
pipeworks[name] = value pipeworks[name] = value
end end

@ -32,6 +32,9 @@ end
if pipeworks.toggles.pipe_mode == "pressure" then if pipeworks.toggles.pipe_mode == "pressure" then
minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!") minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!")
end end
if pipeworks.entity_update_interval >= 0.2 and pipeworks.enable_accelerator_tube then
minetest.log("warning", "pipeworks accelerator tubes will not entirely work with an entity update interval 0.2 or above.")
end
-- Random variables -- Random variables

@ -382,13 +382,36 @@ local move_entities_globalstep_part2 = function(dtime)
end end
end end
local handle_active_blocks_timer = 0.1 -- dtime after which there is an update (or skip).
local dtime_threshold = pipeworks.entity_update_interval
-- Accumulated dtime since last update (or skip).
local dtime_accum = 0
-- Delayed dtime accumulated due to skipped updates.
local dtime_delayed = 0
local skip_update = false
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
handle_active_blocks_timer = handle_active_blocks_timer + dtime if dtime >= 0.2 and dtime_delayed < 1 then
if dtime < 0.2 or handle_active_blocks_timer >= (dtime * 3) then -- Reduce activity when the server is lagging.
handle_active_blocks_timer = 0.1 skip_update = true
move_entities_globalstep_part1(dtime)
move_entities_globalstep_part2(dtime)
end end
dtime_accum = dtime_accum + dtime
if dtime_accum < dtime_threshold then
return
end
if skip_update then
dtime_delayed = dtime_delayed + dtime_accum
skip_update = false
else
move_entities_globalstep_part1(dtime_accum + dtime_delayed)
move_entities_globalstep_part2(dtime_accum + dtime_delayed)
dtime_delayed = 0
end
-- Tune the threshold so that the average interval is pipeworks.entity_update_interval.
dtime_threshold = math.max(dtime_threshold + (pipeworks.entity_update_interval - dtime_accum) / 10, 0)
dtime_accum = 0
end) end)

@ -78,4 +78,9 @@ pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true
#Use real visible entities in tubes within active areas. #Use real visible entities in tubes within active areas.
#When disabled, tubes are made opaque. #When disabled, tubes are made opaque.
pipeworks_use_real_entities (Use real entities) bool true pipeworks_use_real_entities (Use Real Entities) bool true
#Target interval between tube entity steps.
#A high value may cause issues with tube entity visuals.
#A value 0.2 or above may cause issues with accelerator tubes.
pipeworks_entity_update_interval (Entity Update Interval) float 0 0 0.8