aboutsummaryrefslogtreecommitdiff
path: root/js/preloader
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/preloader
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/preloader')
-rwxr-xr-xjs/preloader/Preloader.js287
-rw-r--r--js/preloader/PreloaderWorker.js95
2 files changed, 382 insertions, 0 deletions
diff --git a/js/preloader/Preloader.js b/js/preloader/Preloader.js
new file mode 100755
index 00000000..f137f4b6
--- /dev/null
+++ b/js/preloader/Preloader.js
@@ -0,0 +1,287 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component,
9 defaultEventManager = require("montage/core/event/event-manager").defaultEventManager;
10
11exports.Preloader = Montage.create(Component, {
12
13
14 ninjaJsRequire: {
15 value:
16 [
17 {"type":"js", "url":"js/helper-classes/3D/GLMatrix/gl-matrix.js"},
18 {"type":"js", "url":"js/codemirror/lib/codemirror.js"},
19
20 //{"type":"js", "url":"js/helper-classes/RDGE/rdge-compiled.js"},
21
22 // source RDGE
23 /* */
24 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/math/vec2.js"},
25 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/math/vec3.js"},
26 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/math/vec4.js"},
27 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/math/mat4.js"},
28 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/math/quat.js"},
29 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/util/statTracker.js"},
30 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/util/fpsTracker.js"},
31 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/objectManager.js"},
32 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/precompiled.js"},
33 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/renderer.js"},
34 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/renderUtils.js"},
35 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/jshader.js"},
36 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/jpass.js"},
37 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/RenderProcs.js"},
38 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/RenderInitProcs.js"},
39 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/MeshManager.js"},
40 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/TextureManager.js"},
41 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/ShaderManager.js"},
42 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/fx/blur.js"},
43 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/fx/ssao.js"},
44 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/ScreenQuad.js"},
45 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/box.js"},
46 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/camera.js"},
47 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/shadowLight.js"},
48 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/utilities.js"},
49 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/input.js"},
50 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/engine.js"},
51 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/scenegraphNodes.js"},
52 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/scenegraph.js"},
53 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/lightmanager.js"},
54 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/rendercontext.js"},
55 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/animation.js"},
56 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/particle.js"},
57 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/run_state.js"},
58 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/init_state.js"},
59 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/runtime.js"},
60 {"type":"js", "url":"js/helper-classes/RDGE/src/core/script/util/dbgpanel.js"},
61 /* */
62
63 {"type":"js", "url":"js/helper-classes/RDGE/GLLine.js"},
64 {"type":"js", "url":"js/helper-classes/RDGE/GLMaterial.js"},
65 {"type":"js", "url":"js/helper-classes/RDGE/GLLight.js"},
66 {"type":"js", "url":"js/helper-classes/RDGE/Materials/FlatMaterial.js"},
67 {"type":"js", "url":"js/helper-classes/RDGE/Materials/BrickMaterial.js"},
68 {"type":"js", "url":"js/helper-classes/RDGE/Materials/UberMaterial.js"},
69 {"type":"js", "url":"js/helper-classes/RDGE/Materials/PlasmaMaterial.js"},
70 {"type":"js", "url":"js/helper-classes/RDGE/Materials/RadialGradientMaterial.js"},
71 {"type":"js", "url":"js/helper-classes/RDGE/Materials/RadialBlurMaterial.js"},
72 {"type":"js", "url":"js/helper-classes/RDGE/Materials/PulseMaterial.js"},
73 {"type":"js", "url":"js/helper-classes/RDGE/Materials/TunnelMaterial.js"},
74 {"type":"js", "url":"js/helper-classes/RDGE/Materials/TwistMaterial.js"},
75 {"type":"js", "url":"js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js"},
76 {"type":"js", "url":"js/helper-classes/RDGE/Materials/JuliaMaterial.js"},
77 {"type":"js", "url":"js/helper-classes/RDGE/Materials/MandelMaterial.js"},
78 {"type":"js", "url":"js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js"},
79 {"type":"js", "url":"js/helper-classes/RDGE/Materials/PlasmaMaterial.js"},
80 {"type":"js", "url":"js/helper-classes/RDGE/Materials/LinearGradientMaterial.js"},
81 {"type":"js", "url":"js/helper-classes/RDGE/Materials/BumpMetalMaterial.js"},
82 {"type":"js", "url":"js/helper-classes/RDGE/GLWorld.js"},
83 {"type":"js", "url":"js/helper-classes/RDGE/GLGeomObj.js"},
84 {"type":"js", "url":"js/helper-classes/RDGE/GLCircle.js"},
85 {"type":"js", "url":"js/helper-classes/RDGE/GLRectangle.js"},
86 {"type":"js", "url":"js/helper-classes/RDGE/GLLine.js"},
87 {"type":"js", "url":"js/helper-classes/RDGE/GLPath.js"},
88 {"type":"js", "url": "js/helper-classes/RDGE/GLAnchorPoint.js" },
89 {"type":"js", "url": "js/helper-classes/RDGE/GLSubpath.js" },
90 {"type":"js", "url": "js/helper-classes/RDGE/GLBrushStroke.js" },
91 {"type":"js", "url":"js/helper-classes/RDGE/precompiled.js"},
92 {"type":"js", "url":"js/helper-classes/RDGE/MaterialsLibrary.js"},
93 {"type":"js", "url":"js/helper-classes/3D/glUtils.js"},
94 {"type":"js", "url":"js/codemirror/mode/htmlmixed/htmlmixed.js"},
95 {"type":"js", "url":"js/codemirror/mode/xml/xml.js"},
96 {"type":"js", "url":"js/codemirror/mode/javascript/javascript.js"},
97 {"type":"js", "url":"js/codemirror/mode/css/css.js"}
98 ]
99 },
100
101 ninjaCssRequire: {
102 value:
103 [
104 {"type":"css", "url":"js/codemirror/lib/codemirror.css"},
105 {"type":"css", "url":"js/codemirror/theme/default.css"}
106 ]
107 },
108
109 filesTotal: {
110 value: 0
111 },
112
113 filesLoaded: {
114 value: 0
115 },
116
117 executionHash: {
118 value: {}
119 },
120
121 lastExecutedJsIndex: {
122 value: -1
123 },
124
125 lastExecutedCssIndex: {
126 value: -1
127 },
128
129 executionInProgress: {
130 value: false
131 },
132
133 worker: {
134 value: null
135 },
136
137 deserializedFromTemplate: {
138 value: function() {
139 console.log("Start Preloading");
140
141 this.filesTotal = this.ninjaJsRequire.length + this.ninjaCssRequire.length;
142
143 this.loadFilesWithWorker();
144 //this.loadFilesWithWorker(this.jsFiles, this.cssFiles.reverse(), this.publishLoadingStatus);
145 }
146 },
147
148 loadFilesWithWorker: {
149 value: function() {
150 this.worker = new Worker('js/preloader/PreloaderWorker.js');
151 this.worker.addEventListener("message", this, false);
152 this.worker.addEventListener("error", this, false);
153 var filesExecuted = 0;
154
155 var baseUrl = location.href;
156 if(baseUrl.charAt(baseUrl.length-1) !== "/"){
157 baseUrl = baseUrl.substring(0, (baseUrl.lastIndexOf("/")+1));
158 }
159
160// console.log("baseUrl="+baseUrl);
161 //prepare the json command
162 var startJson = {"command":"start", "jsFiles":this.ninjaJsRequire, "cssFiles":this.ninjaCssRequire.reverse(), "baseUrl":baseUrl};//will load ninjaInitJsDependencies and ninjaInitCssDependencies
163 //start the worker thread
164 this.worker.postMessage(startJson);
165 }
166 },
167
168 handleEvent: {
169 value: function(e) {
170 e.type === "message"? this.workerOnMessage(e) : this.workerOnError(e);
171 }
172 },
173
174 workerOnMessage: {
175 value: function(e) {
176 var msgJson;
177 msgJson = e.data;
178
179 switch(msgJson.command){
180 case "newFile":
181 //console.log("**worker downloaded file: "+msgJson.url);
182 this.executionHash[""+msgJson.fileType+msgJson.fileIndex]={"url":msgJson.url, "fileContent":msgJson.fileContent};
183 this.triggerExecution(msgJson.fileIndex, msgJson.fileType);
184 break;
185 case "log":
186 console.log(""+ msgJson.logMsg);
187 break;
188 case "stop":
189 this.worker.terminate();
190 break;
191 default:
192 break;
193 }
194
195 }
196 },
197
198 workerOnError: {
199 value: function(e) {
200 console.log("error from worker: "+ e.message);
201 this.worker.terminate();
202 }
203 },
204
205 triggerExecution: {
206 value: function(originIndex, fileType) {
207 var sourceURLComment = "",
208 url = "",
209 fileContent = "";
210
211 if(this.executionInProgress === false) {
212 this.executionInProgress = true;
213 while((this.executionHash != null) && (typeof this.executionHash[""+fileType+originIndex] != 'undefined')){
214 if(fileType === "js"){
215 if((originIndex -1)!== this.lastExecutedJsIndex) { //don't execute if previous file is not yet executed
216 break;
217 }
218 url = this.executionHash[""+fileType+originIndex].url;
219 fileContent = this.executionHash[""+fileType+originIndex].fileContent;
220
221 sourceURLComment = "\n//@ sourceURL="+this.extractFileName(url);
222 window.eval(""+fileContent+sourceURLComment);