Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix platform detection #5635

Merged
merged 8 commits into from Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions cocos2d/core/assets/CCAsset.js
Expand Up @@ -65,13 +65,13 @@ cc.Asset = cc.Class({
/**
* !#en
* Points to the true url of this asset's native object, only valid when asset is loaded and asyncLoadAsset is not enabled.
* Url equals nativeUrl on web(web-mobile, web-desktop) or native(iOS, Android etc) platform. The difference between
* nativeUrl and url is that url may points to temporary path or cached path on mini game platform which has cache mechanism (WeChat etc).
* The difference between nativeUrl and url is that the latter is final path, there is no needs to transform url by md5 and subpackage.
* Besides, url may points to temporary path or cached path on mini game platform which has cache mechanism (WeChat etc).
* If you want to make use of the native file on those platforms, you should use url instead of nativeUrl.
*
* !#zh
* 资源的原生文件的真实url,只在资源被加载后以及没有启用延迟加载时才有效。在web平台(web-mobile, web-desktop)或者原生平台(iOS,安卓等)上url与
* nativeUrl是相等的,nativeUrl与url的区别在于,某些带缓存机制的小游戏平台(微信等)上url可能会指向临时文件路径或者缓存路径,如果你需要在这些平台上使用资源的原生文件,
* 请使用url,避免使用nativeUrl
* 资源的原生文件的真实url,只在资源被加载后以及没有启用延迟加载时才有效。 nativeUrl 与 url 的区别在于,url 是资源最终路径,所以 url 不需要再经过 md5 以及子包的路径转换,
* 另外某些带缓存机制的小游戏平台(微信等)上url可能会指向临时文件路径或者缓存路径,如果你需要在这些平台上使用资源的原生文件,请使用url,避免使用nativeUrl
* @property url
* @type {String}
*/
Expand Down
40 changes: 40 additions & 0 deletions cocos2d/core/load-pipeline/pack-downloader.js
Expand Up @@ -39,6 +39,7 @@ var PackState = {
function UnpackerData () {
this.unpacker = null;
this.state = PackState.Invalid;
this.timeStamp = 0;
jareguo marked this conversation as resolved.
Show resolved Hide resolved
}

// {assetUuid: packUuid|[packUuid]}
Expand All @@ -53,12 +54,19 @@ var packIndices = {};
// We have to cache all packs in global because for now there's no operation context in loader.
var globalUnpackers = {};

var toBeChecked = {};

var timer = null;
var checkPeriod = 5000;

function error (uuid, packUuid) {
return new Error('Can not retrieve ' + uuid + ' from packer ' + packUuid);
}

module.exports = {
// two minutes
msToRelease: 2 * 60 * 1000,

initPacks: function (packs) {
packIndices = packs;
uuidToPack = {};
Expand All @@ -81,6 +89,7 @@ module.exports = {
cc.errorID(4916, uuid);
return callback(err);
}
globalUnpackers[packUuid].url = packUrl;
var res = self._doLoadNewPack(uuid, packUuid, packJson);
if (res) {
callback(null, res);
Expand Down Expand Up @@ -120,6 +129,26 @@ module.exports = {
}
unpackerData.unpacker.load(packIndices[packUuid], packedJson);
unpackerData.state = PackState.Loaded;
unpackerData.timeStamp = performance.now();
jareguo marked this conversation as resolved.
Show resolved Hide resolved
toBeChecked[packUuid] = unpackerData;
jareguo marked this conversation as resolved.
Show resolved Hide resolved
var self = this;
if (!timer) timer = setInterval(function () {
var now = performance.now();
var empty = true;
for (var packUuid in toBeChecked) {
var pack = toBeChecked[packUuid];
if (now - pack.timeStamp > self.msToRelease) {
self.remove(packUuid);
jareguo marked this conversation as resolved.
Show resolved Hide resolved
}
else {
empty = false;
}
}
if (empty) {
clearInterval(timer);
timer = null;
}
}, checkPeriod);
}

return unpackerData.unpacker.retrieve(uuid);
Expand Down Expand Up @@ -165,6 +194,8 @@ module.exports = {

var unpackerData = globalUnpackers[packUuid];
if (unpackerData && unpackerData.state === PackState.Loaded) {
// update timestamp
unpackerData.timeStamp = performance.now();
// ensure async
var json = unpackerData.unpacker.retrieve(uuid);
if (json) {
Expand All @@ -186,6 +217,15 @@ module.exports = {
}
// Return null to let caller know it's loading asynchronously
return null;
},

remove (packUuid) {
var unpackerData = globalUnpackers[packUuid];
if (unpackerData) {
cc.loader.release(unpackerData.url);
delete globalUnpackers[packUuid];
delete toBeChecked[packUuid];
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion cocos2d/core/platform/CCSys.js
Expand Up @@ -821,7 +821,8 @@ function initSys () {
osVersion = uaResult[2] || '';
osMainVersion = parseInt(osVersion) || 0;
}
else if (/(iPhone|iPad|iPod)/.exec(nav.platform)) {
// refer to https://github.com/cocos-creator/engine/pull/5542 , thanks for contribition from @krapnikkk
else if (/(iPhone|iPad|iPod|MacIntel)/.exec(nav.platform)) {
iOS = true;
osVersion = '';
osMainVersion = 0;
Expand Down