Skip to content

Commit 430a321

Browse files
author
David DeSimone
committed
Merge branch 'develop' into program-state
# Conflicts: # cocos2d/core/layers/CCLayerWebGLRenderCmd.js
2 parents 2c13088 + 440f792 commit 430a321

23 files changed

+643
-824
lines changed

CCBoot.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ cc.loader = (function () {
623623
getXMLHttpRequest: function () {
624624
var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
625625
xhr.timeout = 10000;
626+
if (xhr.ontimeout === undefined) {
627+
xhr._timeoutId = -1;
628+
}
626629
return xhr;
627630
},
628631

@@ -770,12 +773,24 @@ cc.loader = (function () {
770773
} else {
771774
if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8");
772775
xhr.onload = function () {
773-
if (xhr.readyState === 4)
776+
if (xhr._timeoutId >= 0) {
777+
clearTimeout(xhr._timeoutId);
778+
}
779+
if (xhr.readyState === 4) {
774780
xhr.status === 200 ? cb(null, xhr.responseText) : cb({status:xhr.status, errorMessage:errInfo}, null);
781+
}
775782
};
776-
xhr.onerror = xhr.ontimeout = function () {
783+
xhr.onerror = function () {
777784
cb({status: xhr.status, errorMessage: errInfo}, null);
778785
};
786+
if (xhr.ontimeout === undefined) {
787+
xhr._timeoutId = setTimeout(function () {
788+
xhr.ontimeout();
789+
}, xhr.timeout);
790+
}
791+
xhr.ontimeout = function () {
792+
cb({status: xhr.status, errorMessage: "Request timeout: " + errInfo}, null);
793+
};
779794
}
780795
xhr.send(null);
781796
} else {
@@ -787,22 +802,34 @@ cc.loader = (function () {
787802
},
788803

789804
loadCsb: function(url, cb){
790-
var xhr = new XMLHttpRequest(),
805+
var xhr = cc.loader.getXMLHttpRequest(),
791806
errInfo = "load " + url + " failed!";
792807
xhr.open("GET", url, true);
793808
xhr.responseType = "arraybuffer";
794809

795810
xhr.onload = function () {
811+
if (xhr._timeoutId >= 0) {
812+
clearTimeout(xhr._timeoutId);
813+
}
796814
var arrayBuffer = xhr.response; // Note: not oReq.responseText
797815
if (arrayBuffer) {
798816
window.msg = arrayBuffer;
799817
}
800-
if(xhr.readyState === 4)
818+
if (xhr.readyState === 4) {
801819
xhr.status === 200 ? cb(null, xhr.response) : cb({status:xhr.status, errorMessage:errInfo}, null);
820+
}
802821
};
803-
xhr.onerror = xhr.ontimeout = function(){
822+
xhr.onerror = function(){
804823
cb({status:xhr.status, errorMessage:errInfo}, null);
805824
};
825+
if (xhr.ontimeout === undefined) {
826+
xhr._timeoutId = setTimeout(function () {
827+
xhr.ontimeout();
828+
}, xhr.timeout);
829+
}
830+
xhr.ontimeout = function () {
831+
cb({status: xhr.status, errorMessage: "Request timeout: " + errInfo}, null);
832+
};
806833
xhr.send(null);
807834
},
808835

@@ -2650,8 +2677,7 @@ cc.game = /** @lends cc.game# */{
26502677
this._renderContext = cc._renderContext = cc.webglContext
26512678
= cc.create3DContext(localCanvas, {
26522679
'stencil': true,
2653-
'alpha': false,
2654-
'preserveDrawingBuffer': false
2680+
'alpha': false
26552681
});
26562682
}
26572683
// WebGL context created successfully

CCDebugger.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ cc._LogInfos = {
6868
Node_resumeSchedulerAndActions: "resumeSchedulerAndActions is deprecated, please use resume instead.",
6969
Node_pauseSchedulerAndActions: "pauseSchedulerAndActions is deprecated, please use pause instead.",
7070
Node__arrayMakeObjectsPerformSelector: "Unknown callback function",
71-
Node_reorderChild: "child must be non-null",
71+
Node_reorderChild: "cc.Node.reorderChild(): child must be non-null",
72+
Node_reorderChild_2: "cc.Node.reorderChild(): this child is not in children list",
7273
Node_runAction: "cc.Node.runAction(): action must be non-null",
7374
Node_schedule: "callback function must be non-null",
7475
Node_schedule_2: "interval must be positive",
@@ -119,7 +120,6 @@ cc._LogInfos = {
119120
animationCache__parseVersion2_2: "cocos2d: cc.AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the cc.SpriteFrameCache. This frame will not be added to the animation.",
120121
animationCache_addAnimations_2: "cc.AnimationCache.addAnimations(): Invalid texture file name",
121122

122-
Sprite_reorderChild: "cc.Sprite.reorderChild(): this child is not in children list",
123123
Sprite_ignoreAnchorPointForPosition: "cc.Sprite.ignoreAnchorPointForPosition(): it is invalid in cc.Sprite when using SpriteBatchNode",
124124
Sprite_setDisplayFrameWithAnimationName: "cc.Sprite.setDisplayFrameWithAnimationName(): Frame not found",
125125
Sprite_setDisplayFrameWithAnimationName_2: "cc.Sprite.setDisplayFrameWithAnimationName(): Invalid frame index",
@@ -130,7 +130,6 @@ cc._LogInfos = {
130130
Sprite_initWithSpriteFrameName1: " is null, please check.",
131131
Sprite_initWithFile: "cc.Sprite.initWithFile(): filename should be non-null",
132132
Sprite_setDisplayFrameWithAnimationName_3: "cc.Sprite.setDisplayFrameWithAnimationName(): animationName must be non-null",
133-
Sprite_reorderChild_2: "cc.Sprite.reorderChild(): child should be non-null",
134133
Sprite_addChild: "cc.Sprite.addChild(): cc.Sprite only supports cc.Sprites as children when using cc.SpriteBatchNode",
135134
Sprite_addChild_2: "cc.Sprite.addChild(): cc.Sprite only supports a sprite using same texture as children when using cc.SpriteBatchNode",
136135
Sprite_addChild_3: "cc.Sprite.addChild(): child should be non-null",

cocos2d/audio/CCAudio.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,15 @@ cc.Audio.WebAudio.prototype = {
359359
loadBuffer: function (url, cb) {
360360
if (!SWA) return; // WebAudio Buffer
361361

362-
var request = new XMLHttpRequest();
362+
var request = cc.loader.getXMLHttpRequest();
363363
request.open("GET", url, true);
364364
request.responseType = "arraybuffer";
365365

366366
// Our asynchronous callback
367367
request.onload = function () {
368+
if (request._timeoutId >= 0) {
369+
clearTimeout(request._timeoutId);
370+
}
368371
context["decodeAudioData"](request.response, function (buffer) {
369372
//success
370373
cb(null, buffer);
@@ -378,6 +381,11 @@ cc.Audio.WebAudio.prototype = {
378381
request.onerror = function () {
379382
cb('request error - ' + url);
380383
};
384+
if (request.ontimeout === undefined) {
385+
request._timeoutId = setTimeout(function () {
386+
request.ontimeout();
387+
}, request.timeout);
388+
}
381389
request.ontimeout = function () {
382390
cb('request timeout - ' + url);
383391
};

cocos2d/core/CCDirectorWebGL.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
160160
cc.eventManager.setEnabled(true);
161161
};
162162

163-
_p._clear = function () {
164-
var gl = cc._renderContext;
165-
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
166-
};
167-
168163
_p.getVisibleSize = function () {
169164
//if (this._openGLView) {
170165
return this._openGLView.getVisibleSize();

cocos2d/core/base-nodes/CCNode.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,13 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
13601360
*/
13611361
reorderChild: function (child, zOrder) {
13621362
cc.assert(child, cc._LogInfos.Node_reorderChild);
1363+
if (this._children.indexOf(child) === -1) {
1364+
cc.log(cc._LogInfos.Node_reorderChild_2);
1365+
return;
1366+
}
1367+
if (zOrder === child.zIndex) {
1368+
return;
1369+
}
13631370
cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
13641371
child.arrivalOrder = cc.s_globalOrderOfArrival;
13651372
cc.s_globalOrderOfArrival++;

cocos2d/core/labelttf/CCLabelTTF.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
133133
this._renderCmd._setFontStyle(this._fontName, fontSize, this._fontStyle, this._fontWeight);
134134
this.string = strInfo;
135135
this._renderCmd._setColorsString();
136-
if (this._string) {
137-
this._renderCmd._updateTexture();
138-
}
136+
this._renderCmd._updateTexture();
139137
this._setUpdateTextureDirty();
140138

141139
// Needed for high dpi text.

cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
402402
proto._updateTexture = function () {
403403
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
404404
var node = this._node;
405+
node._needUpdateTexture = false;
405406
var locContentSize = node._contentSize;
406407
this._updateTTF();
407408
var width = locContentSize.width, height = locContentSize.height;

cocos2d/core/layers/CCLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
7474
return this._renderCmd._isBaked;
7575
},
7676

77-
visit: function () {
77+
visit: function (parent) {
7878
// quick return if not visible
7979
if (!this._visible)
8080
return;

cocos2d/core/layers/CCLayerCanvasRenderCmd.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@
275275
for (i = 0; i < len; i++) {
276276
child = children[i];
277277
if (child._localZOrder < 0)
278-
child._renderCmd.visit(this);
278+
child.visit(node);
279279
else
280280
break;
281281
}
282282
cc.renderer.pushRenderCommand(this);
283283
for (; i < len; i++) {
284-
children[i]._renderCmd.visit(this);
284+
children[i].visit(node);
285285
}
286286
} else
287287
cc.renderer.pushRenderCommand(this);

0 commit comments

Comments
 (0)