This commit is contained in:
koniifer 2024-12-21 12:01:48 +00:00
parent 0fc95160cc
commit 8cce5ef731
8 changed files with 92 additions and 41 deletions

View file

@ -5,7 +5,7 @@
// safety: don't use before init() or you will get a memory access violation
framebuffer := memory.dangling(Color)
utf8_len_table := [u8].(0, 0, 2, 3)
utf8_len_table := u8.[0, 0, 2, 3]
init := fn(doublebuffer: bool): Surface {
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")

View file

@ -175,6 +175,22 @@ fmt_enum := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
return len + 2
}
/* TODO:
* Custom formatters using struct methods (T._fmt(self, str): uint),
* Format struct fields "Name.{a: x, b: y, c: z}"
* Optionally tabulate
* Add more FormatOption fields
* Support scientific notation for floating point
* Support format string
*/
FormatOptions := struct {
precision: uint = 2,
radix: uint = 10,
// temporarily here, will change later maybe
log: LogLevel = .Info,
}
/* SAFETY:
* Assumes the buffer is wide enough for the formatted text and a null char
* Does not clear the buffer for you
@ -190,7 +206,7 @@ format := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
} else if T == bool {
return @inline(fmt_bool, v, str)
} else if float(T) {
return @inline(fmt_float, v, str, opts.decimal_digits, @intcast(opts.radix))
return @inline(fmt_float, v, str, opts.precision, @intcast(opts.radix))
}
},
.Opt => return @inline(fmt_nullable, v, str, opts),
@ -201,19 +217,3 @@ format := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint {
_ => @error("Type: \"\0", T, "\" is not supported.\0"),
}
}
/* TODO:
* Custom formatters using struct methods (T._fmt(self, str): uint),
* Format struct fields "Name.{a: x, b: y, c: z}"
* Optionally tabulate
* Add more FormatOption fields
* Support scientific notation for floating point
* Support format string
*/
FormatOptions := struct {
decimal_digits: uint = 2,
radix: uint = 10,
// temporarily here, will change later maybe
log: LogLevel = .Info,
}

File diff suppressed because one or more lines are too long

View file

@ -6,7 +6,7 @@ WindowServer := struct {
window_count: uint,
channel: Channel,
// ! replace this with a collection when we get an allocator
windows: [?Window; 10],
windows: [10]?Window,
font: text.Font,
}
@ -24,7 +24,7 @@ start := fn(): void {
server = .(
0,
.{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)},
.(null, null, null, null, null, null, null, null, null, null),
.[null, null, null, null, null, null, null, null, null, null],
@as(text.Font, font),
)
log.info("server: started server\0")

View file

@ -3,16 +3,16 @@ 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
// zoom into that weird curve part of the main cardioid
// $X_MIN := 0.25
@ -24,7 +24,7 @@ $MAX_ITERATION := 300
$USE_SUNSET := true
palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
palette := render.Color.[.(50, 0, 60, 0), .(93, 0, 157, 0), .(140, 98, 229, 0), .(191, 190, 255, 0), .(226, 234, 255, 0), .(242, 250, 255, 0), .(226, 234, 255, 0), .(191, 190, 255, 0), .(140, 98, 229, 0), .(93, 0, 157, 0), .(50, 0, 60, 0)]
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
example := fn(): void {

View file

@ -0,0 +1,51 @@
math := @use("stn:math")
render := @use("lib:render")
/* expected result:
red tangent graph
*/
$f := fn(x: uint): int {
x_f := @as(f32, @itf(@bitcast(x)))
y_f := math.tan(x_f * 0.03) * 20
return @fti(y_f)
}
y_asymptote := fn(screen: render.Surface, x: uint): void {
y := 0
loop if y >= screen.height break else {
screen.put_pixel(.(x, y), render.GRAY)
y += 4
}
}
example := fn(): void {
screen := render.init(false)
x := 0
height := @as(int, @bitcast(screen.height))
width := @as(int, @bitcast(screen.width))
screen.put_hline(screen.height / 2, 0, screen.width, render.LIGHT_GRAY)
loop if x >= screen.width break else {
y1 := height / 2 - f(x)
y2 := height / 2 - f(x + 1)
if y1 > height y1 = height else if y1 < 0 {
y_asymptote(screen, x)
x += 1
continue
}
if y2 > height {
y_asymptote(screen, x)
x += 1
continue
} else if y2 < 0 y2 = 0
if math.abs(int, y2 - y1) > 1 {
screen.put_vline(x, @bitcast(y1), @bitcast(y2), render.RED)
} else {
screen.put_pixel(.(x, @bitcast(y1)), render.RED)
screen.put_pixel(.(x, @bitcast(y2)), render.RED)
}
x += 1
}
}

View file

@ -24,7 +24,7 @@ test := fn(): uint {
log.print(StructThingy.(-100, -100, .(-math.PI, true)), .{log: .Warn})
log.print(SubStructThingy.(-math.E, false), .{})
log.print(Color.{r: 255, g: 254, b: 253, a: 252}, .{radix: 2})
log.print(@as(f64, math.LN_2), .{radix: 16, decimal_digits: 1 << 32})
log.print(@as(f64, math.LN_2), .{radix: 16, precision: 1 << 32})
log.print(u8.[1, 2, 3], .{})
log.print(&SubStructThingy.(0.0, true), .{})
log.print(@as(?u32, null), .{})

View file

@ -23,14 +23,14 @@ 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"
[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"
@ -50,5 +50,5 @@ 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"