@@ -11,47 +11,40 @@ import { drawFrame, drawPanel } from '/src/engine/debug/index.js';
1111const theme = new Theme ( ThemeTokens ) ;
1212
1313export default class Phase18FoundationScene extends Scene {
14- constructor ( { runtimeLayer = null } = { } ) {
14+ constructor ( { phase18Flow = null } = { } ) {
1515 super ( ) ;
1616 this . elapsed = 0 ;
17- this . runtimeLayer = runtimeLayer ;
17+ this . phase18Flow = phase18Flow ;
1818 this . lastHeartbeatTick = 0 ;
1919 this . lastHeartbeatTime = 0 ;
2020 this . lastRuntimeTransition = 'idle' ;
21- this . unsubscribeHeartbeat = null ;
2221 this . unsubscribeRuntimeState = null ;
2322 }
2423
2524 enter ( engine ) {
26- if ( ! this . runtimeLayer ) return ;
27- const channel = this . runtimeLayer . getService ( 'phase18.channel' ) ;
28- if ( channel && typeof channel . subscribe === 'function' ) {
29- this . unsubscribeHeartbeat = channel . subscribe ( 'phase18.heartbeat' , ( payload ) => {
30- this . lastHeartbeatTick = Number ( payload ?. tick ) || 0 ;
31- this . lastHeartbeatTime = Number ( payload ?. t ) || 0 ;
32- } ) ;
33- }
34- this . unsubscribeRuntimeState = this . runtimeLayer . onStateChange ( ( { previous, next } ) => {
25+ if ( ! this . phase18Flow ) return ;
26+ this . unsubscribeRuntimeState = this . phase18Flow . onStateChange ( ( { previous, next } ) => {
3527 this . lastRuntimeTransition = `${ previous } -> ${ next } ` ;
3628 } ) ;
37- this . runtimeLayer . start ( { engine, scene : this } ) ;
29+ this . phase18Flow . start ( { engine, scene : this } ) ;
3830 }
3931
4032 update ( dtSeconds ) {
4133 this . elapsed += dtSeconds ;
42- this . runtimeLayer ?. update ( dtSeconds , { scene : this } ) ;
34+ this . phase18Flow ?. update ( dtSeconds , { scene : this } ) ;
35+ const snapshot = this . phase18Flow ?. getSnapshot ?. ( ) ;
36+ if ( snapshot ?. flow ) {
37+ this . lastHeartbeatTick = Number ( snapshot . flow . lastHeartbeatTick ) || 0 ;
38+ this . lastHeartbeatTime = Number ( snapshot . flow . lastHeartbeatSeconds ) || 0 ;
39+ }
4340 }
4441
4542 exit ( ) {
46- if ( typeof this . unsubscribeHeartbeat === 'function' ) {
47- this . unsubscribeHeartbeat ( ) ;
48- this . unsubscribeHeartbeat = null ;
49- }
5043 if ( typeof this . unsubscribeRuntimeState === 'function' ) {
5144 this . unsubscribeRuntimeState ( ) ;
5245 this . unsubscribeRuntimeState = null ;
5346 }
54- this . runtimeLayer ?. stop ( { scene : this } ) ;
47+ this . phase18Flow ?. stop ( { scene : this } ) ;
5548 }
5649
5750 render ( renderer ) {
@@ -72,17 +65,29 @@ export default class Phase18FoundationScene extends Scene {
7265 font : '16px monospace' ,
7366 } ) ;
7467
75- const runtimeSnapshot = this . runtimeLayer ?. getSnapshot ?. ( ) || {
68+ const phase18Snapshot = this . phase18Flow ?. getSnapshot ?. ( ) || {
69+ runtime : {
70+ state : 'idle' ,
71+ tickCount : 0 ,
72+ serviceIds : [ ] ,
73+ } ,
74+ flow : {
75+ runtimeStateEvents : 0 ,
76+ } ,
77+ } ;
78+ const runtimeSnapshot = phase18Snapshot . runtime || {
7679 state : 'idle' ,
7780 tickCount : 0 ,
7881 serviceIds : [ ] ,
7982 } ;
83+ const flowSnapshot = phase18Snapshot . flow || { runtimeStateEvents : 0 } ;
8084 drawPanel ( renderer , 620 , 34 , 300 , 160 , 'Phase 18 Bootstrap' , [
8185 'Status: initialized' ,
8286 'Folder: samples/phase-18' ,
8387 'Entry sample: 1801' ,
8488 `Runtime: ${ runtimeSnapshot . state } | tick ${ runtimeSnapshot . tickCount } ` ,
8589 `Transition: ${ this . lastRuntimeTransition } ` ,
90+ `Flow events: ${ flowSnapshot . runtimeStateEvents } ` ,
8691 `Services: ${ runtimeSnapshot . serviceIds . length } ` ,
8792 `Heartbeat tick: ${ this . lastHeartbeatTick } @ ${ this . lastHeartbeatTime . toFixed ( 2 ) } s` ,
8893 ] ) ;
0 commit comments