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.js290
1 files changed, 157 insertions, 133 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js
index e935767d..1777fc22 100755
--- a/js/helper-classes/RDGE/src/core/script/engine.js
+++ b/js/helper-classes/RDGE/src/core/script/engine.js
@@ -10,73 +10,75 @@ var RDGE = RDGE || {};
10 * Manage state instances 10 * Manage state instances
11 */ 11 */
12RDGE.stateManager = function () { 12RDGE.stateManager = function () {
13 // a stack of states 13 // a stack of states
14 this.stateStack = []; 14 this.stateStack = [];
15 15
16 // number of states on the stack 16 // number of states on the stack
17 this.stateTop = undefined; 17 this.stateTop = undefined;
18 18
19 // the states of the context 19 // the states of the context
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 if (this.stateTop != undefined) 24 if(this.stateTop != undefined)
25 return this.stateStack[this.stateTop]; 25 return this.stateStack[this.stateTop];
26 26
27 return null; 27 return null;
28 }; 28 };
29 29
30 /* 30 /*
31 * Push new IRuntime state - engine executes the new state 31 * Push new IRuntime state - engine executes the new state
32 */ 32 */
33 this.PushState = function (state, flags) { 33 this.PushState = function (state, flags) {
34 if (state != null && typeof state.Init == 'function') { 34 if (state != null && typeof state.Init == 'function') {
35 if (this.stateTop != undefined) 35 if(this.stateTop != undefined)
36 this.stateStack[this.stateTop].LeaveState(); 36 this.stateStack[this.stateTop].LeaveState();
37 37
38 if (flags == undefined || flags != "noInit") 38 if(flags == undefined || flags != "noInit")
39 state.Init(); 39 state.Init();
40 40
41 this.stateTop = this.stateStack.push(state) - 1; 41 this.stateTop = this.stateStack.push(state) - 1;
42 } 42 }
43 }; 43 };
44 44
45 /* 45 /*
46 * Remove IRuntime state from stack, engine executes previous state 46 * Remove IRuntime state from stack, engine executes previous state
47 */ 47 */
48 this.PopState = function () { 48 this.PopState = function () {
49 state = this.stateStack.pop(); 49 state = this.stateStack.pop();
50 if (state != null) { 50 if (state != null) {
51 state.Shutdown(); 51 state.Shutdown();
52 } 52 }
53 53
54 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; 54 this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0;
55 55
56 if (this.stateStack[this.stateTop]) { 56 if (this.stateStack[this.stateTop]) {
57 this.stateStack[this.stateTop].ReInit(); 57 this.stateStack[this.stateTop].ReInit();
58 } 58 }
59 }; 59 };
60 60
61 /* 61 /*
62 * Remove all states from the stack 62 * Remove all states from the stack
63 */ 63 */
64 this.PopAll = function () { 64 this.PopAll = function () {
65 while (this.stateStack[this.stateTop] != null) { 65 while (this.stateStack[this.stateTop] != null) {
66 this.PopState(); 66 this.PopState();
67 } 67 }
68 }; 68 };
69 69
70 this.tick = function (dt) { 70 this.tick = function (dt) {
71 if (this.stateStack[this.stateTop] != null) { 71 if (this.stateStack[this.stateTop] != null) {
72 this.stateStack[this.stateTop].Update(dt); 72 this.stateStack[this.stateTop].Update(dt);
73 this.stateStack[this.stateTop].Resize(); 73 this.stateStack[this.stateTop].Resize();
74 this.stateStack[this.stateTop].Draw(); 74 this.stateStack[this.stateTop].Draw();
75 } 75 }
76 }; 76 };
77}; 77};
78 78
79RDGE.Engine = function() { 79RDGE.Engine = function() {
80 this._assetPath = "assets/";
81
80 // map of scene graphs to names 82 // map of scene graphs to names
81 this.sceneMap = []; 83 this.sceneMap = [];
82 84
@@ -116,34 +118,34 @@ RDGE.Engine = function() {
116 * 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
117 */ 119 */
118 invalidObj = new RegExp("([()]|function)"); 120 invalidObj = new RegExp("([()]|function)");
119 121
120 isValidObj = function (name) { 122 isValidObj = function (name) {
121 // do a quick test make sure user isn't trying to execute a function 123 // do a quick test make sure user isn't trying to execute a function
122 if (invalidObj.test(name)) { 124 if (invalidObj.test(name)) {
123 window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); 125 window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function");
124 return false; 126 return false;
125 } 127 }
126 128
127 return true; 129 return true;
128 }; 130 };
129 131
130 /* 132 /*
131 * The context definition - every context shares these parameters 133 * The context definition - every context shares these parameters
132 */ 134 */
133 contextDef = function () { 135 contextDef = function () {
134 this.id = null; 136 this.id = null;
135 this.renderer = null; 137 this.renderer = null;
136 this.ctxStateManager = null; 138 this.ctxStateManager = null;
137 this.startUpState = null; 139 this.startUpState = null;
138 this.sceneGraphMap = []; 140 this.sceneGraphMap = [];
139 this.currentScene = null; 141 this.currentScene = null;
140 this.getScene = function () { 142 this.getScene = function () {
141 return this.sceneGraphMap[this.currentScene]; 143 return this.sceneGraphMap[this.currentScene];
142 } 144 }
143 this.debug = 145 this.debug =
144 { 146 {
145 'frameCounter': 0, 147 'frameCounter' : 0,
146 'mat4CallCount': 0 148 'mat4CallCount': 0
147 } 149 }
148 }; 150 };
149 151
@@ -156,51 +158,69 @@ RDGE.Engine = function() {
156 158
157 contextManager._addObject = contextManager.addObject; 159 contextManager._addObject = contextManager.addObject;
158 contextManager.contextMap = {}; 160 contextManager.contextMap = {};
159 161
160 contextManager.addObject = function (context) { 162 contextManager.addObject = function (context) {
161 this.contextMap[context.id] = context; 163 this.contextMap[context.id] = context;
162 return this._addObject(context); 164 return this._addObject(context);
163 }; 165 };
164 166
165 contextManager.start = function () { 167 contextManager.start = function () {
166 var len = this.objects.length; 168 var len = this.objects.length;
167 for (var i = 0; i < len; ++i) { 169 for (var i = 0; i < len; ++i) {
168 // set the current context 170 // set the current context
169 contextManager.currentCtx = this.objects[i]; 171 contextManager.currentCtx = this.objects[i];
170 this.objects[i].ctxStateManager.PushState(this.objects[i].startUpState); 172 this.objects[i].ctxStateManager.PushState(this.objects[i].startUpState);
171 } 173 }
172 }; 174 };
173 175
174 contextManager.forEach = function (cb) { 176 contextManager.forEach = function (cb) {
175 var len = this.objects.length; 177 var len = this.objects.length;
176 for (var i = 0; i < len; ++i) { 178 for (var i = 0; i < len; ++i) {
177 cb(this.objects[i]); 179 cb(this.objects[i]);
178 } 180 }
179 }; 181 };
180 182
181 this.getContext = function (optCanvasID) { 183 this.getContext = function (optCanvasID) {
182 if (!optCanvasID) { 184 if (!optCanvasID) {
183 return contextManager.currentCtx; 185 return contextManager.currentCtx;
184 }