Expand description
Scene serialization, node tree instantiation, validation, and binary caching for the Pite game engine.
Human-readable TOML files (.ptscn) serve as the canonical source of truth
for scene layouts, while derived binary snapshots (_cache/*.bin) accelerate
runtime loading. Depends solely on pite-core.
Re-exports§
pub use cache::CacheStatus;pub use cache::CACHE_VERSION;pub use color::format_hex_color;pub use color::parse_hex_color;pub use tilemap::load_tilemap;pub use tilemap::map_to_world;pub use tilemap::parse_tilemap_str;pub use tilemap::save_tilemap;pub use tilemap::world_to_map;pub use tilemap::TileCell;pub use tilemap::TileMapDoc;pub use tilemap::TileMapLayer;
Modules§
- cache
- Binary scene cache: TOML stays source of truth;
_cache/holds content-hash-keyed, version-stamped binaries. - color
- Hex color encoding for the scene file format.
- tilemap
- TileMap document schema, TOML serialization, coordinate math, and layer management.
Structs§
- Scene
Doc - Canonical
.ptscndocument. - Scene
Instance - An instantiation entry: load the referenced file, clone its subtree
under
parent, remap ids withprefix, apply prop overrides. Overrides are keyed"node_id.prop"; unknown targets fail loudly. - Scene
Node - One flat node entry.
propspreserves unknown keys (forward compat). - Scene
Script - Attached script reference (project-relative path + class).
Constants§
- FORMAT_
VERSION - Current scene format version. Bump = migrate or error loudly, never silent.
Functions§
- build_
tree - Build the full runtime tree: host nodes plus every
[[instance]]subtree (loaded, id-remapped, overrides applied). - instantiate
- Load the referenced scene, fill defaults, remap ids with
prefix, apply prop overrides. Returns node records ready to insert into the host tree plus the remapped id of the referenced scene’s root. - load_
cached - Load with the binary cache: a valid cache wins; a missing cache parses TOML and writes the cache; a corrupt or version-mismatched cache parses TOML, rewrites the cache, and reports the fallback loudly via the returned warning — never silently. TOML stays source of truth.
- load_
scene - load_
scene_ cached - Preferred entry point:
load_cachedwith the fallback warning surfaced loudly on stderr. Corruption anywhere falls back to TOML, never silently. - migrate
- Format migration hook (§12). New fields are additive; breaking change = version bump, never silent reinterpretation.
- parse_
scene_ str - prop_
to_ toml - Convert a
PropValueback to its scene-file TOML shape. The inverse oftoml_to_prop:Colorbecomes"#rrggbbaa",Vec2becomes[x, y], primitives map to their natural TOML types, and any unrecognized variant (future) falls back to a string. - resolve_
scene_ ref - save_
scene - to_
node_ tree - Convert a scene document into a runtime
NodeTreewith schema defaults filled. Missing scripts are placeholders here, never a load failure. - toml_
to_ prop - validate
- Structural validation. Missing script = placeholder, never a load failure; unknown props warn and are preserved on save.