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 | 923 |
1 files changed, 462 insertions, 461 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..8331d0a0 100755 --- a/js/helper-classes/RDGE/src/core/script/engine.js +++ b/js/helper-classes/RDGE/src/core/script/engine.js | |||
@@ -1,461 +1,462 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | |
5 | 5 | Redistribution and use in source and binary forms, with or without | |
6 | Redistribution and use in source and binary forms, with or without | 6 | modification, are permitted provided that the following conditions are met: |
7 | modification, are permitted provided that the following conditions are met: | 7 | |
8 | 8 | * Redistributions of source code must retain the above copyright notice, | |
9 | - Redistributions of source code must retain the above copyright notice, | 9 | this list of conditions and the following disclaimer. |
10 | this list of conditions and the following disclaimer. | 10 | |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
12 | notice, this list of conditions and the following disclaimer in the | 12 | this list of conditions and the following disclaimer in the documentation |
13 | documentation and/or other materials provided with the distribution. | 13 | and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | |
15 | may be used to endorse or promote products derived from this software | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | without specific prior written permission. | 16 | contributors may be used to endorse or promote products derived from this |
17 | 17 | software without specific prior written permission. | |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | </copyright> */ | 29 | POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | </copyright> */ | |
31 | var RDGE = RDGE || {}; | 31 | |
32 | 32 | var RDGE = RDGE || {}; | |
33 | /* | 33 | |
34 | * Manage state instances | 34 | /* |
35 | */ | 35 | * Manage state instances |
36 | RDGE.stateManager = function () { | 36 | */ |
37 | // a stack of states | 37 | RDGE.stateManager = function () { |
38 | this.stateStack = []; | 38 | // a stack of states |
39 | 39 | this.stateStack = []; | |
40 | // number of states on the stack | 40 | |
41 | this.stateTop = undefined; | 41 | // number of states on the stack |
42 | 42 | this.stateTop = undefined; | |
43 | // the states of the context | 43 | |
44 | this.RDGEInitState = null; | 44 | // the states of the context |
45 | this.RDGERunState = null; | 45 | this.RDGEInitState = null; |
46 | 46 | this.RDGERunState = null; | |
47 | this.currentState = function () { | 47 | |
48 | if(this.stateTop != undefined) | 48 | this.currentState = function () { |
49 | return this.stateStack[this.stateTop]; | 49 | if(this.stateTop != undefined) |
50 | 50 | return this.stateStack[this.stateTop]; | |
51 | return null; | 51 | |
52 | }; | 52 | return null; |
53 | 53 | }; | |
54 | /* | 54 | |
55 | * Push new IRuntime state - engine executes the new state | 55 | /* |
56 | */ | 56 | * Push new IRuntime state - engine executes the new state |
57 | this.PushState = function (state, flags) { | 57 | */ |
58 | if (state != null && typeof state.Init == 'function') { | 58 | this.PushState = function (state, flags) { |
59 | if(this.stateTop != undefined) | 59 | if (state != null && typeof state.Init == 'function') { |
60 | this.stateStack[this.stateTop].LeaveState(); | 60 | if(this.stateTop != undefined) |
61 | 61 | this.stateStack[this.stateTop].LeaveState(); | |
62 | if(flags == undefined || flags != "noInit") | 62 | |
63 | state.Init(); | 63 | if(flags == undefined || flags != "noInit") |
64 | 64 | state.Init(); | |
65 | this.stateTop = this.stateStack.push(state) - 1; | 65 | |
66 | } | 66 | this.stateTop = this.stateStack.push(state) - 1; |
67 | }; | 67 | } |
68 | 68 | }; | |
69 | /* | 69 | |
70 | * Remove IRuntime state from stack, engine executes previous state | 70 | /* |
71 | */ | 71 | * Remove IRuntime state from stack, engine executes previous state |
72 | this.PopState = function () { | 72 | */ |
73 | state = this.stateStack.pop(); | 73 | this.PopState = function () { |
74 | if (state != null) { | 74 | state = this.stateStack.pop(); |
75 | state.Shutdown(); | 75 | if (state != null) { |
76 | } | 76 | state.Shutdown(); |
77 | 77 | } | |
78 | this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; | 78 | |
79 | 79 | this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; | |
80 | if (this.stateStack[this.stateTop]) { | 80 | |
81 | this.stateStack[this.stateTop].ReInit(); | 81 | if (this.stateStack[this.stateTop]) { |
82 | } | 82 | this.stateStack[this.stateTop].ReInit(); |
83 | }; | 83 | } |
84 | 84 | }; | |
85 | /* | 85 | |
86 | * Remove all states from the stack | 86 | /* |
87 | */ | 87 | * Remove all states from the stack |
88 | this.PopAll = function () { | 88 | */ |
89 | while (this.stateStack[this.stateTop] != null) { | 89 | this.PopAll = function () { |
90 | this.PopState(); | 90 | while (this.stateStack[this.stateTop] != null) { |
91 | } | 91 | this.PopState(); |
92 | }; | 92 | } |
93 | 93 | }; | |
94 | this.tick = function (dt) { | 94 | |
95 | if (this.stateStack[this.stateTop] != null) { | 95 | this.tick = function (dt) { |
96 | this.stateStack[this.stateTop].Update(dt); | 96 | if (this.stateStack[this.stateTop] != null) { |
97 | this.stateStack[this.stateTop].Resize(); | 97 | this.stateStack[this.stateTop].Update(dt); |
98 | this.stateStack[this.stateTop].Draw(); | 98 | this.stateStack[this.stateTop].Resize(); |
99 | } | 99 | this.stateStack[this.stateTop].Draw(); |
100 | }; | 100 | } |
101 | }; | 101 | }; |
102 | 102 | }; | |
103 | RDGE.Engine = function () { | 103 | |
104 | this._assetPath = "assets/"; | 104 | RDGE.Engine = function () { |
105 | 105 | this._assetPath = "assets/"; | |
106 | // map of scene graphs to names | 106 | |
107 | this.sceneMap = []; | 107 | // map of scene graphs to names |
108 | 108 | this.sceneMap = []; | |
109 | // number of states on the stack | 109 | |
110 | this.stateTop = undefined; | 110 | // number of states on the stack |
111 | 111 | this.stateTop = undefined; | |
112 | // size of the browser window | 112 | |
113 | this.lastWindowWidth = window.innerWidth; | 113 | // size of the browser window |
114 | this.lastWindowHeight = window.innerHeight; | 114 | this.lastWindowWidth = window.innerWidth; |
115 | 115 | this.lastWindowHeight = window.innerHeight; | |
116 | this.defaultContext = null; | 116 | |
117 | 117 | this.defaultContext = null; | |
118 | this.lightManager = null; | 118 | |
119 | 119 | this.lightManager = null; | |
120 | clearColor = [0.0, 0.0, 0.0, 0.0]; | 120 | |
121 | 121 | clearColor = [0.0, 0.0, 0.0, 0.0]; | |
122 | this.initializeComplete = false; | 122 | |
123 | 123 | this.initializeComplete = false; | |
124 | this.RDGECanvas = null; | 124 | |
125 | 125 | this.RDGECanvas = null; | |
126 | /* | 126 | |
127 | * a map of canvas names to renderer | 127 | /* |
128 | */ | 128 | * a map of canvas names to renderer |
129 | this.canvasToRendererMap = {}; | 129 | */ |
130 | 130 | this.canvasToRendererMap = {}; | |
131 | /* | 131 | |
132 | * states to canvas map - maps a state stack to the canvas context it belongs to | 132 | /* |
133 | */ | 133 | * states to canvas map - maps a state stack to the canvas context it belongs to |
134 | this.canvasNameToStateStack = {}; | 134 | */ |
135 | 135 | this.canvasNameToStateStack = {}; | |
136 | /* | 136 | |
137 | * the list of context's that are active | 137 | /* |
138 | */ | 138 | * the list of context's that are active |
139 | this.canvasCtxList = []; | 139 | */ |
140 | 140 | this.canvasCtxList = []; | |
141 |