Merge pull request #1324 from VisualSJ/master-loaderCache

Using URL cache(loader)
This commit is contained in:
Wang Nan
2016-12-09 09:43:03 +08:00
committed by GitHub
4 changed files with 24 additions and 10 deletions
+7 -7
View File
@@ -42,7 +42,7 @@ else {
function downloadScript (item, callback, isAsync) {
var url = item.url,
d = document,
d = document,
s = document.createElement('script');
s.async = isAsync;
s.src = urlAppendTimestamp(url);
@@ -129,8 +129,8 @@ var FONT_TYPE = {
'.svg' : 'svg'
};
function _loadFont (name, srcs, type){
var doc = document,
path = cc.path,
var doc = document,
path = cc.path,
fontStyle = document.createElement('style');
fontStyle.type = 'text/css';
doc.body.appendChild(fontStyle);
@@ -167,8 +167,8 @@ function _loadFont (name, srcs, type){
}
function downloadFont (item, callback) {
var url = item.url,
type = item.type,
name = item.name,
type = item.type,
name = item.name,
srcs = item.srcs;
if (name && srcs) {
if (srcs.indexOf(url) === -1) {
@@ -194,7 +194,7 @@ function downloadFont (item, callback) {
var reusedArray = [];
function downloadUuid (item, callback) {
var uuid = item.id;
var uuid = item.uuid;
var self = this;
cc.AssetLibrary.queryAssetInfo(uuid, function (error, url, isRawAsset) {
if (error) {
@@ -308,7 +308,7 @@ var ID = 'Downloader';
* // This will match all url with `.scene` extension or all url with `scene` type
* 'scene' : function (url, callback) {}
* });
*
*
* @method Downloader
* @param {Object} extMap Custom supported types with corresponded handler
*/
+1 -1
View File
@@ -52,7 +52,7 @@ function createItem (id, queueId) {
}
result = {
queueId: queueId,
url: id.url || id.id,
url: id.url,
error: null,
content: null,
complete: false,
+7 -2
View File
@@ -72,7 +72,7 @@ function syncFlow (item) {
var pipeId = this.id;
var itemState = item.states[pipeId];
var next = this.next;
if (item.error || itemState === ItemState.WORKING || itemState === ItemState.ERROR) {
return;
}
@@ -252,6 +252,10 @@ JS.mixin(Pipeline.prototype, {
if (pipe) {
for (i = 0; i < items.length; i++) {
item = items[i];
var url = cc.AssetLibrary._getAssetUrl(item.uuid);
if (url && !item.url) {
item.id = item.url = url;
}
this._cache[item.id] = item;
pipe.flowIn(item);
}
@@ -364,6 +368,7 @@ JS.mixin(Pipeline.prototype, {
if (!item)
return item;
// downloader.js downloadUuid
if (item.alias)
item = this._cache[item.alias];
@@ -409,4 +414,4 @@ JS.mixin(Pipeline.prototype, {
}
});
cc.Pipeline = module.exports = Pipeline;
cc.Pipeline = module.exports = Pipeline;
+9
View File
@@ -73,6 +73,7 @@ var AssetLibrary = {
// var writeMainCache = typeof (options && options.writeMainCache) !== 'undefined' ? writeMainCache : true;
var item = {
id: uuid,
uuid: uuid,
type: 'uuid'
};
if (options && options.existingAsset) {
@@ -143,6 +144,14 @@ var AssetLibrary = {
}
},
_getAssetUrl: function (uuid) {
var info = _uuidToRawAsset[uuid];
if (info) {
return _rawAssetsBase + info.url;
}
return null;
},
/**
* @method queryAssetInfo
* @param {String} uuid