diff options
author | ubq323 <ubq323@ubq323.website> | 2024-04-05 00:57:56 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-04-05 00:57:56 +0100 |
commit | df26827a3f00d64f5af01271818c7c8bd7eaa387 (patch) | |
tree | 3e628dad40d74be0e331edb98454394d474ff412 /client | |
parent | 1762e9f622c7a9045e6ea23a92a81d7dfa5dadda (diff) |
start of networking, and packet_reader
Diffstat (limited to 'client')
-rw-r--r-- | client/drawing.ha | 35 | ||||
-rw-r--r-- | client/main.ha | 2 |
2 files changed, 33 insertions, 4 deletions
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); |