@@ -21,70 +21,74 @@ The theater coordinates your rendering thread and displays the results onto a ca
2121
2222The theater is split into two main parts. Each will live in its own separate bundle.
2323- * The Frontstage* hosts the visible canvas in the dom. It doesn't import Babylon, and will be lean in filesize.
24- - * The Backstage* run inside a web worker, and performs rendering work. It imports Babylon, and will be fat in filesize.
24+ - * The Backstage* runs inside a web worker, and performs rendering work. It imports Babylon, and will be fat in filesize.
2525
2626### Theater project setup
27271 . Write your ` spec.ts ` type, which describes your renderable world
2828 ``` ts
29+ import {AsFigmentSpec } from " @benev/marduk/x/theater/index.pure.js"
30+
2931 export type MySpec = AsFigmentSpec <{
3032
31- // Describe all the renderable objects in your world,
33+ // Describe a renderable object in your world,
3234 // in terms of serializable data.
3335 hippo: {hungry: boolean }
3436 }>
3537 ` ` `
38+ - notice the specific locations from where we're importing things
36391. Establish your ` backstage .ts ` module (this will be a web worker)
3740 ` ` ` ts
3841 import {MySpec } from " ./spec.js"
39- import {theaterWorker , babylonBackstage } from " @benev/marduk/x/theater/index.back .babylon.js"
42+ import {babylonBackstage , theaterWorker } from " @benev/marduk/x/theater/index.babylon.js"
4043
4144 void async function () {
42- await theaterWorker (
43- await babylonBackstage <MySpec >(async stagecraft => ({
44-
45- // now we define a renderer for this object
46- hippo : (id , data ) => {
47- console .log (" spawn" , id , data )
48- return {
49- update : data => console .log (" update" , id , data ),
50- dispose : () => console .log (" dispose" , id , data ),
51- }
52- },
53- }))
54- )
45+
46+ // defining a babylon backstage
47+ // (you could make a backstage for a different kind of renderer)
48+ const backstage = await babylonBackstage <MySpec >(async stagecraft => ({
49+
50+ // now we define a renderer for this object
51+ hippo : (id , data ) => {
52+ console .log (" spawn" , id , data )
53+ return {
54+ update : data => console .log (" update" , id , data ),
55+ dispose : () => console .log (" dispose" , id , data ),
56+ }
57+ },
58+ }))
59+
60+ // establishing the web worker
61+ await theaterWorker (backstage )
5562 }()
5663 ```
5764 - now bundle this module as ` backstage.bundle.js ` using ` rollup ` , ` esbuild ` , ` parcel ` , ` vite ` , or whatever
58- 1. Establish your ` frontstage.ts ` module (this will be your app ' s main entrypoint)
65+ 1. Create your ` frontstage.ts ` module (this will be your app ' s main entrypoint)
5966 ` ` ` ts
6067 import {MySpec} from "./spec.js"
61- import {theaterHost, Frontstage, theaterElement, register} from "@benev/marduk/x/theater/index.front .js"
68+ import {Frontstage, register} from "@benev/marduk/x/theater/index.dom .js"
6269
6370 void async function() {
6471 const workerUrl = new URL("./backstage.bundle.js", import.meta.url)
65- const theater = await theaterHost<MySpec>({workerUrl})
66- const frontstage = new Frontstage(theater)
72+ const frontstage = await Frontstage.make<MySpec>({workerUrl})
6773 register(frontstage.getElements())
6874
6975 // okay, now you're ready to manipulate your world
7076
71- // spawn a hippo
72- await frontstage.theater.backstage.setFigments([[0, ["hippo", {hungry: false}]]])
73-
74- // update the hippo
75- await frontstage.theater.backstage.setFigments([[0, ["hippo", {hungry: true}]]])
76-
77- // delete the hippo
78- await frontstage.theater.backstage.setFigments([[0, undefined]])
77+ // spawn, then update, then delete a hippo (lol, just to exercise the full lifecycle)
78+ await frontstage.syncFigments([[0, ["hippo", {hungry: false}]]])
79+ await frontstage.syncFigments([[0, ["hippo", {hungry: true}]]])
80+ await frontstage.syncFigments([[0, undefined]])
7981 }()
8082 ` ` `
8183 - now bundle this module as ` frontstage.bundle.js `
82- 1. Load the frontstage onto your web page
84+ 1. Load the frontstage bundle onto your web page
8385 ` ` ` html
8486 <script type=module src="./frontstage.bundle.js"></script>
8587 ` ` `
86881. Place the ` <marduk-theater> ` element in your html body
8789 ` ` ` html
8890 <marduk-theater></marduk-theater>
8991 ` ` `
92+ 1. 🎉 You ' re done!
93+ - If you run the page , you should see the console logging about the hippo lifecycle events .
9094
0 commit comments