summaryrefslogtreecommitdiff
path: root/client/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.lua')
-rw-r--r--client/main.lua20
1 files changed, 12 insertions, 8 deletions
diff --git a/client/main.lua b/client/main.lua
index da1b91d..769fccf 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -83,10 +83,7 @@ local function send_settile(hpos,tile)
end
--- hack
-local time_since_last_chunkreq = 100
function love.update(dt)
- time_since_last_chunkreq = time_since_last_chunkreq + dt
if local_player then
update_local_player(local_player,dt)
if love.keyboard.isScancodeDown"q" then camera.zoom = camera.zoom*1.05 end
@@ -107,11 +104,18 @@ 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()
- if map:chunk(player_cp) == nil and time_since_last_chunkreq > 1 then
- time_since_last_chunkreq = 0
- peer:send(json.encode{t="reqchunk",u=player_cp.u,v=player_cp.v})
+ 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
+ end
end
end
@@ -119,7 +123,7 @@ function love.update(dt)
repeat
local ev = host:service()
if ev and ev.type == "receive" then
- print(ev.data)
+ -- print(ev.data)
local j = json.decode(ev.data)
local op = j.t
if op == "join" then
@@ -138,7 +142,7 @@ function love.update(dt)
local_player = {pos=coords.Pos:make(pl.x,pl.y),color=pl.color,id=pl.id}
elseif op == "chunk" then
local ch = Chunk.from_packet_data(j)
- map:add_chunk(ch.cp,ch)
+ map:add_chunk(ch)
elseif op == "settile" then
local h = coords.Hex:make(j.q,j.r)
map:set_at(h,j.tile)