diff options
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 | 298 |
1 files changed, 149 insertions, 149 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 24d92956..1fbc81f3 100755 --- a/js/helper-classes/RDGE/src/core/script/init_state.js +++ b/js/helper-classes/RDGE/src/core/script/init_state.js | |||
@@ -20,118 +20,118 @@ RDGE.LoadState = function(userRunState, context) { | |||
20 | 20 | ||
21 | RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { | 21 | RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { |
22 | var request = new RDGE.sceneRequestDef(addr, sceneName); | 22 | var request = new RDGE.sceneRequestDef(addr, sceneName); |
23 | request.doSceneRequest = true; | 23 | request.doSceneRequest = true; |
24 | this.sceneLoadQueue.push(request); | 24 | this.sceneLoadQueue.push( request ); |
25 | }; | 25 | }; |
26 | 26 | ||
27 | RDGE.LoadState.prototype.loadTexture = function (textureObject) { | 27 | RDGE.LoadState.prototype.loadTexture = function (textureObject) { |
28 | if (this.stateManager.currentState().name != "LoadState") { | 28 | if (this.stateManager.currentState().name != "LoadState") { |
29 | this.stateManager.PushState(this.stateManager.RDGEInitState, "noInit"); | 29 | this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); |
30 | } | 30 | } |
31 | 31 | ||
32 | this.textureLoadQueue.push(textureObject); | 32 | this.textureLoadQueue.push(textureObject); |
33 | }; | 33 | }; |
34 | 34 | ||
35 | RDGE.LoadState.prototype.Init = function () { | 35 | RDGE.LoadState.prototype.Init = function () { |
36 | if (this.sceneName) { | 36 | if (this.sceneName) { |
37 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); | 37 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); |
38 | } | 38 | } |
39 | 39 | ||
40 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 40 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
41 | this.userRunState.onLoadState(); | 41 | this.userRunState.onLoadState(); |
42 | }; | 42 | }; |
43 | 43 | ||
44 | RDGE.LoadState.prototype.ReInit = function () { | 44 | RDGE.LoadState.prototype.ReInit = function () { |
45 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 45 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
46 | this.userRunState.onLoadState(); | 46 | this.userRunState.onLoadState(); |
47 | }; | 47 | }; |
48 | 48 | ||
49 | RDGE.LoadState.prototype.Resize = function () { | 49 | RDGE.LoadState.prototype.Resize = function () { |
50 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { | 50 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { |
51 | this.userRunState.resize(); | 51 | this.userRunState.resize(); |
52 | RDGE.globals.engine.lastWindowWidth = window.innerWidth; | 52 | RDGE.globals.engine.lastWindowWidth = window.innerWidth; |
53 | RDGE.globals.engine.lastWindowHeight = window.innerHeight; | 53 | RDGE.globals.engine.lastWindowHeight = window.innerHeight; |
54 | } | 54 | } |
55 | }; | 55 | }; |
56 | 56 | ||
57 | RDGE.LoadState.prototype.Update = function (dt) { | 57 | RDGE.LoadState.prototype.Update = function (dt) { |
58 | // for the current scene go through processing steps | 58 | // for the current scene go through processing steps |
59 | var sceneLoadTop = this.sceneLoadQueue.length - 1; | 59 | var sceneLoadTop = this.sceneLoadQueue.length - 1; |
60 | var texLoadTop = this.textureLoadQueue.length - 1; | 60 | var texLoadTop = this.textureLoadQueue.length - 1; |
61 | 61 | ||
62 | if (sceneLoadTop > -1) { | 62 | if (sceneLoadTop > -1) { |
63 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; | 63 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; |
64 | 64 | ||
65 | // check for completed mesh requests and load the data | 65 | // check for completed mesh requests and load the data |
66 | RDGE.globals.meshMan.processMeshData(); | 66 | RDGE.globals.meshMan.processMeshData(); |
67 | 67 | ||
68 | if (curSceneReq.doSceneRequest) { | 68 | if (curSceneReq.doSceneRequest) { |
69 | curSceneReq.requestScene(); | 69 | curSceneReq.requestScene(); |
70 | } | 70 | } |
71 | else if (curSceneReq.requestComplete) { | 71 | else if (curSceneReq.requestComplete) { |
72 | if (curSceneReq.sceneBeginProcessing) { | 72 | if (curSceneReq.sceneBeginProcessing) { |
73 | // Load meshes attached to the scene | 73 | // Load meshes attached to the scene |
74 | curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); | 74 | curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); |
75 | curSceneReq.scene.enableShadows(true); | 75 | curSceneReq.scene.enableShadows( true ); |
76 | RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); | 76 | RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); |
77 | 77 | ||
78 | // setup the scene and save a map of mesh names | 78 | // setup the scene and save a map of mesh names |
79 | // that will be check off as the meshes load | 79 | // that will be check off as the meshes load |
80 | curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false); | 80 | curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false); |
81 | 81 | ||
82 | // processing is complete | 82 | // processing is complete |
83 | curSceneReq.sceneBeginProcessing = false; | 83 | curSceneReq.sceneBeginProcessing = false; |
84 | } | 84 | } |
85 | // 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 |
86 | else if (curSceneReq.processingComplete()) { | 86 | else if (curSceneReq.processingComplete()) { |
87 | // pop the head node | 87 | // pop the head node |
88 | var sceneReq = this.sceneLoadQueue.shift(); | 88 | var sceneReq = this.sceneLoadQueue.shift(); |
89 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); | 89 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | // load any waiting textures | 95 | // load any waiting textures |
96 | while (this.textureLoadQueue.length > 0) { | 96 | while (this.textureLoadQueue.length > 0) { |
97 | this.renderer.commitTexture(this.textureLoadQueue.shift()); | 97 | this.renderer.commitTexture( this.textureLoadQueue.shift() ); |
98 | } | 98 | } |
99 | 99 | ||
100 | // 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 |
101 | if (this.sceneLoadQueue.length == 0 && this.textureLoadQueue.length == 0) { | 101 | if (this.sceneLoadQueue.length == 0 && this.textureLoadQueue.length == 0) { |
102 | // loaded... remove the state | 102 | // loaded... remove the state |
103 | var stateMan = RDGE.globals.engine.getContext().ctxStateManager; | 103 | var stateMan = RDGE.globals.engine.getContext().ctxStateManager; |
104 | stateMan.PopState(); | 104 | stateMan.PopState(); |
105 | } | 105 | } |
106 | 106 | ||
107 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.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) |
108 | this.userRunState.update(dt); | 108 | this.userRunState.update(dt); |
109 | }; | 109 | }; |
110 | 110 | ||
111 | RDGE.LoadState.prototype.Draw = function () { | 111 | RDGE.LoadState.prototype.Draw = function () { |
112 | this.renderer._clear(); | 112 | this.renderer._clear(); |
113 | 113 | ||
114 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.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) |
115 | this.userRunState.draw(); | 115 | this.userRunState.draw(); |
116 | }; | 116 | }; |
117 | 117 | ||
118 | RDGE.LoadState.prototype.Shutdown = function () { | 118 | RDGE.LoadState.prototype.Shutdown = function () { |
119 | }; | 119 | }; |
120 | 120 | ||
121 | RDGE.LoadState.prototype.LeaveState = function () { | 121 | RDGE.LoadState.prototype.LeaveState = function () { |
122 | if (this.userRunState.onComplete != undefined) { | 122 | if (this.userRunState.onComplete != undefined) { |
123 | this.userRunState.onComplete(); | 123 | this.userRunState.onComplete(); |
124 | } | 124 | } |
125 | }; | 125 | }; |
126 | 126 | ||
127 | RDGE.LoadState.prototype.MakeSceneRequest = function (addr, name) { | 127 | RDGE.LoadState.prototype.MakeSceneRequest = function (addr, name) { |
128 | 128 | ||
129 | this.hasScene = true; | 129 | this.hasScene = true; |
130 | this.lastSceneName = name; | 130 | this.lastSceneName = name; |
131 | var request = new XMLHttpRequest(); | 131 | var request = new XMLHttpRequest(); |
132 | request.initState = this; | 132 | request.initState = this; |
133 | RDGE.globals.engine.getContext().sceneGraphMap[name] = "not-ready"; | 133 | RDGE.globals.engine.getContext().sceneGraphMap[name] = "not-ready"; |
134 | request.onreadystatechange = function () { | 134 | request.onreadystatechange = function() { |
135 | if (request.readyState == 4) { | 135 | if (request.readyState == 4) { |
136 | if (request.status == 200 || window.location.href.indexOf("http") == -1) { | 136 | if (request.status == 200 || window.location.href.indexOf("http") == -1) { |
137 | this.initState.scene = eval("(" + request.responseText + ")"); //retrieve result as an JavaScript object | 137 | this.initState.scene = eval("(" + request.responseText + ")"); //retrieve result as an JavaScript object |
@@ -153,9 +153,9 @@ RDGE.SetupScene = function () | |||
153 | this.renderer = RDGE.globals.engine.getContext().renderer; | 153 | this.renderer = RDGE.globals.engine.getContext().renderer; |
154 | this.meshLoadingMap = []; | 154 | this.meshLoadingMap = []; |
155 | this.onMeshLoaded = function (meshName) { | 155 | this.onMeshLoaded = function (meshName) { |
156 | // if the mesh was loading (and is defined) mark it as no longer loading | 156 | // if the mesh was loading (and is defined) mark it as no longer loading |
157 | if (this.meshLoadingMap[meshName]) | 157 | if(this.meshLoadingMap[meshName]) |
158 | this.meshLoadingMap[meshName].stillLoading = false; | 158 |