diff options
author | John Mayhew | 2012-04-02 16:28:39 -0700 |
---|---|---|
committer | John Mayhew | 2012-04-02 16:28:39 -0700 |
commit | b4155fb4c33675a8a7cd37473513718043fdf0ba (patch) | |
tree | 3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/helper-classes/RDGE/src/core/script/engine.js | |
parent | 5ba9aeac94c86049423fd5d4b37b277263939c13 (diff) | |
parent | c6de22bf42be90b403491b5f87b1818d9020310c (diff) | |
download | ninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts:
js/helper-classes/RDGE/rdge-compiled.js
js/helper-classes/RDGE/runtime/GLRuntime.js
js/helper-classes/RDGE/src/core/script/MeshManager.js
js/helper-classes/RDGE/src/core/script/engine.js
js/helper-classes/RDGE/src/core/script/fx/ssao.js
js/helper-classes/RDGE/src/core/script/init_state.js
js/helper-classes/RDGE/src/core/script/run_state.js
js/helper-classes/RDGE/src/core/script/scenegraphNodes.js
js/helper-classes/RDGE/src/core/script/utilities.js
js/helper-classes/RDGE/src/tools/compile-rdge-core.bat
js/helper-classes/RDGE/src/tools/compile-rdge-core.sh
js/helper-classes/RDGE/src/tools/rdge-compiled.js
js/lib/drawing/world.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/deform-material.js
js/lib/rdge/materials/flat-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/linear-gradient-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-blur-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/relief-tunnel-material.js
js/lib/rdge/materials/square-tunnel-material.js
js/lib/rdge/materials/star-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/tunnel-material.js
js/lib/rdge/materials/twist-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/uber-material.js
js/lib/rdge/materials/water-material.js
js/lib/rdge/materials/z-invert-material.js
js/preloader/Preloader.js
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/engine.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/engine.js | 290 |
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 | */ |
12 | RDGE.stateManager = function () { | 12 | RDGE.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 | ||
79 | RDGE.Engine = function() { | 79 | RDGE.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 |