1
0
Fork 0
forked from AbleOS/ableos

intouch optimisation & new render example using intouch features

This commit is contained in:
koniifer 2025-02-09 01:25:05 +00:00
parent ffee890842
commit 89e5e2c0ad
6 changed files with 68 additions and 27 deletions
sysdata
libraries/intouch/src
programs
render_example/src
test/src/tests/stn
system_config.toml

View file

@ -2,17 +2,17 @@ keycodes := @use("keycodes.hb");
.{KeyCode} := keycodes
KeyEvent := packed struct {
up: bool,
just_triggered: bool,
key: KeyCode,
up: bool = false,
just_triggered: bool = false,
key: KeyCode = 0,
}
MouseEvent := packed struct {
x_change: i8,
y_change: i8,
left: bool,
middle: bool,
right: bool,
x_change: i8 = 0,
y_change: i8 = 0,
left: bool = false,
middle: bool = false,
right: bool = false,
}
GamepadEvent := struct {}

View file

@ -5,15 +5,19 @@ keycodes := @use("keycodes.hb")
events := @use("events.hb");
.{KeyEvent, MouseEvent} := events
recieve_key_event := fn(): ?KeyEvent {
kevent := KeyEvent.(false, false, 0)
key_buf := 0
mouse_buf := 0
buf_id := buffer.search("PS/2 Keyboard")
recieve_key_event := fn(): ?KeyEvent {
kevent := KeyEvent.{}
if key_buf == 0 key_buf = buffer.search("PS/2 Keyboard")
if key_buf == 0 return null
// Read out of the Keyboard buffer here
buffer.recv(KeyEvent, buf_id, &kevent)
buffer.recv(KeyEvent, key_buf, &kevent)
if kevent.just_triggered {
if kevent != .{} {
return kevent
}
@ -21,14 +25,15 @@ recieve_key_event := fn(): ?KeyEvent {
}
recieve_mouse_event := fn(): ?MouseEvent {
mevent := MouseEvent.(0, 0, false, false, false)
mevent := MouseEvent.{}
buf_id := buffer.search("PS/2 Mouse")
if mouse_buf == 0 mouse_buf = buffer.search("PS/2 Mouse")
if mouse_buf == 0 return null
// Read out of the Mouse buffer here
buffer.recv(MouseEvent, buf_id, &mevent)
buffer.recv(MouseEvent, mouse_buf, &mevent)
if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right {
if mevent != .{} {
return mevent
}

View file

@ -0,0 +1,38 @@
intouch := @use("lib:intouch")
render := @use("lib:render")
stn := @use("stn")
example := fn(): void {
screen := render.init(true)
mouse_pos := stn.math.Vec2(int).(0, 0)
prev_pos := mouse_pos
bg_colour := render.BLACK
pen_colour := render.WHITE
loop {
mouse := intouch.recieve_mouse_event()
if mouse != null {
mouse_pos.x = stn.math.clamp(int, mouse_pos.x + mouse.x_change, 10, @bitcast(screen.width) - 10)
mouse_pos.y = stn.math.clamp(int, mouse_pos.y - mouse.y_change, 10, @bitcast(screen.height) - 10)
prev_pos = mouse_pos
if mouse.left {
screen.put_filled_circle(@bitcast(mouse_pos), 10, pen_colour)
} else if mouse.right {
screen.put_filled_circle(@bitcast(mouse_pos), 10, bg_colour)
} else if mouse.middle {
pen_colour = stn.random.any(render.Color)
}
}
kb := intouch.recieve_key_event()
if kb != null {
if kb.just_triggered {
bg_colour = stn.random.any(render.Color)
screen.clear(bg_colour)
}
}
screen.sync()
}
}

View file

@ -1 +1 @@
.{example: main} := @use("./examples/mandelbrot.hb")
.{example: main} := @use("./examples/intouch.hb")

View file

@ -5,13 +5,11 @@
* assume that `*a` never changes (program doesnt work otherwise)
* (this is a reason why memory sharing is bad)
*/
opaque := fn(ptr: ^bool): bool {
return *ptr
}
// axe := @embed("assets/lily.axe")
test := fn(): uint {
// causes segfault on fakern due to hblang soundness :thumbsup:
// process.spawn(@bitcast(&axe), @sizeof(@TypeOf(axe)))
a: ^bool = @bitcast(memory.request_page(1, true))
@ -22,8 +20,8 @@ test := fn(): uint {
if x == 0 {
// ! NOTE: NEVER DO THIS!!! USE BUFFERS INSTEAD!!! :)
// acts as a lock. when parent is done, this can go ahead.
loop if opaque(a) break else {
}
loop if *a break else {
};
log.info("child done.")
} else {
*a = true

View file

@ -23,8 +23,8 @@ resolution = "1024x768x24"
[boot.limine.ableos.modules]
# [boot.limine.ableos.modules.render_example]
# path = "boot:///render_example.hbf"
[boot.limine.ableos.modules.render_example]
path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.sunset_server]
# path = "boot:///sunset_server.hbf"
@ -50,8 +50,8 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.angels_halo]
# path = "boot:///angels_halo.hbf"
[boot.limine.ableos.modules.test]
path = "boot:///test.hbf"
# [boot.limine.ableos.modules.test]
# path = "boot:///test.hbf"
# [boot.limine.ableos.modules.vfsaur]
# path = "boot:///vfsaur.hbf"