1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
peony 2024-10-16 00:39:27 +02:00
commit 1039db1247
24 changed files with 324 additions and 315 deletions

10
Cargo.lock generated
View file

@ -350,12 +350,12 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
[[package]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
dependencies = [ dependencies = [
"hashbrown 0.15.0", "hashbrown 0.15.0",
"hbbytecode", "hbbytecode",
@ -367,7 +367,7 @@ dependencies = [
[[package]] [[package]]
name = "hbvm" name = "hbvm"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
dependencies = [ dependencies = [
"hbbytecode", "hbbytecode",
] ]
@ -985,9 +985,9 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.17" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
[[package]] [[package]]
name = "ryu" name = "ryu"

View file

@ -3,7 +3,7 @@ pub static SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole {
uart: 0x09000000 as *mut u8, uart: 0x09000000 as *mut u8,
}); });
struct SerialConsole { pub struct SerialConsole {
uart: *mut u8, uart: *mut u8,
} }

View file

@ -1,11 +1,5 @@
.{Color} := @use("./lib.hb"); .{Color, Surface} := @use("./lib.hb");
.{memory, log} := @use("../../stn/src/lib.hb") .{log} := @use("../../stn/src/lib.hb")
Image := struct {
buf: ^Color,
width: i32,
height: i32,
}
BitmapFileHeader := packed struct { BitmapFileHeader := packed struct {
img_type: u16, img_type: u16,
@ -38,14 +32,35 @@ BitmapColorHeader := packed struct {
unused: u32, unused: u32,
} }
from_bmp := fn(bmp: ^u8): Image { surface_from_bmp := fn(bmp: ^u8): Surface {
file_header := @as(^BitmapFileHeader, @bitcast(bmp)) file_header := @as(^BitmapFileHeader, @bitcast(bmp))
if file_header.img_type != 0x4D42 { if file_header.img_type != 0x4D42 {
log.error("failed to load bmp image: not a bmp image, idiot\0") log.error("failed to load bmp image: not a bmp image, idiot\0")
return @as(Image, idk) return @as(Surface, idk)
} }
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader))) info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
bmp += file_header.offset bmp += file_header.offset
return .(@bitcast(bmp), @bitcast(info_header.width), @bitcast(info_header.height)) a := 0
px := info_header.width * info_header.height
ptr := @as(^Color, @bitcast(bmp))
tmp := @as(Color, idk)
row := 0
loop if row == info_header.height / 2 break else {
col := 0
loop if col == info_header.width break else {
top_index := row * info_header.width + col
bottom_index := (info_header.height - 1 - row) * info_header.width + col
tmp = *(ptr + top_index);
*(ptr + top_index) = *(ptr + bottom_index);
*(ptr + bottom_index) = tmp
col += 1
}
row += 1
}
return .(@bitcast(bmp), @intcast(info_header.width), @intcast(info_header.height))
} }

View file

@ -1,4 +1,4 @@
svga := @use("svga.hb") .{memory} := @use("../../stn/src/lib.hb")
software := @use("software.hb") software := @use("software.hb")
image := @use("image.hb") image := @use("image.hb")
@ -8,9 +8,36 @@ mode := software
init := mode.init init := mode.init
doublebuffer := mode.doublebuffer doublebuffer := mode.doublebuffer
Surface := struct {
buf: ^Color,
width: int,
height: int,
}
new_surface := fn(width: int, height: int): Surface {
return .(
@inline(memory.alloc, Color, width * height * @bitcast(@sizeof(Color))),
width,
height,
)
}
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): Surface {
return .(
ptr,
width,
height,
)
}
clone_surface := fn(surface: Surface): Surface {
new := new_surface(surface.width, surface.height)
@inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height))
return new
}
// Colours // Colours
Color := packed struct {b: u8, g: u8, r: u8, a: u8} Color := packed struct {b: u8, g: u8, r: u8, a: u8}
Image := image.Image
white := Color.(255, 255, 255, 255) white := Color.(255, 255, 255, 255)
black := Color.(0, 0, 0, 255) black := Color.(0, 0, 0, 255)
gray := Color.(127, 127, 127, 255) gray := Color.(127, 127, 127, 255)
@ -34,17 +61,17 @@ put_rect := mode.put_rect
put_filled_rect := mode.put_filled_rect put_filled_rect := mode.put_filled_rect
put_line := mode.put_line put_line := mode.put_line
clear := mode.clear clear := mode.clear
put_image := mode.put_image put_surface := mode.put_surface
// thanks peony for these three! // thanks peony for these three!
put_trirect := mode.put_trirect put_trirect := mode.put_trirect
put_vline := mode.put_vline put_vline := mode.put_vline
put_hline := mode.put_hline put_hline := mode.put_hline
// Display // Display
width := mode.width // width := mode.width
height := mode.height // height := mode.height
dimensions := mode.dimensions // dimensions := mode.dimensions
set_height := mode.set_height // set_height := mode.set_height
set_width := mode.set_width // set_width := mode.set_width
set_dimensions := mode.set_dimensions // set_dimensions := mode.set_dimensions
sync := mode.sync sync := mode.sync

