summaryrefslogtreecommitdiff
path: root/client/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.lua')
-rw-r--r--client/main.lua32
1 files changed, 23 insertions, 9 deletions
diff --git a/client/main.lua b/client/main.lua
index 769fccf..63c2fc7 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -104,19 +104,33 @@ function love.update(dt)
send_settile(mh,false)
end
- -- load chunks near player
if local_player then
local player_cp = local_player.pos:to_hex():containing_chunk()
- for du = -1,1 do
- for dv = -1,1 do
- local cp = player_cp+coords.ChunkPos:make(du,dv)
- if map:chunk(cp) == nil then
- print("sending chunk request",cp)
- map:mark_chunk_loading(cp)
- peer:send(json.encode{t="reqchunk",u=cp.u,v=cp.v})
- end
+ -- load chunks near to player (within 3x3 square)
+ for _,cp in ipairs(player_cp:neighborhood()) do
+ if map:chunk(cp) == nil then
+ print("sending chunk request",cp)
+ map:mark_chunk_loading(cp)
+ peer:send(json.encode{t="reqchunk",u=cp.u,v=cp.v})
end
end
+
+ -- unload chunks not near player
+ -- todo maybe: instead of immediately unloading chunks when we move away,
+ -- have some kind of 'last near' time, so that if player is moving back and forth,
+ -- we don't repeatedly unload and reload a given chunk
+ local to_remove = {}
+ for cp in map:iter_chunks() do
+ local d = player_cp:orth_dist(cp)
+ if d > 1 then
+ table.insert(to_remove,cp)
+ end
+ end
+ for _,cp in ipairs(to_remove) do
+ map:remove_chunk(cp)
+ end
+
+
end