[X3D-Public] games > state carryover on anchor between scenes
highaspirations at hotmail.com
Wed Oct 16 08:51:16 PDT 2013
Draft Summary: Holding Game State Across modules/levels/rooms/scenes
Master-Scene holds state for sub-scenes
Method A: Inlines
(tested, preferred if viewer supports IMPORT/EXPORT)
Using prototypes (or inlines), with well defined interfaces, and load by:
a) refreshing/changing the URL on an inline or ExternProto to trigger load or
b) pre-parsing and using a Switch node on instances
For Inlines - use IMPORT/EXPORT and pre-route to the IMPORTs
Method B: Subscene as programmably created nodes
(common practice if no main/subscene state interchange, or viewer supports IMPORT/EXPORT)
- suitable when the interactivity and carryover state is all in the main scene part
- or use IMPORT/EXPORT and pre-route to the IMPORTs as with Inlines
Method C: Scene Handoff
(speculative / not tested)
i) newscene = createX3DfromURL(url) is called first to generate a new X3DScene
ii) then settings are transferred from the current scene to the newscene
iii) then replaceWorld(newscene)
Method D: Programmably adding Proto instances on demand
(should work, sounds do-able)
Browser object holds state between peer scenes
(would require change to SAI specifications for X3DBrowser and new support from viewers)
an SAI field or function on the Browser object that can be set from Script nodes,
- perhaps an array of strings or property list called 'crossSceneState':
Anchor/LoadURL or createX3DfromURL + replaceWorld brings in peer scenes
- each peer scene keeps the Browser.crossSceneState updated
Possibility 1, Method B:
Q. Can programmably created nodes ie from createX3DFromUrl refer to DEF nodes not within its own subscene?
A. No - DEF names outside the own subscene cannot be accessed directly (some Browsers have exceptions to this rule and allow to access DEF names of the "master scene" from some "sub scene" under some circumstances, but generally this is not possible). Use IMPORT/EXPORT.
Q. Could we somehow find a node to talk to by crawling the scenegraph?
A. Possible but not recommended. The method Browser.createVrmlFromUrl() delivers an MFNode with all top level nodes of the loaded scene, so you could define "the nth toplevel node has this and that interface function" and setup dynamic routes. However some browsers invert the order of the loaded nodes.
A. No. You can add it. But each Script node gets a separate copy of the global context, so simply adding properties to objects does not survive between Script nodes in the same scene file, nor between successive loaded scenes. The specs and viewer support would need to change so a specific property is available on the Browser for persisting.
More information about the X3D-Public