.{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") } 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) if response.kind != message.ack { log.error("client: refused syn\0") return null } log.debug("client: got ack\0") 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) } // ! 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) } 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) }