Clean up debug message code
authororwell96 <mono96.mml@gmail.com>
Sun, 8 Jan 2017 20:10:02 +0000 (21:10 +0100)
committerorwell96 <mono96.mml@gmail.com>
Sun, 8 Jan 2017 20:10:02 +0000 (21:10 +0100)
advtrains/advtrains/atc.lua
advtrains/advtrains/helpers.lua
advtrains/advtrains/init.lua
advtrains/advtrains/misc_nodes.lua
advtrains/advtrains/pseudoload.lua
advtrains/advtrains/tracks.lua
advtrains/advtrains/trainlogic.lua
advtrains/advtrains/wagons.lua

index 2bc07be..bd02425 100644 (file)
@@ -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")
index e29eaa5..cc7deb8 100644 (file)
@@ -64,19 +64,19 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
        \r
        local next, chkdir, chkrely, y_offset\r
        y_offset=0\r
-       --atprint("[advtrains] in order mid1,mid2",middir1,middir2)\r
+       --atprint(" in order mid1,mid2",middir1,middir2)\r
        --try if it is dir1\r
        local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<\r
        if cor1.x==prev.x and cor1.z==prev.z then--this was previous\r
                next=advtrains.dirCoordSet(mid, middir1)\r
                if midrely1>=1 then\r
                        next.y=next.y+1\r
-                       --atprint("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       --atprint("found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
                        y_offset=1\r
                end\r
                chkdir=middir1\r
                chkrely=midrely1\r
-               --atprint("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+               --atprint("dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
        end\r
        --dir2???\r
        local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<\r
@@ -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.\r
                if midrely2>=1 then\r
                        next.y=next.y+1\r
-                       --atprint("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       --atprint("found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
                        y_offset=1\r
                end\r
                chkdir=middir2\r
                chkrely=midrely2\r
-               --atprint("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+               --atprint(" dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
        end\r
-       --atprint("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")\r
+       --atprint("dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")\r
        --is there a next\r
        if not next then\r
-               atprint("[advtrains]in conway: no next rail(nil), returning!")\r
+               atprint("in conway: no next rail(nil), returning!")\r
                return nil\r
        end\r
        \r
@@ -102,36 +102,36 @@ function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
        \r
        --is it a rail?\r
        if(not nextnode_ok) then\r
-               atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")\r
+               atprint("in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")\r
                next.y=next.y-1\r
                y_offset=y_offset-1\r
                \r
                nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
                if(not nextnode_ok) then\r
-                       atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       atprint("in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
                        return nil\r
                end\r
        end\r
        \r
        --is this next rail connecting to the mid?\r
        if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then\r
-               atprint("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")\r
+               atprint("in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")\r
                next.y=next.y-1\r
                y_offset=y_offset-1\r
                \r
                nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
                if(not nextnode_ok) then\r
-                       atprint("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       atprint("in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
                        return nil\r
                end\r
                if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then\r
-                       atprint("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")\r
-                       atprint("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)\r
+                       atprint("in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")\r
+                       atprint(" in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)\r
                        return nil\r
                end\r
        end\r
        \r
-       --atprint("[advtrains]conway found rail.")\r
+       --atprint("conway found rail.")\r
        return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir\r
 end\r
 --TODO use this\r
@@ -241,3 +241,4 @@ function advtrains.deserialize_inventory(sers, inv)
        end\r
        return false\r
 end\r
+\r
index ce3cc9f..03ec553 100644 (file)
@@ -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");
index 93829f0..70b18fb 100644 (file)
@@ -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
index 0636d2e..5cbd2c6 100644 (file)
@@ -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")
index 53f5ce7..9fc3a56 100644 (file)
@@ -370,10 +370,10 @@ end
 \r
 function advtrains.get_track_connections(name, param2)\r
        local nodedef=minetest.registered_nodes[name]\r
-       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\r
+       if not nodedef then atprint(" get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end\r
        local noderot=param2\r
        if not param2 then noderot=0 end\r
-       if noderot > 3 then atprint("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end\r
+       if noderot > 3 then atprint(" get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end\r
        \r
        local tracktype\r
        for k,_ in pairs(nodedef.groups) do\r
index ac870c0..07a48cc 100644 (file)
@@ -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
index 8c3cd0a..bedffda 100644 (file)
@@ -47,7 +47,7 @@ end
        wagon will save only uid in staticdata, no serialized table\r
 ]]\r
 function wagon:on_activate(sd_uid, dtime_s)\r
-       atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
+       atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
        self.object:set_armor_groups({immortal=1})\r
        if sd_uid and sd_uid~="" then\r
                --legacy\r
@@ -63,7 +63,7 @@ function wagon:on_activate(sd_uid, dtime_s)
        --duplicates?\r
        for ao_id,wagon in pairs(minetest.luaentities) do\r
                if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!\r
-                       atprint("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
+                       atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
                        self.object:remove()\r
                        minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)\r
                        return\r
@@ -77,7 +77,7 @@ end
 \r
 function wagon:get_staticdata()\r
        if not self:ensure_init() then return end\r
-       atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")\r
+       atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")\r
        --serialize inventory, if it has one\r
        if self.has_inventory then\r
                local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})\r
@@ -209,7 +209,7 @@ function wagon:destroy()
                self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)\r
        end\r
        \r
-       atprint("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")\r
+       atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")\r
        \r
        self.object:remove()\r
 \r
@@ -236,7 +236,7 @@ function wagon:on_step(dtime)
        \r
        --is my train still here\r
        if not self.train_id or not self:train() then\r
-               atprint("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")\r
+               atprint("[wagon "..self.unique_id.."] missing train_id, destroying")\r
                self.object:remove()\r
                return\r
        elseif not self.initialized then\r
@@ -317,7 +317,7 @@ function wagon:on_step(dtime)
        local first_pos=gp.path[math.floor(index)]\r
        local second_pos=gp.path[math.floor(index)+1]\r
        if not first_pos or not second_pos then\r
-               --atprint("[advtrains] object "..self.unique_id.." path end reached!")\r
+               --atprint(" object "..self.unique_id.." path end reached!")\r
                self.object:setvelocity({x=0,y=0,z=0})\r
                return\r
        end\r
@@ -533,10 +533,10 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
                        end\r
                        \r
                        local node=minetest.env:get_node_or_nil(pointed_thing.under)\r
-                       if not node then atprint("[advtrains]Ignore at placer position") return itemstack end\r
+                       if not node then atprint("Ignore at placer position") return itemstack end\r
                        local nodename=node.name\r
                        if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then\r
-                               atprint("[advtrains]no track here, not placing.")\r
+                               atprint("no track here, not placing.")\r
                                return itemstack\r
                        end\r
                        local conn1=advtrains.get_track_connections(node.name, node.param2)\r
@@ -544,7 +544,7 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
                        \r
                        local ob=minetest.env:add_entity(pointed_thing.under, "advtrains:"..sysname)\r
                        if not ob then\r
-                               atprint("[advtrains]couldn't add_entity, aborting")\r
+                               atprint("couldn't add_entity, aborting")\r
                        end\r
                        local le=ob:get_luaentity()\r
                        \r