diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:32:55 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:32:55 +0100 |
| commit | 84840ede6646ed793b61cdd889d3f57ab05e9311 (patch) | |
| tree | 2b62dd73a7321bc71a368b297ab40b3535bd79fc /docs/entities.org | |
| parent | 7903180321bf72b344077a8423930ac161872a2c (diff) | |
Refactor to be functional
Diffstat (limited to 'docs/entities.org')
| -rw-r--r-- | docs/entities.org | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/docs/entities.org b/docs/entities.org index 048cd8e..3766522 100644 --- a/docs/entities.org +++ b/docs/entities.org @@ -126,19 +126,19 @@ The engine recognizes these standard keys. Use them to integrate with the physic | ~#:anim-tick~ | integer | Tick counter for frame timing (0 to ~#:duration - 1~). Incremented by ~animate-entity~; resets when frame advances. | | ~#:group-id~ | symbol | Shared id for one rigid assembly (from ~instantiate-group-prefab~). All parts and the origin share the same symbol. | | ~#:group-origin?~ | boolean | When ~#t~, this entity is the assembly’s pose origin; world ~#:x~ / ~#:y~ drive the group. Members should not set this. | -| ~#:group-local-x~, ~#:group-local-y~ | number | Offset from the origin’s top-left corner; members’ world position is origin + local (updated by ~scene-sync-groups!~). | +| ~#:group-local-x~, ~#:group-local-y~ | number | Offset from the origin’s top-left corner; members’ world position is origin + local (updated by ~scene-sync-groups~). | | ~#:skip-render~ | boolean | When ~#t~, ~render-scene!~ skips drawing this entity (used for invisible origins). | * Entity groups (prefab assemblies) A **group prefab** describes one *origin* entity plus several *parts* with local offsets. Data lives in the optional ~group-prefabs~ section of the prefab file (alongside ~mixins~ and ~prefabs~). Each group entry has the shape ~(name #:type-members SYMBOL #:parts (part ...) ...)~ with two optional flags: -- ~#:pose-only-origin?~ — when ~#t~ (typical for tweened platforms), the origin is invisible, does not run physics pipelines, and is driven by tweens or scripts. When ~#f~ (default), the origin uses a small *physics-driving* profile (~#:gravity? #t~, no ~#:skip-pipelines~): integrate the origin like a mover, then call ~scene-sync-groups!~ so parts stay glued as a rigid body. For that case, set ~#:origin-width~ and ~#:origin-height~ to the full assembly size (same box as the combined parts); otherwise the origin stays 0×0 and tile collision only sees a point at the reference corner, which can leave the raft overlapping solid floor tiles. +- ~#:pose-only-origin?~ — when ~#t~ (typical for tweened platforms), the origin is invisible, does not run physics pipelines, and is driven by tweens or scripts. When ~#f~ (default), the origin uses a small *physics-driving* profile (~#:gravity? #t~, no ~#:skip-pipelines~): integrate the origin like a mover, then call ~scene-sync-groups~ so parts stay glued as a rigid body. For that case, set ~#:origin-width~ and ~#:origin-height~ to the full assembly size (same box as the combined parts); otherwise the origin stays 0×0 and tile collision only sees a point at the reference corner, which can leave the raft overlapping solid floor tiles. - ~#:static-parts?~ — when ~#t~, each part gets static rigid-body defaults (no gravity on parts; pose comes from the origin). When ~#f~ (default), parts only have what you put in each part plist. Each ~part~ is a plist using ~#:local-x~ / ~#:local-y~ (or ~#:group-local-x~ / ~#:group-local-y~) and the usual ~#:width~, ~#:height~, ~#:tile-id~, physics keys, etc. -Use ~(instantiate-group-prefab registry 'name origin-x origin-y)~ from ~downstroke-prefabs~ to obtain ~(origin member ...)~. Append all of them to the scene. After moving origins (tweens and/or physics), ensure updated origins are in ~scene-entities~, then call ~(scene-sync-groups! scene)~ so every part’s ~#:x~ / ~#:y~ matches the origin plus local offsets (see ~docs/api.org~ for ordering). +Use ~(instantiate-group-prefab registry 'name origin-x origin-y)~ from ~downstroke-prefabs~ to obtain ~(origin member ...)~. Append all of them to the scene. After moving origins (tweens and/or physics), ensure updated origins are in ~scene-entities~, then call ~(scene-sync-groups scene)~ so every part’s ~#:x~ / ~#:y~ matches the origin plus local offsets (see ~docs/api.org~ for ordering). * Entities in Scenes @@ -152,17 +152,17 @@ Returns the list of all entities in the scene. (define all-entities (scene-entities scene)) #+end_src -** ~scene-entities-set! scene entities~ +** ~update-scene~ -Mutates the scene to replace the entity list. Use after ~scene-update-entities~ or batch operations. +Returns a new scene with the specified fields changed. Preferred over the mutating ~scene-entities-set!~. #+begin_src scheme -(scene-entities-set! scene (list updated-player updated-enemy)) +(update-scene scene entities: (list updated-player updated-enemy)) #+end_src ** ~scene-add-entity scene entity~ -Adds an entity to the scene and returns the scene. Appends to the entity list. +Returns a new scene with the entity appended to the entity list. #+begin_src scheme (scene-add-entity scene new-enemy) @@ -183,17 +183,15 @@ Maps each procedure over the scene's entities, applying them in sequence. Each p The result is equivalent to: #+begin_src scheme -(let* ((es (scene-entities scene)) - (es (map apply-gravity es)) - (es (map apply-velocity-x es)) - (es (map apply-velocity-y es))) - (scene-entities-set! scene es) - scene) +(chain scene + (scene-update-entities _ apply-gravity) + (scene-update-entities _ apply-velocity-x) + (scene-update-entities _ apply-velocity-y)) #+end_src ** ~scene-filter-entities scene pred~ -Removes all entities that do not satisfy the predicate. Use to despawn dead enemies, collected items, etc. +Keeps only entities satisfying the predicate; returns a new scene. Use to despawn dead enemies, collected items, etc. #+begin_src scheme ;; Remove all entities with #:health <= 0: @@ -392,7 +390,8 @@ Here is a full example showing entity creation, initialization in the scene, and (let ((player (if (< (entity-ref player #:vx 0) 0) (entity-set player #:facing -1) (entity-set player #:facing 1)))) - (scene-entities-set! scene (list player)))))) + (game-scene-set! game + (update-scene scene entities: (list player))))))) #+end_src -Note the let*-chaining pattern: each update builds on the previous result, keeping the data flow clear and each step testable. +Note the let*-chaining pattern: each update builds on the previous result, keeping the data flow clear and each step testable. The single ~game-scene-set!~ at the boundary stores the final scene back on the game struct. |
