ableos/sysdata/libraries/sunset_proto/src/client.hb
2024-11-10 18:57:48 +00:00

62 lines
1.9 KiB
Plaintext

.{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb");
.{Surface, new_surface} := @use("../../render/src/lib.hb");
.{WindowWrapper, WindowID, WindowProps, WindowMessage, message, BUFFER} := @use("./lib.hb")
buffer_id := @as(?uint, null)
new_window := fn(props: WindowProps): ?WindowWrapper {
if buffer_id == null {
log.error("client: (request_new) buffer id is null. did you init the client?\0")
return null
}
buf := memory.uninit(?WindowWrapper)
buffer.write(WindowMessage, &.(message.new, 0, @sizeof(WindowProps), @bitcast(&props), @bitcast(&buf)), @unwrap(buffer_id))
loop if memory.is_uninit(?WindowWrapper, &buf) == false break else {
}
// loop until i write a better socket
i := 0
loop if i >= 1000 break else i += 1
return buf
}
update_window_props := fn(wrapper: WindowWrapper): ?WindowProps {
log.error("todo: sunset_proto/src/client/update_window_props.hb\0")
if buffer_id == null {
log.error("client: (request_update_properties) buffer id is null. did you init the client?\0")
return null
}
// TODO: buffer.write(WINDOWING_BUFFER, update properties) request
return null
}
request_shutdown := fn(): ?bool {
if buffer_id == null {
log.error("client: (request_shutdown) buffer id is null. did you init the client?\0")
return null
}
buf := memory.uninit(?u8)
buffer.write(WindowMessage, &.(message.shutdown, 0, 0, memory.dangling(u8), @bitcast(&buf)), @unwrap(buffer_id))
loop if memory.is_uninit(?u8, &buf) == false break else {
}
// loop until i write a better socket
i := 0
loop if i >= 1000 break else i += 1
// had to do ?u8 here, ?bool didnt work
if buf == null | @unwrap(buf) != 255 {
return false
} else {
return true
}
}
init := fn(): void {
log.info("client: waiting for server\0")
id := 0
loop if id != 0 {
buffer_id = id
log.info("client: done waiting\0")
return
} else {
id = buffer.search(BUFFER)
}
}