View file

@ -1,102 +1,77 @@
.{math, memory, dt} := @use("../../stn/src/lib.hb"); .{math, memory, dt} := @use("../../stn/src/lib.hb");
.{Color, Image} := @use("lib.hb"); .{Color, Surface, new_surface} := @use("lib.hb");
.{Vec2} := math .{Vec2} := math
ctx := @as(Context, idk) framebuffer := @as(^Color, idk)
Context := struct { init := fn(double_buffer: bool): Surface {
fb: ^Color, framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
bb: ^Color,
buf: ^Color,
width: int,
height: int,
pixels: int,
double_buffer: bool,
}
init := fn(): void {
width := dt.get(int, "framebuffer/fb0/width\0") width := dt.get(int, "framebuffer/fb0/width\0")
height := dt.get(int, "framebuffer/fb0/height\0") height := dt.get(int, "framebuffer/fb0/height\0")
pixels := width * height if double_buffer {
back_buffer := memory.alloc(Color, pixels * @bitcast(@sizeof(Color))) return new_surface(width, height)
ctx = Context.{
fb: dt.get(^Color, "framebuffer/fb0/ptr\0"),
bb: back_buffer,
buf: back_buffer,
width,
height,
pixels,
double_buffer: true,
}
return
}
doublebuffer := fn(enable: bool): void {
if enable {
ctx.buf = ctx.bb
} else { } else {
ctx.buf = ctx.fb return .(framebuffer, width, height)
} }
ctx.double_buffer = enable }
clear := fn(surface: Surface, color: Color): void {
return @inline(memory.set, Color, &color, surface.buf, @bitcast(surface.width * surface.height))
}
sync := fn(surface: Surface): void {
return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height))
}
screenidx := fn(surface: Surface, x: int, y: int): int {
return x + surface.width * y
}
put_pixel := fn(surface: Surface, pos: Vec2(int), color: Color): void {
*(surface.buf + @inline(screenidx, surface, pos.x, pos.y)) = color
return return
} }
clear := fn(color: Color): void { put_filled_rect := fn(surface: Surface, pos: Vec2(int), tr: Vec2(int), color: Color): void {
return @inline(memory.set, Color, &color, ctx.buf, @bitcast(ctx.pixels)) top_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y)
bottom_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y + tr.y - 1)
rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else {
@inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x))
@inline(memory.set, Color, &color, bottom_start_idx, @bitcast(tr.x))
top_start_idx += surface.width
bottom_start_idx -= surface.width
rows_to_fill -= 2
} }
sync := fn(): void { if rows_to_fill == 1 {
return @inline(memory.copy, Color, ctx.buf, ctx.fb, @bitcast(ctx.pixels)) @inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x))
}
width := fn(): int {
return ctx.width
}
height := fn(): int {
return ctx.height
}
screenidx := fn(x: int, y: int): int {
return x + ctx.width * y
}
put_pixel := fn(pos: Vec2(int), color: Color): void {
*(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color
return
}
put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
start_idx := @inline(screenidx, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + tr.y)
loop if start_idx >= end_idx break else {
@inline(memory.set, Color, &color, ctx.buf + start_idx, @bitcast(tr.x))
start_idx += ctx.width
} }
return return
} }
put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { put_rect := fn(surface: Surface, pos: Vec2(int), tr: Vec2(int), color: Color): void {
start_idx := @inline(screenidx, pos.x, pos.y) start_idx := @inline(screenidx, surface, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + tr.y) end_idx := @inline(screenidx, surface, pos.x, pos.y + tr.y)
right_start_idx := @inline(screenidx, pos.x + tr.x, pos.y) right_start_idx := @inline(screenidx, surface, pos.x + tr.x, pos.y)
loop if start_idx > end_idx break else { loop if start_idx > end_idx break else {
*(ctx.buf + start_idx) = color; *(surface.buf + start_idx) = color;
*(ctx.buf + right_start_idx) = color *(surface.buf + right_start_idx) = color
start_idx += ctx.width start_idx += surface.width
right_start_idx += ctx.width right_start_idx += surface.width
} }
@inline(memory.set, Color, &color, ctx.buf + @inline(screenidx, pos.x, pos.y), @bitcast(tr.x + 1)) @inline(memory.set, Color, &color, surface.buf + @inline(screenidx, surface, pos.x, pos.y), @bitcast(tr.x + 1))
@inline(memory.set, Color, &color, ctx.buf + @inline(screenidx, pos.x, pos.y + tr.y), @bitcast(tr.x + 1)) @inline(memory.set, Color, &color, surface.buf + @inline(screenidx, surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
return return
} }
put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { put_line_low := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x dx := p1.x - p0.x
dy := p1.y - p0.y dy := p1.y - p0.y
yi := 1 yi := 1
@ -108,7 +83,7 @@ put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
y := p0.y y := p0.y
x := p0.x x := p0.x
loop if x == p1.x break else { loop if x == p1.x break else {
*(ctx.buf + @inline(screenidx, x, y)) = color *(surface.buf + @inline(screenidx, surface, x, y)) = color
if D > 0 { if D > 0 {
y += yi y += yi
D += 2 * (dy - dx) D += 2 * (dy - dx)
@ -120,7 +95,7 @@ put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return return
} }
put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { put_line_high := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x dx := p1.x - p0.x
dy := p1.y - p0.y dy := p1.y - p0.y
xi := 1 xi := 1
@ -132,7 +107,7 @@ put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
x := p0.x x := p0.x
y := p0.y y := p0.y
loop if y == p1.y break else { loop if y == p1.y break else {
*(ctx.buf + @inline(screenidx, x, y)) = color *(surface.buf + @inline(screenidx, surface, x, y)) = color
if D > 0 { if D > 0 {
x += xi x += xi
D += 2 * (dx - dy) D += 2 * (dx - dy)
@ -144,61 +119,50 @@ put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return return
} }
put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { put_line := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) { if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) {
if p0.x > p1.x { if p0.x > p1.x {
@inline(put_line_low, p1, p0, color) @inline(put_line_low, surface, p1, p0, color)
} else { } else {
@inline(put_line_low, p0, p1, color) @inline(put_line_low, surface, p0, p1, color)
} }
} else { } else {
if p0.y > p1.y { if p0.y > p1.y {
@inline(put_line_high, p1, p0, color) @inline(put_line_high, surface, p1, p0, color)
} else { } else {
@inline(put_line_high, p0, p1, color) @inline(put_line_high, surface, p0, p1, color)
} }
} }
return return
} }
set_height := fn(new: int): void { put_surface := fn(surface: Surface, top: Surface, pos: Vec2(int)): void {
return top_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y)
bottom_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y + top.height - 1)
rows_to_copy := top.height
top_cursor := top.buf
bottom_cursor := top.buf + top.width * (top.height - 1)
loop if rows_to_copy <= 1 break else {
@inline(memory.copy, Color, top_cursor, top_start_idx, @bitcast(top.width))
@inline(memory.copy, Color, bottom_cursor, bottom_start_idx, @bitcast(top.width))
top_start_idx += surface.width
bottom_start_idx -= surface.width
top_cursor += top.width
bottom_cursor -= top.width
rows_to_copy -= 2
} }
set_width := fn(new: int): void { if rows_to_copy == 1 {
return @inline(memory.copy, Color, top_cursor, top_start_idx, @bitcast(top.width))
} }
dimensions := fn(): Vec2(int) {
return .(ctx.width, ctx.height)
}
set_dimensions := fn(new: Vec2(int)): void {
return
}
put_image := fn(image: Image, pos: Vec2(int)): void {
// y := 0
// loop if y == image.height break else {
// @inline(memory.copy, Color, image.buf + y * image.width, ctx.buf + @inline(screenidx, pos.x, pos.y + image.height - y), @intcast(image.width))
// y += 1
// }
// return
start_idx := @inline(screenidx, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + image.height)
cursor := image.width * image.height
loop if start_idx >= end_idx break else {
@inline(memory.copy, Color, image.buf + cursor, ctx.buf + start_idx, @intcast(image.width))
start_idx += ctx.width
cursor -= image.width
}
return return
} }
// peony-made // peony-made
put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void { put_trirect := fn(surface: Surface, pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void {
step := Vec2(int).(1, 1) step := Vec2(int).(1, 1)
if size.x < 0 { if size.x < 0 {
step.x = -1 step.x = -1
@ -211,8 +175,8 @@ put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color)
target := pos + size target := pos + size
loop if pos.x == target.x break else { loop if pos.x == target.x break else {
put_vline(pos.x, pos.y, target.y, color0) put_vline(surface, pos.x, pos.y, target.y, color0)
@inline(put_vline, pos.x, pos.y, start_y, color1) @inline(put_vline, surface, pos.x, pos.y, start_y, color1)
pos += step pos += step
} }
@ -220,7 +184,7 @@ put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color)
} }
// peony-made // peony-made
put_vline := fn(x: int, y0: int, y1: int, color: Color): void { put_vline := fn(surface: Surface, x: int, y0: int, y1: int, color: Color): void {
if y1 < y0 { if y1 < y0 {
tmp := y0 tmp := y0
y0 = y1 y0 = y1
@ -229,7 +193,7 @@ put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
y := y0 y := y0
loop if y == y1 break else { loop if y == y1 break else {
*(ctx.buf + @inline(screenidx, x, y)) = color *(surface.buf + @inline(screenidx, surface, x, y)) = color
y += 1 y += 1
} }
@ -237,7 +201,7 @@ put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
} }
// peony-made // peony-made
put_hline := fn(y: int, x0: int, x1: int, color: Color): void { put_hline := fn(surface: Surface, y: int, x0: int, x1: int, color: Color): void {
if x1 < x0 { if x1 < x0 {
tmp := x0 tmp := x0
x0 = x1 x0 = x1
@ -246,7 +210,7 @@ put_hline := fn(y: int, x0: int, x1: int, color: Color): void {
x := x0 x := x0
loop if x == x1 break else { loop if x == x1 break else {
*(ctx.buf + @inline(screenidx, x, y)) = color *(surface.buf + @inline(screenidx, surface, x, y)) = color
x += 1 x += 1
} }

View file

@ -1,78 +0,0 @@
.{Vec2} := @use("../../stn/src/lib.hb").math;
.{Image, Color} := @use("lib.hb")
clear := fn(color: Color): void {
return
}
width := fn(): int {
return 0
}
height := fn(): int {
return 0
}
dimensions := fn(): Vec2(int) {
return .(0, 0)
}
put_pixel := fn(position: Vec2(int), color: Color): void {
return
}
put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return
}
put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return
}
put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
// do not use, use line() instead
put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
set_height := fn(new: int): void {
return
}
set_width := fn(new: int): void {
return
}
set_dimensions := fn(new: Vec2(int)): void {
return
}
sync := fn(): void {
return
}
init := fn(): void {
return
}
put_image := fn(img: Image, pos: Vec2(int)): void {
return
}
put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void {
return
}
put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
return
}
put_hline := fn(y: int, x0: int, x1: int, color: Color): void {
return
}

View file

@ -2,7 +2,7 @@ PAGE_SIZE := 4096
MAX_ALLOC := 0xFF MAX_ALLOC := 0xFF
alloc := fn($Expr: type, bytes: int): ^Expr { alloc := fn($Expr: type, bytes: int): ^Expr {
pages := (1 + bytes) / PAGE_SIZE pages := 1 + bytes / PAGE_SIZE
if pages <= MAX_ALLOC { if pages <= MAX_ALLOC {
return @bitcast(@inline(request_page, pages)) return @bitcast(@inline(request_page, pages))
} }

View file

@ -3,5 +3,6 @@ any := fn($Expr: type): Expr {
} }
range := fn($Expr: type, min: Expr, max: Expr): Expr { range := fn($Expr: type, min: Expr, max: Expr): Expr {
return @eca(3, 4) % (max - min + 1) + min // wtf is this
return @intcast(@as(int, @eca(3, 4)) % @as(int, @intcast(max) - @intcast(min)) + 1 + @intcast(min))
} }

View file

@ -1,11 +1,52 @@
stn := @use("../../../libraries/stn/src/lib.hb"); stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer} := stn .{string, memory, buffer, random} := stn;
.{Vec2} := stn.math
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb") horizon_api := @use("../../../libraries/horizon_api/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb")
Window := struct {
// TODO: Replace this with widgets
implicit_framebuffer: render.Surface,
width: int,
height: int,
x: int,
y: int,
}
main := fn(): int { main := fn(): int {
a := buffer.create("XHorizon\0") a := buffer.create("XHorizon\0")
// BUG: Backbuffering is disabled
screen := render.init(true)
// Clear the screen to black.
render.clear(screen, render.black)
window := render.new_surface(screen.width / 3, screen.height / 3)
pos := Vec2(int).(100, 100)
color := random.range(render.Color, render.black, render.white)
loop { loop {
// Clear the screen
render.clear(screen, render.black)
// TODO: Read the window buffer here
// TODO: Get windows out of a collection and iter through
//
{
render.clear(window, render.white)
// Apply the image to the screen
render.put_surface(screen, window, pos)
}
// Sync the screen
render.sync(screen)
} }
return 0 return 0

View file

@ -8,28 +8,28 @@ ignim := @use("../../../libraries/ignim/src/lib.hb");
.{errors} := ignim .{errors} := ignim
main := fn(): int { main := fn(): int {
windowing_system_buffer := buffer.create("XHorizon\0") windowing_system_buffer := buffer.search("XHorizon\0")
// TODO: get WindowID // TODO: get WindowID
create_window(windowing_system_buffer) create_window(windowing_system_buffer)
program_name := "Horizon Testing Program\0" // program_name := "Horizon Testing Program\0"
program_version := ignim.version.make_version(0, 1, 0) // program_version := ignim.version.make_version(0, 1, 0)
engine_name := "None\0" // engine_name := "None\0"
engine_version := ignim.version.make_version(0, 0, 0) // engine_version := ignim.version.make_version(0, 0, 0)
api_version := ignim.version.make_api_version(0, 1, 0, 0) // api_version := ignim.version.make_api_version(0, 1, 0, 0)
app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version) // app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version)
create_info := ignim.instance.new_create_info(&app_info) // create_info := ignim.instance.new_create_info(&app_info)
instance := ignim.instance.void_instance() // instance := ignim.instance.void_instance()
// TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance // // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
ret := ignim.instance.create_instance(&create_info, 0, &instance) // ret := ignim.instance.create_instance(&create_info, 0, &instance)
if ret == errors.IncompatibleDriver { // if ret == errors.IncompatibleDriver {
log.error("Driver Incompatible with Vulkan\0") // log.error("Driver Incompatible with Vulkan\0")
} // }
return 0 return 0
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

View file

@ -4,16 +4,16 @@ render := @use("../../../../libraries/render/src/lib.hb")
the impostor travels left and loops around the screen */ the impostor travels left and loops around the screen */
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
x := 0 x := 0
loop { loop {
render.put_rect(.(200 - x, 80), .(430, 380), render.red) render.put_rect(screen, .(200 - x, 80), .(430, 380), render.red)
render.put_rect(.(630 - x, 120), .(120, 300), render.red) render.put_rect(screen, .(630 - x, 120), .(120, 300), render.red)
render.put_rect(.(200 - x, 460), .(160, 270), render.red) render.put_rect(screen, .(200 - x, 460), .(160, 270), render.red)
render.put_rect(.(470 - x, 460), .(160, 270), render.red) render.put_rect(screen, .(470 - x, 460), .(160, 270), render.red)
render.put_rect(.(140 - x, 140), .(340, 250), render.cyan) render.put_rect(screen, .(140 - x, 140), .(340, 250), render.cyan)
render.sync() render.sync(screen)
render.clear(render.black) render.clear(screen, render.black)
x += 1 x += 1
} }
return return

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View file

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View file

@ -6,12 +6,12 @@ render := @use("../../../../libraries/render/src/lib.hb")
note that this may happen too fast for you to notice... */ note that this may happen too fast for you to notice... */
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
color := render.light_cyan color := render.light_cyan
n := @as(u8, 1) n := @as(u8, 1)
loop { loop {
render.clear(color) render.clear(screen, color)
render.sync() render.sync(screen)
if (color.b & 255) == 255 | (color.b & 255) == 0 { if (color.b & 255) == 255 | (color.b & 255) == 0 {
n = -n n = -n
} }

View file

@ -4,25 +4,31 @@ render := @use("../../../../libraries/render/src/lib.hb")
/* expected result: /* expected result:
a cute image bounces around the screen */ a cute image bounces around the screen */
bmp := @embed("./able.bmp") bmp_1 := @embed("./assets/able.bmp")
bmp_2 := @embed("./assets/mini.bmp")
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
image := render.image.from_bmp(@bitcast(&bmp)) images := [render.Surface; 2].(
render.image.surface_from_bmp(@bitcast(&bmp_1)),
render.image.surface_from_bmp(@bitcast(&bmp_2)),
)
vel := Vec2(int).(1, 1) vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100) pos := Vec2(int).(100, 100)
width := render.width() n := -1
height := render.height()
loop { loop {
render.put_image(image, pos) image := images[n]
render.sync() render.put_surface(screen, image, pos)
render.clear(render.black) render.sync(screen)
render.clear(screen, render.black)
if pos.x == 0 | pos.x == width - image.width { if pos.x == 0 | pos.x == screen.width - image.width {
vel.x = -vel.x vel.x = -vel.x
n = -1 - n
} }
if pos.y == 0 | pos.y == height - image.height { if pos.y == 0 | pos.y == screen.height - image.height {
vel.y = -vel.y vel.y = -vel.y
n = -1 - n
} }
pos += vel pos += vel

View file

@ -6,18 +6,16 @@ render := @use("../../../../libraries/render/src/lib.hb")
created on a blue background */ created on a blue background */
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
render.clear(.(100, 50, 0, 255)) render.clear(screen, .(100, 50, 0, 255))
width := render.width()
height := render.height()
p0 := Vec2(int).(0, 0) p0 := Vec2(int).(0, 0)
p1 := Vec2(int).(0, height) p1 := Vec2(int).(0, screen.height)
loop if p0.y >= height break else { loop if p0.y >= screen.height break else {
render.put_line(p0, p1, .(255, 180, 100, 255)) render.put_line(screen, p0, p1, .(255, 180, 100, 255))
render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255)) render.put_line(screen, .(screen.width, screen.height) - p0, .(screen.width, screen.height) - p1, .(255, 180, 100, 255))
p0.y += height >> 6 p0.y += screen.height >> 6
p1.x += width >> 6 p1.x += screen.width >> 6
} }
render.sync() render.sync(screen)
return return
} }

View file

@ -2,16 +2,15 @@
render := @use("../../../../libraries/render/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
render.init() screen := render.init(false)
render.doublebuffer(false) render.clear(screen, render.black)
render.clear(render.black)
loop { loop {
x := random.range(int, 0, 1024) x := random.range(int, 0, 1024)
y := random.range(int, 0, 768) y := random.range(int, 0, 768)
r := random.range(int, 0, 255) r := random.range(int, 0, 255)
g := random.range(int, 0, 75) g := random.range(int, 0, 75)
b := random.range(int, 0, 155) b := random.range(int, 0, 155)
render.put_pixel(.(x, y), .(b, g, r, 255)) render.put_pixel(screen, .(x, y), .(b, g, r, 255))
} }
return return
} }

View file

@ -6,24 +6,23 @@ render := @use("../../../../libraries/render/src/lib.hb")
a square that changes colour bounces around the screen */ a square that changes colour bounces around the screen */
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
vel := Vec2(int).(1, 1) vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100) side := screen.width / 8
width := render.width() pos := Vec2(int).((screen.width - side) / 2, (screen.height - side) / 2)
height := render.height() color := random.range(render.Color, render.black, render.white)
color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
loop { loop {
render.put_filled_rect(pos, .(100, 100), color) render.put_filled_rect(screen, pos, .(side, side), color)
render.sync() render.sync(screen)
render.clear(render.black) render.clear(screen, render.black)
if pos.x == 0 | pos.x == width - 100 { if pos.x == 0 | pos.x == screen.width - side {
vel.x = -vel.x vel.x = -vel.x
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) color = random.range(render.Color, render.black, render.white)
} }
if pos.y == 0 | pos.y == height - 100 { if pos.y == 0 | pos.y == screen.height - side {
vel.y = -vel.y vel.y = -vel.y
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) color = random.range(render.Color, render.black, render.white)
} }
pos += vel pos += vel

View file

@ -0,0 +1,48 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
.{random} := @use("../../../../libraries/stn/src/lib.hb")
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
the square example bounces around the screen */
example := fn(): void {
screen := render.init(true)
image := render.new_surface(screen.width / 3, screen.height / 3)
vel := Vec2(int).(-1, -1)
pos := Vec2(int).(100, 100)
side := image.width / 8
vel_inner := Vec2(int).(1, 1)
pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2)
color := random.range(render.Color, render.black, render.white)
loop {
render.clear(image, render.black)
render.clear(screen, render.black)
render.put_filled_rect(image, pos_inner, .(side, side), color)
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), render.white)
render.put_surface(screen, image, pos)
render.sync(screen)
if pos_inner.x == 0 | pos_inner.x == image.width - side {
vel_inner.x = -vel_inner.x
color = random.range(render.Color, render.black, render.white)
}
if pos_inner.y == 0 | pos_inner.y == image.height - side {
vel_inner.y = -vel_inner.y
color = random.range(render.Color, render.black, render.white)
}
if pos.x == 0 | pos.x == screen.width - image.width {
vel.x = -vel.x
}
if pos.y == 0 | pos.y == screen.height - image.height {
vel.y = -vel.y
}
pos += vel
pos_inner += vel_inner
}
return
}

View file

@ -1,8 +0,0 @@
render := @use("../../../../libraries/render/src/lib.hb")
render.mode = render.svga
example := fn(): void {
render.init()
return
}

View file

@ -7,10 +7,10 @@ Vec2 := math.Vec2
with a "target" randomly apperaing in one of them and a "seeker" "catching" it */ with a "target" randomly apperaing in one of them and a "seeker" "catching" it */
example := fn(): void { example := fn(): void {
render.init() screen := render.init(true)
width := render.width() width := screen.width
height := render.height() height := screen.height
cell_size := 0 cell_size := 0
range := Vec2(int).(0, 0) range := Vec2(int).(0, 0)
if width > height { if width > height {
@ -33,32 +33,32 @@ example := fn(): void {
seeker := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y)) seeker := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y))
loop { loop {
render.clear(render.black) render.clear(screen, render.black)
target_pixel_coord := target * .(cell_size, cell_size) + .(scroll, scroll) target_pixel_coord := target * .(cell_size, cell_size) + .(scroll, scroll)
render.put_trirect(target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red) render.put_trirect(screen, target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red)
render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red) render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red)
render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red) render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red)
render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red) render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red)
render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red) render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red)
x := scroll x := scroll
loop if x > width break else { loop if x > width break else {
render.put_vline(x, 0, height, .(0, 127, 0, 127)) render.put_vline(screen, x, 0, height, .(0, 127, 0, 127))
x += cell_size x += cell_size
} }
y := scroll y := scroll
loop if y > height break else { loop if y > height break else {
render.put_hline(y, 0, width, .(0, 127, 0, 127)) render.put_hline(screen, y, 0, width, .(0, 127, 0, 127))
y += cell_size y += cell_size
} }
render.put_hline(seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green) render.put_hline(screen, seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green)
render.put_vline(seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green) render.put_vline(screen, seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green)
render.sync() render.sync(screen)
if seeker.x < target.x { if seeker.x < target.x {
seeker.x += 1 seeker.x += 1

View file

@ -1,6 +1,3 @@
.{example} := @use("./examples/image.hb") .{example} := @use("./examples/surface.hb")
main := fn(): void { main := example
@inline(example)
return
}