aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/init_state.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-04-02 14:57:31 -0700
committerJohn Mayhew2012-04-02 14:57:31 -0700
commitfb0a659c9ca3479fd6799325498b11f074689936 (patch)
tree46342298281aa93e48756e040715f42770ccc526 /js/helper-classes/RDGE/src/core/script/init_state.js
parentc24f58c10231c30d3a8a4c9fb9a4f395dd746180 (diff)
downloadninja-fb0a659c9ca3479fd6799325498b11f074689936.tar.gz
-Namespaced all RDGE javascript.
-Removed the following unused files from the build script /core/script/fx/blur.js /core/script/fx/ssao.js /core/script/animation.js - Fully removed the following from the build and from source control as they are unused or no longer needed /core/script/util/dbgpanel.js /core/script/util/fpsTracker.js /core/script/util/statTracker.js /core/script/input.js /core/script/TextureManager.js /core/script/ubershader.js
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/init_state.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/init_state.js553
1 files changed, 249 insertions, 304 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 4b97a4f4..c695f41b 100755
--- a/js/helper-classes/RDGE/src/core/script/init_state.js
+++ b/js/helper-classes/RDGE/src/core/script/init_state.js
@@ -4,344 +4,289 @@ 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 7var RDGE = RDGE || {};
8
9var loadTag = document.getElementById("loading");
10 8
11function LoadState(userRunState, context) 9// init the view
12{ 10RDGE.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
23LoadState.prototype.loadScene = function(addr, sceneName) 21RDGE.LoadState.prototype.loadScene = function (addr, sceneName) {
24{ 22 var request = new RDGE.sceneRequestDef(addr, sceneName);
25 var request = new sceneRequestDef(addr, sceneName); 23 request.doSceneRequest = true;
26 request.doSceneRequest = true; 24 this.sceneLoadQueue.push(request);
27 this.sceneLoadQueue.push( request ); 25};
28}
29 26
30LoadState.prototype.loadTexture = function(textureObject) 27RDGE.LoadState.prototype.loadTexture = function (textureObject) {
31{ 28 if (this.stateManager.currentState().name != "LoadState") {
32 if(this.stateManager.currentState().name != "LoadState") 29 this.stateManager.PushState(this.stateManager.RDGEInitState, "noInit");
33 { 30 }
34 this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" );
35 }
36
37 this.textureLoadQueue.push(textureObject);
38}
39 31
40LoadState.prototype.Init = function() 32 this.textureLoadQueue.push(textureObject);
41{ 33};
42 if(this.sceneName)
43 {
44 this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName);
45 }
46
47 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
48 this.userRunState.onLoadState();
49}
50
51LoadState.prototype.ReInit = function()
52{
53 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
54 this.userRunState.onLoadState();
55}
56 34
57LoadState.prototype.Resize = function() 35RDGE.LoadState.prototype.Init = function () {
58{ 36 if (this.sceneName) {
59 if(g_Engine.lastWindowWidth == window.innerWidth && g_Engine.lastWindowHeight == window.innerHeight) 37 this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName);
60 { 38 }
61 this.userRunState.resize();
62 g_Engine.lastWindowWidth = window.innerWidth;
63 g_Engine.lastWindowHeight = window.innerHeight;
64 }
65}
66
67LoadState.prototype.Update = function(dt)
68{
69 // for the current scene go through processing steps
70 var sceneLoadTop = this.sceneLoadQueue.length - 1;
71 var texLoadTop = this.textureLoadQueue.length - 1;
72
73 if(sceneLoadTop > -1)
74 {
75 var curSceneReq = this.sceneLoadQueue[sceneLoadTop];
76
77 // check for completed mesh requests and load the data
78 g_meshMan.processMeshData();
79
80 if(curSceneReq.doSceneRequest)
81 {
82 curSceneReq.requestScene();
83 }
84 else if(curSceneReq.requestComplete)
85 {
86 if(curSceneReq.sceneBeginProcessing)
87 {
88 // Load meshes attached to the scene
89 curSceneReq.scene = new SceneGraph(curSceneReq.rawData);
90 curSceneReq.scene.enableShadows( true );
91 g_Engine.AddScene(curSceneReq.name, curSceneReq.scene);
92
93 // setup the scene and save a map of mesh names
94 // that will be check off as the meshes load
95 curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false);
96
97 // processing is complete
98 curSceneReq.sceneBeginProcessing = false;
99 }
100 // if we are here than the scene is processed but meshes are still loading/processing asynchronously
101 else if(curSceneReq.processingComplete())
102 {
103 // pop the head node
104 var sceneReq = this.sceneLoadQueue.shift();
105 this.userRunState.onComplete(sceneReq.name, sceneReq.scene);
106 }
107 }
108
109 }
110
111 // load any waiting textures
112 while(this.textureLoadQueue.length > 0)
113 {
114 this.renderer.commitTexture( this.textureLoadQueue.shift() );
115 }
116
117 // if there is nothing left to load move back to the run state
118 if( 0 == this.sceneLoadQueue.length && 0 == this.textureLoadQueue.length )
119 {
120 // loaded... remove the state
121 var stateMan = g_Engine.getContext().ctxStateManager;
122 stateMan.PopState();
123
124 // Remove loading text
125 if(loadTag)
126 {
127 loadTag.innerHTML="done";
128 }
129 }
130
131 if(g_Engine.getContext().getScene() && g_Engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized)
132 this.userRunState.update(dt);
133 39
134} 40 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
41 this.userRunState.onLoadState();
42};
135 43
136LoadState.prototype.Draw = function() 44RDGE.LoadState.prototype.ReInit = function () {
137{ 45 if (this.hasUserState && this.userRunState && this.userRunState.onLoadState)
138 this.renderer._clear(); 46 this.userRunState.onLoadState();
139 47};
140 if(g_Engine.getContext().getScene() && g_Engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized)
141 this.userRunState.draw();
142
143}
144 48
145LoadState.prototype.Shutdown = function() 49RDGE.LoadState.prototype.Resize = function () {
146{ 50 if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) {
51 this.userRunState.resize();
52 RDGE.globals.engine.lastWindowWidth = window.innerWidth;
53 RDGE.globals.engine.lastWindowHeight = window.innerHeight;
54 }
55};
147 56
148} 57RDGE.LoadState.prototype.Update = function (dt) {
58 // for the current scene go through processing steps
59 var sceneLoadTop = this.sceneLoadQueue.length - 1;
60 var texLoadTop = this.textureLoadQueue.length - 1;
149 61
150LoadState.prototype.LeaveState = function() 62 if (sceneLoadTop > -1) {
151{ 63 var curSceneReq = this.sceneLoadQueue[sceneLoadTop];
152 if(this.userRunState.onComplete != undefined) 64
153 { 65 // check for completed mesh requests and load the data
154 this.userRunState.onComplete(); 66 RDGE.globals.meshMan.processMeshData();
155 } 67
156} 68 if (curSceneReq.doSceneRequest) {
69 curSceneReq.requestScene();
70 }
71 else if (curSceneReq.requestComplete) {
72 if (curSceneReq.sceneBeginProcessing) {
73 // Load meshes attached to the scene
74 curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData);