From df26827a3f00d64f5af01271818c7c8bd7eaa387 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 5 Apr 2024 00:57:56 +0100 Subject: start of networking, and packet_reader --- client/drawing.ha | 35 +++++++++++++++++++++++++++++++---- client/main.ha | 2 ++ 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'client') diff --git a/client/drawing.ha b/client/drawing.ha index e164d33..2d093ae 100644 --- a/client/drawing.ha +++ b/client/drawing.ha @@ -1,5 +1,8 @@ use sdl2; use fmt; +use io; +use endian; +use math::random; // 2d position, x and y export type pos = (i32, i32); @@ -9,6 +12,9 @@ export type drawing_state = struct { drawing: bool, pos: pos, pictures: []picture, + + // hack. change this + conn: io::file, }; export type picture = struct { @@ -90,11 +96,32 @@ export fn circle(picture: *picture, c: pos, r: i32, color: u32) void = { }; }; + + export fn do_drawing(dstate: *drawing_state) void = { - if (dstate.drawing) for (let i = 0z; i < 4; i+=1) { - const pic = &dstate.pictures[i]; - const p = (dstate.pos.0 - pic.pos.0, dstate.pos.1 - pic.pos.1); - circle(pic, p, 20, 0xff0088); + if (dstate.drawing) { + for (let i = 0z; i < 4; i+=1) { + const pic = &dstate.pictures[i]; + const p = (dstate.pos.0 - pic.pos.0, dstate.pos.1 - pic.pos.1); + circle(pic, p, 20, 0xff0088); + }; + // hack, change this + // let buf: [8]u8 = [0...]; + // fmt::printfln("C {},{}",dstate.pos.0,dstate.pos.1)!; + // endian::leputu32(buf[0..4],dstate.pos.0: u32); + // endian::leputu32(buf[4..8],dstate.pos.1: u32); + // io::write(dstate.conn, buf)!; + + static let rand: u64 = 12345; + static let cur = 0; + let buf: [20]u8 = [0...]; + const n = random::u32n(&rand, 10) : int; + for (let i = 0; i < n; i += 1) { + buf[i] = (cur+i) : u8; + }; + cur += n; + fmt::println(n)!; + io::writeall(dstate.conn, buf[..n])!; }; }; diff --git a/client/main.ha b/client/main.ha index ba1736e..a0c25d8 100644 --- a/client/main.ha +++ b/client/main.ha @@ -1,6 +1,7 @@ use fmt; use sdl2; use math; +use net::dial; def CHUNKSIZE = 512; def NCHUNKS = 4; @@ -29,6 +30,7 @@ export fn main() void = { drawing = false, pos = (0,0), pictures = pictures, + conn = dial::dial("tcp","localhost:41460","unknown")!, }; let camera_pos: pos = (25, 50); -- cgit v1.2.3