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

View File

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

View File

@ -32,6 +32,9 @@ end
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!")
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

View File

@ -382,13 +382,36 @@ local move_entities_globalstep_part2 = function(dtime)
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)
handle_active_blocks_timer = handle_active_blocks_timer + dtime
if dtime < 0.2 or handle_active_blocks_timer >= (dtime * 3) then
handle_active_blocks_timer = 0.1
move_entities_globalstep_part1(dtime)
move_entities_globalstep_part2(dtime)
if dtime >= 0.2 and dtime_delayed < 1 then
-- Reduce activity when the server is lagging.
skip_update = true
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)

View File

@ -78,4 +78,9 @@ pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true
#Use real visible entities in tubes within active areas.
#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