feat(assets): #82 incremental asset preloading + loading-scene pattern
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 22s
ci / build-and-test (push) Successful in 2m27s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 28s

Assets loaded synchronously in Boot stalled the first frame(s). Adds an
Assets.* preload queue over the #81 atlas: Assets.enqueue(name, path) queues a
named image without loading it, Assets.pump(max) loads up to max per frame
(returns how many), and Assets.total/loaded/ready/progress (0..100) drive a
progress bar. A loading scene pumps a few per frame, draws Assets.progress(),
and becomes the play scene once Assets.ready() — the deterministic, no-threads
form of async preloading (work spread across frames; same enqueue+pump order
loads identically every run). Loaded assets are reachable by name via
Assets.get / Sprite.named.

Example preload (enqueue 3, pump incrementally 0->33->66->100, ready flips, get
by name) prints 3 0 0 0 1 33 66 1 100 1. 6 docs pages. Full suite 117/0,
fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-02 08:19:19 +03:00
parent 23e232e380
commit f2cb3cd7e8
12 changed files with 22197 additions and 21863 deletions

View file

@ -0,0 +1,14 @@
---
id: assets-enqueue
name: Assets.enqueue
category: assets
kind: namespace-method
tokens: Assets.enqueue
sig: Assets.enqueue(name, path)
tip: Queue a named image file to preload later.
order: 4
ns: Assets
member: enqueue
---
Adds a named image file to the preload queue without loading it now. Load the queue incrementally with <a href="assets-pump"><code>Assets.pump</code></a> from a loading scene, then reach each asset by name with <a href="assets-get"><code>Assets.get</code></a> once <a href="assets-ready"><code>Assets.ready</code></a>. Enqueueing is deterministic — the same order loads the same assets in the same order every run.

View file

@ -0,0 +1,14 @@
---
id: assets-loaded
name: Assets.loaded
category: assets
kind: namespace-method
tokens: Assets.loaded
sig: Assets.loaded() -> int
tip: How many enqueued assets have loaded so far.
order: 7
ns: Assets
member: loaded
---
Returns how many of the enqueued assets have loaded so far (advanced by <a href="assets-pump"><code>Assets.pump</code></a>) — the numerator for a progress bar.

View file

@ -0,0 +1,14 @@
---
id: assets-progress
name: Assets.progress
category: assets
kind: namespace-method
tokens: Assets.progress
sig: Assets.progress() -> int
tip: Loading progress as a 0..100 percent.
order: 9
ns: Assets
member: progress
---
Returns the loading progress as a whole-number percent (<code>0..100</code>); an empty queue is <code>100</code>. Draw it as a progress bar on the loading screen.

View file

@ -0,0 +1,14 @@
---
id: assets-pump
name: Assets.pump
category: assets
kind: namespace-method
tokens: Assets.pump
sig: Assets.pump(max) -> int
tip: Load up to max queued assets this frame; returns how many it loaded.
order: 5
ns: Assets
member: pump
---
Loads up to <code>max</code> queued assets this frame, registering each under its name, and returns how many it loaded. Call it each frame in a loading scene with a small <code>max</code> so the frame stays short and the loading screen animates; <a href="assets-ready"><code>Assets.ready</code></a> flips true when the queue is drained. This is the deterministic, no-threads form of async preloading — the work is spread across frames instead of stalling one.

View file

@ -0,0 +1,14 @@
---
id: assets-ready
name: Assets.ready
category: assets
kind: namespace-method
tokens: Assets.ready
sig: Assets.ready() -> int
tip: 1 once every enqueued asset has loaded.
order: 8
ns: Assets
member: ready
---
Returns <code>1</code> once every enqueued asset has been loaded (the queue is drained), else <code>0</code>. A loading scene pumps until this is true, then enters play (e.g. <code>become</code> the game scene).

View file

@ -0,0 +1,14 @@
---
id: assets-total
name: Assets.total
category: assets
kind: namespace-method
tokens: Assets.total
sig: Assets.total() -> int
tip: How many assets are enqueued.
order: 6
ns: Assets
member: total
---
Returns the total number of assets enqueued with <a href="assets-enqueue"><code>Assets.enqueue</code></a> — the denominator for a progress bar.