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.js417
1 files changed, 176 insertions, 241 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js
index 1341d032..d437d5f8 100755
--- a/js/helper-classes/RDGE/src/core/script/engine.js
+++ b/js/helper-classes/RDGE/src/core/script/engine.js
@@ -4,12 +4,12 @@ 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
7var RDGE = RDGE || {};
7 8
8/* 9/*
9 * Manage state instances 10 * Manage state instances
10 */ 11 */
11stateManager = function() 12RDGE.stateManager = function () {
12{
13 // a stack of states 13 // a stack of states
14 this.stateStack = []; 14 this.stateStack = [];
15 15
@@ -20,21 +20,18 @@ stateManager = function()
20 this.RDGEInitState = null; 20 this.RDGEInitState = null;
21 this.RDGERunState = null; 21 this.RDGERunState = null;
22 22
23 this.currentState = function() 23 this.currentState = function () {
24 {
25 if(this.stateTop != undefined) 24 if(this.stateTop != undefined)
26 return this.stateStack[this.stateTop]; 25 return this.stateStack[this.stateTop];
27 26
28 return null; 27 return null;
29 } 28 };
30 29
31 /* 30 /*
32 * Push new IRuntime state - engine executes the new state 31 * Push new IRuntime state - engine executes the new state
33 */ 32 */
34 this.PushState = function(state, flags) 33 this.PushState = function (state, flags) {
35 { 34 if (state != null && typeof state.Init == 'function') {
36 if(state!=null && typeof state.Init == 'function')
37 {
38 if(this.stateTop != undefined) 35 if(this.stateTop != undefined)
39 this.stateStack[this.stateTop].LeaveState(); 36 this.stateStack[this.stateTop].LeaveState();
40 37
@@ -43,261 +40,226 @@ stateManager = function()
43 40
44 this.stateTop = this.stateStack.push(state) - 1; 41 this.stateTop = this.stateStack.push(state) - 1;
45 } 42 }
46 } 43 };
47 44
48 /* 45 /*
49 * Remove IRuntime state from stack, engine executes previous state 46 * Remove IRuntime state from stack, engine executes previous state
50 */ 47 */
51 this.PopState = function() 48 this.PopState = function () {
52 {
53 state = this.stateStack.pop(); 49 state = this.stateStack.pop();
54 if(state!=null) 50 if (state != null) {
55 {
56 state.Shutdown(); 51 state.Shutdown();
57 } 52 }
58 53
59 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; 54 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0;
60 55
61 if(this.stateStack[this.stateTop]) 56 if (this.stateStack[this.stateTop]) {
62 {
63 this.stateStack[this.stateTop].ReInit(); 57 this.stateStack[this.stateTop].ReInit();
64 } 58 }
65 } 59 };
66 60
67 /* 61 /*
68 * Remove all states from the stack 62 * Remove all states from the stack
69 */ 63 */
70 this.PopAll = function() 64 this.PopAll = function () {
71 { 65 while (this.stateStack[this.stateTop] != null) {
72 while(this.stateStack[this.stateTop] != null)
73 {
74 this.PopState(); 66 this.PopState();
75 } 67 }
76 } 68 };
77 69
78 this.tick = function(dt) 70 this.tick = function (dt) {
79 { 71 if (this.stateStack[this.stateTop] != null) {
80 if(this.stateStack[this.stateTop]!=null)
81 {
82 this.stateStack[this.stateTop].Update(dt); 72 this.stateStack[this.stateTop].Update(dt);
83 this.stateStack[this.stateTop].Resize(); 73 this.stateStack[this.stateTop].Resize();
84 this.stateStack[this.stateTop].Draw(); 74 this.stateStack[this.stateTop].Draw();
85 } 75 }
86 } 76 };
87} 77};
88 78
89g_enableBenchmarks = true; 79RDGE.Engine = function () {
90function Engine() 80 this._assetPath = "assets/";
91{
92 this._assetPath = "assets/";
93 81
94 // map of scene graphs to names 82 // map of scene graphs to names
95 this.sceneMap = []; 83 this.sceneMap = [];
96 84
97 // number of states on the stack 85 // number of states on the stack
98 this.stateTop = undefined; 86 this.stateTop = undefined;
99 87
100 // size of the browser window 88 // size of the browser window
101 this.lastWindowWidth = window.innerWidth; 89 this.lastWindowWidth = window.innerWidth;
102 this.lastWindowHeight = window.innerHeight; 90 this.lastWindowHeight = window.innerHeight;
103 91
104 this.defaultContext = null; 92 this.defaultContext = null;
105 93
106 this.lightManager = null; 94 this.lightManager = null;
107 95
108 clearColor = [0.0, 0.0, 0.0, 0.0]; 96 clearColor = [0.0, 0.0, 0.0, 0.0];
109 97
110 panelObjectManager = new objectManager();
111
112 this.initializeComplete = false; 98 this.initializeComplete = false;
113 99
114 this.RDGECanvas = null; 100 this.RDGECanvas = null;
115 101
116 /* 102 /*
117 * a map of canvas names to renderer 103 * a map of canvas names to renderer
118 */ 104 */
119 this.canvasToRendererMap = {}; 105 this.canvasToRendererMap = {};
120 106
121 /* 107 /*
122 * states to canvas map - maps a state stack to the canvas context it belongs to 108 * states to canvas map - maps a state stack to the canvas context it belongs to
123 */ 109 */
124 this.canvasNameToStateStack = {}; 110 this.canvasNameToStateStack = {};
125 111
126 /* 112 /*
127 * the list of context's that are active 113 * the list of context's that are active
128 */ 114 */
129 this.canvasCtxList = []; 115 this.canvasCtxList = [];
130 116
131 /* 117 /*
132 * regex object to verify runtime object is not some sort of exploit 118 * regex object to verify runtime object is not some sort of exploit
133 */ 119 */
134 invalidObj = new RegExp("([()]|function)"); 120 invalidObj = new RegExp("([()]|function)");
135 121
136 isValidObj = function( name ) 122 isValidObj = function (name) {
137 { 123 // do a quick test make sure user isn't trying to execute a function
138 // do a quick test make sure user isn't trying to execute a function 124 if (invalidObj.test(name)) {
139 if(invalidObj.test(name)) 125 window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function");
140 { 126 return false;
141 window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); 127 }
142 return false; 128
143 } 129 return true;
144 130 };
145 return true; 131
146 }
147
148 /* 132 /*
149 * The context definition - every context shares these parameters 133 * The context definition - every context shares these parameters
150 */ 134 */
151 contextDef = function() 135 contextDef = function () {
152 { 136 this.id = null;
153 this.id = null;
154 this.renderer = null; 137 this.renderer = null;
155 this.ctxStateManager = null; 138 this.ctxStateManager = null;
156 this.startUpState = null; 139 this.startUpState = null;