4#include <simplesquirrel/simplesquirrel.hpp>
9const char *kSceneComponentScript = R
"SQ(
10if (!("_sceneComponents" in eve)) eve._sceneComponents <- []
11if (!("_flushingSceneComponents" in eve)) eve._flushingSceneComponents <- false
12eve._scheduleSceneComponent <- function(component) {
13 if (component._scheduled) return
14 component._scheduled = true
15 eve._sceneComponents.append(component)
17::eve_scene_flush_components <- function() {
18 if (eve._flushingSceneComponents) return
19 eve._flushingSceneComponents = true
20 local pending = eve._sceneComponents
21 eve._sceneComponents = []
22 for (local i = 0; i < pending.len(); i += 1) {
23 local component = pending[i]
24 component._scheduled = false
26 if (component._mounted && component.dirty) component.updateIfDirty()
28 for (local j = i + 1; j < pending.len(); j += 1) eve._sceneComponents.append(pending[j])
29 eve._flushingSceneComponents = false
33 eve._flushingSceneComponents = false
35eve.SceneComponent <- class {
43 constructor(sceneInstance = null) {
44 _scene = sceneInstance
51 function setScene(sceneInstance) { _scene = sceneInstance }
53 function mountAs(name) {
60 function setState() { markDirty() }
61 function markDirty() {
63 if (_mounted) eve._scheduleSceneComponent(this)
67 // Override: call this.scene().beginNode / addNode / end ...
71 if (_scene != null) return _scene
73 if (::scene != null) return ::scene
75 _scene = ::eve.Scene()
79 function updateIfDirty() {
80 if (!dirty) return false
81 local s = this.scene()
88 if (name == null || name == "") name = "default"
93 s.remountBuildAs(name)
99 if (dirty) eve._scheduleSceneComponent(this)
100 } catch (error) { markDirty(); throw error }
104 function rebuild(force = false) {
107 return updateIfDirty()
The single Squirrel projection for common Result, Status and Value.
void injectSceneComponentClass(ssq::Table &eveTable)
SQRESULT compileAndRunChunk(HSQUIRRELVM vm, const char *name, const char *source)
Compile and run one embedded script chunk against the root table.