aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-01-14 11:08:16 +0100
committerorwell96 <orwell@bleipb.de>2021-02-10 16:42:15 +0100
commit1b8a3dfaf21cd485b7018491c70ebff4c639bfcf (patch)
tree3692266b5244096e991d51882f7875e93d38ca94
parent4d13b158420d4a8d5fc0020ee2b0f9a0014c5541 (diff)
downloadadvtrains-1b8a3dfaf21cd485b7018491c70ebff4c639bfcf.tar.gz
advtrains-1b8a3dfaf21cd485b7018491c70ebff4c639bfcf.tar.bz2
advtrains-1b8a3dfaf21cd485b7018491c70ebff4c639bfcf.zip
Add save interval setting, fix accidental global variable, at_sync_ndb on server priv not limited, timetaking for restore_all
-rw-r--r--advtrains/init.lua7
-rw-r--r--advtrains/lzb.lua2
-rw-r--r--advtrains/nodedb.lua5
-rw-r--r--advtrains/settingtypes.txt4
4 files changed, 11 insertions, 7 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 13e5f70..2e10530 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -52,7 +52,7 @@ local NO_SAVE = false
-- Use a global slowdown factor to slow down train movements. Now a setting
local DTIME_LIMIT = tonumber(minetest.settings:get("advtrains_dtime_limit")) or 0.2
-
+local SAVE_INTERVAL = tonumber(minetest.settings:get("advtrains_save_interval")) or 60
--Constant for maximum connection value/division of the circle
AT_CMAX = 16
@@ -564,8 +564,7 @@ end
--## MAIN LOOP ##--
--Calls all subsequent main tasks of both advtrains and atlatc
local init_load=false
-local save_interval=60
-local save_timer=save_interval
+local save_timer = SAVE_INTERVAL
advtrains.mainloop_runcnt=0
advtrains.global_slowdown = 1
@@ -624,7 +623,7 @@ minetest.register_globalstep(function(dtime_mt)
local t=os.clock()
--save
advtrains.save()
- save_timer=save_interval
+ save_timer = SAVE_INTERVAL
atprintbm("saving", t)
end
end)
diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua
index 1aa9e5f..15d217e 100644
--- a/advtrains/lzb.lua
+++ b/advtrains/lzb.lua
@@ -83,7 +83,7 @@ local function look_ahead(id, train)
--local brake_i = advtrains.path_get_index_by_offset(train, train.index, brakedst + params.BRAKE_SPACE)
-- worst case (don't use index_by_offset)
- brake_i = atfloor(train.index + brakedst + params.BRAKE_SPACE)
+ local brake_i = atfloor(train.index + brakedst + params.BRAKE_SPACE)
atprint("LZB: looking ahead up to ", brake_i)
--local aware_i = advtrains.path_get_index_by_offset(train, brake_i, AWARE_ZONE)
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua
index ca7b195..c664792 100644
--- a/advtrains/nodedb.lua
+++ b/advtrains/nodedb.lua
@@ -327,6 +327,7 @@ minetest.register_lbm({
--used when restoring stuff after a crash
ndb.restore_all = function()
--atlog("Updating the map from the nodedb, this may take a while")
+ local t1 = os.clock()
local cnt=0
local dcnt=0
for y, ny in pairs(ndb_nodes) do
@@ -352,7 +353,7 @@ ndb.restore_all = function()
end
end
end
- local text="Restore node database: Replaced "..cnt.." nodes, removed "..dcnt.." ghost nodes."
+ local text="Restore node database: Replaced "..cnt.." nodes, removed "..dcnt.." ghost nodes. (took "..math.floor((os.clock()-t1) * 1000).."ms)"
atlog(text)
return text
end
@@ -379,7 +380,7 @@ minetest.register_chatcommand("at_sync_ndb",
description = "Write node db back to map and find ghost nodes", -- Full description
privs = {train_operator=true},
func = function(name, param)
- if os.time() < ptime+30 then
+ if os.time() < ptime+30 and not minetest.get_player_privs(name, "server") then
return false, "Please wait at least 30s from the previous execution of /at_restore_ndb!"
end
local text = ndb.restore_all()
diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index d3c711b..6acff80 100644
--- a/advtrains/settingtypes.txt
+++ b/advtrains/settingtypes.txt
@@ -52,3 +52,7 @@ advtrains_wagon_load_range (Wagon Entity Load/Unload Range) int 96 32 512
# acceleration of wagons to decrease server load.
# A value of 0 (default) disables this behavior.
advtrains_dtime_limit (DTime Limit for slow-down) float 0.2 0 5
+
+# Time interval in seconds in which advtrains stores its save data to disk
+# Nevertheless, advtrains saves all data when shutting down the server.
+advtrains_save_interval (Save Interval) int 60 20 3600