quarry restart issues fixed

This commit is contained in:
Joachim Stolberg 2019-01-03 10:28:07 +01:00
parent 3f98da7961
commit d69b96928e
3 changed files with 15 additions and 13 deletions

@ -508,7 +508,7 @@ end
-- Data Maintenance -- Data Maintenance
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
local function data_maintenance() local function data_maintenance()
print("[Tubelib] Data maintenance started") minetest.log("info", "[Tubelib] Data maintenance started")
if Version == 1 then if Version == 1 then
-- Add day_count for aging of unused positions -- Add day_count for aging of unused positions
for num,item in pairs(Number2Pos) do for num,item in pairs(Number2Pos) do
@ -526,27 +526,28 @@ local function data_maintenance()
if item.name then if item.name then
Number2Pos[num] = item Number2Pos[num] = item
-- data not older than 5 real days -- data not older than 5 real days
elseif item.time and (item.time + 360) > day_cnt then elseif item.time and (item.time + (72*5)) > day_cnt then
Number2Pos[num] = item Number2Pos[num] = item
else else
print("Position deleted", num) minetest.log("info", "Position deleted", num)
end end
end end
end end
-- collect unused node numbers -- collect unused node numbers
for idx = 1,NextNumber-1 do for idx = NextNumber-1,1,-1 do
--FreeNumbers --FreeNumbers
local num = string.format("%.04u", idx) local num = string.format("%.04u", idx)
if not Number2Pos[num] then if not Number2Pos[num] then
FreeNumbers[#FreeNumbers+1] = num FreeNumbers[#FreeNumbers+1] = num
end end
end end
print("[Tubelib] Data maintenance finished") minetest.log("info", "[Tubelib] "..#FreeNumbers.." numbers recycled")
minetest.log("info", "[Tubelib] Data maintenance finished")
end end
generate_Key2Number() generate_Key2Number()
-- maintain data after one minute -- maintain data after 5 seconds
-- (minetest.get_day_count() will not be valid at start time) -- (minetest.get_day_count() will not be valid at start time)
minetest.after(5, data_maintenance) minetest.after(5, data_maintenance)

@ -358,7 +358,7 @@ function NodeStates:on_receive_message(pos, topic, payload)
end end
-- repair corrupt node data and/or migrate node to state2 -- repair corrupt node data and/or migrate node to state2
function NodeStates:on_node_load(pos) function NodeStates:on_node_load(pos, not_start_timer)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
-- legacy node number/state/counter? -- legacy node number/state/counter?
@ -398,7 +398,7 @@ function NodeStates:on_node_load(pos)
else else
meta:set_int("tubelib_state", STOPPED) meta:set_int("tubelib_state", STOPPED)
end end
elseif state == RUNNING then elseif state == RUNNING and not not_start_timer then
minetest.get_node_timer(pos):start(self.cycle_time) minetest.get_node_timer(pos):start(self.cycle_time)
elseif state == STANDBY then elseif state == STANDBY then
minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks) minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks)

@ -459,11 +459,12 @@ tubelib.register_node("tubelib_addons1:quarry",
return "unsupported" return "unsupported"
end end
end, end,
-- Function has some negative impact on the cycle time for the on_node_load = function(pos)
-- cobble generator mode (5s on/5s off) local depth = M(pos):get_int("max_levels") or 1
-- on_node_load = function(pos) -- If depth is 1, it is likely that the quarry is used as cobble generator,
-- State:on_node_load(pos) -- controlled by a sequencer. If so, don't restart the timer.
-- end, State:on_node_load(pos, depth == 1)
end,
on_node_repair = function(pos) on_node_repair = function(pos)
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,