aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/engine.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/engine.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/engine.js44
1 files changed, 22 insertions, 22 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js
index b2191197..96c3d502 100755
--- a/js/helper-classes/RDGE/src/core/script/engine.js
+++ b/js/helper-classes/RDGE/src/core/script/engine.js
@@ -36,21 +36,21 @@ var RDGE = RDGE || {};
36RDGE.stateManager = function () { 36RDGE.stateManager = function () {
37 // a stack of states 37 // a stack of states
38 this.stateStack = []; 38 this.stateStack = [];
39 39
40 // number of states on the stack 40 // number of states on the stack
41 this.stateTop = undefined; 41 this.stateTop = undefined;
42 42
43 // the states of the context 43 // the states of the context
44 this.RDGEInitState = null; 44 this.RDGEInitState = null;
45 this.RDGERunState = null; 45 this.RDGERunState = null;
46 46
47 this.currentState = function () { 47 this.currentState = function () {
48 if(this.stateTop != undefined) 48 if(this.stateTop != undefined)
49 return this.stateStack[this.stateTop]; 49 return this.stateStack[this.stateTop];
50 50
51 return null; 51 return null;
52 }; 52 };
53 53
54 /* 54 /*
55 * Push new IRuntime state - engine executes the new state 55 * Push new IRuntime state - engine executes the new state
56 */ 56 */
@@ -58,10 +58,10 @@ RDGE.stateManager = function () {
58 if (state != null && typeof state.Init == 'function') { 58 if (state != null && typeof state.Init == 'function') {
59 if(this.stateTop != undefined) 59 if(this.stateTop != undefined)
60 this.stateStack[this.stateTop].LeaveState(); 60 this.stateStack[this.stateTop].LeaveState();
61 61
62 if(flags == undefined || flags != "noInit") 62 if(flags == undefined || flags != "noInit")
63 state.Init(); 63 state.Init();
64 64
65 this.stateTop = this.stateStack.push(state) - 1; 65 this.stateTop = this.stateStack.push(state) - 1;
66 } 66 }
67 }; 67 };
@@ -74,9 +74,9 @@ RDGE.stateManager = function () {
74 if (state != null) { 74 if (state != null) {
75 state.Shutdown(); 75 state.Shutdown();
76 } 76 }
77 77
78 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; 78 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0;
79 79
80 if (this.stateStack[this.stateTop]) { 80 if (this.stateStack[this.stateTop]) {
81 this.stateStack[this.stateTop].ReInit(); 81 this.stateStack[this.stateTop].ReInit();
82 } 82 }
@@ -90,7 +90,7 @@ RDGE.stateManager = function () {
90 this.PopState(); 90 this.PopState();
91 } 91 }
92 }; 92 };
93 93
94 this.tick = function (dt) { 94 this.tick = function (dt) {
95 if (this.stateStack[this.stateTop] != null) { 95 if (this.stateStack[this.stateTop] != null) {
96 this.stateStack[this.stateTop].Update(dt); 96 this.stateStack[this.stateTop].Update(dt);
@@ -256,7 +256,7 @@ RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject
256 globalParamFuncSet = function (param) { 256 globalParamFuncSet = function (param) {
257 this.data = param.data; 257 this.data = param.data;
258 this.type =param.type; 258 this.type =param.type;
259 259
260 this.set = function (v) { 260 this.set = function (v) {
261 var len = this.data ? this.data.length : 0; 261 var len = this.data ? this.data.length : 0;
262 for(var i=0;i<len;++i) 262 for(var i=0;i<len;++i)
@@ -271,10 +271,10 @@ RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject
271 } 271 }
272 } 272 }
273 }; 273 };
274 274
275 // light manager init before global parameters structure is reconfigured 275 // light manager init before global parameters structure is reconfigured
276 this.lightManager = new RDGE.LightManager(RDGE.rdgeGlobalParameters.rdge_lights); 276 this.lightManager = new RDGE.LightManager(RDGE.rdgeGlobalParameters.rdge_lights);
277 277
278 // added getter and setter to global uniforms 278 // added getter and setter to global uniforms
279 for (var p in RDGE.rdgeGlobalParameters) { 279 for (var p in RDGE.rdgeGlobalParameters) {
280 if (p != "rdge_lights") { 280 if (p != "rdge_lights") {
@@ -287,7 +287,7 @@ RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject
287 } 287 }
288 } 288 }
289 } 289 }
290 290
291 // initial window 291 // initial window
292 this.lastWindowWidth = window.innerWidth; 292 this.lastWindowWidth = window.innerWidth;
293 this.lastWindowHeight = window.innerHeight; 293 this.lastWindowHeight = window.innerHeight;
@@ -302,10 +302,10 @@ RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject
302 { 'name': "u_matShininess", 'value': [128.0] }, 302 { 'name': "u_matShininess", 'value': [128.0] },
303 { 'name': "u_matEmission", 'value': [0.0, 0.0, 0.0, 1.0] } 303 { 'name': "u_matEmission", 'value': [0.0, 0.0, 0.0, 1.0] }
304 ]; 304 ];
305 305
306 // startup the contexts 306 // startup the contexts
307 contextManager.start(); 307 contextManager.start();
308 308
309 this.initializeComplete = true; 309 this.initializeComplete = true;
310}; 310};
311 311
@@ -318,12 +318,12 @@ RDGE.Engine.prototype.Shutdown = function () {
318RDGE.Engine.prototype.GlInit = function (canvasObject) { 318RDGE.Engine.prototype.GlInit = function (canvasObject) {
319 // Initialize 319 // Initialize
320 var canvases = document.getElementsByTagName("canvas"); 320 var canvases = document.getElementsByTagName("canvas");
321 321
322 // transverse the canvases and create the contexts 322 // transverse the canvases and create the contexts
323 var numCv = canvases.length; 323 var numCv = canvases.length;
324 for (var cvIdx = 0; cvIdx < numCv; ++cvIdx) { 324 for (var cvIdx = 0; cvIdx < numCv; ++cvIdx) {
325 var canvas; 325 var canvas;
326 326
327 // if this canvas has a rdge attribute initialize the render context 327 // if this canvas has a rdge attribute initialize the render context
328 var rdgeAttr = canvases[cvIdx].getAttribute("rdge"); 328 var rdgeAttr = canvases[cvIdx].getAttribute("rdge");
329 if (rdgeAttr == "true") { 329 if (rdgeAttr == "true") {
@@ -338,17 +338,17 @@ RDGE.Engine.prototype.GlInit = function (canvasObject) {
338 canvas.addEventListener("webglcontextrestored", contextRestoredHandler, false); 338 canvas.addEventListener("webglcontextrestored", contextRestoredHandler, false);
339*/ 339*/
340}; 340};
341 341
342RDGE.Engine.prototype.loadScene = function (name) { 342RDGE.Engine.prototype.loadScene = function (name) {
343 var url = "assets_web/mesh/" + name + ".json" 343 var url = "assets_web/mesh/" + name + ".json"
344 344
345 // if we are not in the load state than push it on again 345 // if we are not in the load state than push it on again
346 if (contextManager.currentCtx.stateMan.currentState().name == "RunState") { 346 if (contextManager.currentCtx.stateMan.currentState().name == "RunState") {
347 contextManager.currentCtx.stateMan.PushState(contextManager.currentCtx.stateMan.RDGEInitState); 347 contextManager.currentCtx.stateMan.PushState(contextManager.currentCtx.stateMan.RDGEInitState);
348 contextManager.currentCtx.loadScene(url, name); 348 contextManager.currentCtx.loadScene(url, name);
349 } 349 }
350}; 350};
351 351
352RDGE.Engine.prototype.getScene = function (name) { 352RDGE.Engine.prototype.getScene = function (name) {
353 return contextManager.currentCtx.sceneGraphMap[name]; 353 return contextManager.currentCtx.sceneGraphMap[name];
354}; 354};
@@ -361,7 +361,7 @@ RDGE.Engine.prototype.AddScene = function (name, sceneGraph) {
361RDGE.Engine.prototype.registerCanvas = function (canvas, runState) { 361RDGE.Engine.prototype.registerCanvas = function (canvas, runState) {
362 if (canvas && this.getContext(canvas.rdgeid)) 362 if (canvas && this.getContext(canvas.rdgeid))
363 return; 363 return;
364 364
365 canvas.renderer = new RDGE._renderer(canvas); // create the renderer for the context 365 canvas.renderer = new RDGE._renderer(canvas); // create the renderer for the context
366 this.canvasToRendererMap[canvas.rdgeid] = canvas; // store the canvas in the context map 366 this.canvasToRendererMap[canvas.rdgeid] = canvas; // store the canvas in the context map
367 canvas.renderer.id = canvas.rdgeid; 367 canvas.renderer.id = canvas.rdgeid;