feat: fireworks!

This commit is contained in:
Loïc Grégoire
2026-04-18 20:44:52 -04:00
parent 712a8012af
commit 8fc133cc3c
18 changed files with 186 additions and 127 deletions
+8 -13
View File
@@ -1,13 +1,10 @@
//! Fireworks test ported from the Boron operating system.
const std = @import("std");
const base = @import("root");
const ke = base.ke;
const r = @import("root");
const ke = r.ke;
const mm = r.mm;
const sintab = @import("sintab.zig");
const c = @cImport({
@cInclude("stdlib.h");
});
var pixel_buffer: [*]u8 = undefined;
var fb_width: usize = 0;
var fb_height: usize = 0;
@@ -130,8 +127,6 @@ fn particle(param: ?*anyopaque) void {
data.act_y = parent_data.act_y;
const explosion_range = parent_data.explosion_range;
c.free(param);
const angle = @rem(rand(), 65536);
data.vel_x = mul_fp_fp(cos(angle), rand_fp_sign()) * explosion_range;
data.vel_y = mul_fp_fp(sin(angle), rand_fp_sign()) * explosion_range;
@@ -169,10 +164,10 @@ fn particle(param: ?*anyopaque) void {
}
fn make_thread(entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) *ke.Thread {
var ret: *ke.Thread = @ptrCast(@alignCast(c.malloc(@sizeOf(ke.Thread))));
const stack = std.heap.page_allocator.alloc(u8, 16384) catch @panic("wtf");
var ret: *ke.Thread = mm.zone.gpa.create(ke.Thread) catch @panic("oom");
const stack = mm.heap.alloc(r.kib(16)) catch @panic("wtf");
ret.init(@intFromPtr(stack.ptr), 16384, entry, arg);
ret.init(@intFromPtr(stack), r.kib(16), entry, arg);
ret.priority = ke.Thread.Priority.default;
ret.priority_class = .Batch;
@@ -235,7 +230,7 @@ fn explodeable(_: ?*anyopaque) void {
const part_count: usize = @intCast(@rem(rand(), 100) + 100);
for (0..part_count) |_| {
const param: *FireworkData = @ptrCast(@alignCast(c.malloc(@sizeOf(FireworkData))));
const param: *FireworkData = mm.zone.gpa.create(FireworkData) catch @panic("oom");
param.* = data;
spawn_particle(param);
}
@@ -244,7 +239,7 @@ fn explodeable(_: ?*anyopaque) void {
}
pub fn start(param: ?*anyopaque) void {
const boot_info: *base.pl.BootInfo = @ptrCast(@alignCast(param));
const boot_info: *r.pl.BootInfo = @ptrCast(@alignCast(param));
rand_gen ^= rand_tsc_based();
+5 -9
View File
@@ -3,11 +3,10 @@ const r = @import("root");
const pl = r.pl;
const ke = r.ke;
const mm = r.mm;
const ex = r.ex;
const amd64 = @import("arch");
fn callback(_: ?*anyopaque) void {
std.log.info("Timer callback called", .{});
}
var thread0: ke.Thread = undefined;
pub fn init(boot_info: *pl.BootInfo) void {
mm.init(boot_info);
@@ -16,12 +15,9 @@ pub fn init(boot_info: *pl.BootInfo) void {
mm.late_init();
ke.sched.late_init();
var timer: ke.Timer = undefined;
var dpc: ke.Dpc = .init(callback);
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * 50, &dpc);
const sp = mm.heap.alloc(r.kib(16)) catch @panic("oom");
thread0.init(@intFromPtr(sp), r.kib(16), ex.fireworks.start, boot_info);
ke.sched.enqueue(&thread0);
while (true) {
std.atomic.spinLoopHint();