Expand description
Formats are plugins (ADR-0007, ADR-0019). An asset kind is a plain
type (AssetKind): an image’s size, a palette, a dialogue file’s
scenes. A format is a value that reads one kind from the bytes of
one file (Format). Formats holds the formats of every kind; the
engine’s standard ones are there from the start
(Formats::standard), and a game registers its own kinds and formats
at start-up. Code that uses an asset asks for its kind by id
(Formats::load) and never sees which file it came from.
The rules of the registry:
- Lookup. For each file, the formats of the kind whose
sniffsays yes are tried first, in the order they were registered, then the one that claims the file’s extension. The first that decodes the file gives the asset; when none does, the errors are the first one’s. - Conflicts. Within one kind, two formats may not have the same id
or claim the same extension:
Formats::registerrefuses the second with a message naming both, andFormats::replaceputs it in place of the first. Different kinds may claim one extension (every RON file is.ron). - Limits. A file bigger than its format’s
max_bytes, or than the registry’s ownLimits, is refused before it is decoded. - One file. A format reads one file, and the files it names
through
DecodeCx. A check against another kind of asset (a scene against the game’s characters, a cinematic against its music) runs after, on the assets loaded.
A format may read settings for its file (ADR-0057,
import_settings): a section of the
.meta file beside it, or of a folder’s _folder.meta
(DecodeCx::import_settings). The registry knows each section’s type
(Formats::register_import_settings) and checks every settings file
of a bundle (Formats::check_import_settings); no format may claim
meta.
A front end may watch every decode the registry makes
(watch_decodes): its kind, its file, its size and whether it read,
told before and after each, on the thread that decodes. A debug build
tags what each decode allocates with its kind this way, so the heap
counter says what the game holds of each kind of asset.
Structs§
- Asset
Path - Where a file is: its path in the bundle (relative to a layer’s root,
/-separated), and the name errors show it by (base/images/a.png). - Decode
Cx - What a format has besides the file it decodes: the limits, and the bundle the file is in, for the files it names (a sidecar’s picture, a manifest’s sounds). Without a bundle, every file named is missing.
- Decode
Watch - What is told of every decode the registry makes, once set
(
watch_decodes): two plain functions, called on the thread that decodes. Build it withDecodeWatch::new(ADR-0039). - Decoded
- One decode the registry made (
Formats::decode), as aDecodeWatchis told it. Build it withDecoded::new(ADR-0039). - Formats
- The formats of every kind (module docs).
- Limits
- How much a decoding may read, beyond each format’s own
max_bytes.
Enums§
- Register
Error - Why a format, or a section of import settings, could not be registered. More reasons may come (ADR-0039).
Constants§
- DEFAULT_
MAX_ BYTES - The most bytes a format reads unless it says otherwise
(
Format::max_bytes): 16 MiB. - NOT_
FOUND - What a file asked for and missing is told.
- TEXT_
MAX_ BYTES - The most bytes the engine’s text formats read: 4 MiB, forty times the biggest text file of the game the engine was carved from.
Traits§
- Asset
Kind - A kind of asset: the plain type a
Formatreads into. The engine’s kinds are its own types (ImageInfo,PaletteDef,DialogueFile…); a game makes one of each of its data tables. - Encode
- A format that can also write its kind: what tools and an optimized format derived from a source (ADR-0007 §4) use.
- Format
- A file format: reads one
AssetKindfrom a file’s bytes.
Functions§
- decode_
with format’s asset inbytes(the filefile), unless the file is bigger thanformatorcxallow.- join
nameinsidedir(""for the root).- text
- The text of a text format’s file
bytes, or the error that it isn’t valid UTF-8. - watch_
decodes - Tells
watchof every decode any registry makes from now on (Formats::decode, soFormats::loadand the rest):beforeas it starts, with its kind, andafteronce it is decided, withbefore’s token, the file and whether it read. For a front end that tags, logs or tallies what it loads. Set once: a second call gives its watch back and changes nothing.