[X3D-Public] games > state carryover on anchor between scenes

doug sanden highaspirations at hotmail.com
Wed Oct 16 07:39:14 PDT 2013


>>>>> Yes it could be fun for games! If you anchor between rooms or
>>>>> indoor/outdoor scenes all those scenes can be be parsed separately as
>>>>> needed. Which may render faster depending on viewer.
>>>>
>>>>>> The idea of bundling resources in a zip file is common in game engines
>>>>>> (especially useful to distribute game mods), and as I'm implementing a
>>>>>> game engine using X3D --- it would be cool if it would be just a
>>>>>> standard X3D feature :)
>>>>>>
>>>>
>>>> Q. for multi-scene games, how / where is game state -such as scoring, level, persona- carried over to subsequent scenes after an Anchor? Is there an SAI field on the Browser that can be set with (name,value) pairs from Script nodes/javascript, and if so which field(s)? Or is there another paradigm?
>>>
>>> [Christoph:] You could load one "master scene" by the Web3D browser, add modules/levels (whatever you call them) dynamically using the method Browser.createVrmlFromUrl() as children of a grouping node. Then you could store your state in the "master scene". You would need to define an interface between the "master scene" and your modules/levels
>>>
>>> Do not know whether to call this a "paradigm", it's just a possibility, and it needs more scripting than a simple anchor.
>>>
>>
>> Thanks Christoph.
>> Q. how does the interface work? Can createX3DFromUrl nodes refer to DEF
>> nodes not within its own subscene? Or would we somehow find a node to
>> talk to by crawling the scenegraph?
>>
> As Dave wrote, you could wrap your levels within prototypes. Prototypes can define arbitrary interfaces.
>
> You are right, 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).
>
> 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 I would not recommend this because some browsers invert the order of the loaded nodes. Using prototypes (and inlines) is more straight forward. I myself have tried prototypes.
>

Thanks Dave and Christoph. I've incorporated some of your ideas/comments in a summary below.

Q. exactly how are the inlines and protos loaded during game play? Do you just set a new URL? 
If so, for Inlines that could be done by ROUTE, since Inline nodes are part of the scenegraph and expose a URL field.
For
 Protos, would they need to be ExternProtos? If I remember correctly, 
the url field is on the ExternProtoDeclaration, not the ProtoInstance. 
And the ExternProtoDeclaration is not in the scenegraph, so you couldn't
 route to the URL. So you would need to do it somehow from javascript?
-Doug

more...

Summary: Holding Game State Across modules/levels/rooms/scenes
 
Possibility 1:
Master-Scene holds state for sub-scenes

Method A:
(tested, preferred)
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
http://www.web3d.org/files/specifications/19775-1/V3.3/Part01/components/networking.html#IMPORTStatement 


Method B: Subscene as nodes
(awkward)
Browser.createVrmlFromUrl()/createX3DfromUrl() brings in sub-scenes to children of group node in master scene. 
- awkward to communicate between main and subscene; suitable when the interactivity and carryover state is all in the main scene part, and passive geometry and localized interactivity is in the subscene.
 
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)
 
 
Possibility 2:
Browser object holds state between peer scenes
(would require change to SAI specifications for X3DBrowser)
Method: Browser.crossSceneState
an SAI field or function on the Browser object that can be set from Script nodes, 
http://www.web3d.org/files/specifications/19777-1/V3.0/Part1/functions.html#BrowserServices 
- perhaps an array of strings or property list called 'crossSceneState':
http://www.web3d.org/files/specifications/19777-1/V3.0/Part1/types.html#SAIPropertyList
Anchor/LoadURL or createX3DfromURL + replaceWorld brings in peer scenes
- each peer scene keeps the Browser.crossSceneState updated
 
FAQ
Possibility 1, Method B:
Q. Can createX3DFromUrl nodes 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).
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.

Possibility 2
Q. can I just add more properties to X3DBrowser object from javascript ie Browser.mystate = new array()? If so would it stick around after an Anchor?
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. 		 	   		  


More information about the X3D-Public mailing list