1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/libraries/sunset_proto/src/client.hb

59 lines
1.9 KiB
Plaintext
Raw Normal View History

2024-11-10 12:57:48 -06:00
.{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb");
.{Window, WindowData, WindowProps, MessageHeader, send_message, message, await_buffer, await_message, BUFFER} := @use("./lib.hb")
render := @use("../../render/src/lib.hb")
server_id := @as(uint, idk)
screen := @as(render.Surface, idk)
find_server := fn(): void {
// ! to be removed in the future
screen = render.init(false)
render.clear(screen, render.black)
log.debug("client: waiting for server\0")
server_id = await_buffer(BUFFER)
log.debug("client: found server\0")
2024-11-10 12:57:48 -06:00
}
2024-11-10 19:03:01 -06:00
new := fn(props: WindowProps): ?Window {
send_message(MessageHeader, .(message.syn, 0), server_id)
log.debug("client: sent syn\0")
response := await_message(MessageHeader, server_id)
2024-11-10 19:03:01 -06:00
if response.kind != message.ack {
log.error("client: refused syn\0")
2024-11-10 19:03:01 -06:00
return null
2024-11-10 12:57:48 -06:00
}
log.debug("client: got ack\0")
2024-11-10 12:57:48 -06:00
2024-11-10 19:03:01 -06:00
buffer_id := response.data
send_message(WindowProps, props, buffer_id)
log.debug("client: sent props\0")
response2 := await_message(WindowData, buffer_id)
log.debug("client: got window data\0")
surface := render.new_surface(
response2.props.dimensions.x,
response2.props.dimensions.y,
)
return .(response2, surface)
}
2024-11-10 19:03:01 -06:00
// ! client buffers are not being read by the server yet
quit := fn(client: Window): void {
send_message(MessageHeader, .(message.quit, 0), client.data.buffer_id)
}
2024-11-10 19:03:01 -06:00
shutdown_server := fn(): void {
send_message(MessageHeader, .(message.shutdown, 0), server_id)
}
update_props := fn(client: Window): bool {
log.error("client: update props unimplemented\0")
return false
}
//! temporarily just throw our window at the screen
frame_ready := fn(client: Window): void {
send_message(MessageHeader, .(message.ready, 0), client.data.buffer_id)
log.warn("client: we are blitting to screen from the client\n\r this is temporary behaviour\0")
render.put_surface(screen, client.surface, client.data.props.position, false)
2024-11-10 12:57:48 -06:00
}