diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/main.ha | 20 | ||||
-rw-r--r-- | client/pictures.ha | 4 |
2 files changed, 14 insertions, 10 deletions
diff --git a/client/main.ha b/client/main.ha index 081c422..30a8341 100644 --- a/client/main.ha +++ b/client/main.ha @@ -47,9 +47,11 @@ export fn main() void = { }; const pollfd: [1]poll::pollfd = [ poll::pollfd { - fd = conn, events=poll::event::POLLIN, revents = 0 + fd = conn, + events=poll::event::POLLIN | poll::event::POLLOUT, + ... }]; - const packet_reader = packet_reader::new(); + const packet_reader = packet_reader::new(conn); // paintui state let pstate = paintui::state { size_idx = 4, ... }; @@ -64,7 +66,7 @@ export fn main() void = { let mouse_down = false; - process_chunk_loadedness(&pmgr, conn, camera_pos); + process_chunk_loadedness(&pmgr, &packet_reader, camera_pos); const win_pic = picture_from_surface(wsurf, (9,9)); for (!quit) { @@ -108,18 +110,20 @@ export fn main() void = { case void => yield; case let op: drawing::op => perform_drawop(&pmgr, op); - packet_reader::send(conn, op: packet_reader::packet_drawop)!; + packet_reader::write(&packet_reader, op: packet_reader::packet_drawop)!; }; if (did_move) { - packet_reader::send(conn, camera_pos: packet_reader::packet_position)!; - process_chunk_loadedness(&pmgr, conn, camera_pos); + packet_reader::write(&packet_reader, camera_pos: packet_reader::packet_position)!; + process_chunk_loadedness(&pmgr, &packet_reader, camera_pos); }; const n = poll::poll(pollfd, poll::NONBLOCK)!; if (n > 0) { - packet_reader::read(&packet_reader, conn)!; - for (true) match (packet_reader::next(&packet_reader)) { + const should_read = 0 != pollfd[0].revents & poll::event::POLLIN; + const should_write = 0 != pollfd[0].revents & poll::event::POLLOUT; + packet_reader::service(&packet_reader, should_read, should_write)!; + for (true) match (packet_reader::read_next(&packet_reader)) { case done => break; case let e: packet_reader::error => fmt::fatalf("death: packet_reader: {}", e); diff --git a/client/pictures.ha b/client/pictures.ha index ce6c600..0ae17d6 100644 --- a/client/pictures.ha +++ b/client/pictures.ha @@ -92,7 +92,7 @@ fn is_request_inflight(pmgr: *picture_mgr, world_pos: pos) bool = { // request it. fn process_chunk_loadedness( pmgr: *picture_mgr, - conn: net::socket, + pr: *packet_reader::packet_reader, camera_pos: pos, ) void = { @@ -133,7 +133,7 @@ fn process_chunk_loadedness( }; fmt::printfln("!! requesting {},{}", world_pos.0, world_pos.1)!; - packet_reader::send(conn, world_pos: packet_reader::packet_reqchunk)!; + packet_reader::write(pr, world_pos: packet_reader::packet_reqchunk)!; append(pmgr.requests, world_pos); }; }; |