Skip to content

Commit

Permalink
Cleanup CCCommon, CCConfig, CCMacro, CCShaders
Browse files Browse the repository at this point in the history
  • Loading branch information
pandamicro committed Mar 13, 2016
1 parent 3ae96a2 commit 334d99f
Show file tree
Hide file tree
Showing 94 changed files with 2,317 additions and 2,586 deletions.
125 changes: 14 additions & 111 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,19 @@ _p.ctor;
_p = null;

/**
* Device oriented vertically, home button on the bottom
* @constant
* @type {Number}
* The current version of Cocos2d-JS being used.<br/>
* Please DO NOT remove this String, it is an important flag for bug tracking.<br/>
* If you post a bug to forum, please attach this flag.
* @type {String}
* @name cc.ENGINE_VERSION
*/
cc.ORIENTATION_PORTRAIT = 0;

/**
* Device oriented vertically, home button on the top
* @constant
* @type {Number}
*/
cc.ORIENTATION_PORTRAIT_UPSIDE_DOWN = 1;

/**
* Device oriented horizontally, home button on the right
* @constant
* @type {Number}
*/
cc.ORIENTATION_LANDSCAPE_LEFT = 2;

/**
* Device oriented horizontally, home button on the left
* @constant
* @type {Number}
*/
cc.ORIENTATION_LANDSCAPE_RIGHT = 3;
var engineVersion;
if (CC_EDITOR) {
engineVersion = 'Cocos Creator v' + Editor.remote.versions.CocosCreator;
} else {
engineVersion = 'Cocos Creator';
}
window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion;

/**
* drawing primitive of game engine
Expand Down Expand Up @@ -107,90 +94,6 @@ cc._gameDiv = null;

cc.isEditor = typeof Editor !== 'undefined';

/**
* Iterate over an object or an array, executing a function for each matched element.
* @param {object|array} obj
* @param {function} iterator
* @param {object} [context]
*/
cc.each = function (obj, iterator, context) {
if (!obj)
return;
if (obj instanceof Array) {
for (var i = 0, li = obj.length; i < li; i++) {
if (iterator.call(context, obj[i], i) === false)
return;
}
} else {
for (var key in obj) {
if (iterator.call(context, obj[key], key) === false)
return;
}
}
};

/**
* Check the url whether cross origin
* @param {String} url
* @returns {boolean}
*/
cc.isCrossOrigin = function (url) {
if (!url) {
cc.log("invalid URL");
return false;
}
var startIndex = url.indexOf("://");
if (startIndex === -1)
return false;

var endIndex = url.indexOf("/", startIndex + 3);
var urlOrigin = (endIndex === -1) ? url : url.substring(0, endIndex);
return urlOrigin !== location.origin;
};

/**
* A string tool to construct a string with format string.
* for example:
* cc.formatStr("a: %d, b: %b", a, b);
* cc.formatStr(a, b, c);
* @returns {String}
*/
cc.formatStr = function(){
var args = arguments;
var l = args.length;
if(l < 1)
return "";

var str = args[0];
var needToFormat = true;
if(typeof str === "object"){
needToFormat = false;
}
for(var i = 1; i < l; ++i){
var arg = args[i];
if(needToFormat){
while(true){
var result = null;
if(typeof arg === "number"){
result = str.match(/(%d)|(%s)/);
if(result){
str = str.replace(/(%d)|(%s)/, arg);
break;
}
}
result = str.match(/%s/);
if(result)
str = str.replace(/%s/, arg);
else
str += " " + arg;
break;
}
}else
str += " " + arg;
}
return str;
};

require('../cocos2d/core/utils');
require('../cocos2d/core/platform/CCSys');
require('../cocos2d/core/load-pipeline/CCLoader');
Expand Down Expand Up @@ -306,7 +209,7 @@ cc.initEngine = function (config, cb) {
_engineLoadedCallback = function () {
previousCallback && previousCallback();
cb && cb();
}
};
return;
}

