diff options
author | Jose Antonio Marquez | 2012-04-04 15:54:33 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-04-04 15:54:33 -0700 |
commit | a9bcc403df76ad2cb7c31ff7fdd42a85c35cf424 (patch) | |
tree | 9415f5ba25ad643df678e561719d2708fd3ead5a /js/helper-classes/RDGE/src/core/script/init_state.js | |
parent | 0a469a14757b8cea262c21f652e75c85c9903f4b (diff) | |
parent | e721a7c1009f298a1bd8fea583da14535e039880 (diff) | |
download | ninja-a9bcc403df76ad2cb7c31ff7fdd42a85c35cf424.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/init_state.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/init_state.js | 249 |
1 files changed, 96 insertions, 153 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 5ffbbd13..1fbc81f3 100755 --- a/js/helper-classes/RDGE/src/core/script/init_state.js +++ b/js/helper-classes/RDGE/src/core/script/init_state.js | |||
@@ -4,91 +4,76 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | // init the view | 7 | var RDGE = RDGE || {}; |
8 | |||
9 | var loadTag = document.getElementById("loading"); | ||
10 | 8 | ||
11 | function LoadState(userRunState, context) | 9 | // init the view |
12 | { | 10 | RDGE.LoadState = function(userRunState, context) { |
13 | this.name = "LoadState"; | 11 | this.name = "LoadState"; |
14 | this.userRunState = userRunState != undefined ? userRunState : new RDGEState; | 12 | this.userRunState = userRunState !== undefined ? userRunState : new RDGE.core.RDGEState; |
15 | this.hasUserState = userRunState != undefined ? true : false; | 13 | this.hasUserState = userRunState !== undefined ? true : false; |
16 | this.renderer = context.renderer; | 14 | this.renderer = context.renderer; |
17 | this.loadingDone = false; | 15 | this.loadingDone = false; |
18 | this.stateManager = context.ctxStateManager; | 16 | this.stateManager = context.ctxStateManager; |
19 | this.sceneLoadQueue = []; | 17 | this.sceneLoadQueue = []; |
20 | this.textureLoadQueue = []; | 18 | this.textureLoadQueue = []; |
21 | } | 19 | }; |
22 | 20 | ||
23 | LoadState.prototype.loadScene = function(addr, sceneName) | 21 | RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { |
24 | { | 22 | var request = new RDGE.sceneRequestDef(addr, sceneName); |
25 | var request = new sceneRequestDef(addr, sceneName); | ||
26 | request.doSceneRequest = true; | 23 | request.doSceneRequest = true; |
27 | this.sceneLoadQueue.push( request ); | 24 | this.sceneLoadQueue.push( request ); |
28 | } | 25 | }; |
29 | 26 | ||
30 | LoadState.prototype.loadTexture = function(textureObject) | 27 | RDGE.LoadState.prototype.loadTexture = function (textureObject) { |
31 | { | 28 | if (this.stateManager.currentState().name != "LoadState") { |
32 | if(this.stateManager.currentState().name != "LoadState") | ||
33 | { | ||
34 | this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); | 29 | this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); |
35 | } | 30 | } |
36 | 31 | ||
37 | this.textureLoadQueue.push(textureObject); | 32 | this.textureLoadQueue.push(textureObject); |
38 | } | 33 | }; |
39 | 34 | ||
40 | LoadState.prototype.Init = function() | 35 | RDGE.LoadState.prototype.Init = function () { |
41 | { | 36 | if (this.sceneName) { |
42 | if(this.sceneName) | ||
43 | { | ||
44 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); | 37 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); |
45 | } | 38 | } |
46 | 39 | ||
47 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 40 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
48 | this.userRunState.onLoadState(); | 41 | this.userRunState.onLoadState(); |
49 | } | 42 | }; |
50 | 43 | ||
51 | LoadState.prototype.ReInit = function() | 44 | RDGE.LoadState.prototype.ReInit = function () { |
52 | { | 45 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
53 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 46 | this.userRunState.onLoadState(); |
54 | this.userRunState.onLoadState(); | 47 | }; |
55 | } | ||
56 | 48 | ||
57 | LoadState.prototype.Resize = function() | 49 | RDGE.LoadState.prototype.Resize = function () { |
58 | { | 50 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { |
59 | if(g_Engine.lastWindowWidth == window.innerWidth && g_Engine.lastWindowHeight == window.innerHeight) | ||
60 | { | ||
61 | this.userRunState.resize(); | 51 | this.userRunState.resize(); |
62 | g_Engine.lastWindowWidth = window.innerWidth; | 52 | RDGE.globals.engine.lastWindowWidth = window.innerWidth; |
63 | g_Engine.lastWindowHeight = window.innerHeight; | 53 | RDGE.globals.engine.lastWindowHeight = window.innerHeight; |
64 | } | ||
65 | } | 54 | } |
55 | }; | ||
66 | 56 | ||
67 | LoadState.prototype.Update = function(dt) | 57 | RDGE.LoadState.prototype.Update = function (dt) { |
68 | { | ||
69 | // for the current scene go through processing steps | 58 | // for the current scene go through processing steps |
70 | var sceneLoadTop = this.sceneLoadQueue.length - 1; | 59 | var sceneLoadTop = this.sceneLoadQueue.length - 1; |
71 | var texLoadTop = this.textureLoadQueue.length - 1; | 60 | var texLoadTop = this.textureLoadQueue.length - 1; |
72 | 61 | ||
73 | if(sceneLoadTop > -1) | 62 | if (sceneLoadTop > -1) { |
74 | { | ||
75 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; | 63 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; |
76 | 64 | ||
77 | // check for completed mesh requests and load the data | 65 | // check for completed mesh requests and load the data |
78 | g_meshMan.processMeshData(); | 66 | RDGE.globals.meshMan.processMeshData(); |
79 | 67 | ||
80 | if(curSceneReq.doSceneRequest) | 68 | if (curSceneReq.doSceneRequest) { |
81 | { | ||
82 | curSceneReq.requestScene(); | 69 | curSceneReq.requestScene(); |
83 | } | 70 | } |
84 | else if(curSceneReq.requestComplete) | 71 | else if (curSceneReq.requestComplete) { |
85 | { | 72 | if (curSceneReq.sceneBeginProcessing) { |
86 | if(curSceneReq.sceneBeginProcessing) | ||
87 | { | ||
88 | // Load meshes attached to the scene | 73 | // Load meshes attached to the scene |
89 | curSceneReq.scene = new SceneGraph(curSceneReq.rawData); | 74 | curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); |
90 | curSceneReq.scene.enableShadows( true ); | 75 | curSceneReq.scene.enableShadows( true ); |
91 | g_Engine.AddScene(curSceneReq.name, curSceneReq.scene); | 76 | RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); |
92 | 77 | ||
93 | // setup the scene and save a map of mesh names | 78 | // setup the scene and save a map of mesh names |
94 | // that will be check off as the meshes load | 79 | // that will be check off as the meshes load |
@@ -98,8 +83,7 @@ LoadState.prototype.Update = function(dt) | |||
98 | curSceneReq.sceneBeginProcessing = false; | 83 | curSceneReq.sceneBeginProcessing = false; |
99 | } | 84 | } |
100 | // if we are here than the scene is processed but meshes are still loading/processing asynchronously | 85 | // if we are here than the scene is processed but meshes are still loading/processing asynchronously |
101 | else if(curSceneReq.processingComplete()) | 86 | else if (curSceneReq.processingComplete()) { |
102 | { | ||
103 | // pop the head node | 87 | // pop the head node |
104 | var sceneReq = this.sceneLoadQueue.shift(); | 88 | var sceneReq = this.sceneLoadQueue.shift(); |
105 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); | 89 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); |
@@ -109,133 +93,107 @@ LoadState.prototype.Update = function(dt) | |||
109 | } | 93 | } |
110 | 94 | ||
111 | // load any waiting textures | 95 | // load any waiting textures |
112 | while(this.textureLoadQueue.length > 0) | 96 | while (this.textureLoadQueue.length > 0) { |
113 | { | ||
114 | this.renderer.commitTexture( this.textureLoadQueue.shift() ); | 97 | this.renderer.commitTexture( this.textureLoadQueue.shift() ); |
115 | } | 98 | } |
116 | 99 | ||
117 | // if there is nothing left to load move back to the run state | 100 | // if there is nothing left to load move back to the run state |
118 | if( 0 == this.sceneLoadQueue.length && 0 == this.textureLoadQueue.length ) | 101 | if (this.sceneLoadQueue.length == 0 && this.textureLoadQueue.length == 0) { |
119 | { | ||
120 | // loaded... remove the state | 102 | // loaded... remove the state |
121 | var stateMan = g_Engine.getContext().ctxStateManager; | 103 | var stateMan = RDGE.globals.engine.getContext().ctxStateManager; |
122 | stateMan.PopState(); | 104 | stateMan.PopState(); |
123 | |||
124 | // Remove loading text | ||
125 | if(loadTag) | ||
126 | { | ||
127 | loadTag.innerHTML="done"; | ||
128 | } | ||
129 | } | 105 | } |
130 | 106 | ||
131 | if(g_Engine.getContext().getScene() && g_Engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) | 107 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) |
132 | this.userRunState.update(dt); | 108 | this.userRunState.update(dt); |
109 | }; | ||
133 | 110 | ||
134 | } | 111 | RDGE.LoadState.prototype.Draw = function () { |
135 | |||
136 | LoadState.prototype.Draw = function() | ||
137 | { | ||
138 | this.renderer._clear(); | 112 | this.renderer._clear(); |
139 | 113 | ||
140 | if(g_Engine.getContext().getScene() && g_Engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) | 114 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) |
141 | this.userRunState.draw(); | 115 | this.userRunState.draw(); |
116 | }; | ||