aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/init_state.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/init_state.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/init_state.js593
1 files changed, 297 insertions, 296 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/init_state.js b/js/helper-classes/RDGE/src/core/script/init_state.js
index d8d6d4c5..7a324b2d 100755
--- a/js/helper-classes/RDGE/src/core/script/init_state.js
+++ b/js/helper-classes/RDGE/src/core/script/init_state.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -26,289 +27,289 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 29POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 30</copyright> */
30 31
31var RDGE = RDGE || {}; 32var RDGE = RDGE || {};
32 33
33// init the view 34// init the view
34RDGE.LoadState = function(userRunState, context) { 35RDGE.LoadState = function(userRunState, context) {
35 this.name = "LoadState"; 36 this.name = "LoadState";
36 this.userRunState = userRunState !== undefined ? userRunState : new RDGE.core.RDGEState; 37 this.userRunState = userRunState !== undefined ? userRunState : new RDGE.core.RDGEState;
37 this.hasUserState = userRunState !== undefined ? true : false; 38 this.hasUserState = userRunState !== undefined ? true : false;
38 this.renderer = context.renderer; 39 this.renderer = context.renderer;
39 this.loadingDone = false; 40 this.loadingDone = false;
40 this.stateManager = context.ctxStateManager; 41 this.stateManager = context.ctxStateManager;
41 this.sceneLoadQueue = []; 42 this.sceneLoadQueue = [];
42 this.textureLoadQueue = []; 43 this.textureLoadQueue = [];
43}; 44};
44 45
45RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { 46RDGE.LoadState.prototype.loadScene = function (addr, sceneName) {
46 var request = new RDGE.sceneRequestDef(addr, sceneName); 47 var request = new RDGE.sceneRequestDef(addr, sceneName);
47 request.doSceneRequest = true; 48 request.doSceneRequest = true;
48 this.sceneLoadQueue.push( request ); 49 this.sceneLoadQueue.push( request );
49}; 50};
50 51
51RDGE.LoadState.prototype.loadTexture = function (textureObject) { 52RDGE.LoadState.prototype.loadTexture = function (textureObject) {
52 if (this.stateManager.currentState().name != "LoadState") { 53 if (this.stateManager.currentState().name != "LoadState") {
53 this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); 54 this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" );
54 } 55 }
55 56
56 this.textureLoadQueue.push(textureObject); 57 this.textureLoadQueue.push(textureObject);
57}; 58};
58 59
59RDGE.LoadState.prototype.Init = function () { 60RDGE.LoadState.prototype.Init = function () {
60 if (this.sceneName) { 61 if (this.sceneName) {
61 this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); 62 this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName);
62 } 63 }
63 64
64 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) 65 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
65 this.userRunState.onLoadState(); 66 this.userRunState.onLoadState();
66}; 67};
67 68
68RDGE.LoadState.prototype.ReInit = function () { 69RDGE.LoadState.prototype.ReInit = function () {
69 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) 70 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
70 this.userRunState.onLoadState(); 71 this.userRunState.onLoadState();
71}; 72};
72 73
73RDGE.LoadState.prototype.Resize = function () { 74RDGE.LoadState.prototype.Resize = function () {
74 if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { 75 if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) {
75 this.userRunState.resize(); 76 this.userRunState.resize();
76 RDGE.globals.engine.lastWindowWidth = window.innerWidth; 77 RDGE.globals.engine.lastWindowWidth = window.innerWidth;
77 RDGE.globals.engine.lastWindowHeight = window.innerHeight; 78 RDGE.globals.engine.lastWindowHeight = window.innerHeight;
78} 79}
79}; 80};
80 81
81RDGE.LoadState.prototype.Update = function (dt) { 82RDGE.LoadState.prototype.Update = function (dt) {
82 // for the current scene go through processing steps 83 // for the current scene go through processing steps
83 var sceneLoadTop = this.sceneLoadQueue.length - 1; 84 var sceneLoadTop = this.sceneLoadQueue.length - 1;
84 var texLoadTop = this.textureLoadQueue.length - 1; 85 var texLoadTop = this.textureLoadQueue.length - 1;
85 86
86 if (sceneLoadTop > -1) { 87 if (sceneLoadTop > -1) {
87 var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; 88 var curSceneReq = this.sceneLoadQueue[sceneLoadTop];
88 89
89 // check for completed mesh requests and load the data 90 // check for completed mesh requests and load the data
90 RDGE.globals.meshMan.processMeshData(); 91 RDGE.globals.meshMan.processMeshData();
91 92
92 if (curSceneReq.doSceneRequest) { 93 if (curSceneReq.doSceneRequest) {
93 curSceneReq.requestScene(); 94 curSceneReq.requestScene();
94 } 95 }
95 else if (curSceneReq.requestComplete) { 96 else if (curSceneReq.requestComplete) {
96 if (curSceneReq.sceneBeginProcessing) { 97 if (curSceneReq.sceneBeginProcessing) {
97 // Load meshes attached to the scene 98 // Load meshes attached to the scene
98 curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); 99 curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData);
99 curSceneReq.scene.enableShadows( true ); 100 curSceneReq.scene.enableShadows( true );
100 RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); 101 RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene);
101 102
102 // setup the scene and save a map of mesh names 103 // setup the scene and save a map of mesh names
103 // that will be check off as the meshes load 104 // that will be check off as the meshes load
104 curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false); 105 curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false);
105 106
106 // processing is complete 107 // processing is complete
107 curSceneReq.sceneBeginProcessing = false; 108 curSceneReq.sceneBeginProcessing = false;
108 } 109 }
109 // if we are here than the scene is processed but meshes are still loading/processing asynchronously 110 // if we are here than the scene is processed but meshes are still loading/processing asynchronously
110 else if (curSceneReq.processingComplete()) { 111 else if (curSceneReq.processingComplete()) {
111 // pop the head node 112 // pop the head node
112 var sceneReq = this.sceneLoadQueue.shift(); 113 var sceneReq = this.sceneLoadQueue.shift();
113 this.userRunState.onComplete(sceneReq.name, sceneReq.scene); 114 this.userRunState.onComplete(sceneReq.name, sceneReq.scene);
114 } 115 }
115 } 116 }
116 117
117 } 118 }
118 119
119 // load any waiting textures 120 // load any waiting textures
120 while (this.textureLoadQueue.length > 0) { 121 while (this.textureLoadQueue.length > 0) {
121 this.renderer.commitTexture( this.textureLoadQueue.shift() ); 122 this.renderer.commitTexture( this.textureLoadQueue.shift() );
122