diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/runtime.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/runtime.js | 280 |
1 files changed, 117 insertions, 163 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/runtime.js b/js/helper-classes/RDGE/src/core/script/runtime.js index 3d824faf..eb327d1f 100755 --- a/js/helper-classes/RDGE/src/core/script/runtime.js +++ b/js/helper-classes/RDGE/src/core/script/runtime.js | |||
@@ -4,103 +4,77 @@ 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 | // RDGE namespaces | ||
8 | var RDGE = RDGE || {}; | ||
9 | RDGE.core = RDGE.core || {}; | ||
10 | RDGE.utilities = RDGE.utilities || {}; | ||
11 | |||
7 | // runtime globals | 12 | // runtime globals |
8 | g_Engine = new Engine(); | 13 | RDGE.globals = (function () { |
9 | g_width = 0; | 14 | return { |
10 | g_height = 0; | 15 | engine: new RDGE.Engine(), |
11 | g_cam = null; | 16 | width: 0, |
12 | g_camMoveSpeed = 25.0; | 17 | height: 0, |
13 | gl = null; //webGL handle | 18 | cam: null, |
14 | g_worldObjects = []; | 19 | shaderMan: null, |
15 | g_shaderMan = null | 20 | meshMan: null, |
16 | g_defaultTex = null; | 21 | poolList: [], |
17 | g_alphaTex = null; | 22 | gl: null |
18 | g_hiQu = true; | 23 | }; |
19 | g_meshMan = null; | 24 | })(); |
25 | |||
26 | // new code is above | ||
27 | /***************************************************************************************************************/ | ||
20 | 28 | ||
21 | /* | 29 | /* |
22 | * RDGEState a RDGEstate is an interface that is defined by the user and called by the engine | 30 | * RDGEState a RDGEstate is an interface that is defined by the user and called by the engine |
23 | */ | 31 | */ |
24 | function RDGEState() | 32 | RDGE.core.RDGEState = function RDGEState() { }; |
25 | { | 33 | RDGE.core.RDGEState.prototype.init = function () { }; |
26 | this.init = function() | 34 | RDGE.core.RDGEState.prototype.update = function () { }; |
27 | { | 35 | RDGE.core.RDGEState.prototype.draw = function () { }; |
28 | 36 | RDGE.core.RDGEState.prototype.resize = function () { }; | |
29 | } | 37 | RDGE.core.RDGEState.prototype.shutdown = function () { }; |
30 | 38 | RDGE.core.RDGEState.prototype.onComplete = function () { }; | |
31 | this.update = function(dt) | ||
32 | { | ||
33 | |||
34 | } | ||
35 | |||
36 | this.draw = function() | ||
37 | { | ||
38 | |||
39 | } | ||
40 | |||
41 | this.resize = function() | ||
42 | { | ||
43 | |||
44 | } | ||
45 | |||
46 | this.shutdown = function() | ||
47 | { | ||
48 | |||
49 | } | ||
50 | |||
51 | this.onComplete = function() | ||
52 | { | ||
53 | |||
54 | } | ||
55 | } | ||
56 | 39 | ||
57 | /* | 40 | /* |
58 | * Calling this makes sure the passed in run state has all the functions | 41 | * Calling this makes sure the passed in run state has all the functions |
59 | * that are required, adding dummy functions where needed | 42 | * that are required, adding dummy functions where needed |
60 | */ | 43 | */ |
61 | function validateUserState( userState ) | 44 | RDGE.utilities.validateUserState = function (userState) { |
62 | { | 45 | if (!userState.init) { |
63 | if(!userState.init) | 46 | userState.init = function () { }; |
64 | { | 47 | } |
65 | userState.init = function(){}; | 48 | if (!userState.update) { |
66 | } | 49 | userState.update = function (dt) { |
67 | if(!userState.update) | 50 | var currentScene = RDGE.globals.engine.getContext().currentScene; |
68 | { | 51 | currentScene = RDGE.globals.engine.getScene(currentScene); |
69 | userState.update = function(dt) | 52 | |
70 | { | 53 | if (currentScene != null) |
71 | var currentScene = g_Engine.getContext().currentScene; | 54 | currentScene.update(dt); |
72 | currentScene = g_Engine.getScene(currentScene); | 55 | } |
73 | 56 | } | |
74 | if(currentScene != null) | 57 | if (!userState.draw) { |
75 | currentScene.update(dt); | 58 | userState.draw = function () { |
76 | } | 59 | var currentScene = RDGE.globals.engine.getContext().currentScene; |
77 | } | 60 | currentScene = RDGE.globals.engine.getScene(currentScene); |
78 | if(!userState.draw) | 61 | |
79 | { | 62 | if (currentScene == null) |
80 | userState.draw = function() | 63 | return; |
81 | { | 64 | |
82 | var currentScene = g_Engine.getContext().currentScene; | 65 | currentScene.render(); |
83 | currentScene = g_Engine.getScene(currentScene); | 66 | } |
84 | 67 | } | |
85 | if(currentScene==null) | 68 | if (!userState.resize) { |
86 | return; | 69 | userState.resize = function () { }; |
87 | 70 | } | |
88 | currentScene.render(); | 71 | if (!userState.shutdown) { |
89 | } | 72 | userState.shutdown = function () { }; |
90 | } | 73 | } |
91 | if(!userState.resize) | 74 | if (!userState.onComplete) { |
92 | { | 75 | userState.onComplete = function () { }; |
93 | userState.resize = function(){}; | 76 | } |
94 | } | 77 | }; |
95 | if(!userState.shutdown) | ||
96 | { | ||
97 | userState.shutdown = function(){}; | ||
98 | } | ||
99 | if(!userState.onComplete) | ||
100 | { | ||
101 | userState.onComplete = function(){}; | ||
102 | } | ||
103 | } | ||
104 | 78 | ||
105 | /* | 79 | /* |
106 | * Used to start the RDGE engine, pass the initState and runState, both of which are RDGEState objects | 80 | * Used to start the RDGE engine, pass the initState and runState, both of which are RDGEState objects |
@@ -109,76 +83,59 @@ function validateUserState( userState ) | |||
109 | * @param initState - the initialization state, false if you don't want to use one | 83 | * @param initState - the initialization state, false if you don't want to use one |
110 | * @param runState - the run state | 84 | * @param runState - the run state |
111 | */ | 85 | */ |
112 | function RDGEStart(canvasOrID) | 86 | RDGE.RDGEStart = function (canvasOrID) { |
113 | { | 87 | var canvas = canvasOrID; |
114 | var canvas = canvasOrID; | ||
115 | |||
116 | if (typeof(canvasOrID) === "string") | ||
117 | canvas = document.getElementById(canvasOrID); | ||
118 | |||
119 | if (!canvas) | ||
120 | return; | ||
121 | |||
122 | g_Engine.registerCanvas(canvas); | ||
123 | |||
124 | canvas.task = new RDGETask(canvas, true); | ||
125 | |||
126 | if (!g_shaderMan) | ||
127 | g_shaderMan = new ShaderManager(); | ||
128 | |||
129 | if (!g_meshMan) | ||
130 | g_meshMan = new MeshManager(); | ||
131 | |||
132 | // start rdge | ||
133 | if (!g_Engine.initializeComplete) | ||
134 | g_Engine.init(); | ||
135 | } | ||
136 | |||
137 | function RDGEStop() | ||
138 | { | ||
139 | if(RDGEShutdown != undefined) | ||
140 | { | ||
141 | RDGEShutdown(); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | // the runtime interface | ||
146 | function IRuntime() | ||
147 | { | ||
148 | this.init = null; // called when state is pushed on the stack | ||
149 | this.ReInit = null; // called when state above is popped from stack | ||
150 | this.Resize = null; // called every tick to setup the viewport/projection | ||
151 | this.Update = null; // called every tick to update scene | ||
152 | this.Draw = null; // called every tick to draw scene | ||
153 | this.Shutdown = null; // called when state is popped from stack | ||
154 | } | ||
155 | |||
156 | // add the connection Pool's to this list for auto polling | ||
157 | g_poolList = []; | ||
158 | function ConnPoll() | ||
159 | { | ||
160 | var len = g_poolList.length; | ||
161 | for(var i = 0; i < len; ++i) | ||
162 | { | ||
163 | g_poolList[i].Poll(); | ||
164 | } | ||
165 | } | ||
166 | 88 | ||
167 | /* RDGE Task */ | 89 | if (typeof (canvasOrID) === "string") |
168 | RDGERequestAnimationFrame = (function() { | 90 | canvas = document.getElementById(canvasOrID); |
169 | return window.requestAnimationFrame || | 91 | |
92 | if (!canvas) | ||
93 | return; | ||
94 | |||
95 | RDGE.globals.engine.registerCanvas(canvas); | ||
96 | |||
97 | canvas.task = new RDGE.RDGETask(canvas, true); | ||