classic-ecs

Documents hecs entity-component patterns and 2D orthographic camera math for the classic-wgl Rust engine.

1|1|Updated Aug 18, 2021
One-click install
npx skills add https://github.com/guilledk/classic-wgl --skill classic-ecs-guilledk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: classic-ecs
Source: https://github.com/guilledk/classic-wgl/tree/main/.agents/skills/classic-ecs
Command: npx skills add https://github.com/guilledk/classic-wgl --skill classic-ecs-guilledk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Working on the classic-wgl Rust engine requires knowing its exact ECS conventions: how hecs entities are spawned and queried, how the component registry round-trips state.json, how Disabled visibility propagates through UI hierarchies, and how the 2D camera matrix is composed. This Skill consolidates those patterns so changes to components, visibility, or camera behavior follow the engine's established rules instead of introducing borrow-order bugs or matrix-order errors. ## Core Features & Use Cases - hecs usage patterns: Spawn, query, insert, and remove components with the borrow-order rule (extract data, drop the Ref, then mutate the world). - Component registry and serialization: Register components with spawners, dumpers, subsumes de-duplication, and dump ordering for state.json round-trips. - Visibility and shared state: set_enabled with collider sync, is_disabled parent-chain walks, and Rc<Cell>/Rc<RefCell> state sharing between click handlers and on_update closures. - Camera math: fix() formula, T(-fix) * S(scale) matrix order, proportional zoom, WASD panning, and orthographic projection setup. - Use Case: When adding a new serializable component to the engine, follow the registry section to write its spawner and dumper, set its subsumes list, and place its dump order so state.json output stays consistent. ## Quick Start Ask the assistant to explain how to add a new serializable component to the classic-wgl registry or to review ECS code for borrow-order and visibility-sync mistakes.

Frequently Asked Questions about classic-ecs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I spawn and query entities with hecs in Rust?

Spawn entities with world.spawn((Transform::new(pos, scale), SpriteRender { ... })) and query with world.query::<(&Transform, &SpriteRender)>().iter(). For single-entity mutable access use world.get::<&mut T>(entity), and release the borrow before calling other world methods.

How do I add a serializable component to an ECS registry?

Add a ComponentReg entry in register_all_components() with a name, a spawner closure (JSON to EntityBuilder), an optional dumper, a dump order, and a subsumes list. The registry is populate-once via OnceLock, so new components require a source edit.

Why does hecs borrow checker fail when mutating components?

You cannot hold a Ref or RefMut from world.get() while calling other world methods. Extract the needed values into locals, drop the borrow (unwrap_or consumes the Ref), then perform inserts or further queries.

How do I share state between click handlers and update closures in Rust?

Use Rc<Cell<T>> for Copy values and Rc<RefCell<T>> for heap values like String, cloning the Rc into each FnMut closure. Click handlers run before on_update closures each frame, so writes are visible in the same frame.

What is the correct matrix order for a 2D orthographic camera?

Use T(-fix) * S(scale), where fix = position * scale - size / 2 maps position*scale to the viewport centre. Reversing to S * T multiplies the translation by the scale and breaks panning at high zoom.

What are the limitations of this ECS architecture?

There is no system scheduler or parallel dispatch; on_update closures run sequentially in registration order. Collider, UiNode, and SdfTextRender have no dumpers and are not serialized, and the camera supports only 2D pan and uniform zoom with no rotation.