diff options
-rw-r--r-- | client/main.ha | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/client/main.ha b/client/main.ha index 977827c..2a341c4 100644 --- a/client/main.ha +++ b/client/main.ha @@ -63,10 +63,12 @@ export fn main() void = { let n = 0; let lasttime = sdl2::SDL_GetTicks(); + let requested_chunks: []pos = []; + // in WORLD coords let mouse_pos: pos = (0,0); let mouse_down = false; - request_visible_chunks(pictures, conn, camera_pos); + request_visible_chunks(pictures, conn, camera_pos, &requested_chunks); for (!quit) { const did_move = do_movement(&camera_pos); @@ -106,8 +108,7 @@ export fn main() void = { if (did_move) { packet_reader::send(conn, camera_pos: packet_reader::packet_position)!; - request_visible_chunks(pictures, conn, camera_pos); - + request_visible_chunks(pictures, conn, camera_pos, &requested_chunks); }; const n = poll::poll(pollfd, poll::NONBLOCK)!; @@ -124,6 +125,17 @@ export fn main() void = { const pic = find_picture_for_chunkdata(camera_pos, packet.world_pos, pictures); pic.world_pos = packet.world_pos; pic.d[..len(packet.chunk_data)] = packet.chunk_data[..]; + + for (let i = 0z; i < len(requested_chunks); i += 1) { + const rc = requested_chunks[i]; + if (rc.0 == packet.world_pos.0 && rc.1 == packet.world_pos.1) { + delete(requested_chunks[i]); + fmt::printfln("fulfilling chunk request {},{}", + packet.world_pos.0, packet.world_pos.1)!; + break; + }; + }; + }; }; }; @@ -231,12 +243,26 @@ fn find_chunk(pictures: []drawing::picture, world_pos: pos) return null; }; -fn request_visible_chunks(pictures: []drawing::picture, conn: net::socket, camera_pos: pos) void = { +fn request_visible_chunks( + pictures: []drawing::picture, + conn: net::socket, + camera_pos: pos, + requested_chunks: *[]pos, +) void = { const x0 = CHUNKSIZE*floor_div(camera_pos.0,CHUNKSIZE); const y0 = CHUNKSIZE*floor_div(camera_pos.1,CHUNKSIZE); for (let dx = 0i32; dx < 3; dx += 1) for (let dy = 0i32; dy < 3; dy += 1) { let world_pos = (x0+CHUNKSIZE*dx, y0+CHUNKSIZE*dy): pos; + + for (const rc .. requested_chunks) { + if (rc.0 == world_pos.0 && rc.1 == world_pos.1) { + fmt::printfln("not requesting {},{} again", rc.0, rc.1)!; + return; + }; + }; + + if (!is_picture_visible(camera_pos, world_pos)) { // fmt::printfln("invisible {},{}", world_pos.0, world_pos.1)!; continue; @@ -249,6 +275,7 @@ fn request_visible_chunks(pictures: []drawing::picture, conn: net::socket, camer case null => fmt::printfln("\trequesting {},{}", world_pos.0, world_pos.1)!; packet_reader::send(conn, world_pos: packet_reader::packet_reqchunk)!; + append(requested_chunks, world_pos); }; }; }; |