From 986077435fb0b278c02945d47d7a5bec8fe277e7 Mon Sep 17 00:00:00 2001 From: koniifer Date: Thu, 26 Dec 2024 00:38:46 +0000 Subject: [PATCH] (sunset) fix mouse cursor and one multi-program crash bug --- Cargo.lock | 6 +-- kernel/src/holeybytes/mem.rs | 6 +-- sysdata/libraries/stn/src/buffer.hb | 4 +- sysdata/libraries/stn/src/math.hb | 3 ++ sysdata/libraries/sunset_proto/src/server.hb | 3 +- sysdata/programs/sunset_server/src/main.hb | 52 ++++++-------------- sysdata/system_config.toml | 4 +- 7 files changed, 28 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33bd358..3924f4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#3491814b4f1723e6b1f3ae485ed5d3b5cad16df0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#3491814b4f1723e6b1f3ae485ed5d3b5cad16df0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#3491814b4f1723e6b1f3ae485ed5d3b5cad16df0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5" dependencies = [ "hbbytecode", ] diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index a8f4495..2bd591a 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -61,8 +61,8 @@ impl hbvm::mem::Memory for Memory { #[inline(always)] fn log_instr(&mut self, at: Address, regs: &[hbvm::value::Value]) { - //log::debug!("exec: [{:02x}] {}", at.get(), unsafe { - // self.logger.display_instr(at, regs) - //}); + log::debug!("exec: [{:02x}] {}", at.get(), unsafe { + self.logger.display_instr(at, regs) + }); } } diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 346ca0b..dd5315c 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,5 +1,3 @@ -string := @use("string.hb") - $await := fn(buffer_id: uint): void { return @eca(7, buffer_id) } @@ -30,7 +28,7 @@ $create_nameless := fn(): uint { return @eca(1, 0) } -$delete_buffer := fn(buffer_id: uint): void { +$delete := fn(buffer_id: uint): void { return @eca(2, buffer_id) } diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index 2422575..e1db685 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -26,6 +26,9 @@ $max := fn($T: type, a: T, b: T): T { return @itf(a > b) * a + @itf(a <= b) * b } } +$clamp := fn($T: type, x: T, minimum: T, maximum: T): T { + return max(T, min(T, x, maximum), minimum) +} $sign := fn($T: type, x: T): i8 { if signed_int(T) { return @intcast(x >> @sizeof(T) * 8 - 1) | x != 0 diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index c082410..84b46a5 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -100,7 +100,8 @@ collect_frames := fn(): void { send_header(message.ack, window.data.channel.client) ptr := await_message(^Color, window.data.channel.server) if ptr.header.kind != message.ack { - return + i += 1 + continue } window.surface.put_surface( Surface.( diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index cbab955..5902c0f 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -6,14 +6,14 @@ horizon_api := @use("lib:horizon_api"); .{set_color, render_label_to_surface, Label} := horizon_api.widgets.label stn := @use("stn"); -.{Vec2} := stn.math +.{Vec2, clamp} := stn.math psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf") img := @embed("sysdata:assets/wallpaper.qoi") Mouse := struct { - x: uint, - y: uint, + x: int, + y: int, // TODO: Make this configurable via wm config cursor_width: u8, @@ -24,7 +24,7 @@ Mouse := struct { center_x := max_x / 2 center_y := max_y / 2 - return Self.(center_x, center_y, 3, max_x, max_y) + return Self.(@bitcast(center_x), @bitcast(center_y), 3, max_x, max_y) } /* center := fn(self: Self){ @@ -63,51 +63,26 @@ main := fn(): int { loop { mouse_event := intouch.recieve_mouse_event() if mouse_event != null { - change_x := @as(i16, mouse_event.x_change) - change_x = change_x << 8 - change_x = change_x >> 8 - - mouse.x += change_x - if mouse.x <= 0 { - mouse.x = 0 - } - if mouse.x >= screen.width - 20 { - mouse.x = @intcast(screen.width - 21) - } - - change_y := @as(i16, mouse_event.y_change) - change_y = change_y << 8 - change_y = change_y >> 8 - - mouse.y -= change_y - if mouse.y < 0 { - mouse.y = 1 - } - if mouse.y >= screen.height - 20 { - mouse.y = @intcast(screen.height - 21) - } + mouse.x = clamp(int, mouse.x + mouse_event.x_change, mouse.cursor_width, @bitcast(screen.width - mouse.cursor_width)) + mouse.y = clamp(int, mouse.y - mouse_event.y_change, mouse.cursor_width, @bitcast(screen.height - mouse.cursor_width)) if mouse_event.left { text_label.set_label_text("LEFT CLICK") - } - if mouse_event.middle { + } else if mouse_event.middle { text_label.set_label_text("MIDDLE CLICK") - } - if mouse_event.right { + } else if mouse_event.right { text_label.set_label_text("RIGHT CLICK") } } { - screen.clear(render.BLACK) screen.put_surface(wallpaper, .(0, 0), false) screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR) } - if sunset.server.incoming() { - sunset.server.collect_frames() - sunset.server.render_clients(screen) - } + _ = sunset.server.incoming() + sunset.server.collect_frames() + sunset.server.render_clients(screen) { /* Omnibar */ @@ -119,8 +94,9 @@ main := fn(): int { // Mouse cursor { - screen.put_filled_circle(.(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER) - screen.put_circle(.(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR) + p := Vec2(uint).(@bitcast(mouse.x), @bitcast(mouse.y)) + screen.put_filled_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER) + screen.put_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR) } screen.sync() diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index a9ae4e1..c12372c 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -38,8 +38,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.ps2_driver] # path = "boot:///ps2_driver.hbf" -# [boot.limine.ableos.modules.sunset_client_2] -# path = "boot:///sunset_client_2.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" # [boot.limine.ableos.modules.ablefetch] # path = "boot:///ablefetch.hbf"