From 79a9af88e53a6b0f7070a5fe97bbd399d139d00d Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 10 Apr 2024 23:03:50 +0100 Subject: the PAINT is now MULTIPLAYER !!!!! --- client/main.ha | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'client/main.ha') diff --git a/client/main.ha b/client/main.ha index 6c9208a..542c8f9 100644 --- a/client/main.ha +++ b/client/main.ha @@ -6,6 +6,8 @@ use net::dial; use drawing; use drawing::{pos}; use client::paintui; +use unix::poll; +use packet_reader; def CHUNKSIZE = 512; def NCHUNKS = 4; @@ -43,7 +45,10 @@ export fn main() void = { case let err: net::error => fmt::fatal("couldn't connect to server:",net::strerror(err)); }; - + const pollfd: [1]poll::pollfd = [ poll::pollfd { + fd = conn, events=poll::event::POLLIN, revents = 0 + }]; + const packet_reader = packet_reader::new(); // paintui state let pstate = paintui::state { ... }; @@ -84,6 +89,17 @@ export fn main() void = { drawing::send_op(conn, op)!; }; + const n = poll::poll(pollfd, poll::NONBLOCK)!; + if (n > 0) { + fmt::println("data available")!; + packet_reader::read(&packet_reader, conn)!; + for (const packet_bytes => packet_reader::next(&packet_reader)) { + const op = drawing::deser_op(packet_bytes); + drawing::perform(pictures, op); + }; + }; + + for (let i = 0z; i < len(pictures); i += 1) { const psurf = picture_surfaces[i]; const pic = &pictures[i]; -- cgit v1.2.3