forked from AbleOS/ableos
math changes & compiler update
This commit is contained in:
parent
5cb3b956d9
commit
98c3fa059f
|
@ -38,9 +38,9 @@ Label := struct {
|
|||
}
|
||||
|
||||
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
||||
// if label.is_dirty {
|
||||
// render.clear(label.surface, label.bg)
|
||||
// render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
|
||||
// }
|
||||
// render.put_surface(surface, label.surface, pos, false)
|
||||
if label.is_dirty {
|
||||
label.surface.clear(label.bg)
|
||||
label.surface.put_text(font, .(0, 0), label.fg, label.text)
|
||||
}
|
||||
surface.put_surface(label.surface, pos, false)
|
||||
}
|
|
@ -33,7 +33,6 @@ $sign := fn($T: type, x: T): i8 {
|
|||
sign_bit := @as(float_bytes(T), @bitcast(x)) >> @sizeof(T) * 8 - 1
|
||||
return (1 - 2 * @intcast(sign_bit)) * (x != 0)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
log := fn($T: type, base: T, x: T): T {
|
||||
if integer(T) {
|
||||
|
@ -47,6 +46,19 @@ log := fn($T: type, base: T, x: T): T {
|
|||
return ln(T, x) / ln(T, base)
|
||||
}
|
||||
}
|
||||
pow := fn($T: type, base: T, x: T): T {
|
||||
if integer(T) {
|
||||
result := base
|
||||
i := 1
|
||||
loop if i == x break else {
|
||||
result *= x
|
||||
i += 1
|
||||
}
|
||||
return result
|
||||
} else if float(T) {
|
||||
return exp(T, x * ln(T, base))
|
||||
}
|
||||
}
|
||||
$lerp := fn($T: type, v0: T, v1: T, t: T): T {
|
||||
if float(T) {
|
||||
return v0 + t * (v1 - v0)
|
||||
|
@ -90,19 +102,29 @@ tan := fn(theta: f32): f32 {
|
|||
|
||||
exp := fn($T: type, x: T): T {
|
||||
if float(T) {
|
||||
result := @as(T, 1.0)
|
||||
if x == 0.0 return 1.0
|
||||
if x > 709.0 return 100000000000000000000000.0
|
||||
if x < -709.0 return 0.0
|
||||
|
||||
sum := @as(T, 1.0)
|
||||
term := @as(T, 1.0)
|
||||
c := @as(T, 0.0)
|
||||
|
||||
n := @as(int, 1)
|
||||
|
||||
loop if n == 20 break else {
|
||||
prev_term := term
|
||||
term = term * x / @itf(n)
|
||||
result += term
|
||||
|
||||
if abs(T, term) < 0.0000000001 break
|
||||
y := term - c
|
||||
t := sum + y
|
||||
c = t - sum - y
|
||||
sum = t
|
||||
|
||||
if abs(T, term) < 0.00000000000001 * abs(T, sum) break
|
||||
n += 1
|
||||
}
|
||||
|
||||
return result
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,32 +135,33 @@ ln := fn($T: type, x: T): T {
|
|||
if x == E return 1.0
|
||||
|
||||
scale := @as(T, 0.0)
|
||||
scaled_x := x
|
||||
|
||||
if scaled_x > 2.0 {
|
||||
loop if scaled_x <= 2.0 break else {
|
||||
scaled_x = scaled_x / E
|
||||
if x > 2.0 {
|
||||
loop if x <= 2.0 break else {
|
||||
x /= E
|
||||
scale += 1.0
|
||||
}
|
||||
} else if scaled_x < 1.0 {
|
||||
loop if scaled_x >= 1.0 {
|
||||
scaled_x = scaled_x * E
|
||||
} else if x < 1.0 {
|
||||
loop if x >= 1.0 break else {
|
||||
x *= E
|
||||
scale -= 1.0
|
||||
}
|
||||
}
|
||||
|
||||
guess := (scaled_x - 1.0) / (scaled_x + 1.0)
|
||||
y := x - 1.0
|
||||
z := y / (x + 1.0)
|
||||
z2 := z * z
|
||||
|
||||
guess := z * (1.0 + z2 * (1.0 / 3.0 + z2 * (1.0 / 5.0 + z2 * 1.0 / 7.0)))
|
||||
|
||||
max_iter := 30
|
||||
i := 0
|
||||
loop if i == max_iter break else {
|
||||
exp_g := exp(T, guess)
|
||||
f := exp_g - scaled_x
|
||||
f_prime := exp_g
|
||||
loop if i == 10 break else {
|
||||
exp_val := exp(T, guess)
|
||||
f := exp_val - x
|
||||
f_prime := exp_val
|
||||
|
||||
delta := f / (f_prime * (1.0 - 0.5 * f * f_prime / (f_prime * f_prime)))
|
||||
|
||||
guess = guess - delta
|
||||
guess -= delta
|
||||
|
||||
if abs(T, delta) < 0.0000000001 break
|
||||
i += 1
|
||||
|
|
|
@ -31,23 +31,12 @@ main := fn(): void {
|
|||
pos1 := Vec2(uint).(1, 1)
|
||||
pos2 := Vec2(uint).(1, 20)
|
||||
pos3 := Vec2(uint).(1, 40)
|
||||
// render.clear(window.surface, render.black)
|
||||
|
||||
render_label_to_surface(window.surface, text_label, font, pos1)
|
||||
render_label_to_surface(window.surface, text_label_2, font, pos2)
|
||||
render_label_to_surface(window.surface, text_label_3, font, pos3)
|
||||
loop {
|
||||
render.clear(window.surface, render.BLACK)
|
||||
// render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 40), false)
|
||||
pos := Vec2(uint).(1, 100)
|
||||
|
||||
render_label_to_surface(window.surface, text_label, font, pos)
|
||||
pos = Vec2(uint).(1, 120)
|
||||
|
||||
render_label_to_surface(window.surface, text_label_2, font, pos)
|
||||
|
||||
pos = Vec2(uint).(1, 140)
|
||||
render_label_to_surface(window.surface, text_label_3, font, pos)
|
||||
|
||||
// stn.log.info("AAAA\0")
|
||||
_ = sunset.client.send_frame(window)
|
||||
// stn.sleep.sleep_until_interrupt(100)
|
||||
}
|
||||
|
|
|
@ -3,30 +3,25 @@ sunset := @use("lib:sunset_proto");
|
|||
.{math, log} := @use("stn")
|
||||
|
||||
// full mandelbrot
|
||||
$X_MIN := -2.0
|
||||
$X_MAX := 0.47
|
||||
$Y_MIN := -1.12
|
||||
$Y_MAX := 1.12
|
||||
// $X_MIN := -2.0
|
||||
// $X_MAX := 0.47
|
||||
// $Y_MIN := -1.12
|
||||
// $Y_MAX := 1.12
|
||||
|
||||
// a minibrot
|
||||
// $X_MIN := -0.94
|
||||
// $X_MAX := -0.93
|
||||
// $Y_MIN := 0.31
|
||||
// $Y_MAX := 0.306
|
||||
$X_MIN := -0.94
|
||||
$X_MAX := -0.93
|
||||
$Y_MIN := 0.31
|
||||
$Y_MAX := 0.306
|
||||
|
||||
$MAX_ITERATION := 300
|
||||
|
||||
$USE_SUNSET := false
|
||||
$USE_SUNSET := true
|
||||
|
||||
palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
|
||||
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
|
||||
|
||||
example := fn(): void {
|
||||
z := math.log(f32, 10.0, 100.0)
|
||||
z2 := math.sign(f32, 10.0)
|
||||
z = math.min(f32, 10.0, 100.0)
|
||||
z = math.max(f32, 10.0, 100.0)
|
||||
|
||||
screen := @as(render.Surface, idk)
|
||||
window := @as(?sunset.Window, null)
|
||||
if USE_SUNSET {
|
||||
|
@ -91,4 +86,7 @@ example := fn(): void {
|
|||
_ = sunset.client.send_frame(window)
|
||||
}
|
||||
}
|
||||
if USE_SUNSET loop {
|
||||
_ = sunset.client.send_frame(window)
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
||||
sunset := @use("lib:sunset_proto")
|
||||
render := @use("lib:render")
|
||||
intouch := @use("lib:intouch")
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
horizon_api := @use("lib:horizon_api");
|
||||
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
||||
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{Vec2} := stn.math
|
||||
|
||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("../../../assets/wallpaper.qoi")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("sysdata:assets/wallpaper.qoi")
|
||||
|
||||
Mouse := struct {
|
||||
x: uint,
|
||||
|
@ -119,8 +119,8 @@ main := fn(): int {
|
|||
|
||||
// Mouse cursor
|
||||
{
|
||||
screen.put_filled_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
|
||||
screen.put_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
|
||||
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)
|
||||
}
|
||||
|
||||
screen.sync()
|
||||
|
|
|
@ -25,12 +25,11 @@ resolution = "1024x768x24"
|
|||
|
||||
[boot.limine.ableos.modules.render_example]
|
||||
path = "boot:///render_example.hbf"
|
||||
[boot.limine.ableos.modules.sunset_server]
|
||||
path = "boot:///sunset_server.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_server]
|
||||
# path = "boot:///sunset_server.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
# path = "boot:///ps2_mouse_driver.hbf"
|
||||
[boot.limine.ableos.modules.ps2_mouse_driver]
|
||||
path = "boot:///ps2_mouse_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||
|
|
Loading…
Reference in a new issue