2024-11-11 15:48:43 -06:00
|
|
|
.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb");
|
2024-11-10 12:57:48 -06:00
|
|
|
.{Surface} := @use("../../render/src/lib.hb")
|
|
|
|
|
|
|
|
$BUFFER := "sunset\0"
|
|
|
|
|
|
|
|
client := @use("./client.hb")
|
|
|
|
server := @use("./server.hb")
|
|
|
|
message := @use("./message.hb")
|
|
|
|
|
2024-11-11 15:48:43 -06:00
|
|
|
receive_message := fn($Expr: type, buffer_id: uint): ?Expr {
|
|
|
|
recv := @as(?Expr, null)
|
2024-11-12 14:14:37 -06:00
|
|
|
buffer.recv(?Expr, buffer_id, &recv)
|
2024-11-11 15:48:43 -06:00
|
|
|
return recv
|
|
|
|
}
|
|
|
|
|
|
|
|
send_message := fn($Expr: type, msg: Expr, buffer_id: uint): void {
|
2024-11-12 14:14:37 -06:00
|
|
|
buffer.write(?Expr, buffer_id, &@as(?Expr, msg))
|
2024-11-11 15:48:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
await_buffer := fn(name: ^u8): uint {
|
|
|
|
id := 0
|
|
|
|
loop if id != 0 return id else id = buffer.search(BUFFER)
|
|
|
|
}
|
|
|
|
|
|
|
|
await_message := fn($Expr: type, buffer_id: uint): Expr {
|
|
|
|
response := @as(?Expr, null)
|
|
|
|
loop {
|
2024-11-12 14:14:37 -06:00
|
|
|
buffer.recv(?Expr, buffer_id, &response)
|
2024-11-11 15:48:43 -06:00
|
|
|
if response != null {
|
|
|
|
i := 0
|
|
|
|
return @as(Expr, response)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ! we need a better message format but this will do for now.
|
|
|
|
// enums would be nice
|
2024-11-10 19:03:01 -06:00
|
|
|
MessageHeader := packed struct {
|
|
|
|
kind: uint,
|
|
|
|
data: uint,
|
2024-11-10 12:57:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowProps := struct {
|
|
|
|
position: Vec2(uint),
|
|
|
|
dimensions: Vec2(uint),
|
2024-11-11 15:48:43 -06:00
|
|
|
// ! replace with owned string type later
|
2024-11-10 12:57:48 -06:00
|
|
|
title: ^u8,
|
|
|
|
}
|
|
|
|
|
2024-11-10 19:03:01 -06:00
|
|
|
WindowData := struct {
|
2024-11-10 12:57:48 -06:00
|
|
|
props: WindowProps,
|
2024-11-10 19:03:01 -06:00
|
|
|
buffer_id: uint,
|
2024-11-10 12:57:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Window := struct {
|
2024-11-10 19:03:01 -06:00
|
|
|
data: WindowData,
|
2024-11-10 12:57:48 -06:00
|
|
|
surface: Surface,
|
|
|
|
}
|