aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-02-03 20:40:30 +0100
committerorwell96 <mono96.mml@gmail.com>2017-02-03 20:40:30 +0100
commit328d5054a105869c7e12df1941ceedb308ef1faa (patch)
tree736df563aa116e08e8ae4284b38a90852b25bd1e /advtrains/advtrains_luaautomation
parenta72dda17be2175d5df8f1b7dd28e5ddeabe1494d (diff)
downloadadvtrains-328d5054a105869c7e12df1941ceedb308ef1faa.tar.gz
advtrains-328d5054a105869c7e12df1941ceedb308ef1faa.tar.bz2
advtrains-328d5054a105869c7e12df1941ceedb308ef1faa.zip
Revert change to node pos hashes, and rewrite trackdb to use individual coordinates
The precision of integers was not sufficient for saving pos node hashes in most cases, leading to strange bugs. This fixes broken ATC rails, broken LuaAutomation stuff and trackdb on Windows. Probably also fixes trains randomly stopping.
Diffstat (limited to 'advtrains/advtrains_luaautomation')
-rw-r--r--advtrains/advtrains_luaautomation/active_common.lua14
-rw-r--r--advtrains/advtrains_luaautomation/atc_rail.lua12
-rw-r--r--advtrains/advtrains_luaautomation/init.lua7
3 files changed, 22 insertions, 11 deletions
diff --git a/advtrains/advtrains_luaautomation/active_common.lua b/advtrains/advtrains_luaautomation/active_common.lua
index 474838e..50a5051 100644
--- a/advtrains/advtrains_luaautomation/active_common.lua
+++ b/advtrains/advtrains_luaautomation/active_common.lua
@@ -3,7 +3,9 @@
local ac = {nodes={}}
function ac.load(data)
- ac.nodes=data and data.nodes or {}
+ if data then
+ ac.nodes=data.nodes
+ end
end
function ac.save()
return {nodes = ac.nodes}
@@ -14,7 +16,7 @@ function ac.after_place_node(pos, player)
local meta=minetest.get_meta(pos)
meta:set_string("formspec", ac.getform(pos, meta))
meta:set_string("infotext", "LuaAutomation component, unconfigured.")
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
--just get first available key!
for en,_ in pairs(atlatc.envs) do
ac.nodes[ph]={env=en}
@@ -25,7 +27,7 @@ function ac.getform(pos, meta_p)
local meta = meta_p or minetest.get_meta(pos)
local envs_asvalues={}
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
local nodetbl = ac.nodes[ph]
local env, code, err = nil, "", ""
if nodetbl then
@@ -49,7 +51,7 @@ end
function ac.after_dig_node(pos, node, player)
advtrains.invalidate_all_paths()
advtrains.ndb.clear(pos)
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
ac.nodes[ph]=nil
end
@@ -59,7 +61,7 @@ function ac.on_receive_fields(pos, formname, fields, player)
end
local meta=minetest.get_meta(pos)
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
local nodetbl = ac.nodes[ph] or {}
--if fields.quit then return end
if fields.env then
@@ -85,7 +87,7 @@ function ac.on_receive_fields(pos, formname, fields, player)
end
function ac.run_in_env(pos, evtdata, customfct_p)
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
local nodetbl = ac.nodes[ph] or {}
local meta
diff --git a/advtrains/advtrains_luaautomation/atc_rail.lua b/advtrains/advtrains_luaautomation/atc_rail.lua
index b2a8aad..f52252c 100644
--- a/advtrains/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains/advtrains_luaautomation/atc_rail.lua
@@ -7,8 +7,14 @@ local r={}
function r.fire_event(pos, evtdata)
- local ph=minetest.hash_node_position(pos)
- local railtbl = atlatc.active.nodes[ph] or {}
+ local ph=minetest.pos_to_string(pos)
+ local railtbl = atlatc.active.nodes[ph]
+
+ if not railtbl then
+ atprint("missing rail table entry!")
+ return
+ end
+
local arrowconn = railtbl.arrowconn
@@ -70,7 +76,7 @@ advtrains.register_tracks("default", {
atlatc.active.on_receive_fields(pos, ...)
--set arrowconn (for ATC)
- local ph=minetest.hash_node_position(pos)
+ local ph=minetest.pos_to_string(pos)
local _, conn1=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
atlatc.active.nodes[ph].arrowconn=conn1
end,
diff --git a/advtrains/advtrains_luaautomation/init.lua b/advtrains/advtrains_luaautomation/init.lua
index 37e5714..d88944f 100644
--- a/advtrains/advtrains_luaautomation/init.lua
+++ b/advtrains/advtrains_luaautomation/init.lua
@@ -25,7 +25,9 @@ dofile(mp.."/interrupt.lua")
dofile(mp.."/active_common.lua")
dofile(mp.."/atc_rail.lua")
dofile(mp.."/operation_panel.lua")
-dofile(mp.."/p_mesecon_iface.lua")
+if mesecon then
+ dofile(mp.."/p_mesecon_iface.lua")
+end
dofile(mp.."/chatcmds.lua")
@@ -34,8 +36,10 @@ local file, err = io.open(filename, "r")
if not file then
minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error"))
else
+ atprint("luaautomation reading file:",filename)
local tbl = minetest.deserialize(file:read("*a"))
if type(tbl) == "table" then
+ atprint(tbl)
if tbl.version==1 then
for envname, data in pairs(tbl.envs) do
atlatc.envs[envname]=atlatc.env_load(envname, data)
@@ -97,4 +101,3 @@ minetest.register_globalstep(function(dtime)
atlatc.save()
end
end)
-minetest.register_on_shutdown(atlatc.save)