mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Lots of noise removal and fixed loader processing queue.
This commit is contained in:
parent
2d90ae2b08
commit
04ecaefc48
10 changed files with 70 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'c61e8bf0-bc13-11e6-b7e8-cb3f69be926d'
|
||||
build: '3f078d90-bc1a-11e6-92af-355773f175c0'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -48,7 +48,7 @@ var CanvasPool = function ()
|
|||
|
||||
if (container === null)
|
||||
{
|
||||
console.log('CanvasPool.create new');
|
||||
// console.log('CanvasPool.create new');
|
||||
|
||||
container = {
|
||||
parent: parent,
|
||||
|
@ -62,7 +62,7 @@ var CanvasPool = function ()
|
|||
}
|
||||
else
|
||||
{
|
||||
console.log('CanvasPool.create existing');
|
||||
// console.log('CanvasPool.create existing');
|
||||
|
||||
container.parent = parent;
|
||||
|
||||
|
@ -127,7 +127,7 @@ var CanvasPool = function ()
|
|||
{
|
||||
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.canvas.width = 1;
|
||||
container.canvas.height = 1;
|
||||
|
|
|
@ -17,18 +17,18 @@ var factories = {};
|
|||
|
||||
var FactoryContainer = function ()
|
||||
{
|
||||
console.log('FactoryContainer is alive');
|
||||
// console.log('FactoryContainer is alive');
|
||||
|
||||
this.register = function (factory)
|
||||
{
|
||||
if (factories.hasOwnProperty(factory.KEY))
|
||||
{
|
||||
console.log('Already registered', factory.KEY);
|
||||
// console.log('Already registered', factory.KEY);
|
||||
|
||||
return this.getType(factory.KEY);
|
||||
}
|
||||
|
||||
console.log('registering', factory.KEY);
|
||||
// console.log('registering', factory.KEY);
|
||||
|
||||
factories[factory.KEY] = {
|
||||
add: factory.add,
|
||||
|
|
|
@ -17,8 +17,6 @@ var BaseLoader = function ()
|
|||
|
||||
this.events = new EventDispatcher();
|
||||
|
||||
this.forceImageTags = false;
|
||||
|
||||
// Move to a 'setURL' method?
|
||||
this.baseURL = '';
|
||||
this.path = '';
|
||||
|
@ -36,7 +34,6 @@ var BaseLoader = function ()
|
|||
this.inflight = new Set();
|
||||
this.failed = new Set();
|
||||
this.queue = new Set();
|
||||
|
||||
this.storage = new Set();
|
||||
|
||||
this._state = CONST.LOADER_IDLE;
|
||||
|
@ -193,7 +190,7 @@ BaseLoader.prototype = {
|
|||
|
||||
finishedLoading: function ()
|
||||
{
|
||||
console.log('BaseLoader.finishedLoading PROCESSING');
|
||||
// console.log('BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files');
|
||||
|
||||
this._state = CONST.LOADER_PROCESSING;
|
||||
|
||||
|
@ -210,10 +207,19 @@ BaseLoader.prototype = {
|
|||
},
|
||||
|
||||
processUpdate: function (file)
|
||||
{
|
||||
if (file.state === CONST.FILE_ERRORED)
|
||||
{
|
||||
this.failed.add(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
this.processComplete();
|
||||
|
@ -226,18 +232,18 @@ BaseLoader.prototype = {
|
|||
this.inflight.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.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this));
|
||||
},
|
||||
|
||||
getLoadedFiles: function ()
|
||||
{
|
||||
return this.storage.slice();
|
||||
},
|
||||
|
||||
reset: function ()
|
||||
{
|
||||
this.list.clear();
|
||||
|
|
|
@ -57,12 +57,6 @@ File.prototype = {
|
|||
// ProgressEvent
|
||||
onLoad: function (event)
|
||||
{
|
||||
console.log('image loaded');
|
||||
// console.log(event);
|
||||
// this.onStateChange(LOADING);
|
||||
|
||||
// this.process();
|
||||
|
||||
this.resetXHR();
|
||||
|
||||
this.callback(this, true);
|
||||
|
@ -70,22 +64,22 @@ File.prototype = {
|
|||
|
||||
onError: function (event)
|
||||
{
|
||||
// console.log('image error');
|
||||
// console.log(event);
|
||||
|
||||
this.resetXHR();
|
||||
|
||||
this.callback(this, false);
|
||||
},
|
||||
|
||||
onProgress: function (event)
|
||||
{
|
||||
if (event.lengthComputable)
|
||||
{
|
||||
this.bytesLoaded = event.loaded;
|
||||
this.bytesTotal = event.total;
|
||||
|
||||
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)
|
||||
|
@ -100,8 +94,6 @@ File.prototype = {
|
|||
|
||||
onComplete: function ()
|
||||
{
|
||||
console.log('File completed, ready to add to the Loader store');
|
||||
|
||||
this.state = CONST.FILE_COMPLETE;
|
||||
},
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@ var FILE_CONST = {
|
|||
FILE_LOADED: 7, // file has loaded successfully, awaiting processing
|
||||
FILE_FAILED: 8, // file failed to load
|
||||
FILE_PROCESSING: 9, // file is being processed (onProcess callback)
|
||||
FILE_COMPLETE: 10, // file has finished processing
|
||||
FILE_DESTROYED: 11 // file has been destroyed
|
||||
FILE_ERRORED: 10, // file is being processed (onProcess callback)
|
||||
FILE_COMPLETE: 11, // file has finished processing
|
||||
FILE_DESTROYED: 12 // file has been destroyed
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ ImageFile.prototype.constructor = ImageFile;
|
|||
|
||||
ImageFile.prototype.onProcess = function (callback)
|
||||
{
|
||||
console.log('ImageFile.onProcess');
|
||||
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
this.data = new Image();
|
||||
|
@ -38,11 +36,20 @@ ImageFile.prototype.onProcess = function (callback)
|
|||
|
||||
this.data.onload = function ()
|
||||
{
|
||||
window.URL.revokeObjectURL(_this.src);
|
||||
|
||||
callback(_this);
|
||||
window.URL.revokeObjectURL(_this.data.src);
|
||||
|
||||
_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);
|
||||
|
|
|
@ -10,7 +10,6 @@ var Loader = function (state)
|
|||
* @protected
|
||||
*/
|
||||
this.state = state;
|
||||
|
||||
};
|
||||
|
||||
Loader.prototype = Object.create(BaseLoader.prototype);
|
||||
|
@ -25,4 +24,23 @@ Loader.prototype.image = function (key, url)
|
|||
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;
|
||||
|
|
|
@ -29,7 +29,7 @@ Set.prototype = {
|
|||
{
|
||||
for (var i = 0; i < this.values.length; i++)
|
||||
{
|
||||
if (!callback(this.values[i]))
|
||||
if (callback(this.values[i]) === false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var CONST = require('../const');
|
||||
var IsPowerOfTwo = require('../math/IsPowerOfTwo');
|
||||
|
||||
/**
|
||||
|
@ -55,8 +56,8 @@ var TextureSource = function (texture, source)
|
|||
* @type {Number}
|
||||
* @default Phaser.scaleModes.DEFAULT;
|
||||
*/
|
||||
// this.scaleMode = Phaser.scaleModes.DEFAULT;
|
||||
this.scaleMode = Phaser.scaleModes.NEAREST;
|
||||
this.scaleMode = CONST.scaleModes.DEFAULT;
|
||||
// this.scaleMode = CONST.scaleModes.NEAREST;
|
||||
|
||||
/**
|
||||
* Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)
|
||||
|
|
Loading…
Reference in a new issue