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:
@@ -14,10 +14,17 @@ dependencies {
|
||||
// Build-time projection of owner-maintained sources; no second normative copy is edited by Studio.
|
||||
val pbsSpecs = rootProject.layout.projectDirectory.dir("docs/specs/compiler-languages/pbs")
|
||||
val pbsResources = layout.projectDirectory.dir("src/main/resources")
|
||||
val beaconWorkshop = rootProject.layout.projectDirectory.dir("test-projects/beacon-workshop")
|
||||
val beaconFiles = fileTree(beaconWorkshop) {
|
||||
include("src/**", "assets/**", "tools/*.py", "*.md", "prometeu.json", ".gitignore")
|
||||
exclude("**/__pycache__/**")
|
||||
}
|
||||
val generatePbsKnowledge by tasks.registering(Sync::class) {
|
||||
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
||||
from(beaconFiles) { into("pbs-knowledge/examples/game/1/beacon-workshop") }
|
||||
into(layout.buildDirectory.dir("generated/pbsKnowledge"))
|
||||
inputs.files(fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel", "pbs-knowledge/examples/**") })
|
||||
inputs.files(beaconFiles)
|
||||
doLast {
|
||||
val entries = mutableListOf<Map<String, Any?>>()
|
||||
fun entry(id: String, title: String, kind: String, resource: String, source: File, sdk: Int? = null, target: String? = null) {
|
||||
@@ -72,6 +79,23 @@ val generatePbsKnowledge by tasks.registering(Sync::class) {
|
||||
entry("pbs:example:game:1:$relative", "PBS Game / SDK 1 example: $relative", "EXAMPLE",
|
||||
"pbs-knowledge/examples/game/1/$relative", source, 1, "Game")
|
||||
}
|
||||
// Binary glyphs travel as resources, never as UTF-8 reference payloads.
|
||||
val distributed = beaconFiles.files.sorted().map { source ->
|
||||
val relative = source.relativeTo(beaconWorkshop.asFile).invariantSeparatorsPath
|
||||
val resource = "pbs-knowledge/examples/game/1/beacon-workshop/$relative"
|
||||
if (source.extension != "png") {
|
||||
entry("pbs:example:game:1:beacon-workshop/$relative", "Beacon Workshop / $relative",
|
||||
"EXAMPLE", resource, source, 1, "Game")
|
||||
}
|
||||
mapOf("path" to relative, "resource" to resource,
|
||||
"sha256" to MessageDigest.getInstance("SHA-256").digest(source.readBytes())
|
||||
.joinToString("") { "%02x".format(it) })
|
||||
}
|
||||
val inventory = destinationDir.resolve("pbs-knowledge/examples/game/1/beacon-workshop/distribution.json")
|
||||
inventory.writeText(groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(
|
||||
mapOf("schemaVersion" to 1, "files" to distributed))))
|
||||
entry("pbs:example:game:1:beacon-workshop/distribution.json", "Beacon Workshop / packaged files",
|
||||
"EXAMPLE", "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json", inventory, 1, "Game")
|
||||
check(entries.map { it["id"] }.distinct().size == entries.size) { "Duplicate PBS reference IDs" }
|
||||
destinationDir.resolve("pbs-knowledge/index.json").writeText(groovy.json.JsonOutput.prettyPrint(
|
||||
groovy.json.JsonOutput.toJson(mapOf("schemaVersion" to 1, "owner" to "pbs", "references" to entries))))
|
||||
|
||||
+7
-2
@@ -40,7 +40,7 @@ final class PbsExecutableMetadataIndexFactory {
|
||||
}
|
||||
final var importedGlobalsBySlot = PbsImportedGlobalSlots.index(ownedNames, importedGlobals);
|
||||
importedGlobalsBySlot.forEach((slot,global) -> globalSlotByNameId.put(nameTable.register(global.localName()),slot));
|
||||
final var constDeclByNameId = indexConstDecls(ast, nameTable);
|
||||
final var constDeclByNameId = indexConstDecls(ast, supplementalTopDecls, nameTable);
|
||||
final var addressableByAddress = indexAddressables(feSurfaceContext);
|
||||
final var builtinSignatureByOwnerAndMethod = indexBuiltinSignatures(
|
||||
ast,
|
||||
@@ -132,9 +132,14 @@ final class PbsExecutableMetadataIndexFactory {
|
||||
|
||||
private Map<NameId, PbsAst.ConstDecl> indexConstDecls(
|
||||
final PbsAst.File ast,
|
||||
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
||||
final NameTable nameTable) {
|
||||
final var constDeclByNameId = new HashMap<NameId, PbsAst.ConstDecl>();
|
||||
for (final var topDecl : ast.topDecls()) {
|
||||
// Semantic admission already filters sibling/imported declarations. They
|
||||
// need the same executable values as locally declared constants.
|
||||
final var declarations = new ArrayList<>(ast.topDecls().asList());
|
||||
declarations.addAll(supplementalTopDecls.asList());
|
||||
for (final var topDecl : declarations) {
|
||||
if (!(topDecl instanceof PbsAst.ConstDecl constDecl)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+60
-5
@@ -22,17 +22,72 @@ For bank UUID `12345678-1234-1234-1234-123456789abc` and animator ID `hero`:
|
||||
|
||||
```pbs
|
||||
import { create_hero } from @app:generated/animations/b_12345678123412341234123456789abc;
|
||||
import { AnimationError } from @core:animation;
|
||||
fn render() -> result<AnimationError> {
|
||||
import { Animator, AnimationError } from @core:animation;
|
||||
import { Composer } from @sdk:composer;
|
||||
import { Log } from @sdk:log;
|
||||
|
||||
declare struct HeroSlot(pub mut value: optional Animator) {
|
||||
ctor make() { this.value = none; }
|
||||
}
|
||||
declare global hero: HeroSlot = new HeroSlot.make();
|
||||
declare global animation_failed: bool = false;
|
||||
|
||||
fn initialize_hero() -> result<AnimationError> {
|
||||
let value = create_hero(3)!;
|
||||
value.play("idle")!;
|
||||
value.advance(2)!;
|
||||
let image = value.sprite();
|
||||
// Supply image.bank_id/image.glyph_id to the existing nine-argument Composer API.
|
||||
hero.value = some(value);
|
||||
return ok(());
|
||||
}
|
||||
fn recover_initialization() -> result<AnimationError> {
|
||||
handle initialize_hero() { _ -> {
|
||||
animation_failed = true;
|
||||
Log.failure("Unable to initialize hero animation");
|
||||
ok(())
|
||||
} };
|
||||
return ok(());
|
||||
}
|
||||
fn recover_frame() -> result<AnimationError> {
|
||||
if animation_failed { return ok(()); }
|
||||
if let value = hero.value {
|
||||
handle value.advance(1) { _ -> {
|
||||
animation_failed = true;
|
||||
Log.failure("Unable to advance hero animation");
|
||||
ok(())
|
||||
} };
|
||||
if animation_failed { return ok(()); }
|
||||
// Scene binding and bank-slot preload belong to project setup.
|
||||
let image = value.sprite();
|
||||
if Composer.emit_sprite(image.glyph_id, 0, 32, 32, 1,
|
||||
image.bank_id, false, false, 0) != 0 {
|
||||
animation_failed = true;
|
||||
Log.failure("Unable to emit hero sprite");
|
||||
}
|
||||
}
|
||||
return ok(());
|
||||
}
|
||||
[Init] fn init() -> void { recover_initialization(); }
|
||||
[Frame] fn frame() -> void { recover_frame(); }
|
||||
```
|
||||
|
||||
PBS requires `handle` inside a result-returning callable. The two recovery helpers
|
||||
consume every domain error and always return `ok`; the required `void` hooks discard
|
||||
only that already-recovered result. Do not discard a raw factory/update result or
|
||||
try to propagate it from a `void` hook. The directly constructed holder avoids a
|
||||
procedural factory or `none` expression in a global initializer.
|
||||
|
||||
The example above illustrates lifetime and error handling for the named authored
|
||||
bank; it does not supply that bank or a complete scene. Construct once, retain the
|
||||
same instance, advance explicitly during update and query its current sprite during
|
||||
drawing. Change action clips only on transitions. Repeating a draw must not advance
|
||||
time, and repeating `play` each frame restarts the animation.
|
||||
|
||||
For a complete project with original assets, input, composed body/tool animation,
|
||||
two independent autonomous actors and a play/win/restart loop, use **Beacon Workshop**.
|
||||
Its installed reference prefix is `pbs:example:game:1:beacon-workshop/`; start with
|
||||
`README.md` and `distribution.json`. Its canonical editable source is Studio's
|
||||
`test-projects/beacon-workshop`. The build projects that source into the installed
|
||||
corpus, including the registered banks and authored animation definitions.
|
||||
|
||||
The virtual module is reproducible and read-only. Its CodeLens opens the original
|
||||
JSON field in Studio. A changed definition invalidates older source revisions;
|
||||
navigate again to obtain the current definition. Existing projects without a
|
||||
|
||||
+16
@@ -60,6 +60,22 @@ class PbsProductionLoweringRegressionTest {
|
||||
"""));
|
||||
assertFalse(result.diagnostics().hasErrors(), result.diagnostics().asCollection().toString());
|
||||
}
|
||||
@Test void admittedSiblingConstantsAreMaterializedInCallsAndArithmetic() throws Exception {
|
||||
var result=compile(Map.of(
|
||||
"src/mod.barrel", "pub fn frame() -> void; mod const HOME_X; mod const HOME_Y; mod const SCALE;",
|
||||
"src/settings.pbs", "declare const HOME_X:int=64; declare const HOME_Y:int=256; declare const SCALE:int=256;",
|
||||
"src/main.pbs", """
|
||||
declare struct Position(pub mut x:int,pub mut y:int) {
|
||||
fn reset(x:int,y:int)->void { this.x=x*SCALE; this.y=y*SCALE; }
|
||||
}
|
||||
declare global position:Position=new Position(0,0);
|
||||
[Frame] fn frame()->void {
|
||||
position.reset(HOME_X,HOME_Y);
|
||||
if position.x!=16384 || position.y!=65536 { let failure=1/0; }
|
||||
}
|
||||
"""));
|
||||
assertFalse(result.diagnostics().hasErrors(),result.diagnostics().asCollection().toString());
|
||||
}
|
||||
record Compiled(IRBackend backend, DiagnosticSink diagnostics) {}
|
||||
Compiled compile(Map<String,String> sources) throws Exception {
|
||||
root=root.toRealPath(); var projects=new ProjectTable();var files=new FileTable(1);
|
||||
|
||||
Reference in New Issue
Block a user