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 | 558 |
1 files changed, 279 insertions, 279 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 b8058e65..22f022bf 100755 --- a/js/helper-classes/RDGE/src/core/script/init_state.js +++ b/js/helper-classes/RDGE/src/core/script/init_state.js | |||
@@ -26,289 +26,289 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | var RDGE = RDGE || {}; | 31 | var RDGE = RDGE || {}; |
32 | 32 | ||
33 | // init the view | 33 | // init the view |
34 | RDGE.LoadState = function(userRunState, context) { | 34 | RDGE.LoadState = function(userRunState, context) { |
35 | this.name = "LoadState"; | 35 | this.name = "LoadState"; |
36 | this.userRunState = userRunState !== undefined ? userRunState : new RDGE.core.RDGEState; | 36 | this.userRunState = userRunState !== undefined ? userRunState : new RDGE.core.RDGEState; |
37 | this.hasUserState = userRunState !== undefined ? true : false; | 37 | this.hasUserState = userRunState !== undefined ? true : false; |
38 | this.renderer = context.renderer; | 38 | this.renderer = context.renderer; |
39 | this.loadingDone = false; | 39 | this.loadingDone = false; |
40 | this.stateManager = context.ctxStateManager; | 40 | this.stateManager = context.ctxStateManager; |
41 | this.sceneLoadQueue = []; | 41 | this.sceneLoadQueue = []; |
42 | this.textureLoadQueue = []; | 42 | this.textureLoadQueue = []; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { | 45 | RDGE.LoadState.prototype.loadScene = function (addr, sceneName) { |
46 | var request = new RDGE.sceneRequestDef(addr, sceneName); | 46 | var request = new RDGE.sceneRequestDef(addr, sceneName); |
47 | request.doSceneRequest = true; | 47 | request.doSceneRequest = true; |
48 | this.sceneLoadQueue.push( request ); | 48 | this.sceneLoadQueue.push( request ); |
49 | }; | 49 | }; |
50 | 50 | ||
51 | RDGE.LoadState.prototype.loadTexture = function (textureObject) { | 51 | RDGE.LoadState.prototype.loadTexture = function (textureObject) { |
52 | if (this.stateManager.currentState().name != "LoadState") { | 52 | if (this.stateManager.currentState().name != "LoadState") { |
53 | this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); | 53 | this.stateManager.PushState( this.stateManager.RDGEInitState, "noInit" ); |
54 | } | 54 | } |
55 | 55 | ||
56 | this.textureLoadQueue.push(textureObject); | 56 | this.textureLoadQueue.push(textureObject); |
57 | }; | 57 | }; |
58 | 58 | ||
59 | RDGE.LoadState.prototype.Init = function () { | 59 | RDGE.LoadState.prototype.Init = function () { |
60 | if (this.sceneName) { | 60 | if (this.sceneName) { |
61 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); | 61 | this.loadScene("assets_web/mesh/" + this.sceneName + ".json", this.sceneName); |
62 | } | 62 | } |
63 | 63 | ||
64 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 64 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
65 | this.userRunState.onLoadState(); | 65 | this.userRunState.onLoadState(); |
66 | }; | 66 | }; |
67 | 67 | ||
68 | RDGE.LoadState.prototype.ReInit = function () { | 68 | RDGE.LoadState.prototype.ReInit = function () { |
69 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) | 69 | if (this.hasUserState && this.userRunState && this.userRunState.onLoadState) |
70 | this.userRunState.onLoadState(); | 70 | this.userRunState.onLoadState(); |
71 | }; | 71 | }; |
72 | 72 | ||
73 | RDGE.LoadState.prototype.Resize = function () { | 73 | RDGE.LoadState.prototype.Resize = function () { |
74 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { | 74 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { |
75 | this.userRunState.resize(); | 75 | this.userRunState.resize(); |
76 | RDGE.globals.engine.lastWindowWidth = window.innerWidth; | 76 | RDGE.globals.engine.lastWindowWidth = window.innerWidth; |
77 | RDGE.globals.engine.lastWindowHeight = window.innerHeight; | 77 | RDGE.globals.engine.lastWindowHeight = window.innerHeight; |
78 | } | 78 | } |
79 | }; | 79 | }; |
80 | 80 | ||
81 | RDGE.LoadState.prototype.Update = function (dt) { | 81 | RDGE.LoadState.prototype.Update = function (dt) { |
82 | // for the current scene go through processing steps | 82 | // for the current scene go through processing steps |
83 | var sceneLoadTop = this.sceneLoadQueue.length - 1; | 83 | var sceneLoadTop = this.sceneLoadQueue.length - 1; |
84 | var texLoadTop = this.textureLoadQueue.length - 1; | 84 | var texLoadTop = this.textureLoadQueue.length - 1; |
85 | 85 | ||
86 | if (sceneLoadTop > -1) { | 86 | if (sceneLoadTop > -1) { |
87 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; | 87 | var curSceneReq = this.sceneLoadQueue[sceneLoadTop]; |
88 | 88 | ||
89 | // check for completed mesh requests and load the data | 89 | // check for completed mesh requests and load the data |
90 | RDGE.globals.meshMan.processMeshData(); | 90 | RDGE.globals.meshMan.processMeshData(); |
91 | 91 | ||
92 | if (curSceneReq.doSceneRequest) { | 92 | if (curSceneReq.doSceneRequest) { |
93 | curSceneReq.requestScene(); | 93 | curSceneReq.requestScene(); |
94 | } | 94 | } |
95 | else if (curSceneReq.requestComplete) { | 95 | else if (curSceneReq.requestComplete) { |
96 | if (curSceneReq.sceneBeginProcessing) { | 96 | if (curSceneReq.sceneBeginProcessing) { |
97 | // Load meshes attached to the scene | 97 | // Load meshes attached to the scene |
98 | curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); | 98 | curSceneReq.scene = new RDGE.SceneGraph(curSceneReq.rawData); |
99 | curSceneReq.scene.enableShadows( true ); | 99 | curSceneReq.scene.enableShadows( true ); |
100 | RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); | 100 | RDGE.globals.engine.AddScene(curSceneReq.name, curSceneReq.scene); |
101 | 101 | ||
102 | // setup the scene and save a map of mesh names | 102 | // setup the scene and save a map of mesh names |
103 | // that will be check off as the meshes load | 103 | // that will be check off as the meshes load |
104 | curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false); | 104 | curSceneReq.scene.Traverse(curSceneReq.sceneProcessor, false); |
105 | 105 | ||
106 | // processing is complete | 106 | // processing is complete |
107 | curSceneReq.sceneBeginProcessing = false; | 107 | curSceneReq.sceneBeginProcessing = false; |
108 | } | 108 | } |
109 | // if we are here than the scene is processed but meshes are still loading/processing asynchronously | 109 | // if we are here than the scene is processed but meshes are still loading/processing asynchronously |
110 | else if (curSceneReq.processingComplete()) { | 110 | else if (curSceneReq.processingComplete()) { |
111 | // pop the head node | 111 | // pop the head node |
112 | var sceneReq = this.sceneLoadQueue.shift(); | 112 | var sceneReq = this.sceneLoadQueue.shift(); |
113 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); | 113 | this.userRunState.onComplete(sceneReq.name, sceneReq.scene); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | // load any waiting textures | 119 | // load any waiting textures |
120 | while (this.textureLoadQueue.length > 0) { | 120 | while (this.textureLoadQueue.length > 0) { |
121 | this.renderer.commitTexture( this.textureLoadQueue.shift() ); | 121 | this.renderer.commitTexture( this.textureLoadQueue.shift() ); |
122 | } | 122 | } |
123 | 123 | ||
124 | // if there is nothing left to load move back to the run state | 124 | // if there is nothing left to load move back to the run state |
125 | if (this.sceneLoadQueue.length == 0 && this.textureLoadQueue.length == 0) { | 125 | if (this.sceneLoadQueue.length == 0 && this.textureLoadQueue.length == 0) { |
126 | // loaded... remove the state | 126 | // loaded... remove the state |
127 | var stateMan = RDGE.globals.engine.getContext().ctxStateManager; | 127 | var stateMan = RDGE.globals.engine.getContext().ctxStateManager; |
128 | stateMan.PopState(); | 128 | stateMan.PopState(); |
129 | } | 129 | } |
130 | 130 | ||
131 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) | 131 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) |
132 | this.userRunState.update(dt); | 132 | this.userRunState.update(dt); |
133 | }; | 133 | }; |
134 | 134 | ||
135 | RDGE.LoadState.prototype.Draw = function () { | 135 | RDGE.LoadState.prototype.Draw = function () { |
136 | this.renderer._clear(); | 136 | this.renderer._clear(); |
137 | 137 | ||
138 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) | 138 | if (RDGE.globals.engine.getContext().getScene() && RDGE.globals.engine.getContext().getScene() != "not-ready" && this.stateManager.RDGERunState.initialized) |
139 | this.userRunState.draw(); | 139 | this.userRunState.draw(); |
140 | }; | 140 | }; |
141 | 141 | ||
142 | RDGE.LoadState.prototype.Shutdown = function () { | 142 | RDGE.LoadState.prototype.Shutdown = function () { |
143 | }; | 143 | }; |
144 | 144 | ||
145 | RDGE.LoadState.prototype.LeaveState = function () { | 145 | RDGE.LoadState.prototype.LeaveState = function () { |
146 | if (this.userRunState.onComplete != undefined) { | 146 | if (this.userRunState.onComplete != undefined) { |
147 | this.userRunState.onComplete(); | 147 | this.userRunState.onComplete(); |
148 | } | 148 | } |
149 | }; |