diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-08 21:10:02 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-08 21:10:02 +0100 |
commit | 0d2ec6f49a781f4539f934217ec8eb157f6a7796 (patch) | |
tree | 3bb12de6c0a9ae5f59aae409d8143219ff378c90 /advtrains | |
parent | eae99812e95eb74d28a9f7d3ee20f792f7eb8c9e (diff) | |
download | advtrains-0d2ec6f49a781f4539f934217ec8eb157f6a7796.tar.gz advtrains-0d2ec6f49a781f4539f934217ec8eb157f6a7796.tar.bz2 advtrains-0d2ec6f49a781f4539f934217ec8eb157f6a7796.zip |
Clean up debug message code
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/advtrains/atc.lua | 4 | ||||
-rw-r--r-- | advtrains/advtrains/helpers.lua | 29 | ||||
-rw-r--r-- | advtrains/advtrains/init.lua | 34 | ||||
-rw-r--r-- | advtrains/advtrains/misc_nodes.lua | 2 | ||||
-rw-r--r-- | advtrains/advtrains/pseudoload.lua | 8 | ||||
-rw-r--r-- | advtrains/advtrains/tracks.lua | 4 | ||||
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 33 | ||||
-rw-r--r-- | advtrains/advtrains/wagons.lua | 18 |
8 files changed, 82 insertions, 50 deletions
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua index 2bc07be..bd02425 100644 --- a/advtrains/advtrains/atc.lua +++ b/advtrains/advtrains/atc.lua @@ -10,7 +10,7 @@ advtrains.fpath_atc=minetest.get_worldpath().."/advtrains_atc" local file, err = io.open(advtrains.fpath_atc, "r") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed loading advtrains atc save file "..er) + atprint("Failed loading advtrains atc save file "..er) else local tbl = minetest.deserialize(file:read("*a")) if type(tbl) == "table" then @@ -22,7 +22,7 @@ function atc.save() --leave space for more save data. local datastr = minetest.serialize({controllers = atc.controllers}) if not datastr then - minetest.log("error", "[advtrains] Failed to serialize trackdb data!") + minetest.log("error", " Failed to serialize trackdb data!") return end local file, err = io.open(advtrains.fpath_atc, "w") diff --git a/advtrains/advtrains/helpers.lua b/advtrains/advtrains/helpers.lua index e29eaa5..cc7deb8 100644 --- a/advtrains/advtrains/helpers.lua +++ b/advtrains/advtrains/helpers.lua @@ -64,19 +64,19 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return local next, chkdir, chkrely, y_offset
y_offset=0
- --atprint("[advtrains] in order mid1,mid2",middir1,middir2)
+ --atprint(" in order mid1,mid2",middir1,middir2)
--try if it is dir1
local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<
if cor1.x==prev.x and cor1.z==prev.z then--this was previous
next=advtrains.dirCoordSet(mid, middir1)
if midrely1>=1 then
next.y=next.y+1
- --atprint("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
y_offset=1
end
chkdir=middir1
chkrely=midrely1
- --atprint("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint("dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
--dir2???
local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<
@@ -84,17 +84,17 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return next=advtrains.dirCoordSet(mid, middir2)--dir2 wird überprüft, alles gut.
if midrely2>=1 then
next.y=next.y+1
- --atprint("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ --atprint("found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
y_offset=1
end
chkdir=middir2
chkrely=midrely2
- --atprint("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ --atprint(" dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
end
- --atprint("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
+ --atprint("dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
--is there a next
if not next then
- atprint("[advtrains]in conway: no next rail(nil), returning!")
+ atprint("in conway: no next rail(nil), returning!")
return nil
end
@@ -102,36 +102,36 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return --is it a rail?
if(not nextnode_ok) then
- atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
+ atprint("in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
if(not nextnode_ok) then
- atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
return nil
end
end
--is this next rail connecting to the mid?
if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then
- atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
+ atprint("in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
next.y=next.y-1
y_offset=y_offset-1
nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
if(not nextnode_ok) then
- atprint("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ atprint("in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
return nil
end
if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then
- atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
- atprint("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
+ atprint("in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
+ atprint(" in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
return nil
end
end
- --atprint("[advtrains]conway found rail.")
+ --atprint("conway found rail.")
return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir
end
--TODO use this
@@ -241,3 +241,4 @@ function advtrains.deserialize_inventory(sers, inv) end
return false
end
+
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua index ce3cc9f..03ec553 100644 --- a/advtrains/advtrains/init.lua +++ b/advtrains/advtrains/init.lua @@ -4,8 +4,38 @@ advtrains={} advtrains.modpath = minetest.get_modpath("advtrains") -atprint=function() end ---atprint=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end +local function print_concat_table(a) + local str="" + local stra="" + for i=1,50 do + t=a[i] + if t==nil then + stra=stra.."nil " + else + str=str..stra + stra="" + if type(t)=="table" then + if t.x and t.y and t.z then + str=str..minetest.pos_to_string(t) + else + str=str..dump(t) + end + elseif type(t)=="boolean" then + if t then + str=str.."true" + else + str=str.."false" + end + else + str=str..t + end + str=str.." " + end + end + return str +end +--atprint=function() end +atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end sid=function(id) return string.sub(id, -4) end dofile(advtrains.modpath.."/helpers.lua"); diff --git a/advtrains/advtrains/misc_nodes.lua b/advtrains/advtrains/misc_nodes.lua index 93829f0..70b18fb 100644 --- a/advtrains/advtrains/misc_nodes.lua +++ b/advtrains/advtrains/misc_nodes.lua @@ -3,7 +3,7 @@ function advtrains.register_platform(preset) local ndef=minetest.registered_nodes[preset] if not ndef then - minetest.log("warning", "[advtrains] register_platform couldn't find preset node "..preset) + minetest.log("warning", " register_platform couldn't find preset node "..preset) return end local btex=ndef.tiles diff --git a/advtrains/advtrains/pseudoload.lua b/advtrains/advtrains/pseudoload.lua index 0636d2e..5cbd2c6 100644 --- a/advtrains/advtrains/pseudoload.lua +++ b/advtrains/advtrains/pseudoload.lua @@ -20,7 +20,7 @@ for tt, _ in pairs(advtrains.all_traintypes) do local file, err = io.open(pl_fpath, "r") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed loading advtrains trackdb save file "..er) + atprint("Failed loading advtrains trackdb save file "..er) else --custom format to save memory while true do @@ -74,7 +74,7 @@ function advtrains.save_trackdb() local file, err = io.open(pl_fpath, "w") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed saving advtrains trackdb save file "..er) + atprint("Failed saving advtrains trackdb save file "..er) else --custom format to save memory for y,tyl in pairs(advtrains.trackdb[tt]) do @@ -103,7 +103,7 @@ advtrains.fpath_tdb=minetest.get_worldpath().."/advtrains_trackdb2" local file, err = io.open(advtrains.fpath_tdb, "r") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed loading advtrains save file "..er) + atprint("Failed loading advtrains save file "..er) else local tbl = minetest.deserialize(file:read("*a")) if type(tbl) == "table" then @@ -114,7 +114,7 @@ end function advtrains.save_trackdb() local datastr = minetest.serialize(advtrains.trackdb) if not datastr then - minetest.log("error", "[advtrains] Failed to serialize trackdb data!") + minetest.log("error", " Failed to serialize trackdb data!") return end local file, err = io.open(advtrains.fpath_tdb, "w") diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua index 53f5ce7..9fc3a56 100644 --- a/advtrains/advtrains/tracks.lua +++ b/advtrains/advtrains/tracks.lua @@ -370,10 +370,10 @@ end function advtrains.get_track_connections(name, param2)
local nodedef=minetest.registered_nodes[name]
- if not nodedef then atprint("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
+ if not nodedef then atprint(" get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
local noderot=param2
if not param2 then noderot=0 end
- if noderot > 3 then atprint("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
+ if noderot > 3 then atprint(" get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
local tracktype
for k,_ in pairs(nodedef.groups) do
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index ac870c0..07a48cc 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -47,7 +47,7 @@ advtrains.fpath=minetest.get_worldpath().."/advtrains" local file, err = io.open(advtrains.fpath, "r") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed loading advtrains save file "..er) + atprint("Failed loading advtrains save file "..er) else local tbl = minetest.deserialize(file:read("*a")) if type(tbl) == "table" then @@ -59,7 +59,7 @@ advtrains.fpath_ws=minetest.get_worldpath().."/advtrains_wagon_save" local file, err = io.open(advtrains.fpath_ws, "r") if not file then local er=err or "Unknown Error" - atprint("[advtrains]Failed loading advtrains save file "..er) + atprint("Failed loading advtrains save file "..er) else local tbl = minetest.deserialize(file:read("*a")) if type(tbl) == "table" then @@ -70,11 +70,11 @@ end advtrains.save = function() - atprint("[advtrains]saving") + atprint("saving") advtrains.invalidate_all_paths() local datastr = minetest.serialize(advtrains.trains) if not datastr then - minetest.log("error", "[advtrains] Failed to serialize train data!") + minetest.log("error", " Failed to serialize train data!") return end local file, err = io.open(advtrains.fpath, "w") @@ -108,7 +108,7 @@ advtrains.save = function() --atprint(dump(advtrains.wagon_save)) datastr = minetest.serialize(advtrains.wagon_save) if not datastr then - minetest.log("error", "[advtrains] Failed to serialize train data!") + minetest.log("error", " Failed to serialize train data!") return end file, err = io.open(advtrains.fpath_ws, "w") @@ -236,7 +236,7 @@ function advtrains.train_step(id, train, dtime) --remove? if #train.trainparts==0 then - atprint("[advtrains][train "..sid(id).."] has empty trainparts, removing.") + atprint("[train "..sid(id).."] has empty trainparts, removing.") advtrains.detector.leave_node(path[train.detector_old_index], id) advtrains.trains[id]=nil return @@ -284,7 +284,7 @@ function advtrains.train_step(id, train, dtime) local node_range=(math.max((minetest.setting_get("active_block_range") or 0),1)*16) if train.check_trainpartload<=0 then local ori_pos=advtrains.get_real_index_position(path, train.index) --not much to calculate - --atprint("[advtrains][train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos))) + --atprint("[train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos))) local should_check=false for _,p in ipairs(minetest.get_connected_players()) do @@ -417,7 +417,7 @@ function advtrains.pathpredict(id, train) if not train.path or #train.path<2 then if not train.last_pos then --no chance to recover - atprint("[advtrains]train hasn't saved last-pos, removing train.") + atprint("train hasn't saved last-pos, removing train.") advtrains.train[id]=nil return false end @@ -426,17 +426,17 @@ function advtrains.pathpredict(id, train) if node_ok==nil then --block not loaded, do nothing - atprint("[advtrains]last_pos not available") + atprint("last_pos not available") return nil elseif node_ok==false then - atprint("[advtrains]no track here, (fail) removing train.") + atprint("no track here, (fail) removing train.") advtrains.trains[id]=nil return false end if not train.last_pos_prev then --no chance to recover - atprint("[advtrains]train hasn't saved last-pos_prev, removing train.") + atprint("train hasn't saved last-pos_prev, removing train.") advtrains.trains[id]=nil return false end @@ -445,10 +445,10 @@ function advtrains.pathpredict(id, train) if prevnode_ok==nil then --block not loaded, do nothing - atprint("[advtrains]prev not available") + atprint("prev not available") return nil elseif prevnode_ok==false then - atprint("[advtrains]no track at prev, (fail) removing train.") + atprint("no track at prev, (fail) removing train.") advtrains.trains[id]=nil return false end @@ -476,7 +476,7 @@ function advtrains.pathpredict(id, train) local maxn=train.max_index_on_track or 0 while (maxn-train.index) < pregen_front do--pregenerate - --atprint("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1])) + --atprint("maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1])) local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.drives_on) if conway then train.path[maxn+1]=conway @@ -493,7 +493,7 @@ function advtrains.pathpredict(id, train) local minn=train.min_index_on_track or 0 while (train.index-minn) < (train.trainlen or 0) + pregen_back do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here) - --atprint("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1])) + --atprint("minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1])) local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.drives_on) if conway then train.path[minn-1]=conway @@ -558,10 +558,11 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate) local count_l=0 for i, w_id in ipairs(train.trainparts) do local wagon=nil - for _,iwagon in pairs(minetest.luaentities) do + for aoid,iwagon in pairs(minetest.luaentities) do if iwagon.is_wagon and iwagon.initialized and iwagon.unique_id==w_id then if wagon then --duplicate + atprint("update_trainpart_properties: Removing duplicate wagon with id="..aoid) iwagon.object:remove() else wagon=iwagon diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index 8c3cd0a..bedffda 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -47,7 +47,7 @@ end wagon will save only uid in staticdata, no serialized table
]]
function wagon:on_activate(sd_uid, dtime_s)
- atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
self.object:set_armor_groups({immortal=1})
if sd_uid and sd_uid~="" then
--legacy
@@ -63,7 +63,7 @@ function wagon:on_activate(sd_uid, dtime_s) --duplicates?
for ao_id,wagon in pairs(minetest.luaentities) do
if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!
- atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
self.object:remove()
minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)
return
@@ -77,7 +77,7 @@ end function wagon:get_staticdata()
if not self:ensure_init() then return end
- atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
--serialize inventory, if it has one
if self.has_inventory then
local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})
@@ -209,7 +209,7 @@ function wagon:destroy() self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)
end
- atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
self.object:remove()
@@ -236,7 +236,7 @@ function wagon:on_step(dtime) --is my train still here
if not self.train_id or not self:train() then
- atprint("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")
+ atprint("[wagon "..self.unique_id.."] missing train_id, destroying")
self.object:remove()
return
elseif not self.initialized then
@@ -317,7 +317,7 @@ function wagon:on_step(dtime) local first_pos=gp.path[math.floor(index)]
local second_pos=gp.path[math.floor(index)+1]
if not first_pos or not second_pos then
- --atprint("[advtrains] object "..self.unique_id.." path end reached!")
+ --atprint(" object "..self.unique_id.." path end reached!")
self.object:setvelocity({x=0,y=0,z=0})
return
end
@@ -533,10 +533,10 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img) end
local node=minetest.env:get_node_or_nil(pointed_thing.under)
- if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
+ if not node then atprint("Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then
- atprint("[advtrains]no track here, not placing.")
+ atprint("no track here, not placing.")
return itemstack
end
local conn1=advtrains.get_track_connections(node.name, node.param2)
@@ -544,7 +544,7 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img) local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)
if not ob then
- atprint("[advtrains]couldn't add_entity, aborting")
+ atprint("couldn't add_entity, aborting")
end
local le=ob:get_luaentity()
|