Lots of noise removal and fixed loader processing queue.

This commit is contained in:
Richard Davey 2016-12-07 01:13:17 +00:00
parent 2d90ae2b08
commit 04ecaefc48
10 changed files with 70 additions and 45 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: 'c61e8bf0-bc13-11e6-b7e8-cb3f69be926d' build: '3f078d90-bc1a-11e6-92af-355773f175c0'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -48,7 +48,7 @@ var CanvasPool = function ()
if (container === null) if (container === null)
{ {
console.log('CanvasPool.create new'); // console.log('CanvasPool.create new');
container = { container = {
parent: parent, parent: parent,
@ -62,7 +62,7 @@ var CanvasPool = function ()
} }
else else
{ {
console.log('CanvasPool.create existing'); // console.log('CanvasPool.create existing');
container.parent = parent; container.parent = parent;
@ -127,7 +127,7 @@ var CanvasPool = function ()
{ {
if ((isCanvas && container.canvas === parent) || (!isCanvas && container.parent === parent)) if ((isCanvas && container.canvas === parent) || (!isCanvas && container.parent === parent))
{ {
console.log('CanvasPool.remove found and removed'); // console.log('CanvasPool.remove found and removed');
container.parent = null; container.parent = null;
container.canvas.width = 1; container.canvas.width = 1;
container.canvas.height = 1; container.canvas.height = 1;

View file

@ -17,18 +17,18 @@ var factories = {};
var FactoryContainer = function () var FactoryContainer = function ()
{ {
console.log('FactoryContainer is alive'); // console.log('FactoryContainer is alive');
this.register = function (factory) this.register = function (factory)
{ {
if (factories.hasOwnProperty(factory.KEY)) if (factories.hasOwnProperty(factory.KEY))
{ {
console.log('Already registered', factory.KEY); // console.log('Already registered', factory.KEY);
return this.getType(factory.KEY); return this.getType(factory.KEY);
} }
console.log('registering', factory.KEY); // console.log('registering', factory.KEY);
factories[factory.KEY] = { factories[factory.KEY] = {
add: factory.add, add: factory.add,

View file

@ -17,8 +17,6 @@ var BaseLoader = function ()
this.events = new EventDispatcher(); this.events = new EventDispatcher();
this.forceImageTags = false;
// Move to a 'setURL' method? // Move to a 'setURL' method?
this.baseURL = ''; this.baseURL = '';
this.path = ''; this.path = '';
@ -36,7 +34,6 @@ var BaseLoader = function ()
this.inflight = new Set(); this.inflight = new Set();
this.failed = new Set(); this.failed = new Set();
this.queue = new Set(); this.queue = new Set();
this.storage = new Set(); this.storage = new Set();
this._state = CONST.LOADER_IDLE; this._state = CONST.LOADER_IDLE;
@ -193,7 +190,7 @@ BaseLoader.prototype = {
finishedLoading: function () finishedLoading: function ()
{ {
console.log('BaseLoader.finishedLoading PROCESSING'); // console.log('BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files');
this._state = CONST.LOADER_PROCESSING; this._state = CONST.LOADER_PROCESSING;
@ -210,10 +207,19 @@ BaseLoader.prototype = {
}, },
processUpdate: function (file) processUpdate: function (file)
{
if (file.state === CONST.FILE_ERRORED)
{
this.failed.add(file);
}
else
{ {
this.storage.add(file); this.storage.add(file);
}
if (this.storage.size === this.queue.size && this._state === CONST.LOADER_PROCESSING) this.queue.delete(file);
if (this.queue.size === 0 && this._state === CONST.LOADER_PROCESSING)
{ {
// We've processed all the files we loaded // We've processed all the files we loaded
this.processComplete(); this.processComplete();
@ -226,18 +232,18 @@ BaseLoader.prototype = {
this.inflight.clear(); this.inflight.clear();
this.queue.clear(); this.queue.clear();
console.log('Loader Process Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size); console.log('Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
if (this.processCallback)
{
this.processCallback();
}
this._state = CONST.LOADER_COMPLETE; this._state = CONST.LOADER_COMPLETE;
this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this)); this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this));
}, },
getLoadedFiles: function ()
{
return this.storage.slice();
},
reset: function () reset: function ()
{ {
this.list.clear(); this.list.clear();

View file

@ -57,12 +57,6 @@ File.prototype = {
// ProgressEvent // ProgressEvent
onLoad: function (event) onLoad: function (event)
{ {
console.log('image loaded');
// console.log(event);
// this.onStateChange(LOADING);
// this.process();
this.resetXHR(); this.resetXHR();
this.callback(this, true); this.callback(this, true);
@ -70,22 +64,22 @@ File.prototype = {
onError: function (event) onError: function (event)
{ {
// console.log('image error');
// console.log(event);
this.resetXHR(); this.resetXHR();
this.callback(this, false); this.callback(this, false);
}, },
onProgress: function (event) onProgress: function (event)
{
if (event.lengthComputable)
{ {
this.bytesLoaded = event.loaded; this.bytesLoaded = event.loaded;
this.bytesTotal = event.total; this.bytesTotal = event.total;
this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1); this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1);
}
console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)'); // console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)');
}, },
onProcess: function (callback) onProcess: function (callback)
@ -100,8 +94,6 @@ File.prototype = {
onComplete: function () onComplete: function ()
{ {
console.log('File completed, ready to add to the Loader store');
this.state = CONST.FILE_COMPLETE; this.state = CONST.FILE_COMPLETE;
}, },

View file

@ -11,8 +11,9 @@ var FILE_CONST = {
FILE_LOADED: 7, // file has loaded successfully, awaiting processing FILE_LOADED: 7, // file has loaded successfully, awaiting processing
FILE_FAILED: 8, // file failed to load FILE_FAILED: 8, // file failed to load
FILE_PROCESSING: 9, // file is being processed (onProcess callback) FILE_PROCESSING: 9, // file is being processed (onProcess callback)
FILE_COMPLETE: 10, // file has finished processing FILE_ERRORED: 10, // file is being processed (onProcess callback)
FILE_DESTROYED: 11 // file has been destroyed FILE_COMPLETE: 11, // file has finished processing
FILE_DESTROYED: 12 // file has been destroyed
}; };

View file

@ -28,8 +28,6 @@ ImageFile.prototype.constructor = ImageFile;
ImageFile.prototype.onProcess = function (callback) ImageFile.prototype.onProcess = function (callback)
{ {
console.log('ImageFile.onProcess');
this.state = CONST.FILE_PROCESSING; this.state = CONST.FILE_PROCESSING;
this.data = new Image(); this.data = new Image();
@ -38,11 +36,20 @@ ImageFile.prototype.onProcess = function (callback)
this.data.onload = function () this.data.onload = function ()
{ {
window.URL.revokeObjectURL(_this.src); window.URL.revokeObjectURL(_this.data.src);
callback(_this);
_this.onComplete(); _this.onComplete();
callback(_this);
};
this.data.onerror = function ()
{
window.URL.revokeObjectURL(_this.data.src);
_this.state = CONST.FILE_ERRORED;
callback(_this);
}; };
this.data.src = window.URL.createObjectURL(this.xhrLoader.response); this.data.src = window.URL.createObjectURL(this.xhrLoader.response);

View file

@ -10,7 +10,6 @@ var Loader = function (state)
* @protected * @protected
*/ */
this.state = state; this.state = state;
}; };
Loader.prototype = Object.create(BaseLoader.prototype); Loader.prototype = Object.create(BaseLoader.prototype);
@ -25,4 +24,23 @@ Loader.prototype.image = function (key, url)
return this; return this;
}; };
Loader.prototype.processCallback = function ()
{
// All of the files have loaded. Now to put them into the Cache.
if (this.storage.size > 0)
{
var textures = this.state.sys.textures;
this.storage.each(function (file)
{
if (file.type === 'image')
{
textures.addImage(file.key, file.data);
}
});
}
};
module.exports = Loader; module.exports = Loader;

View file

@ -29,7 +29,7 @@ Set.prototype = {
{ {
for (var i = 0; i < this.values.length; i++) for (var i = 0; i < this.values.length; i++)
{ {
if (!callback(this.values[i])) if (callback(this.values[i]) === false)
{ {
break; break;
} }

View file

@ -4,6 +4,7 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/ */
var CONST = require('../const');
var IsPowerOfTwo = require('../math/IsPowerOfTwo'); var IsPowerOfTwo = require('../math/IsPowerOfTwo');
/** /**
@ -55,8 +56,8 @@ var TextureSource = function (texture, source)
* @type {Number} * @type {Number}
* @default Phaser.scaleModes.DEFAULT; * @default Phaser.scaleModes.DEFAULT;
*/ */
// this.scaleMode = Phaser.scaleModes.DEFAULT; this.scaleMode = CONST.scaleModes.DEFAULT;
this.scaleMode = Phaser.scaleModes.NEAREST; // this.scaleMode = CONST.scaleModes.NEAREST;
/** /**
* Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)