.{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"); .{Surface, Color} := @use("../../render/src/lib.hb") // ! in the future this should be safely handled channel := Channel.(0, 0) find_server := fn(): void { log.info("client: locating server\0") channel2 := await_channel() channel.server = channel2.server channel.client = channel2.client log.info("client: server located\0") } new := fn(props: WindowProps): ?Window { send_header(message.syn, channel.server) response := await_message(Channel, channel.client) if response.header.kind != message.ack { return null } 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 := Surface.new(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y) return .(windowdata.body, surface) } quit := fn(client: Window): void { send_header(message.quit, client.data.channel.server) } connected := fn(client: Window): bool { return true } shutdown_server := fn(client: Window): bool { return false } update_props := fn(client: Window): bool { return false } update_permissions := fn(client: Window): bool { return false } send_frame := fn(client: Window): bool { send_header(message.frame_ready, client.data.channel.server) response := await_message(uint, client.data.channel.client) if response.header.kind != message.ack { return false } // ! FOR NOW, server will ALWAYS be local, // ! so we can send pointer to surface. send_message(^Color, message.ack, client.surface.buf, client.data.channel.server) return true }