Skip to content

Commit 04ecaef

Browse files
committed
Lots of noise removal and fixed loader processing queue.
1 parent 2d90ae2 commit 04ecaef

10 files changed

Lines changed: 69 additions & 44 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'c61e8bf0-bc13-11e6-b7e8-cb3f69be926d'
2+
build: '3f078d90-bc1a-11e6-92af-355773f175c0'
33
};
44
module.exports = CHECKSUM;

v3/src/dom/CanvasPool.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var CanvasPool = function ()
4848

4949
if (container === null)
5050
{
51-
console.log('CanvasPool.create new');
51+
// console.log('CanvasPool.create new');
5252

5353
container = {
5454
parent: parent,
@@ -62,7 +62,7 @@ var CanvasPool = function ()
6262
}
6363
else
6464
{
65-
console.log('CanvasPool.create existing');
65+
// console.log('CanvasPool.create existing');
6666

6767
container.parent = parent;
6868

@@ -127,7 +127,7 @@ var CanvasPool = function ()
127127
{
128128
if ((isCanvas && container.canvas === parent) || (!isCanvas && container.parent === parent))
129129
{
130-
console.log('CanvasPool.remove found and removed');
130+
// console.log('CanvasPool.remove found and removed');
131131
container.parent = null;
132132
container.canvas.width = 1;
133133
container.canvas.height = 1;

v3/src/gameobjects/FactoryContainer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ var factories = {};
1717

1818
var FactoryContainer = function ()
1919
{
20-
console.log('FactoryContainer is alive');
20+
// console.log('FactoryContainer is alive');
2121

2222
this.register = function (factory)
2323
{
2424
if (factories.hasOwnProperty(factory.KEY))
2525
{
26-
console.log('Already registered', factory.KEY);
26+
// console.log('Already registered', factory.KEY);
2727

2828
return this.getType(factory.KEY);
2929
}
3030

31-
console.log('registering', factory.KEY);
31+
// console.log('registering', factory.KEY);
3232

3333
factories[factory.KEY] = {
3434
add: factory.add,

v3/src/loader/BaseLoader.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ var BaseLoader = function ()
1717

1818
this.events = new EventDispatcher();
1919

20-
this.forceImageTags = false;
21-
2220
// Move to a 'setURL' method?
2321
this.baseURL = '';
2422
this.path = '';
@@ -36,7 +34,6 @@ var BaseLoader = function ()
3634
this.inflight = new Set();
3735
this.failed = new Set();
3836
this.queue = new Set();
39-
4037
this.storage = new Set();
4138

4239
this._state = CONST.LOADER_IDLE;
@@ -193,7 +190,7 @@ BaseLoader.prototype = {
193190

194191
finishedLoading: function ()
195192
{
196-
console.log('BaseLoader.finishedLoading PROCESSING');
193+
// console.log('BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files');
197194

198195
this._state = CONST.LOADER_PROCESSING;
199196

@@ -211,9 +208,18 @@ BaseLoader.prototype = {
211208

212209
processUpdate: function (file)
213210
{
214-
this.storage.add(file);
211+
if (file.state === CONST.FILE_ERRORED)
212+
{
213+
this.failed.add(file);
214+
}
215+
else
216+
{
217+
this.storage.add(file);
218+
}
215219

216-
if (this.storage.size === this.queue.size && this._state === CONST.LOADER_PROCESSING)
220+
this.queue.delete(file);
221+
222+
if (this.queue.size === 0 && this._state === CONST.LOADER_PROCESSING)
217223
{
218224
// We've processed all the files we loaded
219225
this.processComplete();
@@ -226,18 +232,18 @@ BaseLoader.prototype = {
226232
this.inflight.clear();
227233
this.queue.clear();
228234

229-
console.log('Loader Process Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
235+
console.log('Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
236+
237+
if (this.processCallback)
238+
{
239+
this.processCallback();
240+
}
230241

231242
this._state = CONST.LOADER_COMPLETE;
232243

233244
this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this));
234245
},
235246

236-
getLoadedFiles: function ()
237-
{
238-
return this.storage.slice();
239-
},
240-
241247
reset: function ()
242248
{
243249
this.list.clear();

v3/src/loader/File.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,29 @@ File.prototype = {
5757
// ProgressEvent
5858
onLoad: function (event)
5959
{
60-
console.log('image loaded');
61-
// console.log(event);
62-
// this.onStateChange(LOADING);
63-
64-
// this.process();
65-
6660
this.resetXHR();
6761

6862
this.callback(this, true);
6963
},
7064

7165
onError: function (event)
7266
{
73-
// console.log('image error');
74-
// console.log(event);
75-
7667
this.resetXHR();
7768

7869
this.callback(this, false);
7970
},
8071

8172
onProgress: function (event)
8273
{
83-
this.bytesLoaded = event.loaded;
84-
this.bytesTotal = event.total;
74+
if (event.lengthComputable)
75+
{
76+
this.bytesLoaded = event.loaded;
77+
this.bytesTotal = event.total;
8578

86-
this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1);
79+
this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1);
80+
}
8781

88-
console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
82+
// console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
8983
},
9084

9185
onProcess: function (callback)
@@ -100,8 +94,6 @@ File.prototype = {
10094

10195
onComplete: function ()
10296
{
103-
console.log('File completed, ready to add to the Loader store');
104-
10597
this.state = CONST.FILE_COMPLETE;
10698
},
10799

v3/src/loader/const.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ var FILE_CONST = {
1111
FILE_LOADED: 7, // file has loaded successfully, awaiting processing
1212
FILE_FAILED: 8, // file failed to load
1313
FILE_PROCESSING: 9, // file is being processed (onProcess callback)
14-
FILE_COMPLETE: 10, // file has finished processing
15-
FILE_DESTROYED: 11 // file has been destroyed
14+
FILE_ERRORED: 10, // file is being processed (onProcess callback)
15+
FILE_COMPLETE: 11, // file has finished processing
16+
FILE_DESTROYED: 12 // file has been destroyed
1617

1718
};
1819

v3/src/loader/filetypes/ImageFile.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ ImageFile.prototype.constructor = ImageFile;
2828

2929
ImageFile.prototype.onProcess = function (callback)
3030
{
31-
console.log('ImageFile.onProcess');
32-
3331
this.state = CONST.FILE_PROCESSING;
3432

3533
this.data = new Image();
@@ -38,11 +36,20 @@ ImageFile.prototype.onProcess = function (callback)
3836

3937
this.data.onload = function ()
4038
{
41-
window.URL.revokeObjectURL(_this.src);
39+
window.URL.revokeObjectURL(_this.data.src);
40+
41+
_this.onComplete();
4242

4343
callback(_this);
44+
};
4445

45-
_this.onComplete();
46+
this.data.onerror = function ()
47+
{
48+
window.URL.revokeObjectURL(_this.data.src);
49+
50+
_this.state = CONST.FILE_ERRORED;
51+
52+
callback(_this);
4653
};
4754

4855
this.data.src = window.URL.createObjectURL(this.xhrLoader.response);

v3/src/state/systems/Loader.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var Loader = function (state)
1010
* @protected
1111
*/
1212
this.state = state;
13-
1413
};
1514

1615
Loader.prototype = Object.create(BaseLoader.prototype);
@@ -25,4 +24,23 @@ Loader.prototype.image = function (key, url)
2524
return this;
2625
};
2726

27+
Loader.prototype.processCallback = function ()
28+
{
29+
// All of the files have loaded. Now to put them into the Cache.
30+
31+
if (this.storage.size > 0)
32+
{
33+
var textures = this.state.sys.textures;
34+
35+
this.storage.each(function (file)
36+
{
37+
if (file.type === 'image')
38+
{
39+
textures.addImage(file.key, file.data);
40+
}
41+
});
42+
}
43+
44+
};
45+
2846
module.exports = Loader;

v3/src/structs/Set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Set.prototype = {
2929
{
3030
for (var i = 0; i < this.values.length; i++)
3131
{
32-
if (!callback(this.values[i]))
32+
if (callback(this.values[i]) === false)
3333
{
3434
break;
3535
}

v3/src/textures/TextureSource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
var CONST = require('../const');
78
var IsPowerOfTwo = require('../math/IsPowerOfTwo');
89

910
/**
@@ -55,8 +56,8 @@ var TextureSource = function (texture, source)
5556
* @type {Number}
5657
* @default Phaser.scaleModes.DEFAULT;
5758
*/
58-
// this.scaleMode = Phaser.scaleModes.DEFAULT;
59-
this.scaleMode = Phaser.scaleModes.NEAREST;
59+
this.scaleMode = CONST.scaleModes.DEFAULT;
60+
// this.scaleMode = CONST.scaleModes.NEAREST;
6061

6162
/**
6263
* Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)

0 commit comments

Comments
 (0)