aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-12-27 18:04:42 +0100
committerorwell96 <orwell@bleipb.de>2021-02-10 16:39:45 +0100
commit080b8fb27342827965bab2567dde14e57433b55e (patch)
treec66ee6fb80a191b09ca9ba4a658c2d5a0b3f533b /advtrains
parent9a775eff5b7a49c322119feb4c8248791edab501 (diff)
downloadadvtrains-080b8fb27342827965bab2567dde14e57433b55e.tar.gz
advtrains-080b8fb27342827965bab2567dde14e57433b55e.tar.bz2
advtrains-080b8fb27342827965bab2567dde14e57433b55e.zip
Add IGNORE_WORLD mode to test using only the advtrains save data
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/init.lua35
-rw-r--r--advtrains/nodedb.lua4
-rw-r--r--advtrains/tracks.lua2
-rw-r--r--advtrains/wagons.lua4
4 files changed, 37 insertions, 8 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index fd56d6d..d21a887 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -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)
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua
index 4539529..ca7b195 100644
--- a/advtrains/nodedb.lua
+++ b/advtrains/nodedb.lua
@@ -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)
diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua
index 7037244..ba59720 100644
--- a/advtrains/tracks.lua
+++ b/advtrains/tracks.lua
@@ -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,
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 4e7fb26..7b6a381 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -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