feat(pbs): add Beacon Workshop composition example
Add an original-asset minigame with modern controls, independent movement and tool animations, randomized safe beacon layouts and 2D drone patrols. Distribute the canonical project through installed knowledge and exercise compiled cartridges and animation boundaries. Fix lowering of admitted sibling constants and add a regression test. Focused compiler, installed knowledge and direct native checks passed; user tested and approved. Full make verify remains blocked by sandbox sysctl restrictions in ACP tests. WRK-0022 remains open.
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
# Beacon Workshop
|
||||
|
||||
A small original PBS game and an example of typed composition. Guide a repair
|
||||
robot through one workshop, pulse all three beacons, then reach the exit at the
|
||||
bottom right. Beacons change positions on each new match. Maintenance drones
|
||||
follow independent routes around the central obstacle. Contact returns the robot to
|
||||
the safe starting position and cancels its tool; lit beacons stay lit until restart.
|
||||
|
||||
Open this directory in Studio, select your runtime installation, build with
|
||||
Shipper and use Debug Play. All required art, asset registrations, palettes,
|
||||
scene data and animation definitions are included. No external game or ROM is used.
|
||||
|
||||
| Logical control | Action |
|
||||
| --- | --- |
|
||||
| D-pad | Move in eight directions; opposite directions cancel per axis |
|
||||
| A | Pulse towards the direction faced when the action starts |
|
||||
| Start | New match with a fresh beacon layout, including after victory |
|
||||
|
||||
Desktop keyboard/controller bindings belong to the selected host. The robot can
|
||||
move and turn while its tool completes a pulse. Holding A does not repeat pulses.
|
||||
A new press in the last four ticks of an action queues one next pulse. Earlier
|
||||
presses are discarded; additional presses do not create an unbounded queue.
|
||||
|
||||
## Composition
|
||||
|
||||
These are game-local structs, not a new public entity API or an inheritance tree.
|
||||
|
||||
| Type | Parts |
|
||||
| --- | --- |
|
||||
| `Robot` | `Spatial2D`, `Motor2D`, `LocomotionVisual`, `PulseTool` |
|
||||
| `Drone` | `Spatial2D`, `Motor2D`, independent `Animator`, 2D `PatrolController` |
|
||||
| `Beacon` | `Spatial2D`, independent activation flag, off/on `Sprite` |
|
||||
|
||||
`PlayerController` and `PatrolController` implement the same `Controller` contract
|
||||
and return a named tuple of movement/action intentions. The concrete actor applies
|
||||
its own rules. Only the player controller reads `Pad`. Each controller and actor
|
||||
is constructed once; mutable parts are shared only within their owning composition.
|
||||
For example a robot's motor observes the exact same spatial object as its renderer.
|
||||
Different robots/drones never share their mutable spatial or animator instances.
|
||||
|
||||
Locomotion and tool action have independent state:
|
||||
|
||||
```text
|
||||
body: Idle <-> Moving
|
||||
tool: Ready -> Pulsing -> Ready
|
||||
```
|
||||
|
||||
The body can keep stepping while the tool plays a separate `Once` clip. The tool
|
||||
captures its direction at action start; its visual offset follows the moving robot.
|
||||
The activation event happens once, at pulse start, using that tick's position.
|
||||
Remaining in `Pulsing` never emits another gameplay event.
|
||||
|
||||
`Spatial2D` uses fixed point with 256 units per pixel. Cardinal motion is 512 units
|
||||
per tick; diagonal components are 362 units. The diagonal magnitude is about
|
||||
0.0107% below cardinal motion, never faster. Fractional position is retained for
|
||||
simulation and truncated only for pixel emission. The footprint slides along the
|
||||
room's obstacles; orientation follows nonzero intention even when movement is blocked.
|
||||
|
||||
## Match variation and patrols
|
||||
|
||||
`BeaconLayout` draws one of four authored anchors in each of three regions. All
|
||||
12 positions have walkable approaches within pulse range and avoid the central
|
||||
obstacle, the robot's safe return area and the exit. Three draws produce a layout;
|
||||
if the complete triple repeats the last match, the southern choice advances to
|
||||
the next valid candidate. This bounded rule guarantees a different arrangement
|
||||
without retry loops. The map geometry stays fixed. Lit beacons keep their position
|
||||
and activation across contact; Start clears them and selects the next layout.
|
||||
|
||||
`DEFAULT_SEED` in `src/layout.pbs` is the explicit `long` value `2026`.
|
||||
`make_workshop_seed(seed)` supports controlled replay. Initialization creates
|
||||
independent Random streams for layout and each drone from three successive words
|
||||
of a root generator. Copies of a Random handle would share state; these streams
|
||||
are separately constructed. Start reuses them instead of reseeding. Reopening
|
||||
with the same seed repeats the first layout; matching seeds and ordered inputs
|
||||
reproduce the same sequence. No wall-clock entropy is assumed.
|
||||
|
||||
The drone controller follows a nine-point ring of safe connections around the
|
||||
obstacle, including vertical and diagonal legs. At a waypoint it has a one-in-four
|
||||
chance to reverse its traversal direction. Two-pixel arrival tolerance avoids
|
||||
oscillation. After 24 ticks without progress it returns to its last reached point
|
||||
and tries the opposite connection, without another random reversal on recovery.
|
||||
The ring leaves the return area clear. Each drone keeps its own current waypoint,
|
||||
destination, recovery state, Random stream and animation phase. Movement uses the
|
||||
same bounded motor as the robot; it does not gain diagonal speed or teleport at
|
||||
waypoints. Drawing never consumes random state.
|
||||
|
||||
Actors, visual parts and generators are built once. Layout selection and patrol
|
||||
updates reuse their state without constructing candidate lists, actors or Random
|
||||
objects per frame or per restart. Invalid anchor content is diagnosed at setup;
|
||||
a reset also checks its resulting placement before entering the match.
|
||||
|
||||
## Tick order and errors
|
||||
|
||||
1. Read intentions and resolve movement.
|
||||
2. Resolve contact with drones. Contact takes precedence over pulses and victory,
|
||||
returns the robot to `(64, 256)`, cancels the tool and clears the queued command.
|
||||
3. Resolve tool completion, the input window and a possible new pulse. A pulse
|
||||
activates unlit beacons within 56 pixels and a narrow forward sector.
|
||||
4. Select body clips on transitions and explicitly advance each animator once.
|
||||
5. Emit the resulting scene and sprites, followed by the small control/victory overlay.
|
||||
|
||||
The pulse lasts 12 authored ticks (three frames of four ticks). Its animator's
|
||||
`Finished` state is authoritative. The remaining-tick counter only determines the
|
||||
input window and is decremented alongside that animator's explicit advance.
|
||||
The queued press is valid only through completion of the current action and is
|
||||
consumed once. Restart and contact clear it. A new match also repositions the beacons and resets
|
||||
the drone routes while retaining the independent Random streams.
|
||||
|
||||
Factories run during `[Init]`, not from drawing. PBS requires `handle` within a
|
||||
result-returning callable, so private boundary helpers recover every domain error
|
||||
and always return `ok`. The `void` hooks discard only those recovered results.
|
||||
A directly constructed holder contains the optional game until initialization;
|
||||
global initialization never calls procedural factories. Animation failures and nonzero Composer
|
||||
statuses stop gameplay and produce a Studio log plus an error screen. These paths
|
||||
do not catch VM traps. Rendering never calls `play`/`advance`, changes gameplay or
|
||||
creates actors. Emitting twice within the same tick preserves animation and state.
|
||||
|
||||
## Original assets and installed example
|
||||
|
||||
All visual source is authored in `tools/author_assets.py`: compact pixel drawings
|
||||
of a teal/brass repair robot, coral maintenance drones, glass beacons and a metal
|
||||
workshop. The script uses only Python's standard library to generate PNGs, glyph
|
||||
bindings, the scene, palettes and `animations.studio.json`. It reads no external art.
|
||||
|
||||
```sh
|
||||
python3 tools/author_assets.py
|
||||
python3 tools/author_assets.py --check
|
||||
```
|
||||
|
||||
Edit these authoring sources when changing the art. Animation definitions can also
|
||||
be studied/edited through Studio's existing Assets animation authoring; reconcile
|
||||
intentional definition edits into the generator before regenerating. Generated
|
||||
animation factory modules are read-only and resolve through the registered bank.
|
||||
Runtime glyph slot 0 and scene slot 0 are preloaded by the existing Packer pipeline.
|
||||
Position, palette and ordering are emission inputs, not clip-definition fields.
|
||||
|
||||
This directory is the canonical source. The PBS frontend build projects its source
|
||||
and assets into `pbs-knowledge/examples/game/1/beacon-workshop`. The reference
|
||||
`pbs:example:game:1:beacon-workshop/distribution.json` lists packaged paths and hashes;
|
||||
binary PNGs are packaged resources rather than UTF-8 reference text. The installed
|
||||
runtime tests reconstruct the project from these resources and verify their hashes.
|
||||
|
||||
## What belongs in core?
|
||||
|
||||
`SpriteView` and `Animator` already provide reusable visual contracts. This example
|
||||
exercises spatial state and movement across two actor types, but collision geometry,
|
||||
patrol graph, regional anchor pools, beacon activation and pulse rules belong to
|
||||
this game. A public core
|
||||
entity/controller/motor API is deliberately deferred until other games demonstrate
|
||||
compatible requirements. In particular this room's collision function is not a
|
||||
general physics API, and one `SpriteView` cannot represent the robot's multiple
|
||||
independently emitted parts. Composition uses the current Composer API directly.
|
||||
|
||||
Validation covers the resource-distributed project, deterministic native input,
|
||||
animation boundaries, state independence and the play/win/restart loop. Static
|
||||
inspection of the hot path and executable invariance checks are distinct evidence;
|
||||
neither is presented as a native heap-allocation measurement.
|
||||
Reference in New Issue
Block a user