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

63 lines
1.9 KiB
Plaintext
Raw Normal View History

2024-11-13 11:03:31 -06:00
.{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb");
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb");
2024-12-14 10:39:45 -06:00
.{Surface, Color} := @use("../../render/src/lib.hb")
2024-11-13 11:03:31 -06:00
// ! in the future this should be safely handled
channel := Channel.(0, 0)
find_server := fn(): void {
2024-11-13 11:03:31 -06:00
log.info("client: locating server\0")
2024-11-14 15:28:21 -06:00
channel2 := await_channel()
channel.server = channel2.server
channel.client = channel2.client
2024-11-13 11:03:31 -06:00
log.info("client: server located\0")
2024-11-10 12:57:48 -06:00
}
2024-11-10 19:03:01 -06:00
new := fn(props: WindowProps): ?Window {
2024-11-13 11:03:31 -06:00
send_header(message.syn, channel.server)
response := await_message(Channel, channel.client)
if response.header.kind != message.ack {
2024-11-10 19:03:01 -06:00
return null
2024-11-10 12:57:48 -06:00
}
2024-11-13 11:03:31 -06:00
log.info("client: recv ack\0")
send_message(WindowProps, message.props, props, response.body.server)
windowdata := await_message(WindowData, response.body.client)
if windowdata.header.kind != message.ack {
return null
}
log.info("client: recv windowdata\0")
2024-12-14 10:39:45 -06:00
surface := Surface.new(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
2024-11-13 11:03:31 -06:00
return .(windowdata.body, surface)
}
2024-11-10 19:03:01 -06:00
quit := fn(client: Window): void {
2024-11-13 11:03:31 -06:00
send_header(message.quit, client.data.channel.server)
}
2024-11-10 19:03:01 -06:00
2024-11-13 11:03:31 -06:00
connected := fn(client: Window): bool {
return true
}
shutdown_server := fn(client: Window): bool {
return false
}
update_props := fn(client: Window): bool {
return false
}
2024-11-13 11:03:31 -06:00
update_permissions := fn(client: Window): bool {
return false
}
send_frame := fn(client: Window): bool {
2024-11-14 15:28:21 -06:00
send_header(message.frame_ready, client.data.channel.server)
response := await_message(uint, client.data.channel.client)
2024-11-13 11:03:31 -06:00
if response.header.kind != message.ack {
return false
}
// ! FOR NOW, server will ALWAYS be local,
// ! so we can send pointer to surface.
2024-11-14 15:28:21 -06:00
send_message(^Color, message.ack, client.surface.buf, client.data.channel.server)
return true
2024-11-10 12:57:48 -06:00
}