Expand All @@ -326,7 +229,7 @@ cc.initEngine = function (config, cb) {

document.body ? _load(config) : window.addEventListener('load', _windowLoaded, false);
_engineInitCalled = true;
}
};

})();
//+++++++++++++++++++++++++Engine initialization function end+++++++++++++++++++++++++++++
17 changes: 7 additions & 10 deletions CCDebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cc._LogInfos = {
},

configuration: {
dumpInfo: "cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.js)",
dumpInfo: "cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from CCMacro.js)",
loadConfigFile: "Expected 'data' dict, but not found. Config file: %s",
loadConfigFile_2: "Please load the resource first : %s",
},
Expand Down Expand Up @@ -125,8 +125,6 @@ cc._LogInfos = {
handleTouchesBegin: "The touches is more than MAX_TOUCHES, nUnusedIndex = %s",
},

swap: "cc.swap is being modified from original macro, please check usage",

checkGLErrorDebug: "WebGL error %s",

spriteFrameAnimationCache: {
Expand Down Expand Up @@ -246,7 +244,6 @@ cc._LogInfos = {
},

MissingFile: "Missing file: %s",
radiansToDegress: "cc.radiansToDegress() should be called cc.radiansToDegrees()",
RectWidth: "Rect width exceeds maximum margin: %s",
RectHeight: "Rect height exceeds maximum margin: %s",

Expand Down Expand Up @@ -315,7 +312,7 @@ cc._logToWebPage = function (msg) {
};

//to make sure the cc.log, cc.warn, cc.error and cc.assert would not throw error before init by debugger mode.
cc._formatString = function (arg) {
function _formatString (arg) {
if (cc.js.isObject(arg)) {
try {
return JSON.stringify(arg);
Expand Down Expand Up @@ -386,24 +383,24 @@ cc._initDebugSetting = function (mode) {
//log to web page
locLog = cc._logToWebPage.bind(cc);
cc.error = function(){
locLog("ERROR : " + cc.formatStr.apply(cc, arguments));
locLog("ERROR : " + cc.js.formatStr.apply(cc, arguments));
};
cc.assert = function(cond, msg) {
'use strict';
if (!cond && msg) {
for (var i = 2; i < arguments.length; i++)
msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i]));
msg = msg.replace(/(%s)|(%d)/, _formatString(arguments[i]));
locLog("Assert: " + msg);
}
};
if(mode !== cc.DebugMode.ERROR_FOR_WEB_PAGE){
cc.warn = function(){
locLog("WARN : " + cc.formatStr.apply(cc, arguments));
locLog("WARN : " + cc.js.formatStr.apply(cc, arguments));
};
}
if(mode === cc.DebugMode.INFO_FOR_WEB_PAGE){
cc.log = cc.info = function(){
locLog(cc.formatStr.apply(cc, arguments));
locLog(cc.js.formatStr.apply(cc, arguments));
};
}
} else if(console && console.log.apply){//console is null when user doesn't open dev tool on IE9
Expand Down Expand Up @@ -436,7 +433,7 @@ cc._initDebugSetting = function (mode) {
cc.assert = function (cond, msg) {
if (!cond && msg) {
for (var i = 2; i < arguments.length; i++)
msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i]));
msg = msg.replace(/(%s)|(%d)/, _formatString(arguments[i]));
throw new Error(msg);
}
};
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/actions/CCActionCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ cc.OrbitCamera = cc.ActionCamera.extend({
var r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
var s = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if (s === 0.0)
s = cc.FLT_EPSILON;
s = cc.Macro.FLT_EPSILON;
if (r === 0.0)
r = cc.FLT_EPSILON;
r = cc.Macro.FLT_EPSILON;

zenith = Math.acos(z / r);
if (x < 0)
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/actions/CCActionCatmullRom.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
cc.getControlPointAt(ps, p + 2),
this._tension, lt);

if (cc.ENABLE_STACKABLE_ACTIONS) {
if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
var tempX, tempY;
tempX = this.target.getPositionX() - this._previousPosition.x;
tempY = this.target.getPositionY() - this._previousPosition.y;
Expand Down
6 changes: 3 additions & 3 deletions cocos2d/actions/CCActionInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ cc.MoveBy = cc.ActionInterval.extend({
var x = this._positionDelta.x * dt;
var y = this._positionDelta.y * dt;
var locStartPosition = this._startPosition;
if (cc.ENABLE_STACKABLE_ACTIONS) {
if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
Expand Down Expand Up @@ -1460,7 +1460,7 @@ cc.JumpBy = cc.ActionInterval.extend({

var x = this._delta.x * dt;
var locStartPosition = this._startPosition;
if (cc.ENABLE_STACKABLE_ACTIONS) {
if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
Expand Down Expand Up @@ -1680,7 +1680,7 @@ cc.BezierBy = cc.ActionInterval.extend({
var y = cc.bezierAt(ya, yb, yc, yd, dt);

var locStartPosition = this._startPosition;
if (cc.ENABLE_STACKABLE_ACTIONS) {
if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@
gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);

if (node.alphaThreshold < 1) { //TODO desktop
var program = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLORALPHATEST);
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.UNIFORM_ALPHA_TEST_VALUE_S);
var program = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
// set our alphaThreshold
cc.glUseProgram(program.getProgram());
program.setUniformLocationWith1f(alphaValueLocation, node.alphaThreshold);
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/CCCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,5 @@ cc.Camera = cc._Class.extend({
* @return {Number}
*/
cc.Camera.getZEye = function () {
return cc.FLT_EPSILON;
return cc.Macro.FLT_EPSILON;
};
4 changes: 2 additions & 2 deletions cocos2d/core/CCConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ cc.configuration = /** @lends cc.configuration# */{
var locValueDict = this._valueDict;
locValueDict["cocos2d.x.version"] = cc.ENGINE_VERSION;
locValueDict["cocos2d.x.compiled_with_profiler"] = false;
locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.ENABLE_GL_STATE_CACHE;
locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.Macro.ENABLE_GL_STATE_CACHE;
this._inited = true;
},

Expand Down Expand Up @@ -220,7 +220,7 @@ cc.configuration = /** @lends cc.configuration# */{
* Dumps the current configuration on the console
*/
dumpInfo: function(){
if(cc.ENABLE_GL_STATE_CACHE === 0){
if(cc.Macro.ENABLE_GL_STATE_CACHE === 0){
cc.log("");
cc.log(cc._LogInfos.configuration.dumpInfo);
cc.log("")
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/CCDirectorWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {

_p.setAlphaBlending = function (on) {
if (on)
cc.glBlendFunc(cc.BLEND_SRC, cc.BLEND_DST);
cc.glBlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST);
else
cc.glBlendFunc(cc._renderContext.ONE, cc._renderContext.ZERO);
cc.glBlendFunc(cc.Macro.ONE, cc.Macro.ZERO);
//cc.checkGLErrorDebug();
};

Expand Down
9 changes: 2 additions & 7 deletions cocos2d/core/CCDrawingPrimitivesCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/**
* @const
* @type {number}
*/
cc.PI2 = Math.PI * 2;

/**
* Canvas of DrawingPrimitive implement version use for canvasMode
Expand Down Expand Up @@ -365,7 +360,7 @@ cc.DrawingPrimitiveCanvas = cc._Class.extend(/** @lends cc.DrawingPrimitiveCanva
//context.fillStyle = g1;
context.beginPath();
var startAngle_1 = 0;
var endAngle_1 = cc.PI2;
var endAngle_1 = cc.Macro.PI2;
context.arc(0, 0, radius - subRadius, startAngle_1, endAngle_1, false);
context.closePath();
context.fill();
Expand Down Expand Up @@ -393,7 +388,7 @@ cc.DrawingPrimitiveCanvas = cc._Class.extend(/** @lends cc.DrawingPrimitiveCanva
//context.fillStyle = g1;
context.beginPath();
var startAngle_1 = 0;
var endAngle_1 = cc.PI2;
var endAngle_1 = cc.Macro.PI2;
context.arc(0, 0, radius, startAngle_1, endAngle_1, false);
context.closePath();
context.fill();
Expand Down
Loading

0 comments on commit 334d99f

Please sign in to comment.