Skip to content

Issue fixes and improvements #3271

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

Merged
merged 5 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 70 additions & 17 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ cc.loader = (function () {
_register = {}, //register of loaders
_langPathCache = {}, //cache for lang path
_aliases = {}, //aliases for res url
_queue = {}, // Callback queue for resources already loading
_urlRegExp = new RegExp(
"^" +
// protocol identifier
Expand Down Expand Up @@ -668,6 +669,10 @@ cc.loader = (function () {
return results;
},

isLoading: function (url) {
return (_queue[url] !== undefined);
},

/**
* Load js files.
* If the third parameter doesn't exist, then the baseDir turns to be "".
Expand Down Expand Up @@ -890,6 +895,12 @@ cc.loader = (function () {
return img;
}

var queue = _queue[url];
if (queue) {
queue.callbacks.push(callback);
return queue.img;
}

img = new Image();
if (opt.isCrossOrigin && location.origin !== "file://")
img.crossOrigin = "Anonymous";
Expand All @@ -898,24 +909,53 @@ cc.loader = (function () {
this.removeEventListener('load', loadCallback, false);
this.removeEventListener('error', errorCallback, false);

cc.loader.cache[url] = img;
if (callback)
callback(null, img);
if (!_urlRegExp.test(url)) {
cc.loader.cache[url] = img;
}

var queue = _queue[url];
if (queue) {
callbacks = queue.callbacks;
for (var i = 0; i < callbacks.length; ++i) {
var callback = callbacks[i];
if (callback) {
callback(null, img);
}
}
queue.img = null;
delete _queue[url];
}
};

var self = this;
var errorCallback = function () {
this.removeEventListener('error', errorCallback, false);

if(img.crossOrigin && img.crossOrigin.toLowerCase() === "anonymous"){
if (img.crossOrigin && img.crossOrigin.toLowerCase() === "anonymous") {
opt.isCrossOrigin = false;
self.release(url);
cc.loader.loadImg(url, opt, callback);
}else{
typeof callback === "function" && callback("load image failed");
} else {
var queue = _queue[url];
if (queue) {
callbacks = queue.callbacks;
for (var i = 0; i < callbacks.length; ++i) {
var callback = callbacks[i];
if (callback) {
callback("load image failed");
}
}
queue.img = null;
delete _queue[url];
}
}
};

_queue[url] = {
img: img,
callbacks: callback ? [callback] : []
};

img.addEventListener("load", loadCallback);
img.addEventListener("error", errorCallback);
img.src = url;
Expand Down Expand Up @@ -1803,25 +1843,38 @@ var _initSys = function () {

var _supportCanvas = !!_tmpCanvas1.getContext("2d");
var _supportWebGL = false;
var tmpCanvas = document.createElement("CANVAS");
if (win.WebGLRenderingContext) {
var tmpCanvas = document.createElement("CANVAS");
try{
var context = cc.create3DContext(tmpCanvas, {'stencil': true, 'preserveDrawingBuffer': true });
if(context) {
_supportWebGL = true;
}

// Accept only Android 5+ default browser and QQ Browser 6.2+
if (_supportWebGL && sys.os === sys.OS_ANDROID) {
_supportWebGL = false;
// QQ Brwoser 6.2+
var browserVer = parseFloat(sys.browserVersion);
if (sys.browserType === sys.BROWSER_TYPE_MOBILE_QQ && browserVer >= 6.2) {
_supportWebGL = true;
}
// Android 5+ default browser
else if (sys.osMainVersion && sys.osMainVersion >= 5 && sys.browserType === sys.BROWSER_TYPE_ANDROID) {
_supportWebGL = true;
switch (sys.browserType) {
case sys.BROWSER_TYPE_MOBILE_QQ:
case sys.BROWSER_TYPE_BAIDU:
case sys.BROWSER_TYPE_BAIDU_APP:
// QQ & Baidu Brwoser 6.2+ (using blink kernel)
var browserVer = parseFloat(sys.browserVersion);
if (browserVer >= 6.2) {
_supportWebGL = true;
}
else {
_supportWebGL = false;
}
break;
case sys.BROWSER_TYPE_ANDROID:
// Android 5+ default browser
if (sys.osMainVersion && sys.osMainVersion >= 5) {
_supportWebGL = true;
}
break;
case sys.BROWSER_TYPE_UNKNOWN:
case sys.BROWSER_TYPE_360:
case sys.BROWSER_TYPE_MIUI:
_supportWebGL = false;
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions cocos2d/core/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
cc.eventManager.dispatchEvent(this._eventAfterUpdate);
}

renderer.clear();

/* to avoid flickr, nextScene MUST be here: after tick and before draw.
XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
if (this._nextScene) {
Expand All @@ -230,15 +228,25 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
this._beforeVisitScene();

// draw the scene
var skipRendering = false;
if (this._runningScene) {
if (renderer.childrenOrderDirty === true) {
cc.renderer.clearRenderCommands();
cc.renderer.assignedZ = 0;
this._runningScene._renderCmd._curLevel = 0; //level start from 0;
this._runningScene.visit();
renderer.resetFlag();
} else if (renderer.transformDirty() === true)
}
else if (renderer.transformDirty() === true) {
renderer.transform();
}
else {
skipRendering = true;
}
}

if (!skipRendering) {
renderer.clear();
}

// draw the notifications node
Expand All @@ -251,7 +259,9 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
if (this._afterVisitScene)
this._afterVisitScene();

renderer.rendering(cc._renderContext);
if (!skipRendering) {
renderer.rendering(cc._renderContext);
}
this._totalFrames++;

cc.eventManager.dispatchEvent(this._eventAfterDraw);
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCEGLView.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ cc.ContainerStrategy = cc.Class.extend(/** @lends cc.ContainerStrategy# */{
// Setup pixel ratio for retina display
var devicePixelRatio = view._devicePixelRatio = 1;
if (view.isRetinaEnabled())
devicePixelRatio = view._devicePixelRatio = window.devicePixelRatio || 1;
devicePixelRatio = view._devicePixelRatio = Math.min(2, window.devicePixelRatio || 1);
// Setup canvas
locCanvasElement.width = w * devicePixelRatio;
locCanvasElement.height = h * devicePixelRatio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
this._cacheScale9Sprite();
this._dirtyFlag = this._dirtyFlag & flags.cacheDirty ^ this._dirtyFlag;
}
}
};

proto._cacheScale9Sprite = function() {
var node = this._node;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ccui/base-classes/UIWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{
this._positionPercent = cc.p(0, 0);
this._nodes = [];
this._layoutParameterType = ccui.LayoutParameter.NONE;
this.init(); //TODO
ccui.Widget.prototype.init.call(this);
},

/**
Expand Down
31 changes: 3 additions & 28 deletions extensions/ccui/layouts/UIHBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,12 @@ ccui.HBox = ccui.Layout.extend(/** @lends ccui.HBox# */{
* @param {cc.Size} [size]
*/
ctor: function(size){
ccui.Layout.prototype.ctor.call(this, size);
if(size !== undefined)
this.initWithSize(size);
else
this.init();
},
ccui.Layout.prototype.ctor.call(this);
this.setLayoutType(ccui.Layout.LINEAR_HORIZONTAL);

/**
* Initialize a HBox. please do not call this function by yourself, you should pass the parameters to constructor to initialize it.
* @override
* @returns {boolean}
*/
init: function(){
if(ccui.Layout.prototype.init.call(this)){
this.setLayoutType(ccui.Layout.LINEAR_HORIZONTAL);
return true;
}
return false;
},

/**
* Initializes a HBox with size.
* @param size
* @returns {boolean}
*/
initWithSize: function(size){
if(this.init()){
if(size) {
this.setContentSize(size);
return true;
}
return false;
}
});

Expand Down
34 changes: 11 additions & 23 deletions extensions/ccui/layouts/UILayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
ctor: function () {
this._layoutType = ccui.Layout.ABSOLUTE;
this._widgetType = ccui.Widget.TYPE_CONTAINER;
this._clippingType = ccui.Layout.CLIPPING_STENCIL;
this._clippingType = ccui.Layout.CLIPPING_SCISSOR;
this._colorType = ccui.Layout.BG_COLOR_NONE;

ccui.Widget.prototype.ctor.call(this);

this.ignoreContentAdaptWithSize(false);
this.setContentSize(cc.size(0, 0));
this.setAnchorPoint(0, 0);
this.onPassFocusToChild = this._findNearestChildWidgetIndex.bind(this);

this._backGroundImageCapInsets = cc.rect(0, 0, 0, 0);

this._color = cc.color(255, 255, 255, 255);
Expand Down Expand Up @@ -236,22 +242,6 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
*/
onPassFocusToChild: null,

/**
* override "init" method of widget. please do not call this function by yourself, you should pass the parameters to constructor to initialize it.
* @returns {boolean}
* @override
*/
init: function () {
if (ccui.Widget.prototype.init.call(this)) {
this.ignoreContentAdaptWithSize(false);
this.setContentSize(cc.size(0, 0));
this.setAnchorPoint(0, 0);
this.onPassFocusToChild = this._findNearestChildWidgetIndex.bind(this);
return true;
}
return false;
},

/**
* Adds a widget to the container.
* @param {ccui.Widget} widget
Expand Down Expand Up @@ -330,8 +320,9 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
default:
break;
}
} else
} else {
ccui.Widget.prototype.visit.call(this, parentCmd);
}
},

/**
Expand All @@ -344,6 +335,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
return;
this._clippingEnabled = able;
switch (this._clippingType) {
case ccui.Layout.CLIPPING_SCISSOR:
case ccui.Layout.CLIPPING_STENCIL:
if (able){
this._clippingStencil = new cc.DrawNode();
Expand All @@ -369,10 +361,6 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
setClippingType: function (type) {
if (type === this._clippingType)
return;
if(cc._renderType === cc.game.RENDER_TYPE_CANVAS && type === ccui.Layout.CLIPPING_SCISSOR){
cc.log("Only supports STENCIL on canvas mode.");
return;
}
var clippingEnabled = this.isClippingEnabled();
this.setClippingEnabled(false);
this._clippingType = type;
Expand All @@ -388,7 +376,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
},

_setStencilClippingSize: function (size) {
if (this._clippingEnabled && this._clippingType === ccui.Layout.CLIPPING_STENCIL) {
if (this._clippingEnabled) {
var rect = [];
rect[0] = cc.p(0, 0);
rect[1] = cc.p(size.width, 0);
Expand Down
7 changes: 4 additions & 3 deletions extensions/ccui/layouts/UILayoutCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
default:
break;
}
} else
} else {
ccui.Widget.CanvasRenderCmd.prototype.visit.call(this, parentCmd);
}
};

proto._onRenderSaveCmd = function(ctx, scaleX, scaleY){
Expand Down Expand Up @@ -103,7 +104,7 @@
context.globalCompositeOperation = "destination-over";
context.drawImage(this._locCache, 0, 0);
context.restore();
}else{
} else {
wrapper.restore(); //use for restore clip operation
}
};
Expand All @@ -126,7 +127,7 @@
}
};

proto.stencilClippingVisit = proto.scissorClippingVisit = function(parentCmd){
proto.stencilClippingVisit = proto.scissorClippingVisit = function (parentCmd) {
var node = this._node;
if (!node._clippingStencil || !node._clippingStencil.isVisible())
return;
Expand Down
Loading