Expand description
The asset bundle: the files a game embeds in its binary, read from layers the game gives, in order. A file is read from the first layer that has it, so a layer laid over another replaces its files at the same paths and adds its own; a listing merges every layer’s files.
A layer may also come from outside the binary: Layer::owned takes
files handed in at run time (a player’s mod, a level they made), kept
for the life of the program, so a game’s loaders read them as they read
its own. shuyi-app’s read_folder reads a folder on disk into one.
Two flags shape a layer. A private layer holds files that may not be
handed out (bought art): Bundle::is_private tells a tool which shown
names come from one. A test layer holds the files of the tests and
debug tools, which a build that ships leaves out: test layers are read
after every other layer, and story_only hides them from a thread.
A layer may also name the files it leaves out on purpose
(Layer::leaving_out): a smaller build (a handheld’s) that keeps only
what it uses. Bundle::left_out lets a loader tell such a file from
one that is missing.
A layer may be for a target (ADR-0008 §4): assets@playdate is
assets’ layer for the Playdate, used only when baking or running
for it. Bundle::for_target lays it right above assets, so any
file there (a hand-drawn one-bit hero.png, a settings file) replaces
the one at the same path, and leaves out every other target’s.
A bundle’s fingerprint stands for the content
that ships, the same on every platform: what a record or a save is
stamped with (shuyi_core::made).
The game registers its bundle once (install or get_or_install),
and its loaders read files as &'static data from it. A front end can
watch every file read, to log or time what it loads; with std,
reading makes one thread read another bundle (a test of a smaller
build’s bundle), and recording lists the files a stretch of code
read on its thread.
In a debug build a file of a run-time layer may change on disk:
Bundle::replace takes its new bytes, and hot values
decode again.
Structs§
- Bundle
- The layers a game reads its files from.
- Layer
- One layer of the bundle.
- Layer
Error - A layer that could not be made (
Layer::owned): one of its paths was refused. - Load
File - One file of a folder, as
Bundle::load_eachhands it to a parser. - NotText
- A file that is not valid UTF-8: what
Bundle::load_eachturns into the loader’s own error type. - Owned
Files - The files of a layer handed in at run time (
Layer::owned), with checked paths, kept for the life of the program so every read of them is&'static. Withstda file can be replaced (Layer::replace); its old bytes stay, so what was read of them stays valid.
Enums§
- BadPath
- Why a path handed to
Layer::ownedwas refused: a layer’s paths are relative to its root and/-separated, as every read names them. - Files
- Where a layer’s files are.
Constants§
- TARGET_
MARK - What a layer’s name puts between the name of the layer it is laid over
and the target it is for:
assets@playdate(Bundle::for_target).
Functions§
- get_
or_ install - The process-wide bundle, installing the one
makebuilds if none is. When two threads race to install, one bundle wins and both get it. Insidereading, the bundle this thread reads instead, and nothing is installed. - install
- Makes
bundlethe process-wide bundle. Done once: a second call gives its bundle back and changes nothing. - installed
- The process-wide bundle, once installed; inside
reading, the bundle this thread reads instead. - reading
- Runs
fwith this thread readingbundleinstead of the installed one (installed,get_or_install): for a test of another build’s bundle (a handheld’s smaller one) in a process that installed the whole. Other threads are never affected. - recording
- What
fgives, and the pathsBundle::bytesfound while it ran on this thread (also throughBundle::fileand the formats that read a bundle). Unlikewatch, it is scoped, and more than one tool can use it at once. Nested, the outer call sees the inner one’s reads too.Bundle::hasrecords nothing. - shown_
under - Whether
shown(a human-facing name) names a file under the layer namedname:base/x.pngis underbase,bases/x.pngandbaseare not. - story_
only - Runs
fwith the test layers of every bundle hidden from this thread: each answers as it does in a build that ships. For the tests that check what such a build holds. - target_
layer_ name - The name of
layer’s layer fortarget:assets@playdateforassetsandplaydate. - watch
- Tells
watcherof every file any bundle reads from now on (Bundle::bytesandBundle::file), on the thread that reads it: for a front end that logs or times what it loads. Set once: a second call gives its watcher back and changes nothing.