Skip to content

Commit 35d19b7

Browse files
author
pandamicro
committed
A set of small improvements
1 parent a6dd034 commit 35d19b7

File tree

15 files changed

+65
-162
lines changed

15 files changed

+65
-162
lines changed

CCBoot.js

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -594,37 +594,7 @@ cc.loader = (function () {
594594
_langPathCache = {}, //cache for lang path
595595
_aliases = {}, //aliases for res url
596596
_queue = {}, // Callback queue for resources already loading
597-
_urlRegExp = new RegExp(
598-
"^" +
599-
// protocol identifier
600-
"(?:(?:https?|ftp)://)" +
601-
// user:pass authentication
602-
"(?:\\S+(?::\\S*)?@)?" +
603-
"(?:" +
604-
// IP address dotted notation octets
605-
// excludes loopback network 0.0.0.0
606-
// excludes reserved space >= 224.0.0.0
607-
// excludes network & broacast addresses
608-
// (first & last IP address of each class)
609-
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
610-
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
611-
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
612-
"|" +
613-
// host name
614-
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
615-
// domain name
616-
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
617-
// TLD identifier
618-
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
619-
"|" +
620-
"(?:localhost)" +
621-
")" +
622-
// port number
623-
"(?::\\d{2,5})?" +
624-
// resource path
625-
"(?:/\\S*)?" +
626-
"$", "i"
627-
);
597+
_urlRegExp = new RegExp("^(?:https?|ftp)://\\S*$", "i");
628598

629599
return /** @lends cc.Loader# */{
630600
/**
@@ -650,7 +620,9 @@ cc.loader = (function () {
650620
* @returns {XMLHttpRequest}
651621
*/
652622
getXMLHttpRequest: function () {
653-
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
623+
var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
624+
xhr.timeout = 10000;
625+
return xhr;
654626
},
655627

656628
//@MODE_BEGIN DEV
@@ -1863,13 +1835,13 @@ var _initSys = function () {
18631835
if (win.WebGLRenderingContext) {
18641836
var tmpCanvas = document.createElement("CANVAS");
18651837
try{
1866-
var context = cc.create3DContext(tmpCanvas, {'stencil': true});
1838+
var context = cc.create3DContext(tmpCanvas);
18671839
if (context && context.getShaderPrecisionFormat) {
18681840
_supportWebGL = true;
18691841
}
18701842

1871-
if (_supportWebGL && sys.os === sys.OS_IOS) {
1872-
// Not activating WebGL in iOS UIWebView because it may crash when entering background
1843+
if (_supportWebGL && sys.os === sys.OS_IOS && sys.osMainVersion === 9) {
1844+
// Not activating WebGL in iOS 9 UIWebView because it may crash when entering background
18731845
if (!window.indexedDB) {
18741846
_supportWebGL = false;
18751847
}
@@ -2691,8 +2663,8 @@ cc.game = /** @lends cc.game# */{
26912663
this._renderContext = cc._renderContext = cc.webglContext
26922664
= cc.create3DContext(localCanvas, {
26932665
'stencil': true,
2694-
'antialias': !cc.sys.isMobile,
2695-
'alpha': false
2666+
'alpha': false,
2667+
'preserveDrawingBuffer': false
26962668
});
26972669
}
26982670
// WebGL context created successfully
@@ -2809,35 +2781,3 @@ Function.prototype.bind = Function.prototype.bind || function (oThis) {
28092781

28102782
return fBound;
28112783
};
2812-
2813-
cc._urlRegExp = new RegExp(
2814-
"^" +
2815-
// protocol identifier
2816-
"(?:(?:https?|ftp)://)" +
2817-
// user:pass authentication
2818-
"(?:\\S+(?::\\S*)?@)?" +
2819-
"(?:" +
2820-
// IP address dotted notation octets
2821-
// excludes loopback network 0.0.0.0
2822-
// excludes reserved space >= 224.0.0.0
2823-
// excludes network & broacast addresses
2824-
// (first & last IP address of each class)
2825-
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
2826-
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
2827-
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
2828-
"|" +
2829-
// host name
2830-
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
2831-
// domain name
2832-
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
2833-
// TLD identifier
2834-
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
2835-
"|" +
2836-
"(?:localhost)" +
2837-
")" +
2838-
// port number
2839-
"(?::\\d{2,5})?" +
2840-
// resource path
2841-
"(?:/\\S*)?" +
2842-
"$", "i"
2843-
);

cocos2d/audio/CCAudio.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ cc.Audio.WebAudio.prototype = {
834834
}
835835
list.length = 0;
836836
}
837+
ap.length = 0;
837838
},
838839

839840
/**
@@ -850,7 +851,12 @@ cc.Audio.WebAudio.prototype = {
850851

851852
cc.loader.release(url);
852853
var pool = this._audioPool[url];
853-
if(pool) pool.length = 0;
854+
if (pool) {
855+
for (var i = 0; i < pool.length; i++) {
856+
pool[i].stop();
857+
}
858+
pool.length = 0;
859+
}
854860
delete this._audioPool[url];
855861
},
856862

cocos2d/core/CCDirector.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
239239
this.setNextScene();
240240
}
241241

242-
if (this._beforeVisitScene)
243-
this._beforeVisitScene();
244-
245242
// draw the scene
246243
if (this._runningScene) {
247244
if (renderer.childrenOrderDirty) {
@@ -265,9 +262,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
265262
cc.eventManager.dispatchEvent(this._eventAfterVisit);
266263
cc.g_NumberOfDraws = 0;
267264

268-
if (this._afterVisitScene)
269-
this._afterVisitScene();
270-
271265
renderer.rendering(cc._renderContext);
272266
this._totalFrames++;
273267

@@ -277,9 +271,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
277271
this._calculateMPF();
278272
},
279273

280-
_beforeVisitScene: null,
281-
_afterVisitScene: null,
282-
283274
/**
284275
* End the life of director in the next frame
285276
*/

cocos2d/core/CCScheduler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ cc.inject({
237237
}
238238
}
239239

240-
if (!this._runForever && this._timesExecuted > this._repeat)
240+
if (this._callback && !this._runForever && this._timesExecuted > this._repeat)
241241
this.cancel();
242242
}
243243
}
@@ -596,7 +596,7 @@ cc.Scheduler = cc.Class.extend(/** @lends cc.Scheduler# */{
596596

597597
if (!element) {
598598
// Is this the 1st element ? Then set the pause level to all the callback_fns of this target
599-
element = HashTimerEntry.get(null, target, 0, null, null, paused, null);
599+
element = HashTimerEntry.get(null, target, 0, null, null, paused);
600600
this._arrayForTimers.push(element);
601601
this._hashForTimers[target.__instanceId] = element;
602602
} else {

cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ cc.CustomRenderCmd = function (target, func) {
2727
this._needDraw = true;
2828
this._target = target;
2929
this._callback = func;
30-
31-
this.rendering = function (ctx, scaleX, scaleY) {
32-
if (!this._callback)
33-
return;
34-
this._callback.call(this._target, ctx, scaleX, scaleY);
35-
};
36-
this.needDraw = function () {
37-
return this._needDraw;
38-
};
30+
};
31+
cc.CustomRenderCmd.prototype.rendering = function (ctx, scaleX, scaleY) {
32+
if (!this._callback)
33+
return;
34+
this._callback.call(this._target, ctx, scaleX, scaleY);
35+
};
36+
cc.CustomRenderCmd.prototype.needDraw = function () {
37+
return this._needDraw;
3938
};
4039

4140
var dirtyFlags = cc.Node._dirtyFlags = {

cocos2d/core/cocoa/CCAffineTransform.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,14 @@ cc.affineTransformInvert = function (t) {
292292
tx: determinant * (t.c * t.ty - t.d * t.tx), ty: determinant * (t.b * t.tx - t.a * t.ty)
293293
};
294294
};
295+
296+
cc.affineTransformInvertOut = function (t, out) {
297+
var a = t.a, b = t.b, c = t.c, d = t.d;
298+
var determinant = 1 / (a * d - b * c);
299+
out.a = determinant * d;
300+
out.b = -determinant * b;
301+
out.c = -determinant * c;
302+
out.d = determinant * a;
303+
out.tx = determinant * (c * t.ty - d * t.tx);
304+
out.ty = determinant * (b * t.tx - a * t.ty);
305+
};

cocos2d/core/platform/CCCommon.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ cc.getImageFormatByData = function (imgData) {
244244
|| (imgData[0] === 0xff && imgData[1] === 0xd8))) {
245245
return cc.FMT_TIFF;
246246
}
247-
return cc.FMT_UNKNOWN;
247+
return cc.FMT_UNKNOWN;
248248
};
249249

250250
/**
@@ -265,39 +265,4 @@ cc.inherits = function (childCtor, parentCtor) {
265265
// for( var i in parentCtor ) {
266266
// childCtor[ i ] = parentCtor[ i ];
267267
// }
268-
};
269-
270-
/**
271-
* @deprecated since v3.0, please use cc.Class.extend and _super
272-
* @cc.Class.extend
273-
*/
274-
cc.base = function(me, opt_methodName, var_args) {
275-
var caller = arguments.callee.caller;
276-
if (caller.superClass_) {
277-
// This is a constructor. Call the superclass constructor.
278-
ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
279-
return ret;
280-
}
281-
282-
var args = Array.prototype.slice.call(arguments, 2);
283-
var foundCaller = false;
284-
for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
285-
if (ctor.prototype[opt_methodName] === caller) {
286-
foundCaller = true;
287-
} else if (foundCaller) {
288-
return ctor.prototype[opt_methodName].apply(me, args);
289-
}
290-
}
291-
292-
// If we did not find the caller in the prototype chain,
293-
// then one of two things happened:
294-
// 1) The caller is an instance method.
295-
// 2) This method was not called by the right caller.
296-
if (me[opt_methodName] === caller) {
297-
return me.constructor.prototype[opt_methodName].apply(me, args);
298-
} else {
299-
throw Error(
300-
'cc.base called from a method of one name ' +
301-
'to a method of a different name');
302-
}
303-
};
268+
};

cocos2d/core/platform/CCEGLView.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,9 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
678678

679679
this.setResolutionPolicy(resolutionPolicy);
680680
var policy = this._resolutionPolicy;
681-
if (!policy){
682-
cc.log(cc._LogInfos.EGLView_setDesignResolutionSize_2);
683-
return;
681+
if (policy) {
682+
policy.preApply(this);
684683
}
685-
policy.preApply(this);
686684

687685
// Reinit frame size
688686
if (cc.sys.isMobile)
@@ -692,6 +690,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
692690
this._orientationChanging = true;
693691
this._initFrameSize();
694692

693+
if (!policy) {
694+
cc.log(cc._LogInfos.EGLView_setDesignResolutionSize_2);
695+
return;
696+
}
697+
695698
this._originalDesignResolutionSize.width = this._designResolutionSize.width = width;
696699
this._originalDesignResolutionSize.height = this._designResolutionSize.height = height;
697700

@@ -768,7 +771,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
768771
this._setViewportMeta({"width": width}, true);
769772

770773
// Set body width to the exact pixel resolution
771-
document.html.style.width = width + 'px';
774+
document.documentElement.style.width = width + 'px';
772775
document.body.style.width = "100%";
773776

774777
// Reset the resolution size and policy

cocos2d/core/renderer/RendererWebGL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ return {
126126

127127
this.mat4Identity = new cc.math.Matrix4();
128128
this.mat4Identity.identity();
129-
initQuadBuffer(2000);
129+
initQuadBuffer(500);
130130
if (cc.sys.os === cc.sys.OS_IOS) {
131131
_IS_IOS = true;
132132
}

cocos2d/core/sprites/CCSprite.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
354354
cc.Node.prototype.removeChild.call(this, child, cleanup);
355355
},
356356

357-
/**
358-
* Sets whether the sprite is visible or not.
359-
* @param {Boolean} visible
360-
* @override
361-
*/
362-
setVisible:function (visible) {
363-
cc.Node.prototype.setVisible.call(this, visible);
364-
this._renderCmd.setDirtyRecursively(true);
365-
},
366-
367357
/**
368358
* Removes all children from the container.
369359
* @param cleanup whether or not cleanup all running actions

0 commit comments

Comments
 (0)