summaryrefslogtreecommitdiff
path: root/server/map.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/map.lua')
-rw-r--r--server/map.lua34
1 files changed, 13 insertions, 21 deletions
diff --git a/server/map.lua b/server/map.lua
index 0bb09c7..9627de9 100644
--- a/server/map.lua
+++ b/server/map.lua
@@ -2,7 +2,7 @@ local Map = require"common.map".Map
local class = require"common.class"
local worldgen = require"worldgen"
local json = require"common.dkjson"
-local Chunk = require"common.chunk".Chunk
+local ChunkS = require"chunk".ChunkS
local MapS = class.extend(Map)
function MapS.obtain(self,cp)
@@ -12,36 +12,28 @@ function MapS.obtain(self,cp)
-- otherwise, generate a new chunk, load it, then return it.
-- false is not used on serverside. yet.
+ --
local ch = self:chunk(cp)
- if ch then return ch end
-
- local f = io.open(cp:filename(),"r")
- if f then
- print("loading from file",cp)
- local j = json.decode(f:read("a"))
- print(j)
- for k in pairs(j) do print(k) end
- ch = Chunk.from_packet_data(j)
- f:close()
+ if ch then
+ return ch
else
- ch = worldgen.gen_chunk(cp)
- end
+ ch = ChunkS:load_from_disk(cp)
+ if not ch then
+ ch = worldgen.gen_chunk(cp)
+ end
-
- print(ch.cp.u,ch.cp.v)
- self:add_chunk(ch)
- return ch
+ self:add_chunk(ch)
+ return ch
+ end
+
end
function MapS.save_chunk(self,cp)
-- any attempt to save not-loaded chunks is silently ignored
local ch = self:chunk(cp)
if not ch then return end
- local f = io.open(cp:filename(),"w")
- f:write(ch:data_packet())
- f:flush()
- f:close()
+ ch:save_if_dirty()
end
function MapS.save_and_unload(self,cp)
self:save_chunk(cp)