diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/engine.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/engine.js | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js index 36a34689..b2191197 100755 --- a/js/helper-classes/RDGE/src/core/script/engine.js +++ b/js/helper-classes/RDGE/src/core/script/engine.js | |||
@@ -31,72 +31,72 @@ POSSIBILITY OF SUCH DAMAGE. | |||
31 | var RDGE = RDGE || {}; | 31 | var RDGE = RDGE || {}; |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * Manage state instances | 34 | * Manage state instances |
35 | */ | 35 | */ |
36 | RDGE.stateManager = function () { | 36 | RDGE.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 | */ |
57 | this.PushState = function (state, flags) { | 57 | this.PushState = function (state, flags) { |
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 | }; |
68 | 68 | ||
69 | /* | 69 | /* |
70 | * Remove IRuntime state from stack, engine executes previous state | 70 | * Remove IRuntime state from stack, engine executes previous state |
71 | */ | 71 | */ |
72 | this.PopState = function () { | 72 | this.PopState = function () { |
73 | state = this.stateStack.pop(); | 73 | state = this.stateStack.pop(); |
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 | } |
83 | }; | 83 | }; |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * Remove all states from the stack | 86 | * Remove all states from the stack |
87 | */ | 87 | */ |
88 | this.PopAll = function () { | 88 | this.PopAll = function () { |
89 | while (this.stateStack[this.stateTop] != null) { | 89 | while (this.stateStack[this.stateTop] != null) { |
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); |
97 | this.stateStack[this.stateTop].Resize(); | 97 | this.stateStack[this.stateTop].Resize(); |
98 | this.stateStack[this.stateTop].Draw(); | 98 | this.stateStack[this.stateTop].Draw(); |
99 | } | 99 | } |
100 | }; | 100 | }; |
101 | }; | 101 | }; |
102 | 102 | ||
@@ -124,22 +124,22 @@ RDGE.Engine = function () { | |||
124 | this.RDGECanvas = null; | 124 | this.RDGECanvas = null; |
125 | 125 | ||
126 | /* | 126 | /* |
127 | * a map of canvas names to renderer | 127 | * a map of canvas names to renderer |
128 | */ | 128 | */ |
129 | this.canvasToRendererMap = {}; | 129 | this.canvasToRendererMap = {}; |
130 | 130 | ||
131 | /* | 131 | /* |
132 | * states to canvas map - maps a state stack to the canvas context it belongs to | 132 | * states to canvas map - maps a state stack to the canvas context it belongs to |
133 | */ | 133 | */ |
134 | this.canvasNameToStateStack = {}; | 134 | this.canvasNameToStateStack = {}; |
135 | 135 | ||
136 | /* | 136 | /* |
137 | * the list of context's that are active | 137 | * the list of context's that are active |
138 | */ | 138 | */ |
139 | this.canvasCtxList = []; | 139 | this.canvasCtxList = []; |
140 | 140 | ||
141 | /* | 141 | /* |
142 | * regex object to verify runtime object is not some sort of exploit | 142 | * regex object to verify runtime object is not some sort of exploit |
143 | */ | 143 | */ |
144 | invalidObj = new RegExp("([()]|function)"); | 144 | invalidObj = new RegExp("([()]|function)"); |
145 | 145 | ||
@@ -154,7 +154,7 @@ RDGE.Engine = function () { | |||
154 | }; | 154 | }; |
155 | 155 | ||
156 | /* | 156 | /* |
157 | * The context definition - every context shares these parameters | 157 | * The context definition - every context shares these parameters |
158 | */ | 158 | */ |
159 | contextDef = function () { | 159 | contextDef = function () { |
160 | this.id = null; | 160 | this.id = null; |
@@ -218,7 +218,7 @@ RDGE.Engine = function () { | |||
218 | }; | 218 | }; |
219 | 219 | ||
220 | /* | 220 | /* |
221 | * give the contextID (canvas id) of the context to set | 221 | * give the contextID (canvas id) of the context to set |
222 | */ | 222 | */ |
223 | this.setContext = function (contextID) { | 223 | this.setContext = function (contextID) { |
224 | contextManager.currentCtx = contextManager.contextMap[contextID]; | 224 | contextManager.currentCtx = contextManager.contextMap[contextID]; |
@@ -254,38 +254,38 @@ RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject | |||
254 | this.GlInit(canvasObject); | 254 | this.GlInit(canvasObject); |
255 | 255 | ||
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) |
263 | this.data[i]=v[i]; | 263 | this.data[i]=v[i]; |
264 | } | 264 | } |
265 | this.get = function () { | 265 | this.get = function () { |
266 | if (this.data.length == undefined) { | 266 | if (this.data.length == undefined) { |
267 | return this.data; | 267 | return this.data; |
268 | } | 268 | } |
269 | else { | 269 | else { |
270 | return this.data.slice(); | 270 | return this.data.slice(); |
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") { |
281 | RDGE.rdgeGlobalParameters[p] = new globalParamFuncSet(RDGE.rdgeGlobalParameters[p]); | 281 | RDGE.rdgeGlobalParameters[p] = new globalParamFuncSet(RDGE.rdgeGlobalParameters[p]); |
282 | } | 282 | } |
283 | else { | 283 | else { |
284 | var lights = RDGE.rdgeGlobalParameters[p]; | 284 | var lights = R |