migrate allocator calls to alloc_bytes / libc_free

This commit is contained in:
swipelab
2026-06-12 09:34:13 +03:00
parent 38815c7d50
commit 1ab74c7d08
3 changed files with 19 additions and 19 deletions

View File

@@ -138,7 +138,7 @@ BoardFxAssets :: struct {
return;
}
n := cast(s64) w * cast(s64) h;
buf : [*]u8 = xx context.allocator.alloc(n * 4);
buf : [*]u8 = xx context.allocator.alloc_bytes(n * 4);
// Loop locals are hoisted: a block-scoped local declared inside a body
// that runs hundreds of thousands of times grows the stack per iteration
// (sx codegen), so the per-pixel tint loop only ASSIGNS pre-declared vars.

26
main.sx
View File

@@ -327,7 +327,7 @@ frame :: () {
main :: () -> void {
inline if OS == .ios {
u : *UIKitPlatform = xx context.allocator.alloc(size_of(UIKitPlatform));
u : *UIKitPlatform = xx context.allocator.alloc_bytes(size_of(UIKitPlatform));
u.gpu_mode = .metal;
if !u.init("m3te", 800, 600) { return; }
g_plat = xx u;
@@ -337,13 +337,13 @@ main :: () -> void {
// return into UIApplicationMain, so attach lazily on the first frame.
// init(null, 0, 0) only needs the MTLDevice, which is enough for the
// texture uploads below.
g_metal_gpu = xx context.allocator.alloc(size_of(MetalGPU));
g_metal_gpu = xx context.allocator.alloc_bytes(size_of(MetalGPU));
// alloc returns uninitialized memory; struct field defaults are NOT
// applied, so List caps/lens would be garbage without this memset.
memset(xx g_metal_gpu, 0, size_of(MetalGPU));
if !g_metal_gpu.init(null, 0, 0) { return; }
} else {
s : *SdlPlatform = xx context.allocator.alloc(size_of(SdlPlatform));
s : *SdlPlatform = xx context.allocator.alloc_bytes(size_of(SdlPlatform));
if !s.init("m3te", 800, 600) { return; }
g_plat = xx s;
}
@@ -353,7 +353,7 @@ main :: () -> void {
g_viewport_h = fc.viewport_h;
g_safe_insets = g_plat.safe_insets();
g_pipeline = xx context.allocator.alloc(size_of(UIPipeline));
g_pipeline = xx context.allocator.alloc_bytes(size_of(UIPipeline));
// Same alloc caveat as above: zero so the optional `gpu` reads as null on
// the desktop path (where set_gpu is not called) and the Lists start empty.
memset(xx g_pipeline, 0, size_of(UIPipeline));
@@ -363,37 +363,37 @@ main :: () -> void {
g_pipeline.init(fc.viewport_w, fc.viewport_h);
g_pipeline.init_font("assets/fonts/default.ttf", 32.0, fc.dpi_scale);
g_board = xx context.allocator.alloc(size_of(Board));
g_board = xx context.allocator.alloc_bytes(size_of(Board));
g_board.init(BOARD_SEED);
g_assets = xx context.allocator.alloc(size_of(BoardAssets));
g_assets = xx context.allocator.alloc_bytes(size_of(BoardAssets));
g_assets.init();
g_assets.load(g_pipeline.gpu);
g_sel = xx context.allocator.alloc(size_of(BoardSelection));
g_sel = xx context.allocator.alloc_bytes(size_of(BoardSelection));
g_sel.init();
g_drag = xx context.allocator.alloc(size_of(DragInput));
g_drag = xx context.allocator.alloc_bytes(size_of(DragInput));
g_drag.init();
g_anim = xx context.allocator.alloc(size_of(BoardAnim));
g_anim = xx context.allocator.alloc_bytes(size_of(BoardAnim));
g_anim.init();
g_fx = xx context.allocator.alloc(size_of(BoardFx));
g_fx = xx context.allocator.alloc_bytes(size_of(BoardFx));
g_fx.init();
g_fxassets = xx context.allocator.alloc(size_of(BoardFxAssets));
g_fxassets = xx context.allocator.alloc_bytes(size_of(BoardFxAssets));
g_fxassets.init();
g_fxassets.load(g_pipeline.gpu);
g_motion = xx context.allocator.alloc(size_of(GemMotion));
g_motion = xx context.allocator.alloc_bytes(size_of(GemMotion));
g_motion.init();
// SFX (P10.2). Loads the System Sound Services cue bank once; board_view
// plays a cue per event. Purely additive — never touches score/board/move
// state. On iOS the platform has already chdir'd to the bundle, so each
// cue's relative path resolves. No-op off iOS.
g_audio = xx context.allocator.alloc(size_of(GameAudio));
g_audio = xx context.allocator.alloc_bytes(size_of(GameAudio));
memset(xx g_audio, 0, size_of(GameAudio));
g_audio.init();

View File

@@ -76,7 +76,7 @@ main :: () -> s32 {
// Per-pixel luminance, plus the checker shades read off the border ring
// (the border is pure checker — the glow never reaches the corners).
lum : [*]s64 = xx context.allocator.alloc(N * size_of(s64));
lum : [*]s64 = xx context.allocator.alloc_bytes(N * size_of(s64));
c_lo : s64 = 255;
c_hi : s64 = 0;
y = 0;
@@ -102,9 +102,9 @@ main :: () -> s32 {
// 8-connected flood fill of the edge-connected checker, seeded from every
// border pixel. `bg[i]==1` marks a removed (transparent) background pixel.
bg : [*]u8 = xx context.allocator.alloc(N);
bg : [*]u8 = xx context.allocator.alloc_bytes(N);
memset(xx bg, 0, N);
stack : [*]s64 = xx context.allocator.alloc(N * size_of(s64));
stack : [*]s64 = xx context.allocator.alloc_bytes(N * size_of(s64));
sp : s64 = 0;
checker_lim := c_hi + LUM_MARGIN;
@@ -153,7 +153,7 @@ main :: () -> s32 {
// checker shade up to pure white, giving the glow its smooth falloff.
denom := cast(f32) (255 - c_hi);
if denom < 1.0 { denom = 1.0; }
alpha : [*]f32 = xx context.allocator.alloc(N * size_of(f32));
alpha : [*]f32 = xx context.allocator.alloc_bytes(N * size_of(f32));
kept : s64 = 0;
n_bg : s64 = 0;
a : f32 = 0.0;
@@ -174,7 +174,7 @@ main :: () -> s32 {
// Area-averaged downscale to OUT_DIM. RGB stays white; only the averaged
// alpha carries the sprite, so no premultiply is needed (white*cov == white).
out_px : [*]u8 = xx context.allocator.alloc(OUT_DIM * OUT_DIM * 4);
out_px : [*]u8 = xx context.allocator.alloc_bytes(OUT_DIM * OUT_DIM * 4);
sxf := cast(f32) W / cast(f32) OUT_DIM;
syf := cast(f32) H / cast(f32) OUT_DIM;
max_a : f32 = 0.0;