diff options
author | ubq323 <ubq323@ubq323.website> | 2023-02-04 23:28:08 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-02-04 23:28:08 +0000 |
commit | 9339e47c79f40fe9c4541e638d7fd67ab634c600 (patch) | |
tree | ad1efddc3608ca506534d3e7ab7b2ae4a35a0476 /client | |
parent | 0dc1276df57aa16b4f0eaecf54fb5cd8f00115c6 (diff) |
improve tracking of loading chunks, and increase load dist around player
Diffstat (limited to 'client')
-rw-r--r-- | client/main.lua | 20 |
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) |