diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-05-30 19:58:09 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-05-30 19:58:09 +0200 |
commit | d81509c049f8c0a46e9002af7ce4666f4284111b (patch) | |
tree | d6fe972604ab07c68420149e082c3a5dc978775f /pseudoload.lua | |
parent | c71b0209270daa2df717c449c67507d9db0dc0a9 (diff) | |
download | advtrains-d81509c049f8c0a46e9002af7ce4666f4284111b.tar.gz advtrains-d81509c049f8c0a46e9002af7ce4666f4284111b.tar.bz2 advtrains-d81509c049f8c0a46e9002af7ce4666f4284111b.zip |
fixed even more lua errors and made stable
Diffstat (limited to 'pseudoload.lua')
-rw-r--r-- | pseudoload.lua | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/pseudoload.lua b/pseudoload.lua index 47318ae..8511811 100644 --- a/pseudoload.lua +++ b/pseudoload.lua @@ -1,3 +1,4 @@ +local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end --pseudoload.lua --responsible for keeping up a database of all rail nodes existant in the world, regardless of whether the mapchunk is loaded. @@ -9,6 +10,9 @@ advtrains.trackdb={} --[] may be missing if 0,0,0 --load initially + +--[[ TODO temporary outcomment + --delayed since all traintypes need to be registered minetest.after(0, function() @@ -23,9 +27,10 @@ for tt, _ in pairs(advtrains.all_traintypes) do --custom format to save memory while true do local xbytes=file:read(2) - if not xbytes then + if not xbytes or #xbytes<2 then break --eof reached end + print(xbytes) local ybytes=file:read(2) local zbytes=file:read(2) local x=(string.byte(xbytes[1])-128)*256+(string.byte(xbytes[2])) @@ -74,9 +79,10 @@ function advtrains.save_trackdb() print("[advtrains]Failed saving advtrains trackdb save file "..er) else --custom format to save memory - for x,txl in pairs(advtrains.trackdb[tt]) do - for y,tyl in pairs(txl) do - for z,rail in pairs(tyl) do + for y,tyl in pairs(advtrains.trackdb[tt]) do + for x,txl in pairs(tyl) do + for z,rail in pairs(txl) do + print("write "..x.." "..y.." "..z.." "..minetest.serialize(rail)) file:write(string.char(math.floor(x/256)+128)..string.char((x%256))) file:write(string.char(math.floor(y/256)+128)..string.char((y%256))) file:write(string.char(math.floor(z/256)+128)..string.char((z%256))) @@ -93,6 +99,33 @@ function advtrains.save_trackdb() end end end +]]--end temp outcomment +advtrains.trackdb={} +advtrains.fpath_tdb=minetest.get_worldpath().."/advtrains_trackdb" +local file, err = io.open(advtrains.fpath_tdb, "r") +if not file then + local er=err or "Unknown Error" + print("[advtrains]Failed loading advtrains save file "..er) +else + local tbl = minetest.deserialize(file:read("*a")) + if type(tbl) == "table" then + advtrains.trackdb=tbl + end + file:close() +end +function advtrains.save_trackdb() + local datastr = minetest.serialize(advtrains.trackdb) + if not datastr then + minetest.log("error", "[advtrains] Failed to serialize trackdb data!") + return + end + local file, err = io.open(advtrains.fpath_tdb, "w") + if err then + return err + end + file:write(datastr) + file:close() +end --get_node with pseudoload. --returns: |