Jazz2::Resources::Metadata struct

Contains assets for specific object type.

Loaded from a metadata file and cached by ContentResolver, it groups the animations and sounds used by one object type together with its bounding box, and resolves an AnimState to the matching GraphicResource at runtime.

Deferred animations

A metadata file that sets "Deferred": true (either for the whole file or on a single animation entry) is parsed as usual, but none of its sheets are read until an animation is actually looked up — the descriptions needed to load them are kept in DeferredAnimations and FindAnimation() resolves an entry the first time it is asked for. This is what a set of assets that are declared together but used* apart wants: the UI metadata describes every gamepad button label, touch button and menu icon in the game, while a given run of the game only ever draws the labels of one gamepad type. Everything else then costs a few dozen bytes of description instead of a decoded sheet and a texture, and the ordinary mark-and-sweep of the resolver still releases whatever was loaded once the metadata itself goes away.

Deferral is opt-in because it trades a load that happens at a known time (a loading screen) for one that happens at first draw, which is right for UI and wrong for an actor that must animate without hitching. A deferred metadata cannot derive its BoundingBox from its first sheet either, so one that needs a bounding box has to declare it explicitly.

Constructors, destructors, conversion operators

Metadata() noexcept
Creates a new instance.

Public functions

auto FindAnimation(AnimState state) -> GraphicResource*
Finds specified animation state.

Public variables

String Path
Metadata path.
String CacheKey
Key this metadata is cached under (usually equals Path, but indexed variants use a distinct key); the cache stores a reference to this string, so it must not be modified after insertion.
MetadataFlags Flags
Metadata flags.
SmallVector<GraphicResource, 0> Animations
Animations.
SmallVector<DeferredGraphicResource, 0> DeferredAnimations
Descriptions of the animations that are loaded on first use (see Deferred animations).
HashMap<String, SoundResource> Sounds
Sounds.
Vector2i BoundingBox
Bounding box.

Function documentation

GraphicResource* Jazz2::Resources::Metadata::FindAnimation(AnimState state)

Finds specified animation state.

Loads the graphics of a deferred animation (see Deferred animations) if this is the first time it is asked for, and returns nullptr if they cannot be loaded.