Add IGNORE_WORLD mode to test using only the advtrains save data

master
orwell96 2020-12-27 18:04:42 +01:00
parent 9a775eff5b
commit 080b8fb273
4 changed files with 37 additions and 8 deletions

View File

@ -26,17 +26,33 @@ minetest.log("action", "[advtrains] Loading...")
attrans = minetest.get_translator ("advtrains")
--advtrains
advtrains = {trains={}, player_to_train_mapping={}}
-- =======================Development/debugging settings=====================
-- DO NOT USE FOR NORMAL OPERATION
local DUMP_DEBUG_SAVE = false
-- dump the save files in human-readable format into advtrains_DUMP
local GENERATE_ATRICIFIAL_LAG = false
local HOW_MANY_LAG = 1.0
-- Simulate a higher server step interval, as it occurs when the server is on high load
advtrains.IGNORE_WORLD = false
-- Run advtrains without respecting the world map
-- - No world collision checks occur
-- - The NDB forcibly places all nodes stored in it into the world regardless of the world's content.
-- - Rails do not set the 'attached_node' group
-- This mode can be useful for debugging/testing a world without the map data available
-- In this case, choose 'singlenode' as mapgen
local NO_SAVE = false
-- Do not save any data to advtrains save files
-- ==========================================================================
--Constant for maximum connection value/division of the circle
AT_CMAX = 16
advtrains = {trains={}, player_to_train_mapping={}}
-- get wagon loading range
advtrains.wagon_load_range = tonumber(minetest.settings:get("advtrains_wagon_load_range"))
if not advtrains.wagon_load_range then
@ -622,6 +638,18 @@ function advtrains.save(remove_players_from_wagons)
atwarn("Instructed to save() but load() was never called!")
return
end
-- Cleanup actions
--TODO very simple yet hacky workaround for the "green signals" bug
advtrains.invalidate_all_paths()
if advtrains.IGNORE_WORLD then
advtrains.ndb.restore_all()
end
if NO_SAVE then
return
end
if no_action then
atlog("[save] Saving requested externally, but Advtrains step is disabled. Not saving any data as state may be inconsistent.")
return
@ -632,9 +660,6 @@ function advtrains.save(remove_players_from_wagons)
atlatc.save()
end
atprint("[save_all]Saved advtrains save files")
--TODO very simple yet hacky workaround for the "green signals" bug
advtrains.invalidate_all_paths()
end
minetest.register_on_shutdown(advtrains.save)

View File

@ -281,6 +281,8 @@ function advtrains.get_rail_info_at(pos, drives_on)
return true, conns, railheight
end
local IGNORE_WORLD = advtrains.IGNORE_WORLD
ndb.run_lbm = function(pos, node)
local cid=ndbget(pos.x, pos.y, pos.z)
if cid then
@ -335,7 +337,7 @@ ndb.restore_all = function()
if node then
local ori_ndef=minetest.registered_nodes[node.name]
local ndbnode=ndb.get_node_raw(pos)
if ori_ndef and ori_ndef.groups.save_in_at_nodedb then --check if this node has been worldedited, and don't replace then
if (ori_ndef and ori_ndef.groups.save_in_at_nodedb) or IGNORE_WORLD then --check if this node has been worldedited, and don't replace then
if (ndbnode.name~=node.name or ndbnode.param2~=node.param2) then
minetest.swap_node(pos, ndbnode)
--atlog("Replaced",node.name,"@",pos,"with",ndbnode.name)

View File

@ -469,7 +469,7 @@ function advtrains.register_tracks(tracktype, def, preset)
tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png"), def.second_texture},
groups = {
attached_node=1,
attached_node = advtrains.IGNORE_WORLD and 0 or 1,
advtrains_track=1,
["advtrains_track_"..tracktype]=1,
save_in_at_nodedb=1,

View File

@ -10,6 +10,8 @@
-- TP delay when getting off wagon
local GETOFF_TP_DELAY = 0.5
local IGNORE_WORLD = advtrains.IGNORE_WORLD
advtrains.wagons = {}
advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {}
@ -446,7 +448,7 @@ function wagon:on_step(dtime)
end
--checking for environment collisions(a 3x3 cube around the center)
if is_in_loaded_area and not train.recently_collided_with_env then
if not IGNORE_WORLD and is_in_loaded_area and not train.recently_collided_with_env then
local collides=false
local exh = self.extent_h or 1
local exv = self.extent_v or 2