aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-27 21:27:12 +0100
committerubq323 <ubq323@ubq323.website>2024-04-27 21:27:17 +0100
commit907cda4c172936c6d5b7ea2ac1a3a0986c875853 (patch)
tree46020134dd1b8c3434fde07ab6cf9346391bf70b /client
parent4c7156d0b20447e29f354679acdcd28480df91bc (diff)
use poll to check writing as well as reading; packet_reader handles both now
Diffstat (limited to 'client')
-rw-r--r--client/main.ha20
-rw-r--r--client/pictures.ha4
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);
};
};