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_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb");
|
|
|
|
.{new_surface, Color} := @use("../../render/src/lib.hb")
|
2024-11-11 15:48:43 -06:00
|
|
|
|
2024-11-13 11:03:31 -06:00
|
|
|
// ! in the future this should be safely handled
|
|
|
|
channel := @as(Channel, idk)
|
2024-11-11 15:48:43 -06:00
|
|
|
|
|
|
|
find_server := fn(): void {
|
2024-11-13 11:03:31 -06:00
|
|
|
log.info("client: locating server\0")
|
|
|
|
channel = await_channel()
|
|
|
|
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 {
|
|
|
|
log.info(string.display_int(@bitcast(response.header.kind), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 10))
|
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")
|
|
|
|
surface := new_surface(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
|
|
|
|
return .(windowdata.body, surface)
|
2024-11-11 15:48:43 -06:00
|
|
|
}
|
2024-11-10 19:03:01 -06:00
|
|
|
|
2024-11-11 15:48:43 -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-11 15:48:43 -06:00
|
|
|
}
|
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
|
2024-11-11 15:48:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
server_id := client.data.channel.server
|
|
|
|
client_id := client.data.channel.client
|
|
|
|
send_header(message.frame_ready, server_id)
|
|
|
|
response := await_message(uint, client_id)
|
|
|
|
if response.header.kind != message.ack {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info("client: recv ack\0")
|
|
|
|
// ! FOR NOW, server will ALWAYS be local,
|
|
|
|
// ! so we can send pointer to surface.
|
|
|
|
send_message(^Color, message.ack, client.surface.buf, server_id)
|
|
|
|
return true
|
2024-11-10 12:57:48 -06:00
|
|
|
}
|