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 | 513 |
1 files changed, 223 insertions, 290 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js index 5bc9305c..0975fcef 100755 --- a/js/helper-classes/RDGE/src/core/script/engine.js +++ b/js/helper-classes/RDGE/src/core/script/engine.js | |||
@@ -4,91 +4,79 @@ 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 | ||
7 | var RDGE = RDGE || {}; | ||
7 | 8 | ||
8 | /* | 9 | /* |
9 | * Manage state instances | 10 | * Manage state instances |
10 | */ | 11 | */ |
11 | stateManager = function() | 12 | RDGE.stateManager = function () { |
12 | { | 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 | { | 24 | if (this.stateTop != undefined) |
25 | if(this.stateTop != undefined) | 25 | return this.stateStack[this.stateTop]; |
26 | return this.stateStack[this.stateTop]; | 26 | |
27 | 27 | return null; | |
28 | return null; | 28 | }; |
29 | } | 29 | |
30 | 30 | /* | |
31 | /* | 31 | * Push new IRuntime state - engine executes the new state |
32 | * Push new IRuntime state - engine executes the new state | 32 | */ |
33 | */ | 33 | this.PushState = function (state, flags) { |
34 | this.PushState = function(state, flags) | 34 | if (state != null && typeof state.Init == 'function') { |
35 | { | 35 | if (this.stateTop != undefined) |
36 | if(state!=null && typeof state.Init == 'function') | 36 | this.stateStack[this.stateTop].LeaveState(); |
37 | { | 37 | |
38 | if(this.stateTop != undefined) | 38 | if (flags == undefined || flags != "noInit") |
39 | this.stateStack[this.stateTop].LeaveState(); | 39 | state.Init(); |
40 | 40 | ||
41 | if(flags == undefined || flags != "noInit") | 41 | this.stateTop = this.stateStack.push(state) - 1; |
42 | state.Init(); | 42 | } |
43 | 43 | }; | |
44 | this.stateTop = this.stateStack.push(state) - 1; | 44 | |
45 | } | 45 | /* |
46 | } | 46 | * Remove IRuntime state from stack, engine executes previous state |
47 | 47 | */ | |
48 | /* | 48 | this.PopState = function () { |
49 | * Remove IRuntime state from stack, engine executes previous state | 49 | state = this.stateStack.pop(); |
50 | */ | 50 | if (state != null) { |
51 | this.PopState = function() | 51 | state.Shutdown(); |
52 | { | 52 | } |
53 | state = this.stateStack.pop(); | 53 | |
54 | if(state!=null) | 54 | this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; |
55 | { | 55 | |
56 | state.Shutdown(); | 56 | if (this.stateStack[this.stateTop]) { |
57 | } | 57 | this.stateStack[this.stateTop].ReInit(); |
58 | 58 | } | |
59 | this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; | 59 | }; |
60 | 60 | ||
61 | if(this.stateStack[this.stateTop]) | 61 | /* |
62 | { | 62 | * Remove all states from the stack |
63 | this.stateStack[this.stateTop].ReInit(); | 63 | */ |
64 | } | 64 | this.PopAll = function () { |
65 | } | 65 | while (this.stateStack[this.stateTop] != null) { |
66 | 66 | this.PopState(); | |
67 | /* | 67 | } |
68 | * Remove all states from the stack | 68 | }; |
69 | */ | 69 | |
70 | this.PopAll = function() | 70 | this.tick = function (dt) { |
71 | { | 71 | if (this.stateStack[this.stateTop] != null) { |
72 | while(this.stateStack[this.stateTop] != null) | 72 | this.stateStack[this.stateTop].Update(dt); |
73 | { | 73 | this.stateStack[this.stateTop].Resize(); |
74 | this.PopState(); | 74 | this.stateStack[this.stateTop].Draw(); |
75 | } | 75 | } |
76 | } | 76 | }; |
77 | 77 | }; | |
78 | this.tick = function(dt) | 78 | |
79 | { | 79 | RDGE.Engine = function() { |
80 | if(this.stateStack[this.stateTop]!=null) | ||
81 | { | ||
82 | this.stateStack[this.stateTop].Update(dt); | ||
83 | this.stateStack[this.stateTop].Resize(); | ||
84 | this.stateStack[this.stateTop].Draw(); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | g_enableBenchmarks = true; | ||
90 | function Engine() | ||
91 | { | ||
92 | // map of scene graphs to names | 80 | // map of scene graphs to names |
93 | this.sceneMap = []; | 81 | this.sceneMap = []; |
94 | 82 | ||
@@ -105,8 +93,6 @@ function Engine() | |||
105 | 93 | ||
106 | clearColor = [0.0, 0.0, 0.0, 0.0]; | 94 | clearColor = [0.0, 0.0, 0.0, 0.0]; |
107 | 95 | ||
108 | panelObjectManager = new objectManager(); | ||
109 | |||
110 | this.initializeComplete = false; | 96 | this.initializeComplete = false; |
111 | 97 | ||
112 | this.RDGECanvas = null; | 98 | this.RDGECanvas = null; |
@@ -130,43 +116,39 @@ function Engine() | |||
130 | * regex object to verify runtime object is not some sort of exploit | 116 | * regex object to verify runtime object is not some sort of exploit |
131 | */ | 117 | */ |
132 | invalidObj = new RegExp("([()]|function)"); | 118 | invalidObj = new RegExp("([()]|function)"); |
133 | 119 | ||
134 | isValidObj = function( name ) | 120 | isValidObj = function (name) { |
135 | { | 121 | // do a quick test make sure user isn't trying to execute a function |
136 | // do a quick test make sure user isn't trying to execute a function | 122 | if (invalidObj.test(name)) { |
137 | if(invalidObj.test(name)) | 123 | window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); |
138 | { | 124 | return false; |
139 | window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); | 125 | } |
140 | return false; | 126 | |
141 | } | 127 | return true; |
142 | 128 | }; | |
143 | return true; | ||
144 | } | ||
145 | 129 | ||
146 | /* | 130 | /* |
147 | * The context definition - every context shares these parameters | 131 | * The context definition - every context shares these parameters |
148 | */ | 132 | */ |
149 | contextDef = function() | 133 | contextDef = function () { |
150 | { | 134 | this.id = null; |
151 | this.id = null; | ||
152 | this.renderer = null; | 135 | this.renderer = null; |
153 | this.ctxStateManager = null; | 136 | this.ctxStateManager = null; |
154 | this.startUpState = null; | 137 | this.startUpState = null; |
155 | this.sceneGraphMap = []; | 138 | this.sceneGraphMap = []; |
156 | this.currentScene = null; | 139 | this.currentScene = null; |
157 | this.getScene = function() | 140 | this.getScene = function () { |
158 | { | 141 | return this.sceneGraphMap[this.currentScene]; |
159 | return this.sceneGraphMap[this.currentScene]; | ||
160 | } | 142 | } |
161 | this.debug = | 143 | this.debug = |
162 | { | 144 | { |
163 | 'frameCounter' : 0, | 145 | 'frameCounter': 0, |
164 | 'mat4CallCount': 0 | 146 | 'mat4CallCount': 0 |
165 | } | 147 | } |
166 | } | 148 | }; |
167 | 149 | ||
168 | // maintains the contexts | 150 | // maintains the contexts |
169 | contextManager = new objectManager(); | 151 | contextManager = new RDGE.objectManager(); |
170 | this.ctxMan = contextManager; | 152 | this.ctxMan = contextManager; |
171 | 153 | ||
172 | // the context currently being updated | 154 | // the context currently being updated |
@@ -174,219 +156,174 @@ function Engine() | |||
174 | 156 | ||
175 | contextManager._addObject = contextManager.addObject; | 157 | contextManager._addObject = contextManager.addObject; |
176 | contextManager.contextMap = {}; | 158 | contextManager.contextMap = {}; |
177 | 159 | ||
178 | contextManager.addObject = function( context ) | 160 | contextManager.addObject = function (context) { |
179 | { | 161 | this.contextMap[context.id] = context; |
180 |