ableos/sysdata/libraries/sunset_proto/src/lib.hb

94 lines
2.1 KiB
Plaintext
Raw Normal View History

.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb");
2024-11-10 12:57:48 -06:00
.{Surface} := @use("../../render/src/lib.hb")
2024-11-13 11:03:31 -06:00
$BUFFER_SERVER := "sunset_server\0"
$BUFFER_CLIENT := "sunset_client\0"
Channel := packed struct {
client: uint,
server: uint,
}
2024-11-10 12:57:48 -06:00
client := @use("./client.hb")
server := @use("./server.hb")
message := @use("./message.hb")
2024-11-13 11:03:31 -06:00
permissions := @use("./permissions.hb")
$send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void {
buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg)))
}
$send_header := fn(kind: uint, buffer_id: uint): void {
buffer.write(?MessageHeader, buffer_id, &@as(?MessageHeader, .(kind)))
}
2024-11-10 12:57:48 -06:00
2024-11-13 11:03:31 -06:00
$recv_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null)
buffer.recv(?Message(Expr), buffer_id, &response)
return response
}
2024-11-13 11:03:31 -06:00
$recv_header := fn(buffer_id: uint): ?MessageHeader {
response := @as(?MessageHeader, null)
buffer.recv(?MessageHeader, buffer_id, &response)
return response
}
await_channel := fn(channel: Channel): Channel {
loop if channel.server != 0 break else {
channel.server = buffer.search(BUFFER_SERVER)
2024-11-13 11:03:31 -06:00
}
loop if channel.client != 0 break else {
channel.client = buffer.search(BUFFER_CLIENT)
2024-11-13 11:03:31 -06:00
}
return channel
}
2024-11-13 11:03:31 -06:00
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null)
loop {
2024-11-13 11:03:31 -06:00
buffer.recv(?Message(Expr), buffer_id, &response)
if response != null {
2024-11-13 11:03:31 -06:00
return @as(Message(Expr), response)
}
}
}
await_header := fn(buffer_id: uint): MessageHeader {
response := @as(?MessageHeader, null)
loop {
buffer.recv(?MessageHeader, buffer_id, &response)
if response != null {
return @as(?MessageHeader, response)
}
}
}
2024-11-10 19:03:01 -06:00
MessageHeader := packed struct {
kind: uint,
2024-11-13 11:03:31 -06:00
}
Message := fn($Expr: type): type {
return packed struct {
header: MessageHeader,
body: Expr,
}
2024-11-10 12:57:48 -06:00
}
WindowProps := struct {
position: Vec2(uint),
dimensions: Vec2(uint),
// ! 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-13 11:03:31 -06:00
channel: Channel,
permissions: 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,
}