diff --git a/CCBoot.js b/CCBoot.js index eb825ffc1f..edd15e71e6 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -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.
+ * Please DO NOT remove this String, it is an important flag for bug tracking.
+ * 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 @@ -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'); @@ -306,7 +209,7 @@ cc.initEngine = function (config, cb) { _engineLoadedCallback = function () { previousCallback && previousCallback(); cb && cb(); - } + }; return; } @@ -326,7 +229,7 @@ cc.initEngine = function (config, cb) { document.body ? _load(config) : window.addEventListener('load', _windowLoaded, false); _engineInitCalled = true; -} +}; })(); //+++++++++++++++++++++++++Engine initialization function end+++++++++++++++++++++++++++++ diff --git a/CCDebugger.js b/CCDebugger.js index a9015122eb..0c37403e0a 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -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", }, @@ -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: { @@ -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", @@ -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); @@ -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 @@ -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); } }; diff --git a/cocos2d/actions/CCActionCamera.js b/cocos2d/actions/CCActionCamera.js index ffc3fe5d5a..90b8a432c0 100644 --- a/cocos2d/actions/CCActionCamera.js +++ b/cocos2d/actions/CCActionCamera.js @@ -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) diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js index 36c7b2b695..b85de71125 100644 --- a/cocos2d/actions/CCActionCatmullRom.js +++ b/cocos2d/actions/CCActionCatmullRom.js @@ -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; diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index 00d3553358..11b0b7822c 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -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; @@ -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; @@ -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; diff --git a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js index 2fb7d1f6d4..c4dd0bdeb9 100644 --- a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js +++ b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js @@ -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); diff --git a/cocos2d/core/CCCamera.js b/cocos2d/core/CCCamera.js index 204e266504..de35d78e95 100644 --- a/cocos2d/core/CCCamera.js +++ b/cocos2d/core/CCCamera.js @@ -278,5 +278,5 @@ cc.Camera = cc._Class.extend({ * @return {Number} */ cc.Camera.getZEye = function () { - return cc.FLT_EPSILON; + return cc.Macro.FLT_EPSILON; }; diff --git a/cocos2d/core/CCConfiguration.js b/cocos2d/core/CCConfiguration.js index ec90b5f533..519b12650a 100644 --- a/cocos2d/core/CCConfiguration.js +++ b/cocos2d/core/CCConfiguration.js @@ -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; }, @@ -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("") diff --git a/cocos2d/core/CCDirectorWebGL.js b/cocos2d/core/CCDirectorWebGL.js index a2f1cdd4d0..3ee7064c32 100644 --- a/cocos2d/core/CCDirectorWebGL.js +++ b/cocos2d/core/CCDirectorWebGL.js @@ -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(); }; diff --git a/cocos2d/core/CCDrawingPrimitivesCanvas.js b/cocos2d/core/CCDrawingPrimitivesCanvas.js index 7ac37e5770..ccd16b324a 100644 --- a/cocos2d/core/CCDrawingPrimitivesCanvas.js +++ b/cocos2d/core/CCDrawingPrimitivesCanvas.js @@ -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 @@ -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(); @@ -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(); diff --git a/cocos2d/core/CCDrawingPrimitivesWebGL.js b/cocos2d/core/CCDrawingPrimitivesWebGL.js index 4c3a75c0ee..90d1c4c949 100644 --- a/cocos2d/core/CCDrawingPrimitivesWebGL.js +++ b/cocos2d/core/CCDrawingPrimitivesWebGL.js @@ -58,7 +58,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# // // Position and 1 color passed as a uniform (to similate glColor4ub ) // - _t._shader = cc.shaderCache.programForKey(cc.SHADER_POSITION_UCOLOR); + _t._shader = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_UCOLOR); _t._colorLocation = _t._renderContext.getUniformLocation(_t._shader.getProgram(), "u_color"); _t._pointSizeLocation = _t._renderContext.getUniformLocation(_t._shader.getProgram(), "u_pointSize"); @@ -83,14 +83,14 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, new Float32Array([point.x, point.y]), glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.POINTS, 0, 1); glContext.deleteBuffer(pointBuffer); @@ -112,14 +112,14 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(points), glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.POINTS, 0, points.length); glContext.deleteBuffer(pointBuffer); @@ -147,13 +147,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray([origin, destination]), glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.LINES, 0, 2); glContext.deleteBuffer(pointBuffer); @@ -202,13 +202,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(vertices), glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); if (closePolygon) glContext.drawArrays(glContext.LINE_LOOP, 0, vertices.length); @@ -233,13 +233,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(poli), glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.TRIANGLE_FAN, 0, poli.length); glContext.deleteBuffer(pointBuffer); @@ -281,13 +281,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.LINE_STRIP, 0, segments + additionalSegment); glContext.deleteBuffer(pointBuffer); @@ -319,13 +319,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1); glContext.deleteBuffer(pointBuffer); @@ -358,13 +358,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1); glContext.deleteBuffer(pointBuffer); @@ -418,13 +418,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL# var glContext = this._renderContext; this._shader.use(); this._shader.setUniformForModelViewAndProjectionMatrixWithMat4(); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); glContext.uniform4fv(this._colorLocation, this._colorArray); var pointBuffer = glContext.createBuffer(); glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer); glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW); - glContext.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); + glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0); glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1); glContext.deleteBuffer(pointBuffer); diff --git a/cocos2d/core/CCScheduler.js b/cocos2d/core/CCScheduler.js index 815490433a..37bdffac25 100644 --- a/cocos2d/core/CCScheduler.js +++ b/cocos2d/core/CCScheduler.js @@ -124,7 +124,7 @@ cc.Timer = cc._Class.extend(/** @lends cc.Timer# */{ this._delay = delay; this._useDelay = (this._delay > 0); this._repeat = repeat; - this._runForever = (this._repeat === cc.REPEAT_FOREVER); + this._runForever = (this._repeat === cc.Macro.REPEAT_FOREVER); }, trigger: function(){ @@ -519,7 +519,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{ * If paused is YES, then it won't be called until it is resumed.
* If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
* If the callback function is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
- * repeat let the action be repeated repeat + 1 times, use cc.REPEAT_FOREVER to let the action run continuously
+ * repeat let the action be repeated repeat + 1 times, use cc.Macro.REPEAT_FOREVER to let the action run continuously
* delay is the amount of time the action will wait before it'll start
*

* @method scheduleCallbackForTarget @@ -563,14 +563,14 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{ key = delay; paused = repeat; delay = 0; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; } }else{ //selector, target, interval, repeat, delay, paused //selector, target, interval, paused if(arguments.length === 4){ paused = repeat; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; } } diff --git a/cocos2d/core/base-nodes/CCAtlasNode.js b/cocos2d/core/base-nodes/CCAtlasNode.js index 9fa71339d7..03a5a677d4 100644 --- a/cocos2d/core/base-nodes/CCAtlasNode.js +++ b/cocos2d/core/base-nodes/CCAtlasNode.js @@ -84,7 +84,7 @@ cc.AtlasNode = _ccsg.Node.extend(/** @lends cc.AtlasNode# */{ _ccsg.Node.prototype.ctor.call(this); EventTarget.call(this); - this._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST}; + this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST}; this._ignoreContentScaleFactor = false; itemsToRender !== undefined && this.initWithTileFile(tile, tileWidth, tileHeight, itemsToRender); }, diff --git a/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js b/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js index 96fb6f551f..f1c08e9e74 100644 --- a/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js +++ b/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js @@ -35,7 +35,7 @@ this._uniformColor = null; //shader stuff - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE_UCOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR); this._uniformColor = cc._renderContext.getUniformLocation(this._shaderProgram.getProgram(), "u_color"); }; @@ -45,8 +45,8 @@ proto._updateBlendFunc = function () { var node = this._node; if (!this._textureAtlas.texture.hasPremultipliedAlpha()) { - node._blendFunc.src = cc.SRC_ALPHA; - node._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + node._blendFunc.src = cc.Macro.SRC_ALPHA; + node._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } }; @@ -74,8 +74,8 @@ this._colorUnmodified = cc.Color.WHITE; node._opacityModifyRGB = true; - node._blendFunc.src = cc.BLEND_SRC; - node._blendFunc.dst = cc.BLEND_DST; + node._blendFunc.src = cc.Macro.BLEND_SRC; + node._blendFunc.dst = cc.Macro.BLEND_DST; var locRealColor = node._realColor; this._colorF32Array = new Float32Array([locRealColor.r / 255.0, locRealColor.g / 255.0, locRealColor.b / 255.0, node._realOpacity / 255.0]); diff --git a/cocos2d/core/base-nodes/CCSGNode.js b/cocos2d/core/base-nodes/CCSGNode.js index 0fc621b6cd..4dff9cd970 100644 --- a/cocos2d/core/base-nodes/CCSGNode.js +++ b/cocos2d/core/base-nodes/CCSGNode.js @@ -1564,27 +1564,27 @@ _ccsg.Node = cc.Class({ if(len === 1){ //callback interval = 0; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; key = this.__instanceId; }else if(len === 2){ if(typeof interval === "number"){ //callback, interval - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; key = this.__instanceId; }else{ //callback, key key = interval; interval = 0; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; } }else if(len === 3){ if(typeof repeat === "string"){ //callback, interval, key key = repeat; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; }else{ //callback, interval, repeat key = this.__instanceId; @@ -1599,10 +1599,10 @@ _ccsg.Node = cc.Class({ //selector, interval, repeat, delay if(len === 1){ interval = 0; - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; }else if(len === 2){ - repeat = cc.REPEAT_FOREVER; + repeat = cc.Macro.REPEAT_FOREVER; delay = 0; } } @@ -1611,7 +1611,7 @@ _ccsg.Node = cc.Class({ cc.assert(interval >= 0, cc._LogInfos.Node.schedule_2); interval = interval || 0; - repeat = (repeat == null) ? cc.REPEAT_FOREVER : repeat; + repeat = (repeat == null) ? cc.Macro.REPEAT_FOREVER : repeat; delay = delay || 0; this.scheduler.schedule(callback, this, interval, repeat, delay, !this._running, key); @@ -2009,7 +2009,7 @@ _ccsg.Node = cc.Class({ * @function * @param {cc.GLProgram} newShaderProgram The shader program which fetches from CCShaderCache. * @example - * node.setGLProgram(cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR)); + * node.setGLProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR)); */ setShaderProgram: function (newShaderProgram) { this._renderCmd.setShaderProgram(newShaderProgram); diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js index 1c7f1f7f2b..caedf8dc2f 100644 --- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js +++ b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js @@ -511,11 +511,11 @@ _ccsg.Node.RenderCmd.prototype = { if (!blendFunc) return "source-over"; else { - if (( blendFunc.src === cc.SRC_ALPHA && blendFunc.dst === cc.ONE) || (blendFunc.src === cc.ONE && blendFunc.dst === cc.ONE)) + if (( blendFunc.src === cc.Macro.SRC_ALPHA && blendFunc.dst === cc.Macro.ONE) || (blendFunc.src === cc.Macro.ONE && blendFunc.dst === cc.Macro.ONE)) return "lighter"; - else if (blendFunc.src === cc.ZERO && blendFunc.dst === cc.SRC_ALPHA) + else if (blendFunc.src === cc.Macro.ZERO && blendFunc.dst === cc.Macro.SRC_ALPHA) return "destination-in"; - else if (blendFunc.src === cc.ZERO && blendFunc.dst === cc.ONE_MINUS_SRC_ALPHA) + else if (blendFunc.src === cc.Macro.ZERO && blendFunc.dst === cc.Macro.ONE_MINUS_SRC_ALPHA) return "destination-out"; else return "source-over"; diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index da25394ff5..da5beee446 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -696,7 +696,7 @@ var Component = cc.Class({ * @method schedule * @param {function} callback The callback function * @param {Number} [interval=0] Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead. - * @param {Number} [repeat=cc.REPEAT_FOREVER] The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely. + * @param {Number} [repeat=cc.Macro.REPEAT_FOREVER] The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely. * @param {Number} [delay=0] The amount of time that the first tick will wait before execution. */ schedule: function (callback, interval, repeat, delay) { @@ -704,7 +704,7 @@ var Component = cc.Class({ cc.assert(interval >= 0, cc._LogInfos.Node.schedule_2); interval = interval || 0; - repeat = isNaN(repeat) ? cc.REPEAT_FOREVER : repeat; + repeat = isNaN(repeat) ? cc.Macro.REPEAT_FOREVER : repeat; delay = delay || 0; cc.director.getScheduler().scheduleCallbackForTarget(this, callback, interval, repeat, delay, !this.enabledInHierarchy); diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js index d308707268..a26447fee5 100644 --- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js @@ -37,7 +37,7 @@ this._labelTexture = new cc.Texture2D(); this._quadWebBuffer = cc._renderContext.createBuffer(); - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); this._quad = new cc.V3F_C4B_T2F_Quad(); this._labelCanvas = document.createElement("canvas"); @@ -72,7 +72,7 @@ cc.glBlendFunc(node._blendFunc.src,node._blendFunc.dst); cc.glBindTexture2DN(0,this._labelTexture); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer); @@ -81,9 +81,9 @@ this._quadDirty = false; } - gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION - gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR - gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.VERTEX_ATTRIB_TEX_COORDS + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION + gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR + gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } diff --git a/cocos2d/core/labelttf/CCLabelTTF.js b/cocos2d/core/labelttf/CCLabelTTF.js index 28a9759a9e..d8d5ecd10c 100644 --- a/cocos2d/core/labelttf/CCLabelTTF.js +++ b/cocos2d/core/labelttf/CCLabelTTF.js @@ -806,10 +806,10 @@ cc.LabelTTF.create = function (text, fontName, fontSize, dimensions, hAlignment, */ cc.LabelTTF.createWithFontDefinition = cc.LabelTTF.create; -if (cc.USE_LA88_LABELS) - cc.LabelTTF._SHADER_PROGRAM = cc.SHADER_POSITION_TEXTURECOLOR; +if (cc.Macro.USE_LA88_LABELS) + cc.LabelTTF._SHADER_PROGRAM = cc.Macro.SHADER_POSITION_TEXTURECOLOR; else - cc.LabelTTF._SHADER_PROGRAM = cc.SHADER_POSITION_TEXTUREA8COLOR; + cc.LabelTTF._SHADER_PROGRAM = cc.Macro.SHADER_POSITION_TEXTUREA8COLOR; cc.LabelTTF.__labelHeightDiv = document.createElement("div"); cc.LabelTTF.__labelHeightDiv.style.fontFamily = "Arial"; diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js index 7eec689eb6..9c4f1d271b 100644 --- a/cocos2d/core/layers/CCLayer.js +++ b/cocos2d/core/layers/CCLayer.js @@ -191,7 +191,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ */ ctor: function(color, width, height){ cc.Layer.prototype.ctor.call(this); - this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); + this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); cc.LayerColor.prototype.init.call(this, color, width, height); }, @@ -204,7 +204,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ */ init: function (color, width, height) { if (cc._renderType !== cc.game.RENDER_TYPE_CANVAS) - this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_COLOR); + this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_COLOR); var winSize = cc.director.getWinSize(); color = color || cc.color(0, 0, 0, 255); diff --git a/cocos2d/core/layers/CCLayerWebGLRenderCmd.js b/cocos2d/core/layers/CCLayerWebGLRenderCmd.js index d7647b7f18..78ebbfe8a4 100644 --- a/cocos2d/core/layers/CCLayerWebGLRenderCmd.js +++ b/cocos2d/core/layers/CCLayerWebGLRenderCmd.js @@ -81,17 +81,17 @@ this._shaderProgram.use(); this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR); cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); // // Attributes // context.bindBuffer(context.ARRAY_BUFFER, this._verticesFloat32Buffer); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0); context.bindBuffer(context.ARRAY_BUFFER, this._colorsUint8Buffer); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0); context.drawArrays(context.TRIANGLE_STRIP, 0, this._squareVertices.length); }; @@ -285,15 +285,15 @@ //draw gradient layer this._shaderProgram.use(); this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR); cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); // // Attributes // context.bindBuffer(context.ARRAY_BUFFER, this._verticesFloat32Buffer); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0); context.bindBuffer(context.ARRAY_BUFFER, this._colorsUint8Buffer); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0); context.drawArrays(context.TRIANGLE_STRIP, 0, this._squareVertices.length); context.disable(context.SCISSOR_TEST); diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 82266c8395..bbb27bc626 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -35,6 +35,20 @@ else { } // var downloadBinary = require('binary-downloader'); +function isUrlCrossOrigin (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; +}; + var _noCacheRex = /\?/; function urlAppendTimestamp (url) { if (cc.game.config['noCache'] && typeof url === 'string') { diff --git a/cocos2d/core/platform/CCCommon.js b/cocos2d/core/platform/CCCommon.js deleted file mode 100644 index 68d3a98ffe..0000000000 --- a/cocos2d/core/platform/CCCommon.js +++ /dev/null @@ -1,741 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Chukong Aipu reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var cc = cc || {}; -cc._tmp = cc._tmp || {}; - -/** - * Function added for JS bindings compatibility. Not needed in cocos2d-html5. - * @method associateWithNative - * @param {Object} jsObj subclass - * @param {Object} superclass - */ -cc.associateWithNative = function (jsObj, superclass) { -}; - -/** - * Key map for keyboard event - * @enum KEY - * @readonly - * @type {Object} - * @example {@link utils/api/engine/docs/cocos2d/core/platform/CCCommon/KEY.js} - */ -cc.KEY = { - /** - * @property {Number} none - * @readonly - */ - none:0, - - // android - /** - * @property {Number} back - * @readonly - */ - back:6, - /** - * @property {Number} menu - * @readonly - */ - menu:18, - - /** - * @property {Number} backspace - * @readonly - */ - backspace:8, - /** - * @property {Number} tab - * @readonly - */ - tab:9, - - /** - * @property {Number} enter - * @readonly - */ - enter:13, - - /** - * @property {Number} shift - * @readonly - */ - shift:16, //should use shiftkey instead - /** - * @property {Number} ctrl - * @readonly - */ - ctrl:17, //should use ctrlkey - /** - * @property {Number} alt - * @readonly - */ - alt:18, //should use altkey - /** - * @property {Number} pause - * @readonly - */ - pause:19, - /** - * @property {Number} capslock - * @readonly - */ - capslock:20, - /** - * @property {Number} escape - * @readonly - */ - escape:27, - /** - * @property {Number} space - * @readonly - */ - space:32, - /** - * @property {Number} pageup - * @readonly - */ - pageup:33, - /** - * @property {Number} pagedown - * @readonly - */ - pagedown:34, - /** - * @property {Number} end - * @readonly - */ - end:35, - /** - * @property {Number} home - * @readonly - */ - home:36, - /** - * @property {Number} left - * @readonly - */ - left:37, - /** - * @property {Number} up - * @readonly - */ - up:38, - /** - * @property {Number} right - * @readonly - */ - right:39, - /** - * @property {Number} down - * @readonly - */ - down:40, - /** - * @property {Number} select - * @readonly - */ - select:41, - - /** - * @property {Number} insert - * @readonly - */ - insert:45, - /** - * @property {Number} Delete - * @readonly - */ - Delete:46, - /** - * @property {Number} 0 - * @readonly - */ - 0:48, - /** - * @property {Number} 1 - * @readonly - */ - 1:49, - /** - * @property {Number} 2 - * @readonly - */ - 2:50, - /** - * @property {Number} 3 - * @readonly - */ - 3:51, - /** - * @property {Number} 4 - * @readonly - */ - 4:52, - /** - * @property {Number} 5 - * @readonly - */ - 5:53, - /** - * @property {Number} 6 - * @readonly - */ - 6:54, - /** - * @property {Number} 7 - * @readonly - */ - 7:55, - /** - * @property {Number} 8 - * @readonly - */ - 8:56, - /** - * @property {Number} 9 - * @readonly - */ - 9:57, - /** - * @property {Number} a - * @readonly - */ - a:65, - /** - * @property {Number} b - * @readonly - */ - b:66, - /** - * @property {Number} c - * @readonly - */ - c:67, - /** - * @property {Number} d - * @readonly - */ - d:68, - /** - * @property {Number} e - * @readonly - */ - e:69, - /** - * @property {Number} f - * @readonly - */ - f:70, - /** - * @property {Number} g - * @readonly - */ - g:71, - /** - * @property {Number} h - * @readonly - */ - h:72, - /** - * @property {Number} i - * @readonly - */ - i:73, - /** - * @property {Number} j - * @readonly - */ - j:74, - /** - * @property {Number} k - * @readonly - */ - k:75, - /** - * @property {Number} l - * @readonly - */ - l:76, - /** - * @property {Number} m - * @readonly - */ - m:77, - /** - * @property {Number} n - * @readonly - */ - n:78, - /** - * @property {Number} o - * @readonly - */ - o:79, - /** - * @property {Number} p - * @readonly - */ - p:80, - /** - * @property {Number} q - * @readonly - */ - q:81, - /** - * @property {Number} r - * @readonly - */ - r:82, - /** - * @property {Number} s - * @readonly - */ - s:83, - /** - * @property {Number} t - * @readonly - */ - t:84, - /** - * @property {Number} u - * @readonly - */ - u:85, - /** - * @property {Number} v - * @readonly - */ - v:86, - /** - * @property {Number} w - * @readonly - */ - w:87, - /** - * @property {Number} x - * @readonly - */ - x:88, - /** - * @property {Number} y - * @readonly - */ - y:89, - /** - * @property {Number} z - * @readonly - */ - z:90, - - /** - * @property {Number} num0 - * @readonly - */ - num0:96, - /** - * @property {Number} num1 - * @readonly - */ - num1:97, - /** - * @property {Number} num2 - * @readonly - */ - num2:98, - /** - * @property {Number} num3 - * @readonly - */ - num3:99, - /** - * @property {Number} num4 - * @readonly - */ - num4:100, - /** - * @property {Number} num5 - * @readonly - */ - num5:101, - /** - * @property {Number} num6 - * @readonly - */ - num6:102, - /** - * @property {Number} num7 - * @readonly - */ - num7:103, - /** - * @property {Number} num8 - * @readonly - */ - num8:104, - /** - * @property {Number} num9 - * @readonly - */ - num9:105, - /** - * @property {Number} * - * @readonly - */ - '*':106, - /** - * @property {Number} + - * @readonly - */ - '+':107, - /** - * @property {Number} - - * @readonly - */ - '-':109, - /** - * @property {Number} numdel - * @readonly - */ - 'numdel':110, - /** - * @property {Number} / - * @readonly - */ - '/':111, - /** - * @property {Number} f1 - * @readonly - */ - f1:112, //f1-f12 dont work on ie - /** - * @property {Number} f2 - * @readonly - */ - f2:113, - /** - * @property {Number} f3 - * @readonly - */ - f3:114, - /** - * @property {Number} f4 - * @readonly - */ - f4:115, - /** - * @property {Number} f5 - * @readonly - */ - f5:116, - /** - * @property {Number} f6 - * @readonly - */ - f6:117, - /** - * @property {Number} f7 - * @readonly - */ - f7:118, - /** - * @property {Number} f8 - * @readonly - */ - f8:119, - /** - * @property {Number} f9 - * @readonly - */ - f9:120, - /** - * @property {Number} f10 - * @readonly - */ - f10:121, - /** - * @property {Number} f11 - * @readonly - */ - f11:122, - /** - * @property {Number} f12 - * @readonly - */ - f12:123, - - /** - * @property {Number} numlock - * @readonly - */ - numlock:144, - /** - * @property {Number} scrolllock - * @readonly - */ - scrolllock:145, - - /** - * @property {Number} ; - * @readonly - */ - ';':186, - /** - * @property {Number} semicolon - * @readonly - */ - semicolon:186, - /** - * @property {Number} equal - * @readonly - */ - equal:187, - /** - * @property {Number} = - * @readonly - */ - '=':187, - /** - * @property {Number} , - * @readonly - */ - ',':188, - /** - * @property {Number} comma - * @readonly - */ - comma:188, - /** - * @property {Number} dash - * @readonly - */ - dash:189, - /** - * @property {Number} . - * @readonly - */ - '.':190, - /** - * @property {Number} period - * @readonly - */ - period:190, - /** - * @property {Number} forwardslash - * @readonly - */ - forwardslash:191, - /** - * @property {Number} grave - * @readonly - */ - grave:192, - /** - * @property {Number} [ - * @readonly - */ - '[':219, - /** - * @property {Number} openbracket - * @readonly - */ - openbracket:219, - /** - * @property {Number} backslash - * @readonly - */ - backslash:220, - /** - * @property {Number} ] - * @readonly - */ - ']':221, - /** - * @property {Number} closebracket - * @readonly - */ - closebracket:221, - /** - * @property {Number} quote - * @readonly - */ - quote:222, - - // gamepad controll - /** - * @property {Number} dpadLeft - * @readonly - */ - dpadLeft:1000, - /** - * @property {Number} dpadRight - * @readonly - */ - dpadRight:1001, - /** - * @property {Number} dpadUp - * @readonly - */ - dpadUp:1003, - /** - * @property {Number} dpadDown - * @readonly - */ - dpadDown:1004, - /** - * @property {Number} dpadCenter - * @readonly - */ - dpadCenter:1005 -}; - -/** - * @module cc - */ - -/** - * Image Format:JPG - * @property {Number} FMT_JPG - * @readonly - */ -cc.FMT_JPG = 0; - -/** - * Image Format:PNG - * @property {Number} FMT_PNG - * @readonly - */ -cc.FMT_PNG = 1; - -/** - * Image Format:TIFF - * @property {Number} FMT_TIFF - * @readonly - */ -cc.FMT_TIFF = 2; - -/** - * Image Format:RAWDATA - * @property {Number} FMT_RAWDATA - * @readonly - */ -cc.FMT_RAWDATA = 3; - -/** - * Image Format:WEBP - * @property {Number} FMT_WEBP - * @readonly - */ -cc.FMT_WEBP = 4; - -/** - * Image Format:UNKNOWN - * @property {Number} FMT_UNKNOWN - * @readonly - */ -cc.FMT_UNKNOWN = 5; - -/** - * get image format by image data - * @method getImageFormatByData - * @param {Array} imgData - * @returns {Number} - */ -cc.getImageFormatByData = function (imgData) { - // if it is a png file buffer. - if (imgData.length > 8 && imgData[0] === 0x89 - && imgData[1] === 0x50 - && imgData[2] === 0x4E - && imgData[3] === 0x47 - && imgData[4] === 0x0D - && imgData[5] === 0x0A - && imgData[6] === 0x1A - && imgData[7] === 0x0A) { - return cc.FMT_PNG; - } - - // if it is a tiff file buffer. - if (imgData.length > 2 && ((imgData[0] === 0x49 && imgData[1] === 0x49) - || (imgData[0] === 0x4d && imgData[1] === 0x4d) - || (imgData[0] === 0xff && imgData[1] === 0xd8))) { - return cc.FMT_TIFF; - } - return cc.FMT_UNKNOWN; -}; - -/** - * Another way to subclass: Using Google Closure. - * The following code was copied + pasted from goog.base / goog.inherits - * @method inherits - * @param {Function} childCtor - * @param {Function} parentCtor - */ -cc.inherits = function (childCtor, parentCtor) { - function tempCtor() {} - tempCtor.prototype = parentCtor.prototype; - childCtor.superClass_ = parentCtor.prototype; - childCtor.prototype = new tempCtor(); - childCtor.prototype.constructor = childCtor; - - // Copy "static" method, but doesn't generate subclasses. -// for( var i in parentCtor ) { -// childCtor[ i ] = parentCtor[ i ]; -// } -}; - -/** - * @deprecated since v3.0, please use cc._Class.extend and _super - * @cc._Class.extend - */ -cc.base = function(me, opt_methodName, var_args) { - var caller = arguments.callee.caller; - if (caller.superClass_) { - // This is a constructor. Call the superclass constructor. - ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1)); - return ret; - } - - var args = Array.prototype.slice.call(arguments, 2); - var foundCaller = false; - for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) { - if (ctor.prototype[opt_methodName] === caller) { - foundCaller = true; - } else if (foundCaller) { - return ctor.prototype[opt_methodName].apply(me, args); - } - } - - // If we did not find the caller in the prototype chain, - // then one of two things happened: - // 1) The caller is an instance method. - // 2) This method was not called by the right caller. - if (me[opt_methodName] === caller) { - return me.constructor.prototype[opt_methodName].apply(me, args); - } else { - throw Error( - 'cc.base called from a method of one name ' + - 'to a method of a different name'); - } -}; diff --git a/cocos2d/core/platform/CCConfig.js b/cocos2d/core/platform/CCConfig.js deleted file mode 100644 index a384437a16..0000000000 --- a/cocos2d/core/platform/CCConfig.js +++ /dev/null @@ -1,319 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -/** - * The current version of Cocos2d-JS being used.
- * Please DO NOT remove this String, it is an important flag for bug tracking.
- * If you post a bug to forum, please attach this flag. - * @type {String} - * @name cc.ENGINE_VERSION - */ -var engineVersion; -if (CC_EDITOR) { - engineVersion = 'Cocos Creator v' + Editor.remote.versions.CocosCreator; -} else { - engineVersion = 'Cocos Creator'; -} -window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion; - -/** - *

- * If enabled, the texture coordinates will be calculated by using this formula:
- * - texCoord.left = (rect.x*2+1) / (texture.wide*2);
- * - texCoord.right = texCoord.left + (rect.width*2-2)/(texture.wide*2);
- *
- * The same for bottom and top.
- *
- * This formula prevents artifacts by using 99% of the texture.
- * The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
- *
- * Affected nodes:
- * - _ccsg.Sprite / cc.SpriteBatchNode and subclasses: cc.LabelBMFont, cc.TMXTiledMap
- * - cc.LabelAtlas
- * - cc.QuadParticleSystem
- * - cc.TileMap
- *
- * To enabled set it to 1. Disabled by default.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * - * @property {Number} FIX_ARTIFACTS_BY_STRECHING_TEXEL - * @readonly - */ -cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL = 0; - -/** - * Position of the FPS (Default: 0,0 (bottom-left corner))
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - * @property {Vec2} DIRECTOR_STATS_POSITION - * @readonly - */ -cc.DIRECTOR_STATS_POSITION = cc.p(0, 0); - -/** - *

- * Seconds between FPS updates.
- * 0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
- * Having a bigger number means a more reliable FPS
- *
- * Default value: 0.1f
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} DIRECTOR_FPS_INTERVAL - * @readonly - */ -cc.DIRECTOR_FPS_INTERVAL = 0.5; - -/** - *

- * If enabled, the ccsg.Node objects (_ccsg.Sprite, _ccsg.Label,etc) will be able to render in subpixels.
- * If disabled, integer pixels will be used.
- *
- * To enable set it to 1. Enabled by default.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} COCOSNODE_RENDER_SUBPIXEL - * @readonly - */ -cc.COCOSNODE_RENDER_SUBPIXEL = 1; - -/** - *

- * If enabled, the _ccsg.Sprite objects rendered with cc.SpriteBatchNode will be able to render in subpixels.
- * If disabled, integer pixels will be used.
- *
- * To enable set it to 1. Enabled by default.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} SPRITEBATCHNODE_RENDER_SUBPIXEL - * @readonly - */ -cc.SPRITEBATCHNODE_RENDER_SUBPIXEL = 1; - -/** - *

- * Automatically premultiply alpha for PNG resources - *

- * @property {Number} AUTO_PREMULTIPLIED_ALPHA_FOR_PNG - * @readonly - */ -cc.AUTO_PREMULTIPLIED_ALPHA_FOR_PNG = 0; - -/** - *

- * If most of your images have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
- * Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)
- *
- * To enable set it to a value different than 0. Enabled by default.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA - * @readonly - */ -cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA = 0; - -/** - *

- * Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas.
- * It seems it is the recommend way, but it is much slower, so, enable it at your own risk
- *
- * To enable set it to a value different than 0. Disabled by default.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} TEXTURE_ATLAS_USE_TRIANGLE_STRIP - * @readonly - */ -cc.TEXTURE_ATLAS_USE_TRIANGLE_STRIP = 0; - -/** - *

- * By default, cc.TextureAtlas (used by many cocos2d classes) will use VAO (Vertex Array Objects).
- * Apple recommends its usage but they might consume a lot of memory, specially if you use many of them.
- * So for certain cases, where you might need hundreds of VAO objects, it might be a good idea to disable it.
- *
- * To disable it set it to 0. disable by default.(Not Supported on WebGL)
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @property {Number} TEXTURE_ATLAS_USE_VAO - * @readonly - */ -cc.TEXTURE_ATLAS_USE_VAO = 0; - -/** - *

- * If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures.
- * NPOT textures have the following limitations:
- * - They can't have mipmaps
- * - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}
- *
- * To enable set it to a value different than 0. Disabled by default.
- *
- * This value governs only the PNG, GIF, BMP, images.
- * This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @readonly - * @type {Number} - * @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it. - */ -cc.TEXTURE_NPOT_SUPPORT = 0; - -/** - *

- * If enabled, cocos2d supports retina display.
- * For performance reasons, it's recommended disable it in games without retina display support, like iPad only games.
- *
- * To enable set it to 1. Use 0 to disable it. Enabled by default.
- *
- * This value governs only the PNG, GIF, BMP, images.
- * This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value.
- * To modify it, in Web engine please refer to CCConfig.js, in JSB please refer to CCConfig.h - *

- * @readonly - * @type {Number} - * @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it. - */ -cc.RETINA_DISPLAY_SUPPORT = 1; - -/** - *

- * It's the suffix that will be appended to the files in order to load "retina display" images.
- *
- * On an iPhone4 with Retina Display support enabled, the file @"sprite-hd.png" will be loaded instead of @"sprite.png".
- * If the file doesn't exist it will use the non-retina display image.
- *
- * Platforms: Only used on Retina Display devices like iPhone 4. - *

- * @property {String} RETINA_DISPLAY_FILENAME_SUFFIX - * @readonly - */ -cc.RETINA_DISPLAY_FILENAME_SUFFIX = '-hd'; - -/** - *

- * If enabled, it will use LA88 (Luminance Alpha 16-bit textures) for CCLabelTTF objects.
- * If it is disabled, it will use A8 (Alpha 8-bit textures).
- * LA88 textures are 6% faster than A8 textures, but they will consume 2x memory.
- *
- * This feature is enabled by default. - *

- * @property {Number} USE_LA88_LABELS - * @readonly - */ -cc.USE_LA88_LABELS = 1; - -/** - *

- * If enabled, all subclasses of _ccsg.Sprite will draw a bounding box
- * Useful for debugging purposes only. It is recommend to leave it disabled.
- *
- * To enable set it to a value different than 0. Disabled by default:
- * 0 -- disabled
- * 1 -- draw bounding box
- * 2 -- draw texture box - *

- * @property {Number} SPRITE_DEBUG_DRAW - * @readonly - */ -cc.SPRITE_DEBUG_DRAW = 0; - -/** - *

- * If enabled, all subclasses of _ccsg.Sprite that are rendered using an cc.SpriteBatchNode draw a bounding box.
- * Useful for debugging purposes only. It is recommend to leave it disabled.
- *
- * To enable set it to a value different than 0. Disabled by default. - *

- * @property {Number} SPRITEBATCHNODE_DEBUG_DRAW - * @readonly - */ -cc.SPRITEBATCHNODE_DEBUG_DRAW = 0; - -/** - *

- * If enabled, all subclasses of cc.LabelBMFont will draw a bounding box
- * Useful for debugging purposes only. It is recommend to leave it disabled.
- *
- * To enable set it to a value different than 0. Disabled by default.
- *

- * @property {Number} LABELBMFONT_DEBUG_DRAW - * @readonly - */ -cc.LABELBMFONT_DEBUG_DRAW = 0; - -/** - *

- * If enabled, all subclasses of cc.LabelAtlas will draw a bounding box
- * Useful for debugging purposes only. It is recommend to leave it disabled.
- *
- * To enable set it to a value different than 0. Disabled by default. - *

- * @property {Number} LABELATLAS_DEBUG_DRAW - * @readonly - */ -cc.LABELATLAS_DEBUG_DRAW = 0; - -/** - * Whether or not support retina display - * @property {Number} IS_RETINA_DISPLAY_SUPPORTED - * @readonly - */ -cc.IS_RETINA_DISPLAY_SUPPORTED = 1; - -/** - * Default engine - * @property {String} DEFAULT_ENGINE - * @readonly - */ -cc.DEFAULT_ENGINE = cc.ENGINE_VERSION + '-canvas'; - -/** - *

- * If enabled, actions that alter the position property (eg: CCMoveBy, CCJumpBy, CCBezierBy, etc..) will be stacked.
- * If you run 2 or more 'position' actions at the same time on a node, then end position will be the sum of all the positions.
- * If disabled, only the last run action will take effect. - *

- * @property {Number} ENABLE_STACKABLE_ACTIONS - * @readonly - */ -cc.ENABLE_STACKABLE_ACTIONS = 1; - -/** - *

- * If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches.
- * In order to use them, you have to use the following functions, instead of the the GL ones:
- * - ccGLUseProgram() instead of glUseProgram()
- * - ccGLDeleteProgram() instead of glDeleteProgram()
- * - ccGLBlendFunc() instead of glBlendFunc()
- *
- * If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache.
- * It is recommend to enable whenever possible to improve speed.
- * If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on. - *

- * @property {Number} ENABLE_GL_STATE_CACHE - * @readonly - */ -cc.ENABLE_GL_STATE_CACHE = 1; \ No newline at end of file diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index 830039c188..22da1cb40a 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -24,71 +24,1541 @@ THE SOFTWARE. ****************************************************************************/ -/** - * @property {Number} INVALID_INDEX - * @readonly - */ -cc.INVALID_INDEX = -1; +require('./_CCClass'); + +cc._tmp = cc._tmp || {}; /** - * PI is the ratio of a circle's circumference to its diameter. - * @property {Number} PI + * Key map for keyboard event + * @enum KEY * @readonly + * @type {Object} + * @example {@link utils/api/engine/docs/cocos2d/core/platform/CCCommon/KEY.js} */ -cc.PI = Math.PI; +cc.KEY = { + /** + * @property none + * @type {Number} + * @readonly + */ + none:0, -/** - * @property {Number} FLT_MAX - * @readonly - */ -cc.FLT_MAX = parseFloat('3.402823466e+38F'); + // android + /** + * @property back + * @type {Number} + * @readonly + */ + back:6, + /** + * @property menu + * @type {Number} + * @readonly + */ + menu:18, -/** - * @property {Number} FLT_MIN - * @readonly - */ -cc.FLT_MIN = parseFloat("1.175494351e-38F"); + /** + * @property backspace + * @type {Number} + * @readonly + */ + backspace:8, + /** + * @property tab + * @type {Number} + * @readonly + */ + tab:9, -/** - * @property {Number} RAD - * @readonly - */ -cc.RAD = cc.PI / 180; + /** + * @property enter + * @type {Number} + * @readonly + */ + enter:13, -/** - * @property {Number} DEG - * @readonly - */ -cc.DEG = 180 / cc.PI; + /** + * @property shift + * @type {Number} + * @readonly + */ + shift:16, //should use shiftkey instead + /** + * @property ctrl + * @type {Number} + * @readonly + */ + ctrl:17, //should use ctrlkey + /** + * @property alt + * @type {Number} + * @readonly + */ + alt:18, //should use altkey + /** + * @property pause + * @type {Number} + * @readonly + */ + pause:19, + /** + * @property capslock + * @type {Number} + * @readonly + */ + capslock:20, + /** + * @property escape + * @type {Number} + * @readonly + */ + escape:27, + /** + * @property space + * @type {Number} + * @readonly + */ + space:32, + /** + * @property pageup + * @type {Number} + * @readonly + */ + pageup:33, + /** + * @property pagedown + * @type {Number} + * @readonly + */ + pagedown:34, + /** + * @property end + * @type {Number} + * @readonly + */ + end:35, + /** + * @property home + * @type {Number} + * @readonly + */ + home:36, + /** + * @property left + * @type {Number} + * @readonly + */ + left:37, + /** + * @property up + * @type {Number} + * @readonly + */ + up:38, + /** + * @property right + * @type {Number} + * @readonly + */ + right:39, + /** + * @property down + * @type {Number} + * @readonly + */ + down:40, + /** + * @property select + * @type {Number} + * @readonly + */ + select:41, -/** - * maximum unsigned int value - * @property {Number} UINT_MAX - * @readonly - */ -cc.UINT_MAX = 0xffffffff; + /** + * @property insert + * @type {Number} + * @readonly + */ + insert:45, + /** + * @property Delete + * @type {Number} + * @readonly + */ + Delete:46, + /** + * @property 0 + * @type {Number} + * @readonly + */ + 0:48, + /** + * @property 1 + * @type {Number} + * @readonly + */ + 1:49, + /** + * @property 2 + * @type {Number} + * @readonly + */ + 2:50, + /** + * @property 3 + * @type {Number} + * @readonly + */ + 3:51, + /** + * @property 4 + * @type {Number} + * @readonly + */ + 4:52, + /** + * @property 5 + * @type {Number} + * @readonly + */ + 5:53, + /** + * @property 6 + * @type {Number} + * @readonly + */ + 6:54, + /** + * @property 7 + * @type {Number} + * @readonly + */ + 7:55, + /** + * @property 8 + * @type {Number} + * @readonly + */ + 8:56, + /** + * @property 9 + * @type {Number} + * @readonly + */ + 9:57, + /** + * @property a + * @type {Number} + * @readonly + */ + a:65, + /** + * @property b + * @type {Number} + * @readonly + */ + b:66, + /** + * @property c + * @type {Number} + * @readonly + */ + c:67, + /** + * @property d + * @type {Number} + * @readonly + */ + d:68, + /** + * @property e + * @type {Number} + * @readonly + */ + e:69, + /** + * @property f + * @type {Number} + * @readonly + */ + f:70, + /** + * @property g + * @type {Number} + * @readonly + */ + g:71, + /** + * @property h + * @type {Number} + * @readonly + */ + h:72, + /** + * @property i + * @type {Number} + * @readonly + */ + i:73, + /** + * @property j + * @type {Number} + * @readonly + */ + j:74, + /** + * @property k + * @type {Number} + * @readonly + */ + k:75, + /** + * @property l + * @type {Number} + * @readonly + */ + l:76, + /** + * @property m + * @type {Number} + * @readonly + */ + m:77, + /** + * @property n + * @type {Number} + * @readonly + */ + n:78, + /** + * @property o + * @type {Number} + * @readonly + */ + o:79, + /** + * @property p + * @type {Number} + * @readonly + */ + p:80, + /** + * @property q + * @type {Number} + * @readonly + */ + q:81, + /** + * @property r + * @type {Number} + * @readonly + */ + r:82, + /** + * @property s + * @type {Number} + * @readonly + */ + s:83, + /** + * @property t + * @type {Number} + * @readonly + */ + t:84, + /** + * @property u + * @type {Number} + * @readonly + */ + u:85, + /** + * @property v + * @type {Number} + * @readonly + */ + v:86, + /** + * @property w + * @type {Number} + * @readonly + */ + w:87, + /** + * @property x + * @type {Number} + * @readonly + */ + x:88, + /** + * @property y + * @type {Number} + * @readonly + */ + y:89, + /** + * @property z + * @type {Number} + * @readonly + */ + z:90, -/** - *

- * simple macro that swaps 2 variables
- * modified from c++ macro, you need to pass in the x and y variables names in string,
- * and then a reference to the whole object as third variable - *

- * @param {String} x - * @param {String} y - * @param {Object} ref - * @method swap - * @deprecated since v3.0 - */ -cc.swap = function (x, y, ref) { - if (cc.js.isObject(ref) && !cc.js.isUndefined(ref.x) && !cc.js.isUndefined(ref.y)) { - var tmp = ref[x]; - ref[x] = ref[y]; - ref[y] = tmp; - } else - cc.log(cc._LogInfos.swap); + /** + * @property num0 + * @type {Number} + * @readonly + */ + num0:96, + /** + * @property num1 + * @type {Number} + * @readonly + */ + num1:97, + /** + * @property num2 + * @type {Number} + * @readonly + */ + num2:98, + /** + * @property num3 + * @type {Number} + * @readonly + */ + num3:99, + /** + * @property num4 + * @type {Number} + * @readonly + */ + num4:100, + /** + * @property num5 + * @type {Number} + * @readonly + */ + num5:101, + /** + * @property num6 + * @type {Number} + * @readonly + */ + num6:102, + /** + * @property num7 + * @type {Number} + * @readonly + */ + num7:103, + /** + * @property num8 + * @type {Number} + * @readonly + */ + num8:104, + /** + * @property num9 + * @type {Number} + * @readonly + */ + num9:105, + /** + * @property {Number} * + * @readonly + */ + '*':106, + /** + * @property {Number} + + * @readonly + */ + '+':107, + /** + * @property {Number} - + * @readonly + */ + '-':109, + /** + * @property numdel + * @type {Number} + * @readonly + */ + 'numdel':110, + /** + * @property {Number} / + * @readonly + */ + '/':111, + /** + * @property f1 + * @type {Number} + * @readonly + */ + f1:112, //f1-f12 dont work on ie + /** + * @property f2 + * @type {Number} + * @readonly + */ + f2:113, + /** + * @property f3 + * @type {Number} + * @readonly + */ + f3:114, + /** + * @property f4 + * @type {Number} + * @readonly + */ + f4:115, + /** + * @property f5 + * @type {Number} + * @readonly + */ + f5:116, + /** + * @property f6 + * @type {Number} + * @readonly + */ + f6:117, + /** + * @property f7 + * @type {Number} + * @readonly + */ + f7:118, + /** + * @property f8 + * @type {Number} + * @readonly + */ + f8:119, + /** + * @property f9 + * @type {Number} + * @readonly + */ + f9:120, + /** + * @property f10 + * @type {Number} + * @readonly + */ + f10:121, + /** + * @property f11 + * @type {Number} + * @readonly + */ + f11:122, + /** + * @property f12 + * @type {Number} + * @readonly + */ + f12:123, + + /** + * @property numlock + * @type {Number} + * @readonly + */ + numlock:144, + /** + * @property scrolllock + * @type {Number} + * @readonly + */ + scrolllock:145, + + /** + * @property {Number} ; + * @readonly + */ + ';':186, + /** + * @property semicolon + * @type {Number} + * @readonly + */ + semicolon:186, + /** + * @property equal + * @type {Number} + * @readonly + */ + equal:187, + /** + * @property {Number} = + * @readonly + */ + '=':187, + /** + * @property {Number} , + * @readonly + */ + ',':188, + /** + * @property comma + * @type {Number} + * @readonly + */ + comma:188, + /** + * @property dash + * @type {Number} + * @readonly + */ + dash:189, + /** + * @property {Number} . + * @readonly + */ + '.':190, + /** + * @property period + * @type {Number} + * @readonly + */ + period:190, + /** + * @property forwardslash + * @type {Number} + * @readonly + */ + forwardslash:191, + /** + * @property grave + * @type {Number} + * @readonly + */ + grave:192, + /** + * @property {Number} [ + * @readonly + */ + '[':219, + /** + * @property openbracket + * @type {Number} + * @readonly + */ + openbracket:219, + /** + * @property backslash + * @type {Number} + * @readonly + */ + backslash:220, + /** + * @property {Number} ] + * @readonly + */ + ']':221, + /** + * @property closebracket + * @type {Number} + * @readonly + */ + closebracket:221, + /** + * @property quote + * @type {Number} + * @readonly + */ + quote:222, + + // gamepad controll + /** + * @property dpadLeft + * @type {Number} + * @readonly + */ + dpadLeft:1000, + /** + * @property dpadRight + * @type {Number} + * @readonly + */ + dpadRight:1001, + /** + * @property dpadUp + * @type {Number} + * @readonly + */ + dpadUp:1003, + /** + * @property dpadDown + * @type {Number} + * @readonly + */ + dpadDown:1004, + /** + * @property dpadCenter + * @type {Number} + * @readonly + */ + dpadCenter:1005 }; +/** + * @module cc + */ + +/** + * Image formats + * @enum ImageFormat + * @static + * @namespace cc + */ +cc.ImageFormat = cc.Enum({ + /** + * Image Format:JPG + * @property JPG + * @type {Number} + * @static + */ + JPG: 0, + /** + * Image Format:PNG + * @property PNG + * @type {Number} + * @static + */ + PNG: 1, + /** + * Image Format:TIFF + * @property TIFF + * @type {Number} + * @static + */ + TIFF: 2, + /** + * Image Format:RAWDATA + * @property RAWDATA + * @type {Number} + * @static + */ + RAWDATA: 3, + /** + * Image Format:WEBP + * @property WEBP + * @type {Number} + * @static + */ + WEBP: 4, + /** + * Image Format:UNKNOWN + * @property UNKNOWN + * @type {Number} + * @static + */ + UNKNOWN: 5 +}); + +/** + * get image format by image data + * @method getImageFormatByData + * @param {Array} imgData + * @returns {Number} + */ +cc.getImageFormatByData = function (imgData) { + // if it is a png file buffer. + if (imgData.length > 8 && imgData[0] === 0x89 + && imgData[1] === 0x50 + && imgData[2] === 0x4E + && imgData[3] === 0x47 + && imgData[4] === 0x0D + && imgData[5] === 0x0A + && imgData[6] === 0x1A + && imgData[7] === 0x0A) { + return cc.ImageFormat.PNG; + } + + // if it is a tiff file buffer. + if (imgData.length > 2 && ((imgData[0] === 0x49 && imgData[1] === 0x49) + || (imgData[0] === 0x4d && imgData[1] === 0x4d) + || (imgData[0] === 0xff && imgData[1] === 0xd8))) { + return cc.ImageFormat.TIFF; + } + return cc.ImageFormat.UNKNOWN; +}; + +/** + * Predefined constants + * @enum Macro + * @static + * @type {Object} + * @namespace cc + */ +cc.Macro = { + /** + * @property INVALID_INDEX + * @type {Number} + * @readonly + */ + INVALID_INDEX: -1, + + /** + * PI is the ratio of a circle's circumference to its diameter. + * @property PI + * @type {Number} + * @readonly + */ + PI: Math.PI, + + /** + * PI * 2 + * @property PI2 + * @type {Number} + * @readonly + */ + PI2: Math.PI * 2, + + /** + * Maximum float value + * @property FLT_MAX + * @type {Number} + * @readonly + */ + FLT_MAX: parseFloat('3.402823466e+38F'), + + /** + * Minimum float value + * @property FLT_MIN + * @type {Number} + * @readonly + */ + FLT_MIN: parseFloat("1.175494351e-38F"), + + /** + * PI / 180 + * @property RAD + * @type {Number} + * @readonly + */ + RAD: Math.PI / 180, + + /** + * One degree + * @property DEG + * @type {Number} + * @readonly + */ + DEG: 180 / Math.PI, + + /** + * Maximum unsigned int value + * @property UINT_MAX + * @type {Number} + * @readonly + */ + UINT_MAX: 0xffffffff, + + /** + * @property REPEAT_FOREVER + * @type {Number} + * @readonly + */ + REPEAT_FOREVER: cc.sys.isNative ? 0xffffffff : (Number.MAX_VALUE - 1), + + /** + * @property FLT_EPSILON + * @type {Number} + * @readonly + */ + FLT_EPSILON: 0.0000001192092896, + + //some gl constant variable + /** + * @property ONE + * @type {Number} + * @readonly + */ + ONE: 1, + + /** + * @property ZERO + * @type {Number} + * @readonly + */ + ZERO: 0, + + /** + * @property SRC_ALPHA + * @type {Number} + * @readonly + */ + SRC_ALPHA: 0x0302, + + /** + * @property SRC_ALPHA_SATURATE + * @type {Number} + * @readonly + */ + SRC_ALPHA_SATURATE: 0x308, + + /** + * @property SRC_COLOR + * @type {Number} + * @readonly + */ + SRC_COLOR: 0x300, + + /** + * @property DST_ALPHA + * @type {Number} + * @readonly + */ + DST_ALPHA: 0x304, + + /** + * @property DST_COLOR + * @type {Number} + * @readonly + */ + DST_COLOR: 0x306, + + /** + * @property ONE_MINUS_SRC_ALPHA + * @type {Number} + * @readonly + */ + ONE_MINUS_SRC_ALPHA: 0x0303, + + /** + * @property ONE_MINUS_SRC_COLOR + * @type {Number} + * @readonly + */ + ONE_MINUS_SRC_COLOR: 0x301, + + /** + * @property ONE_MINUS_DST_ALPHA + * @type {Number} + * @readonly + */ + ONE_MINUS_DST_ALPHA: 0x305, + + /** + * @property ONE_MINUS_DST_COLOR + * @type {Number} + * @readonly + */ + ONE_MINUS_DST_COLOR: 0x0307, + + /** + * @property ONE_MINUS_CONSTANT_ALPHA + * @type {Number} + * @readonly + */ + ONE_MINUS_CONSTANT_ALPHA: 0x8004, + + /** + * @property ONE_MINUS_CONSTANT_COLOR + * @type {Number} + * @readonly + */ + ONE_MINUS_CONSTANT_COLOR: 0x8002, + + /** + * the constant variable equals gl.LINEAR for texture + * @property LINEAR + * @type {Number} + * @readonly + */ + LINEAR: 0x2601, + + /** + * default gl blend dst function. Compatible with premultiplied alpha images. + * @property BLEND_DST + * @type {Number} + * @readonly + */ + BLEND_DST: 0x0303, + + + //Possible device orientations + /** + * Device oriented vertically, home button on the bottom (UIDeviceOrientationPortrait) + * @property DEVICE_ORIENTATION_PORTRAIT + * @type {Number} + * @readonly + */ + DEVICE_ORIENTATION_PORTRAIT: 0, + + /** + * Device oriented horizontally, home button on the right (UIDeviceOrientationLandscapeLeft) + * @property DEVICE_ORIENTATION_LANDSCAPE_LEFT + * @type {Number} + * @readonly + */ + DEVICE_ORIENTATION_LANDSCAPE_LEFT: 1, + + /** + * Device oriented vertically, home button on the top (UIDeviceOrientationPortraitUpsideDown) + * @property DEVICE_ORIENTATION_PORTRAIT_UPSIDE_DOWN + * @type {Number} + * @readonly + */ + DEVICE_ORIENTATION_PORTRAIT_UPSIDE_DOWN: 2, + + /** + * Device oriented horizontally, home button on the left (UIDeviceOrientationLandscapeRight) + * @property DEVICE_ORIENTATION_LANDSCAPE_RIGHT + * @type {Number} + * @readonly + */ + DEVICE_ORIENTATION_LANDSCAPE_RIGHT: 3, + + /** + * In browsers, we only support 2 orientations by change window size. + * @property DEVICE_MAX_ORIENTATIONS + * @type {Number} + * @readonly + */ + DEVICE_MAX_ORIENTATIONS: 2, + + + // ------------------- vertex attrib flags ----------------------------- + /** + * @property VERTEX_ATTRIB_FLAG_NONE + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_FLAG_NONE: 0, + /** + * @property VERTEX_ATTRIB_FLAG_POSITION + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_FLAG_POSITION: 1 << 0, + /** + * @property VERTEX_ATTRIB_FLAG_COLOR + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_FLAG_COLOR: 1 << 1, + /** + * @property VERTEX_ATTRIB_FLAG_TEX_COORDS + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_FLAG_TEX_COORDS: 1 << 2, + /** + * @property VERTEX_ATTRIB_FLAG_POS_COLOR_TEX + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_FLAG_POS_COLOR_TEX: ( (1 << 0) | (1 << 1) | (1 << 2) ), + + /** + * GL server side states + * @property GL_ALL + * @type {Number} + * @readonly + */ + GL_ALL: 0, + + //-------------Vertex Attributes----------- + /** + * @property VERTEX_ATTRIB_POSITION + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_POSITION: 0, + /** + * @property VERTEX_ATTRIB_COLOR + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_COLOR: 1, + /** + * @property VERTEX_ATTRIB_TEX_COORDS + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_TEX_COORDS: 2, + /** + * @property VERTEX_ATTRIB_MAX + * @type {Number} + * @readonly + */ + VERTEX_ATTRIB_MAX: 3, + + //------------Uniforms------------------ + /** + * @property UNIFORM_PMATRIX + * @type {Number} + * @readonly + */ + UNIFORM_PMATRIX: 0, + /** + * @property UNIFORM_MVMATRIX + * @type {Number} + * @readonly + */ + UNIFORM_MVMATRIX: 1, + /** + * @property UNIFORM_MVPMATRIX + * @type {Number} + * @readonly + */ + UNIFORM_MVPMATRIX: 2, + /** + * @property UNIFORM_TIME + * @type {Number} + * @readonly + */ + UNIFORM_TIME: 3, + /** + * @property UNIFORM_SINTIME + * @type {Number} + * @readonly + */ + UNIFORM_SINTIME: 4, + /** + * @property UNIFORM_COSTIME + * @type {Number} + * @readonly + */ + UNIFORM_COSTIME: 5, + /** + * @property UNIFORM_RANDOM01 + * @type {Number} + * @readonly + */ + UNIFORM_RANDOM01: 6, + /** + * @property UNIFORM_SAMPLER + * @type {Number} + * @readonly + */ + UNIFORM_SAMPLER: 7, + /** + * @property UNIFORM_MAX + * @type {Number} + * @readonly + */ + UNIFORM_MAX: 8, + + //------------Shader Name--------------- + /** + * @property SHADER_POSITION_TEXTURECOLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_TEXTURECOLOR: "ShaderPositionTextureColor", + /** + * @property SHADER_POSITION_TEXTURECOLORALPHATEST + * @type {String} + * @readonly + */ + SHADER_POSITION_TEXTURECOLORALPHATEST: "ShaderPositionTextureColorAlphaTest", + /** + * @property SHADER_POSITION_COLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_COLOR: "ShaderPositionColor", + /** + * @property SHADER_POSITION_TEXTURE + * @type {String} + * @readonly + */ + SHADER_POSITION_TEXTURE: "ShaderPositionTexture", + /** + * @property SHADER_POSITION_TEXTURE_UCOLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_TEXTURE_UCOLOR: "ShaderPositionTexture_uColor", + /** + * @property SHADER_POSITION_TEXTUREA8COLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_TEXTUREA8COLOR: "ShaderPositionTextureA8Color", + /** + * @property SHADER_POSITION_UCOLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_UCOLOR: "ShaderPosition_uColor", + /** + * @property SHADER_POSITION_LENGTHTEXTURECOLOR + * @type {String} + * @readonly + */ + SHADER_POSITION_LENGTHTEXTURECOLOR: "ShaderPositionLengthTextureColor", + + //------------uniform names---------------- + /** + * @property UNIFORM_PMATRIX_S + * @type {String} + * @readonly + */ + UNIFORM_PMATRIX_S: "CC_PMatrix", + /** + * @property UNIFORM_MVMATRIX_S + * @type {String} + * @readonly + */ + UNIFORM_MVMATRIX_S: "CC_MVMatrix", + /** + * @property UNIFORM_MVPMATRIX_S + * @type {String} + * @readonly + */ + UNIFORM_MVPMATRIX_S: "CC_MVPMatrix", + /** + * @property UNIFORM_TIME_S + * @type {String} + * @readonly + */ + UNIFORM_TIME_S: "CC_Time", + /** + * @property UNIFORM_SINTIME_S + * @type {String} + * @readonly + */ + UNIFORM_SINTIME_S: "CC_SinTime", + /** + * @property UNIFORM_COSTIME_S + * @type {String} + * @readonly + */ + UNIFORM_COSTIME_S: "CC_CosTime", + /** + * @property UNIFORM_RANDOM01_S + * @type {String} + * @readonly + */ + UNIFORM_RANDOM01_S: "CC_Random01", + /** + * @property UNIFORM_SAMPLER_S + * @type {String} + * @readonly + */ + UNIFORM_SAMPLER_S: "CC_Texture0", + /** + * @property UNIFORM_ALPHA_TEST_VALUE_S + * @type {String} + * @readonly + */ + UNIFORM_ALPHA_TEST_VALUE_S: "CC_alpha_value", + + //------------Attribute names-------------- + /** + * @property ATTRIBUTE_NAME_COLOR + * @type {String} + * @readonly + */ + ATTRIBUTE_NAME_COLOR: "a_color", + /** + * @property ATTRIBUTE_NAME_POSITION + * @type {String} + * @readonly + */ + ATTRIBUTE_NAME_POSITION: "a_position", + /** + * @property ATTRIBUTE_NAME_TEX_COORD + * @type {String} + * @readonly + */ + ATTRIBUTE_NAME_TEX_COORD: "a_texCoord", + + + /** + * default size for font size + * @property ITEM_SIZE + * @type {Number} + * @readonly + */ + ITEM_SIZE: 32, + + /** + * default tag for current item + * @property CURRENT_ITEM + * @type {Number} + * @readonly + */ + CURRENT_ITEM: 0xc0c05001, + /** + * default tag for zoom action tag + * @property ZOOM_ACTION_TAG + * @type {Number} + * @readonly + */ + ZOOM_ACTION_TAG: 0xc0c05002, + /** + * default tag for normal + * @property NORMAL_TAG + * @type {Number} + * @readonly + */ + NORMAL_TAG: 8801, + + /** + * default selected tag + * @property SELECTED_TAG + * @type {Number} + * @readonly + */ + SELECTED_TAG: 8802, + + /** + * default disabled tag + * @property DISABLE_TAG + * @type {Number} + * @readonly + */ + DISABLE_TAG: 8803, + + // General configurations + /** + *

+ * If enabled, the texture coordinates will be calculated by using this formula:
+ * - texCoord.left = (rect.x*2+1) / (texture.wide*2);
+ * - texCoord.right = texCoord.left + (rect.width*2-2)/(texture.wide*2);
+ *
+ * The same for bottom and top.
+ *
+ * This formula prevents artifacts by using 99% of the texture.
+ * The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
+ *
+ * Affected nodes:
+ * - _ccsg.Sprite / cc.SpriteBatchNode and subclasses: cc.LabelBMFont, _ccsg.TMXTiledMap
+ * - cc.LabelAtlas
+ * - cc.QuadParticleSystem
+ * - cc.TileMap
+ *
+ * To enabled set it to 1. Disabled by default.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * + * @property {Number} FIX_ARTIFACTS_BY_STRECHING_TEXEL + * @readonly + */ + FIX_ARTIFACTS_BY_STRECHING_TEXEL: 0, + + /** + * Position of the FPS (Default: 0,0 (bottom-left corner))
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + * @property {Vec2} DIRECTOR_STATS_POSITION + * @readonly + */ + DIRECTOR_STATS_POSITION: cc.p(0, 0), + + /** + *

+ * Seconds between FPS updates.
+ * 0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
+ * Having a bigger number means a more reliable FPS
+ *
+ * Default value: 0.1f
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} DIRECTOR_FPS_INTERVAL + * @readonly + */ + DIRECTOR_FPS_INTERVAL: 0.5, + + /** + *

+ * If enabled, the ccsg.Node objects (_ccsg.Sprite, _ccsg.Label,etc) will be able to render in subpixels.
+ * If disabled, integer pixels will be used.
+ *
+ * To enable set it to 1. Enabled by default.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} COCOSNODE_RENDER_SUBPIXEL + * @readonly + */ + COCOSNODE_RENDER_SUBPIXEL: 1, + + /** + *

+ * If enabled, the _ccsg.Sprite objects rendered with cc.SpriteBatchNode will be able to render in subpixels.
+ * If disabled, integer pixels will be used.
+ *
+ * To enable set it to 1. Enabled by default.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} SPRITEBATCHNODE_RENDER_SUBPIXEL + * @readonly + */ + SPRITEBATCHNODE_RENDER_SUBPIXEL: 1, + + /** + *

+ * Automatically premultiply alpha for PNG resources + *

+ * @property {Number} AUTO_PREMULTIPLIED_ALPHA_FOR_PNG + * @readonly + */ + AUTO_PREMULTIPLIED_ALPHA_FOR_PNG: 0, + + /** + *

+ * If most of your images have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
+ * Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)
+ *
+ * To enable set it to a value different than 0. Enabled by default.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA + * @readonly + */ + OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA: 0, + + /** + *

+ * Use GL_TRIANGLE_STRIP instead of GL_TRIANGLES when rendering the texture atlas.
+ * It seems it is the recommend way, but it is much slower, so, enable it at your own risk
+ *
+ * To enable set it to a value different than 0. Disabled by default.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} TEXTURE_ATLAS_USE_TRIANGLE_STRIP + * @readonly + */ + TEXTURE_ATLAS_USE_TRIANGLE_STRIP: 0, + + /** + *

+ * By default, cc.TextureAtlas (used by many cocos2d classes) will use VAO (Vertex Array Objects).
+ * Apple recommends its usage but they might consume a lot of memory, specially if you use many of them.
+ * So for certain cases, where you might need hundreds of VAO objects, it might be a good idea to disable it.
+ *
+ * To disable it set it to 0. disable by default.(Not Supported on WebGL)
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @property {Number} TEXTURE_ATLAS_USE_VAO + * @readonly + */ + TEXTURE_ATLAS_USE_VAO: 0, + + /** + *

+ * If enabled, NPOT textures will be used where available. Only 3rd gen (and newer) devices support NPOT textures.
+ * NPOT textures have the following limitations:
+ * - They can't have mipmaps
+ * - They only accept GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}
+ *
+ * To enable set it to a value different than 0. Disabled by default.
+ *
+ * This value governs only the PNG, GIF, BMP, images.
+ * This value DOES NOT govern the PVR (PVR.GZ, PVR.CCZ) files. If NPOT PVR is loaded, then it will create an NPOT texture ignoring this value.
+ * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h + *

+ * @readonly + * @type {Number} + * @deprecated This value will be removed in 1.1 and NPOT textures will be loaded by default if the device supports it. + */ + TEXTURE_NPOT_SUPPORT: 0, + + /** + *

+ * If enabled, it will use LA88 (Luminance Alpha 16-bit textures) for CCLabelTTF objects.
+ * If it is disabled, it will use A8 (Alpha 8-bit textures).
+ * LA88 textures are 6% faster than A8 textures, but they will consume 2x memory.
+ *
+ * This feature is enabled by default. + *

+ * @property {Number} USE_LA88_LABELS + * @readonly + */ + USE_LA88_LABELS: 1, + + /** + *

+ * If enabled, all subclasses of _ccsg.Sprite will draw a bounding box
+ * Useful for debugging purposes only. It is recommend to leave it disabled.
+ *
+ * To enable set it to a value different than 0. Disabled by default:
+ * 0 -- disabled
+ * 1 -- draw bounding box
+ * 2 -- draw texture box + *

+ * @property {Number} SPRITE_DEBUG_DRAW + * @readonly + */ + SPRITE_DEBUG_DRAW: 0, + + /** + *

+ * If enabled, all subclasses of cc.LabelBMFont will draw a bounding box
+ * Useful for debugging purposes only. It is recommend to leave it disabled.
+ *
+ * To enable set it to a value different than 0. Disabled by default.
+ *

+ * @property {Number} LABELBMFONT_DEBUG_DRAW + * @readonly + */ + LABELBMFONT_DEBUG_DRAW: 0, + + /** + *

+ * If enabled, all subclasses of cc.LabelAtlas will draw a bounding box
+ * Useful for debugging purposes only. It is recommend to leave it disabled.
+ *
+ * To enable set it to a value different than 0. Disabled by default. + *

+ * @property {Number} LABELATLAS_DEBUG_DRAW + * @readonly + */ + LABELATLAS_DEBUG_DRAW: 0, + + /** + *

+ * If enabled, actions that alter the position property (eg: CCMoveBy, CCJumpBy, CCBezierBy, etc..) will be stacked.
+ * If you run 2 or more 'position' actions at the same time on a node, then end position will be the sum of all the positions.
+ * If disabled, only the last run action will take effect. + *

+ * @property {Number} ENABLE_STACKABLE_ACTIONS + * @readonly + */ + ENABLE_STACKABLE_ACTIONS: 1, + + /** + *

+ * If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches.
+ * In order to use them, you have to use the following functions, instead of the the GL ones:
+ * - ccGLUseProgram() instead of glUseProgram()
+ * - ccGLDeleteProgram() instead of glDeleteProgram()
+ * - ccGLBlendFunc() instead of glBlendFunc()
+ *
+ * If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache.
+ * It is recommend to enable whenever possible to improve speed.
+ * If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on. + *

+ * @property {Number} ENABLE_GL_STATE_CACHE + * @readonly + */ + ENABLE_GL_STATE_CACHE: 1 +}; + +/** + * default gl blend src function. Compatible with premultiplied alpha images. + * @property BLEND_SRC + * @type {Number} + * @readonly + */ +cc.defineGetterSetter(cc.Macro, "BLEND_SRC", function (){ + if (cc._renderType === cc.game.RENDER_TYPE_WEBGL + && cc.Macro.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) { + return cc.Macro.ONE; + } + else { + return cc.Macro.SRC_ALPHA; + } +}); + /** *

* Linear interpolation between 2 numbers, the ratio sets how much it is biased to each end @@ -121,13 +1591,6 @@ cc.randomMinus1To1 = function () { return (Math.random() - 0.5) * 2; }; -/** - * returns a random float between 0 and 1 - * @return {Number} - * @method random0To1 - */ -cc.random0To1 = Math.random; - /** * converts degrees to radians * @param {Number} angle @@ -135,7 +1598,7 @@ cc.random0To1 = Math.random; * @method degreesToRadians */ cc.degreesToRadians = function (angle) { - return angle * cc.RAD; + return angle * cc.Macro.RAD; }; /** @@ -145,24 +1608,8 @@ cc.degreesToRadians = function (angle) { * @method radiansToDegrees */ cc.radiansToDegrees = function (angle) { - return angle * cc.DEG; + return angle * cc.Macro.DEG; }; -/** - * converts radians to degrees - * @param {Number} angle - * @return {Number} - * @method radiansToDegress - */ -cc.radiansToDegress = function (angle) { - cc.log(cc._LogInfos.radiansToDegress); - return angle * cc.DEG; -}; - -/** - * @property {Number} REPEAT_FOREVER - * @readonly - */ -cc.REPEAT_FOREVER = cc.sys.isNative ? 0xffffffff : (Number.MAX_VALUE - 1); /** * Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix @@ -178,7 +1625,7 @@ cc.nodeDrawSetup = function (node) { } }; -/** +/* *

* GL states that are enabled:
* - GL_TEXTURE_2D
@@ -188,16 +1635,16 @@ cc.nodeDrawSetup = function (node) { *

* @method enableDefaultGLStates */ -cc.enableDefaultGLStates = function () { +// cc.enableDefaultGLStates = function () { //TODO OPENGL STUFF /* glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D);*/ -}; +// }; -/** +/* *

* Disable default GL states:
* - GL_TEXTURE_2D
@@ -206,7 +1653,7 @@ cc.enableDefaultGLStates = function () { *

* @method disableDefaultGLStates */ -cc.disableDefaultGLStates = function () { +// cc.disableDefaultGLStates = function () { //TODO OPENGL /* glDisable(GL_TEXTURE_2D); @@ -214,7 +1661,7 @@ cc.disableDefaultGLStates = function () { glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); */ -}; +// }; /** *

@@ -228,120 +1675,6 @@ cc.incrementGLDraws = function (addNumber) { cc.g_NumberOfDraws += addNumber; }; -/** - * @property {Number} FLT_EPSILON - * @readonly - */ -cc.FLT_EPSILON = 0.0000001192092896; - -//some gl constant variable -/** - * @property {Number} ONE - * @readonly - */ -cc.ONE = 1; - -/** - * @property {Number} ZERO - * @readonly - */ -cc.ZERO = 0; - -/** - * @property {Number} SRC_ALPHA - * @readonly - */ -cc.SRC_ALPHA = 0x0302; - -/** - * @property {Number} SRC_ALPHA_SATURATE - * @readonly - */ -cc.SRC_ALPHA_SATURATE = 0x308; - -/** - * @property {Number} SRC_COLOR - * @readonly - */ -cc.SRC_COLOR = 0x300; - -/** - * @property {Number} DST_ALPHA - * @readonly - */ -cc.DST_ALPHA = 0x304; - -/** - * @property {Number} DST_COLOR - * @readonly - */ -cc.DST_COLOR = 0x306; - -/** - * @property {Number} ONE_MINUS_SRC_ALPHA - * @readonly - */ -cc.ONE_MINUS_SRC_ALPHA = 0x0303; - -/** - * @property {Number} ONE_MINUS_SRC_COLOR - * @readonly - */ -cc.ONE_MINUS_SRC_COLOR = 0x301; - -/** - * @property {Number} ONE_MINUS_DST_ALPHA - * @readonly - */ -cc.ONE_MINUS_DST_ALPHA = 0x305; - -/** - * @property {Number} ONE_MINUS_DST_COLOR - * @readonly - */ -cc.ONE_MINUS_DST_COLOR = 0x0307; - -/** - * @property {Number} ONE_MINUS_CONSTANT_ALPHA - * @readonly - */ -cc.ONE_MINUS_CONSTANT_ALPHA = 0x8004; - -/** - * @property {Number} ONE_MINUS_CONSTANT_COLOR - * @readonly - */ -cc.ONE_MINUS_CONSTANT_COLOR = 0x8002; - -/** - * the constant variable equals gl.LINEAR for texture - * @property {Number} LINEAR - * @readonly - */ -cc.LINEAR = 0x2601; - -/** - * default gl blend src function. Compatible with premultiplied alpha images. - * @property {Number} BLEND_SRC - * @readonly - */ -cc.defineGetterSetter(cc, "BLEND_SRC", function (){ - if (cc._renderType === cc.game.RENDER_TYPE_WEBGL - && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) { - return cc.ONE; - } - else { - return cc.SRC_ALPHA; - } -}); - -/** - * default gl blend dst function. Compatible with premultiplied alpha images. - * @property {Number} BLEND_DST - * @readonly - */ -cc.BLEND_DST = 0x0303; - /** * Check webgl error.Error will be shown in console if exists. * @method checkGLErrorDebug @@ -354,290 +1687,3 @@ cc.checkGLErrorDebug = function () { } } }; - -//Possible device orientations -/** - * Device oriented vertically, home button on the bottom (UIDeviceOrientationPortrait) - * @property {Number} DEVICE_ORIENTATION_PORTRAIT - * @readonly - */ -cc.DEVICE_ORIENTATION_PORTRAIT = 0; - -/** - * Device oriented horizontally, home button on the right (UIDeviceOrientationLandscapeLeft) - * @property {Number} DEVICE_ORIENTATION_LANDSCAPE_LEFT - * @readonly - */ -cc.DEVICE_ORIENTATION_LANDSCAPE_LEFT = 1; - -/** - * Device oriented vertically, home button on the top (UIDeviceOrientationPortraitUpsideDown) - * @property {Number} DEVICE_ORIENTATION_PORTRAIT_UPSIDE_DOWN - * @readonly - */ -cc.DEVICE_ORIENTATION_PORTRAIT_UPSIDE_DOWN = 2; - -/** - * Device oriented horizontally, home button on the left (UIDeviceOrientationLandscapeRight) - * @property {Number} DEVICE_ORIENTATION_LANDSCAPE_RIGHT - * @readonly - */ -cc.DEVICE_ORIENTATION_LANDSCAPE_RIGHT = 3; - -/** - * In browsers, we only support 2 orientations by change window size. - * @property {Number} DEVICE_MAX_ORIENTATIONS - * @readonly - */ -cc.DEVICE_MAX_ORIENTATIONS = 2; - - -// ------------------- vertex attrib flags ----------------------------- -/** - * @property {Number} VERTEX_ATTRIB_FLAG_NONE - * @readonly - */ -cc.VERTEX_ATTRIB_FLAG_NONE = 0; -/** - * @property {Number} VERTEX_ATTRIB_FLAG_POSITION - * @readonly - */ -cc.VERTEX_ATTRIB_FLAG_POSITION = 1 << 0; -/** - * @property {Number} VERTEX_ATTRIB_FLAG_COLOR - * @readonly - */ -cc.VERTEX_ATTRIB_FLAG_COLOR = 1 << 1; -/** - * @property {Number} VERTEX_ATTRIB_FLAG_TEX_COORDS - * @readonly - */ -cc.VERTEX_ATTRIB_FLAG_TEX_COORDS = 1 << 2; -/** - * @property {Number} VERTEX_ATTRIB_FLAG_POS_COLOR_TEX - * @readonly - */ -cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = ( cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR | cc.VERTEX_ATTRIB_FLAG_TEX_COORDS ); - -/** - * GL server side states - * @property {Number} GL_ALL - * @readonly - */ -cc.GL_ALL = 0; - -//-------------Vertex Attributes----------- -/** - * @property {Number} VERTEX_ATTRIB_POSITION - * @readonly - */ -cc.VERTEX_ATTRIB_POSITION = 0; -/** - * @property {Number} VERTEX_ATTRIB_COLOR - * @readonly - */ -cc.VERTEX_ATTRIB_COLOR = 1; -/** - * @property {Number} VERTEX_ATTRIB_TEX_COORDS - * @readonly - */ -cc.VERTEX_ATTRIB_TEX_COORDS = 2; -/** - * @property {Number} VERTEX_ATTRIB_MAX - * @readonly - */ -cc.VERTEX_ATTRIB_MAX = 3; - -//------------Uniforms------------------ -/** - * @property {Number} UNIFORM_PMATRIX - * @readonly - */ -cc.UNIFORM_PMATRIX = 0; -/** - * @property {Number} UNIFORM_MVMATRIX - * @readonly - */ -cc.UNIFORM_MVMATRIX = 1; -/** - * @property {Number} UNIFORM_MVPMATRIX - * @readonly - */ -cc.UNIFORM_MVPMATRIX = 2; -/** - * @property {Number} UNIFORM_TIME - * @readonly - */ -cc.UNIFORM_TIME = 3; -/** - * @property {Number} UNIFORM_SINTIME - * @readonly - */ -cc.UNIFORM_SINTIME = 4; -/** - * @property {Number} UNIFORM_COSTIME - * @readonly - */ -cc.UNIFORM_COSTIME = 5; -/** - * @property {Number} UNIFORM_RANDOM01 - * @readonly - */ -cc.UNIFORM_RANDOM01 = 6; -/** - * @property {Number} UNIFORM_SAMPLER - * @readonly - */ -cc.UNIFORM_SAMPLER = 7; -/** - * @property {Number} UNIFORM_MAX - * @readonly - */ -cc.UNIFORM_MAX = 8; - -//------------Shader Name--------------- -/** - * @property {String} SHADER_POSITION_TEXTURECOLOR - * @readonly - */ -cc.SHADER_POSITION_TEXTURECOLOR = "ShaderPositionTextureColor"; -/** - * @property {String} SHADER_POSITION_TEXTURECOLORALPHATEST - * @readonly - */ -cc.SHADER_POSITION_TEXTURECOLORALPHATEST = "ShaderPositionTextureColorAlphaTest"; -/** - * @property {String} SHADER_POSITION_COLOR - * @readonly - */ -cc.SHADER_POSITION_COLOR = "ShaderPositionColor"; -/** - * @property {String} SHADER_POSITION_TEXTURE - * @readonly - */ -cc.SHADER_POSITION_TEXTURE = "ShaderPositionTexture"; -/** - * @property {String} SHADER_POSITION_TEXTURE_UCOLOR - * @readonly - */ -cc.SHADER_POSITION_TEXTURE_UCOLOR = "ShaderPositionTexture_uColor"; -/** - * @property {String} SHADER_POSITION_TEXTUREA8COLOR - * @readonly - */ -cc.SHADER_POSITION_TEXTUREA8COLOR = "ShaderPositionTextureA8Color"; -/** - * @property {String} SHADER_POSITION_UCOLOR - * @readonly - */ -cc.SHADER_POSITION_UCOLOR = "ShaderPosition_uColor"; -/** - * @property {String} SHADER_POSITION_LENGTHTEXTURECOLOR - * @readonly - */ -cc.SHADER_POSITION_LENGTHTEXTURECOLOR = "ShaderPositionLengthTextureColor"; - -//------------uniform names---------------- -/** - * @property {String} UNIFORM_PMATRIX_S - * @readonly - */ -cc.UNIFORM_PMATRIX_S = "CC_PMatrix"; -/** - * @property {String} UNIFORM_MVMATRIX_S - * @readonly - */ -cc.UNIFORM_MVMATRIX_S = "CC_MVMatrix"; -/** - * @property {String} UNIFORM_MVPMATRIX_S - * @readonly - */ -cc.UNIFORM_MVPMATRIX_S = "CC_MVPMatrix"; -/** - * @property {String} UNIFORM_TIME_S - * @readonly - */ -cc.UNIFORM_TIME_S = "CC_Time"; -/** - * @property {String} UNIFORM_SINTIME_S - * @readonly - */ -cc.UNIFORM_SINTIME_S = "CC_SinTime"; -/** - * @property {String} UNIFORM_COSTIME_S - * @readonly - */ -cc.UNIFORM_COSTIME_S = "CC_CosTime"; -/** - * @property {String} UNIFORM_RANDOM01_S - * @readonly - */ -cc.UNIFORM_RANDOM01_S = "CC_Random01"; -/** - * @property {String} UNIFORM_SAMPLER_S - * @readonly - */ -cc.UNIFORM_SAMPLER_S = "CC_Texture0"; -/** - * @property {String} UNIFORM_ALPHA_TEST_VALUE_S - * @readonly - */ -cc.UNIFORM_ALPHA_TEST_VALUE_S = "CC_alpha_value"; - -//------------Attribute names-------------- -/** - * @property {String} ATTRIBUTE_NAME_COLOR - * @readonly - */ -cc.ATTRIBUTE_NAME_COLOR = "a_color"; -/** - * @property {String} ATTRIBUTE_NAME_POSITION - * @readonly - */ -cc.ATTRIBUTE_NAME_POSITION = "a_position"; -/** - * @property {String} ATTRIBUTE_NAME_TEX_COORD - * @readonly - */ -cc.ATTRIBUTE_NAME_TEX_COORD = "a_texCoord"; - - -/** - * default size for font size - * @property {Number} ITEM_SIZE - * @readonly - */ -cc.ITEM_SIZE = 32; - -/** - * default tag for current item - * @property {Number} CURRENT_ITEM - * @readonly - */ -cc.CURRENT_ITEM = 0xc0c05001; -/** - * default tag for zoom action tag - * @property {Number} ZOOM_ACTION_TAG - * @readonly - */ -cc.ZOOM_ACTION_TAG = 0xc0c05002; -/** - * default tag for normal - * @property {Number} NORMAL_TAG - * @readonly - */ -cc.NORMAL_TAG = 8801; - -/** - * default selected tag - * @property {Number} SELECTED_TAG - * @readonly - */ -cc.SELECTED_TAG = 8802; - -/** - * default disabled tag - * @property {Number} DISABLE_TAG - * @readonly - */ -cc.DISABLE_TAG = 8803; diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index f4a1d5f162..ee1294934a 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -529,6 +529,49 @@ js.obsoletes = function (obj, objName, props, writable) { } }; +/** + * A string tool to construct a string with format string. + * for example: + * cc.js.formatStr("a: %d, b: %b", a, b); + * cc.js.formatStr(a, b, c); + * @returns {String} + */ +js.formatStr = function formatStr() { + 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; +}; + /** * @class array * @static diff --git a/cocos2d/core/sprites/CCAnimationCache.js b/cocos2d/core/sprites/CCAnimationCache.js index 6246e0b73c..613150fcdb 100644 --- a/cocos2d/core/sprites/CCAnimationCache.js +++ b/cocos2d/core/sprites/CCAnimationCache.js @@ -172,7 +172,7 @@ cc.spriteFrameAnimationCache = { var isLoop = animationDict["loop"]; var loopsTemp = parseInt(animationDict["loops"]); - var loops = isLoop ? cc.REPEAT_FOREVER : ((isNaN(loopsTemp)) ? 1 : loopsTemp); + var loops = isLoop ? cc.Macro.REPEAT_FOREVER : ((isNaN(loopsTemp)) ? 1 : loopsTemp); var restoreOriginalFrame = (animationDict["restoreOriginalFrame"] && animationDict["restoreOriginalFrame"] == true) ? true : false; var frameArray = animationDict["frames"]; diff --git a/cocos2d/core/sprites/CCSGSprite.js b/cocos2d/core/sprites/CCSGSprite.js index e8d8ead0fd..818c7ae057 100644 --- a/cocos2d/core/sprites/CCSGSprite.js +++ b/cocos2d/core/sprites/CCSGSprite.js @@ -130,7 +130,7 @@ _ccsg.Sprite = _ccsg.Node.extend({ self._shouldBeHidden = false; self._offsetPosition = cc.p(0, 0); self._unflippedOffsetPositionFromCenter = cc.p(0, 0); - self._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST}; + self._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST}; self._rect = cc.rect(0, 0, 0, 0); self._softInit(fileName, rect, rotated); @@ -627,8 +627,8 @@ _ccsg.Sprite = _ccsg.Node.extend({ _ccsg.Node.prototype.init.call(_t); _t.dirty = _t._recursiveDirty = false; - _t._blendFunc.src = cc.BLEND_SRC; - _t._blendFunc.dst = cc.BLEND_DST; + _t._blendFunc.src = cc.Macro.BLEND_SRC; + _t._blendFunc.dst = cc.Macro.BLEND_DST; _t.texture = null; _t._flippedX = _t._flippedY = false; @@ -704,8 +704,8 @@ _ccsg.Sprite = _ccsg.Node.extend({ _t.dirty = false; _t._opacityModifyRGB = true; - _t._blendFunc.src = cc.BLEND_SRC; - _t._blendFunc.dst = cc.BLEND_DST; + _t._blendFunc.src = cc.Macro.BLEND_SRC; + _t._blendFunc.dst = cc.Macro.BLEND_DST; _t._flippedX = _t._flippedY = false; diff --git a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js index 60ebb6a47f..eeba97d680 100644 --- a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js @@ -155,7 +155,7 @@ var left, right, top, bottom, tempSwap, locQuad = this._quad; if (node._rectRotated) { - if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { + if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { left = (2 * rect.x + 1) / (2 * atlasWidth); right = left + (rect.height * 2 - 2) / (2 * atlasWidth); top = (2 * rect.y + 1) / (2 * atlasHeight); @@ -188,7 +188,7 @@ locQuad.tr.texCoords.u = right; locQuad.tr.texCoords.v = bottom; } else { - if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { + if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { left = (2 * rect.x + 1) / (2 * atlasWidth); right = left + (rect.width * 2 - 2) / (2 * atlasWidth); top = (2 * rect.y + 1) / (2 * atlasHeight); @@ -279,12 +279,12 @@ // it's possible to have an untextured sprite var node = this._node; if (!node._texture || !node._texture.hasPremultipliedAlpha()) { - node._blendFunc.src = cc.SRC_ALPHA; - node._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + node._blendFunc.src = cc.Macro.SRC_ALPHA; + node._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; node.opacityModifyRGB = false; } else { - node._blendFunc.src = cc.BLEND_SRC; - node._blendFunc.dst = cc.BLEND_DST; + node._blendFunc.src = cc.Macro.BLEND_SRC; + node._blendFunc.dst = cc.Macro.BLEND_DST; node.opacityModifyRGB = true; } }; @@ -306,9 +306,9 @@ } if (texture) - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); else - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_COLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_COLOR); }; @@ -365,7 +365,7 @@ var dy = x1 * sr + y2 * cr2 + y; var locVertexZ = node._vertexZ; - if (!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) { + if (!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) { ax = 0 | ax; ay = 0 | ay; bx = 0 | bx; @@ -389,7 +389,7 @@ if (node._hasChildren) node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform); - /*if (cc.SPRITE_DEBUG_DRAW) { //TODO + /*if (cc.Macro.SPRITE_DEBUG_DRAW) { //TODO // draw bounding box var vertices = [ cc.p(_t._quad.bl.vertices.x, _t._quad.bl.vertices.y), @@ -436,16 +436,16 @@ cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); //optimize performance for javascript cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer); if (this._quadDirty) { gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW); this._quadDirty = false; } - gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION - gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR - gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.VERTEX_ATTRIB_TEX_COORDS + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION + gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR + gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } } else { @@ -455,20 +455,20 @@ cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); cc.glBindTexture2D(null); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR); gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer); if (this._quadDirty) { gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.STATIC_DRAW); this._quadDirty = false; } - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } cc.g_NumberOfDraws++; - if (cc.SPRITE_DEBUG_DRAW === 0 && !node._showNode) + if (cc.Macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode) return; cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW); @@ -476,7 +476,7 @@ cc.current_stack.stack.push(cc.current_stack.top); cc.current_stack.top = this._stackMatrix; - if (cc.SPRITE_DEBUG_DRAW === 1 || node._showNode) { + if (cc.Macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) { // draw bounding box var locQuad = this._quad; var verticesG1 = [ @@ -486,7 +486,7 @@ cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y) ]; cc._drawingUtil.drawPoly(verticesG1, 4, true); - } else if (cc.SPRITE_DEBUG_DRAW === 2) { + } else if (cc.Macro.SPRITE_DEBUG_DRAW === 2) { // draw texture box var drawRectG2 = node.getTextureRect(); var offsetPixG2 = node.getOffsetPosition(); diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index 8bba89cbe5..415ee6f04f 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -996,12 +996,12 @@ cc.Scale9Sprite = _ccsg.Node.extend({ */ setBlendFunc: function (blendFunc, dst) { if (dst === undefined) { - this._blendFunc.src = blendFunc.src || cc.BLEND_SRC; - this._blendFunc.dst = blendFunc.dst || cc.BLEND_DST; + this._blendFunc.src = blendFunc.src || cc.Macro.BLEND_SRC; + this._blendFunc.dst = blendFunc.dst || cc.Macro.BLEND_DST; } else { - this._blendFunc.src = blendFunc || cc.BLEND_SRC; - this._blendFunc.dst = dst || cc.BLEND_DST; + this._blendFunc.src = blendFunc || cc.Macro.BLEND_SRC; + this._blendFunc.dst = dst || cc.Macro.BLEND_DST; } }, diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js index 01857724a3..d9276a7f32 100644 --- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js @@ -65,14 +65,14 @@ cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); //optimize performance for javascript cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer); var quads = node._quads; var bufferOffset = 0; var quadsLength = quads.length; - if(quadsLength == 0) return; + if (quadsLength === 0) return; if (needRebuildWebBuffer) { gl.bufferData(gl.ARRAY_BUFFER,quads[0].arrayBuffer.byteLength * quads.length, gl.DYNAMIC_DRAW); @@ -84,9 +84,9 @@ bufferOffset = 0; for(var i = 0; i < quads.length; ++i) { - gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, bufferOffset); //cc.VERTEX_ATTRIB_POSITION - gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12 + bufferOffset); //cc.VERTEX_ATTRIB_COLOR - gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16 + bufferOffset); //cc.VERTEX_ATTRIB_TEX_COORDS + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, bufferOffset); //cc.Macro.VERTEX_ATTRIB_POSITION + gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12 + bufferOffset); //cc.Macro.VERTEX_ATTRIB_COLOR + gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16 + bufferOffset); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS if(node._isTriangle) { gl.drawArrays(gl.TRIANGLES, 0, 3); } else { @@ -116,7 +116,7 @@ proto.setState = function (state) { var node = this._node; if (state === cc.Scale9Sprite.state.NORMAL) { - node.setShaderProgram(cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR)); + node.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR)); } else if (state === cc.Scale9Sprite.state.GRAY) { node.setShaderProgram(cc.Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram()); } @@ -129,10 +129,10 @@ return grayShader; grayShader = new cc.GLProgram(); - grayShader.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_COLOR_VERT, cc.Scale9Sprite.WebGLRenderCmd._grayShaderFragment); - grayShader.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - grayShader.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); - grayShader.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + grayShader.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Scale9Sprite.WebGLRenderCmd._grayShaderFragment); + grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); + grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); grayShader.link(); grayShader.updateUniforms(); diff --git a/cocos2d/core/sprites/CCSpriteBatchNode.js b/cocos2d/core/sprites/CCSpriteBatchNode.js index 6a081e1e5a..d432f29424 100644 --- a/cocos2d/core/sprites/CCSpriteBatchNode.js +++ b/cocos2d/core/sprites/CCSpriteBatchNode.js @@ -64,7 +64,7 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{ ctor: function (fileImage, capacity) { _ccsg.Node.prototype.ctor.call(this); this._descendants = []; - this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + this._blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST); var texture2D; capacity = capacity || cc.SpriteBatchNode.DEFAULT_CAPACITY; @@ -272,7 +272,7 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{ // ignore parent Z if parent is spriteSheet var ignoreParent = selParent === this; var previous = null; - if (childIndex > 0 && childIndex < cc.UINT_MAX) + if (childIndex > 0 && childIndex < cc.Macro.UINT_MAX) previous = brothers[childIndex - 1]; // first child of the sprite sheet diff --git a/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js b/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js index c3251a5b6b..87732bffe0 100644 --- a/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js @@ -114,7 +114,7 @@ this._textureAtlas = new cc.TextureAtlas(); this._textureAtlas.initWithTexture(texture, capacity); this._updateBlendFunc(); - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; proto.insertQuad = function(sprite, index){ @@ -224,8 +224,8 @@ proto._updateBlendFunc = function () { if (!this._textureAtlas.texture.hasPremultipliedAlpha()) { var blendFunc = this._node._blendFunc; - blendFunc.src = cc.SRC_ALPHA; - blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + blendFunc.src = cc.Macro.SRC_ALPHA; + blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } }; diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js index ab82021e97..ddc01ea42b 100644 --- a/cocos2d/core/textures/CCTextureAtlas.js +++ b/cocos2d/core/textures/CCTextureAtlas.js @@ -179,7 +179,7 @@ var TextureAtlas = Class.extend(/** @lends cc.TextureAtlas# */{ //WebGL only return; var locIndices = this._indices, locCapacity = this._capacity; for (var i = 0; i < locCapacity; i++) { - if (cc.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) { + if (cc.Macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) { locIndices[i * 6 + 0] = i * 4 + 0; locIndices[i * 6 + 1] = i * 4 + 0; locIndices[i * 6 + 2] = i * 4 + 2; @@ -669,7 +669,7 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) { //vertices //gl.bindBuffer(gl.ARRAY_BUFFER, _t._buffersVBO[0]); // XXX: update is done in draw... perhaps it should be done in a timer - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer); if (_t.dirty){ @@ -677,13 +677,13 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) { _t.dirty = false; } - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]); - if (cc.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) + if (cc.Macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) gl.drawElements(gl.TRIANGLE_STRIP, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT); else gl.drawElements(gl.TRIANGLES, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT); diff --git a/cocos2d/core/textures/CCTextureCache.js b/cocos2d/core/textures/CCTextureCache.js index 5947268eee..0573eb8264 100644 --- a/cocos2d/core/textures/CCTextureCache.js +++ b/cocos2d/core/textures/CCTextureCache.js @@ -349,7 +349,7 @@ game.once(game.EVENT_RENDERER_INITED, function () { tex = locTexs[url] = new Texture2D(); tex.url = url; } - premultiplied = cc.AUTO_PREMULTIPLIED_ALPHA_FOR_PNG && (cc.path.extname(url) === ".png"); + premultiplied = cc.Macro.AUTO_PREMULTIPLIED_ALPHA_FOR_PNG && (cc.path.extname(url) === ".png"); tex.handleLoadedTexture(premultiplied); }; diff --git a/cocos2d/core/utils/Async.js b/cocos2d/core/utils/Async.js deleted file mode 100644 index b9b0838cf2..0000000000 --- a/cocos2d/core/utils/Async.js +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Chukong Aipu reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -/** - * Async Pool class, a helper of cc.async - * @class AsyncPool - * @constructor - * @param {Object|Array} srcObj - * @param {Number} limit the limit of parallel number - * @param {Function} iterator - * @param {Function} onEnd - * @param {Object} target - */ -cc.AsyncPool = function(srcObj, limit, iterator, onEnd, target){ - var self = this; - self._srcObj = srcObj; - self._limit = limit; - self._pool = []; - self._iterator = iterator; - self._iteratorTarget = target; - self._onEnd = onEnd; - self._onEndTarget = target; - self._errors = []; - self._results = srcObj instanceof Array ? [] : {}; - - cc.each(srcObj, function(value, index){ - self._pool.push({index : index, value : value}); - }); - - self.size = self._pool.length; - self.finishedSize = 0; - self._workingSize = 0; - - self._limit = self._limit || self.size; - - self.onIterator = function(iterator, target){ - self._iterator = iterator; - self._iteratorTarget = target; - }; - - self.onEnd = function(endCb, endCbTarget){ - self._onEnd = endCb; - self._onEndTarget = endCbTarget; - }; - - self._handleItem = function(){ - var self = this; - if(self._pool.length === 0 || self._workingSize >= self._limit) - return; //return directly if the array's length = 0 or the working size great equal limit number - - var item = self._pool.shift(); - var value = item.value, index = item.index; - self._workingSize++; - self._iterator.call(self._iteratorTarget, value, index, - function(err, res){ - self.finishedSize++; - self._workingSize--; - - if (err) { - self._errors.push(err); - } - self._results[this.index] = res; - - if (self.finishedSize === self.size) { - if (self._onEnd) - self._onEnd.call(self._onEndTarget, self._errors.length > 0 ? self._errors : null, self._results); - return; - } - self._handleItem(); - }.bind(item), - self); - }; - - self.flow = function(){ - var self = this; - if(self._pool.length === 0) { - if(self._onEnd) - self._onEnd.call(self._onEndTarget, null, []); - return; - } - for(var i = 0; i < self._limit; i++) - self._handleItem(); - } -}; - -/** - * @class async - */ -cc.async = /** @lends cc.async# */{ - /** - * Do tasks series. - * @method series - * @param {Array|Object} tasks - * @param {Function} [cb] - callback - * @param {Object} [target] - * @return {AsyncPool} - */ - series : function(tasks, cb, target){ - var asyncPool = new cc.AsyncPool(tasks, 1, function(func, index, cb1){ - func.call(target, cb1); - }, cb, target); - asyncPool.flow(); - return asyncPool; - }, - - /** - * Do tasks parallel. - * @method parallel - * @param {Array|Object} tasks - * @param {Function} cb - callback - * @param {Object} [target] - * @return {AsyncPool} - */ - parallel : function(tasks, cb, target){ - var asyncPool = new cc.AsyncPool(tasks, 0, function(func, index, cb1){ - func.call(target, cb1); - }, cb, target); - asyncPool.flow(); - return asyncPool; - }, - - /** - * Do tasks waterfall. - * @method waterfall - * @param {Array|Object} tasks - * @param {Function} cb - callback - * @param {Object} [target] - * @return {AsyncPool} - */ - waterfall : function(tasks, cb, target){ - var args = []; - var lastResults = [null];//the array to store the last results - var asyncPool = new cc.AsyncPool(tasks, 1, - function (func, index, cb1) { - args.push(function (err) { - args = Array.prototype.slice.call(arguments, 1); - if(tasks.length - 1 === index) lastResults = lastResults.concat(args);//while the last task - cb1.apply(null, arguments); - }); - func.apply(target, args); - }, function (err) { - if (!cb) - return; - if (err) - return cb.call(target, err); - cb.apply(target, lastResults); - }); - asyncPool.flow(); - return asyncPool; - }, - - /** - * Do tasks by iterator. - * @method map - * @param {Array|Object} tasks - * @param {Function|Object} iterator - * @param {Function} [callback] - * @param {Object} [target] - * @return {AsyncPool} - */ - map : function(tasks, iterator, callback, target){ - var locIterator = iterator; - if(typeof(iterator) === "object"){ - callback = iterator.cb; - target = iterator.iteratorTarget; - locIterator = iterator.iterator; - } - var asyncPool = new cc.AsyncPool(tasks, 0, locIterator, callback, target); - asyncPool.flow(); - return asyncPool; - }, - - /** - * Do tasks by iterator limit. - * @method mapLimit - * @param {Array|Object} tasks - * @param {Number} limit - * @param {Function} iterator - * @param {Function} cb callback - * @param {Object} [target] - */ - mapLimit : function(tasks, limit, iterator, cb, target){ - var asyncPool = new cc.AsyncPool(tasks, limit, iterator, cb, target); - asyncPool.flow(); - return asyncPool; - } -}; \ No newline at end of file diff --git a/cocos2d/core/utils/CCProfiler.js b/cocos2d/core/utils/CCProfiler.js index 26af34020a..9ecb57fbc5 100644 --- a/cocos2d/core/utils/CCProfiler.js +++ b/cocos2d/core/utils/CCProfiler.js @@ -45,7 +45,7 @@ cc.profiler = (function () { var createStatsLabel = function () { var fontSize = 0; var w = cc.winSize.width, h = cc.winSize.height; - var locStatsPosition = cc.DIRECTOR_STATS_POSITION; + var locStatsPosition = cc.Macro.DIRECTOR_STATS_POSITION; if (w > h) fontSize = 0 | (h / 320 * 20); else @@ -110,7 +110,7 @@ cc.profiler = (function () { _frames++; _accumDt += cc.director.getDeltaTime(); - if (_accumDt > cc.DIRECTOR_FPS_INTERVAL) { + if (_accumDt > cc.Macro.DIRECTOR_FPS_INTERVAL) { _frameRate = _frames / _accumDt; _frames = 0; _accumDt = 0; @@ -151,7 +151,7 @@ cc.profiler = (function () { setProfileDuration: function (duration) { if (!isNaN(duration) && duration > 0) { - _levelDetCycle = duration / cc.DIRECTOR_FPS_INTERVAL; + _levelDetCycle = duration / cc.Macro.DIRECTOR_FPS_INTERVAL; } }, diff --git a/cocos2d/core/utils/index.js b/cocos2d/core/utils/index.js index 7e5d7cf47d..6ba602bde0 100644 --- a/cocos2d/core/utils/index.js +++ b/cocos2d/core/utils/index.js @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -require('./Async'); + require('./CCPath'); require('./CCProfiler'); require('./find'); diff --git a/cocos2d/core/value-types/CCTypes.js b/cocos2d/core/value-types/CCTypes.js index f15ea7a001..f0445309c3 100644 --- a/cocos2d/core/value-types/CCTypes.js +++ b/cocos2d/core/value-types/CCTypes.js @@ -61,16 +61,16 @@ cc.BlendFunc = function (src1, dst1) { }; var BlendFactor = cc.Enum({ - ONE: 1, //cc.ONE - ZERO: 0, //cc.ZERO - SRC_ALPHA: 0x302, //cc.SRC_ALPHA - SRC_COLOR: 0x300, //cc.SRC_COLOR - DST_ALPHA: 0x304, //cc.DST_ALPHA - DST_COLOR: 0x306, //cc.DST_COLOR - ONE_MINUS_SRC_ALPHA: 0x303, //cc.ONE_MINUS_SRC_ALPHA - ONE_MINUS_SRC_COLOR: 0x301, //cc.ONE_MINUS_SRC_COLOR - ONE_MINUS_DST_ALPHA: 0x305, //cc.ONE_MINUS_DST_ALPHA - ONE_MINUS_DST_COLOR: 0x307, //cc.ONE_MINUS_DST_COLOR + ONE: 1, //cc.Macro.ONE + ZERO: 0, //cc.Macro.ZERO + SRC_ALPHA: 0x302, //cc.Macro.SRC_ALPHA + SRC_COLOR: 0x300, //cc.Macro.SRC_COLOR + DST_ALPHA: 0x304, //cc.Macro.DST_ALPHA + DST_COLOR: 0x306, //cc.Macro.DST_COLOR + ONE_MINUS_SRC_ALPHA: 0x303, //cc.Macro.ONE_MINUS_SRC_ALPHA + ONE_MINUS_SRC_COLOR: 0x301, //cc.Macro.ONE_MINUS_SRC_COLOR + ONE_MINUS_DST_ALPHA: 0x305, //cc.Macro.ONE_MINUS_DST_ALPHA + ONE_MINUS_DST_COLOR: 0x307, //cc.Macro.ONE_MINUS_DST_COLOR }); //var BlendFactor = cc; diff --git a/cocos2d/effects/CCGrid.js b/cocos2d/effects/CCGrid.js index dc6a59182d..9260ee5100 100644 --- a/cocos2d/effects/CCGrid.js +++ b/cocos2d/effects/CCGrid.js @@ -228,7 +228,7 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{ if (!this._grabber) return false; this._grabber.grab(this._texture); - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE); this.calculateVertexPoints(); return true; }, @@ -449,7 +449,7 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{ blit:function (target) { var n = this._gridSize.width * this._gridSize.height; - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_TEX_COORDS); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS); this._shaderProgram.use(); //this._shaderProgram.setUniformsForBuiltins(); this._shaderProgram._setUniformForMVPMatrixWithMat4(target._renderCmd._stackMatrix); @@ -462,13 +462,13 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{ gl.bindBuffer(gl.ARRAY_BUFFER, this._verticesBuffer); if (locDirty) gl.bufferData(gl.ARRAY_BUFFER, this._vertices, gl.DYNAMIC_DRAW); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, 0); // texCoords gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordinateBuffer); if (locDirty) gl.bufferData(gl.ARRAY_BUFFER, this._texCoordinates, gl.DYNAMIC_DRAW); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer); if (locDirty) @@ -715,19 +715,19 @@ cc.TiledGrid3D = cc.GridBase.extend(/** @lends cc.TiledGrid3D# */{ // Attributes // var gl = cc._renderContext, locDirty = this._dirty; - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_TEX_COORDS); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS); // position gl.bindBuffer(gl.ARRAY_BUFFER, this._verticesBuffer); if (locDirty) gl.bufferData(gl.ARRAY_BUFFER, this._vertices, gl.DYNAMIC_DRAW); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, this._vertices); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, this._vertices); // texCoords gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordinateBuffer); if (locDirty) gl.bufferData(gl.ARRAY_BUFFER, this._texCoordinates, gl.DYNAMIC_DRAW); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, this._texCoordinates); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, this._texCoordinates); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer); if (locDirty) diff --git a/cocos2d/kazmath/utility.js b/cocos2d/kazmath/utility.js index 9cd3fb4c71..2ffe652038 100644 --- a/cocos2d/kazmath/utility.js +++ b/cocos2d/kazmath/utility.js @@ -35,9 +35,9 @@ */ cc.math = cc.math || {}; -//cc.kmPIOver180 = 0.017453; please use cc.RAD +//cc.kmPIOver180 = 0.017453; please use cc.Macro.RAD -//cc.kmPIUnder180 = 57.295779; please use cc.DEG +//cc.kmPIUnder180 = 57.295779; please use cc.Macro.DEG cc.math.EPSILON = 1.0 / 64.0; //cc.kmEpsilon diff --git a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js index b60438c28e..3e0b3bccc7 100644 --- a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js +++ b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js @@ -39,7 +39,7 @@ proto.rendering = function(ctx){ cc.AtlasNode.WebGLRenderCmd.prototype.rendering.call(this, ctx); - if (cc.LABELATLAS_DEBUG_DRAW) { + if (cc.Macro.LABELATLAS_DEBUG_DRAW) { var node = this._node; var s = node.getContentSize(); var locRect = node.getBoundingBoxToWorld(); @@ -82,7 +82,7 @@ cr++; var left, right, top, bottom; - if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { + if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { // Issue #938. Don't use texStepX & texStepY left = (2 * row * itemWidth + 1) / (2 * textureWide); right = left + (itemWidth * 2 - 2) / (2 * textureWide); diff --git a/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js b/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js index 48e292e771..37031c5b6a 100644 --- a/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js +++ b/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js @@ -71,7 +71,7 @@ var node = this._node; //LabelBMFont - Debug draw - if (cc.LABELBMFONT_DEBUG_DRAW) { + if (cc.Macro.LABELBMFONT_DEBUG_DRAW) { var size = node.getContentSize(); var pos = cc.p(0 | ( -this._anchorPointInPoints.x), 0 | ( -this._anchorPointInPoints.y)); var vertices = [cc.p(pos.x, pos.y), cc.p(pos.x + size.width, pos.y), cc.p(pos.x + size.width, pos.y + size.height), cc.p(pos.x, pos.y + size.height)]; diff --git a/cocos2d/menus/CCMenuItem.js b/cocos2d/menus/CCMenuItem.js index 64c7579048..7a6ee83580 100644 --- a/cocos2d/menus/CCMenuItem.js +++ b/cocos2d/menus/CCMenuItem.js @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -cc._globalFontSize = cc.ITEM_SIZE; +cc._globalFontSize = cc.Macro.ITEM_SIZE; cc._globalFontName = "Arial"; cc._globalFontNameRelease = false; @@ -362,14 +362,14 @@ cc.MenuItemLabel = cc.MenuItem.extend(/** @lends cc.MenuItemLabel# */{ if (this._enabled) { cc.MenuItem.prototype.selected.call(this); - var action = this.getActionByTag(cc.ZOOM_ACTION_TAG); + var action = this.getActionByTag(cc.Macro.ZOOM_ACTION_TAG); if (action) this.stopAction(action); else this._originalScale = this.scale; var zoomAction = cc.scaleTo(0.1, this._originalScale * 1.2); - zoomAction.setTag(cc.ZOOM_ACTION_TAG); + zoomAction.setTag(cc.Macro.ZOOM_ACTION_TAG); this.runAction(zoomAction); } }, @@ -380,9 +380,9 @@ cc.MenuItemLabel = cc.MenuItem.extend(/** @lends cc.MenuItemLabel# */{ unselected: function () { if (this._enabled) { cc.MenuItem.prototype.unselected.call(this); - this.stopActionByTag(cc.ZOOM_ACTION_TAG); + this.stopActionByTag(cc.Macro.ZOOM_ACTION_TAG); var zoomAction = cc.scaleTo(0.1, this._originalScale); - zoomAction.setTag(cc.ZOOM_ACTION_TAG); + zoomAction.setTag(cc.Macro.ZOOM_ACTION_TAG); this.runAction(zoomAction); } } @@ -732,7 +732,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{ return; } if (normalImage) { - this.addChild(normalImage, 0, cc.NORMAL_TAG); + this.addChild(normalImage, 0, cc.Macro.NORMAL_TAG); normalImage.anchorX = 0; normalImage.anchorY = 0; } @@ -773,7 +773,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{ return; if (selectedImage) { - this.addChild(selectedImage, 0, cc.SELECTED_TAG); + this.addChild(selectedImage, 0, cc.Macro.SELECTED_TAG); selectedImage.anchorX = 0; selectedImage.anchorY = 0; } @@ -803,7 +803,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{ return; if (disabledImage) { - this.addChild(disabledImage, 0, cc.DISABLE_TAG); + this.addChild(disabledImage, 0, cc.Macro.DISABLE_TAG); disabledImage.anchorX = 0; disabledImage.anchorY = 0; } @@ -1180,12 +1180,12 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{ setSelectedIndex: function (SelectedIndex) { if (SelectedIndex !== this._selectedIndex) { this._selectedIndex = SelectedIndex; - var currItem = this.getChildByTag(cc.CURRENT_ITEM); + var currItem = this.getChildByTag(cc.Macro.CURRENT_ITEM); if (currItem) currItem.removeFromParent(false); var item = this.subItems[this._selectedIndex]; - this.addChild(item, 0, cc.CURRENT_ITEM); + this.addChild(item, 0, cc.Macro.CURRENT_ITEM); var w = item.width, h = item.height; this.width = w; this.height = h; @@ -1235,7 +1235,7 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{ if (args[i]) locSubItems.push(args[i]); } - this._selectedIndex = cc.UINT_MAX; + this._selectedIndex = cc.Macro.UINT_MAX; this.setSelectedIndex(0); this.setCascadeColorEnabled(true); diff --git a/cocos2d/motion-streak/CCMotionStreak.js b/cocos2d/motion-streak/CCMotionStreak.js index 0f850fe210..66d533c48d 100644 --- a/cocos2d/motion-streak/CCMotionStreak.js +++ b/cocos2d/motion-streak/CCMotionStreak.js @@ -84,7 +84,7 @@ cc.MotionStreak = _ccsg.Node.extend(/** @lends cc.MotionStreak# */{ ctor: function (fade, minSeg, stroke, color, texture) { _ccsg.Node.prototype.ctor.call(this); this._positionR = cc.p(0, 0); - this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); + this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); this.fastMode = false; this.startingPositionInitialized = false; diff --git a/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js b/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js index 621aae5b47..b47388541a 100644 --- a/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js +++ b/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js @@ -25,7 +25,7 @@ cc.MotionStreak.WebGLRenderCmd = function(renderableObject){ _ccsg.Node.WebGLRenderCmd.call(this, renderableObject); this._needDraw = true; - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; cc.MotionStreak.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype); @@ -40,7 +40,7 @@ cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){ ctx = ctx || cc._renderContext; this._shaderProgram.use(); this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); cc.glBindTexture2D(node.texture); @@ -48,17 +48,17 @@ cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){ //position ctx.bindBuffer(ctx.ARRAY_BUFFER, node._verticesBuffer); ctx.bufferData(ctx.ARRAY_BUFFER, node._vertices, ctx.DYNAMIC_DRAW); - ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0); + ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0); //texcoords ctx.bindBuffer(ctx.ARRAY_BUFFER, node._texCoordsBuffer); ctx.bufferData(ctx.ARRAY_BUFFER, node._texCoords, ctx.DYNAMIC_DRAW); - ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0); + ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0); //colors ctx.bindBuffer(ctx.ARRAY_BUFFER, node._colorPointerBuffer); ctx.bufferData(ctx.ARRAY_BUFFER, node._colorPointer, ctx.DYNAMIC_DRAW); - ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0); + ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0); ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, node._nuPoints * 2); cc.g_NumberOfDraws++; diff --git a/cocos2d/node-grid/CCNodeGrid.js b/cocos2d/node-grid/CCNodeGrid.js index c9f6a58248..efa4bcd0dd 100644 --- a/cocos2d/node-grid/CCNodeGrid.js +++ b/cocos2d/node-grid/CCNodeGrid.js @@ -109,7 +109,7 @@ cc.NodeGrid = _ccsg.Node.extend({ apx = app.x, apy = app.y, translate = (apx !== 0.0 || apy !== 0.0); if (translate) { - if(!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) { + if(!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) { apx = 0 | apx; apy = 0 | apy; } diff --git a/cocos2d/particle/CCParticleBatchNode.js b/cocos2d/particle/CCParticleBatchNode.js index 1ae02c35a2..daff2faf5b 100644 --- a/cocos2d/particle/CCParticleBatchNode.js +++ b/cocos2d/particle/CCParticleBatchNode.js @@ -93,7 +93,7 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{ */ ctor:function (fileImage, capacity) { _ccsg.Node.prototype.ctor.call(this); - this._blendFunc = {src:cc.BLEND_SRC, dst:cc.BLEND_DST}; + this._blendFunc = {src:cc.Macro.BLEND_SRC, dst:cc.Macro.BLEND_DST}; if (cc.js.isString(fileImage)) { this.init(fileImage, capacity); } else if (fileImage instanceof cc.Texture2D) { @@ -350,9 +350,9 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{ // If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it var locBlendFunc = this._blendFunc; - if (texture && !texture.hasPremultipliedAlpha() && ( locBlendFunc.src === cc.BLEND_SRC && locBlendFunc.dst === cc.BLEND_DST )) { - locBlendFunc.src = cc.SRC_ALPHA; - locBlendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + if (texture && !texture.hasPremultipliedAlpha() && ( locBlendFunc.src === cc.Macro.BLEND_SRC && locBlendFunc.dst === cc.Macro.BLEND_DST )) { + locBlendFunc.src = cc.Macro.SRC_ALPHA; + locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } }, @@ -485,8 +485,8 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{ _updateBlendFunc:function () { if (!this.textureAtlas.texture.hasPremultipliedAlpha()) { - this._blendFunc.src = cc.SRC_ALPHA; - this._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + this._blendFunc.src = cc.Macro.SRC_ALPHA; + this._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } }, diff --git a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js index 93a6ef22be..ba8caa0ab9 100644 --- a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js +++ b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js @@ -46,7 +46,7 @@ }; proto._initWithTexture = function(){ - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; proto.visit = function(parentCmd){ diff --git a/cocos2d/particle/CCSGParticleSystem.js b/cocos2d/particle/CCSGParticleSystem.js index b854f8b820..c05f659798 100644 --- a/cocos2d/particle/CCSGParticleSystem.js +++ b/cocos2d/particle/CCSGParticleSystem.js @@ -290,7 +290,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ this.emitterMode = _ccsg.ParticleSystem.Mode.GRAVITY; this.modeA = new _ccsg.ParticleSystem.ModeA(); this.modeB = new _ccsg.ParticleSystem.ModeB(); - this._blendFunc = {src:cc.BLEND_SRC, dst:cc.BLEND_DST}; + this._blendFunc = {src:cc.Macro.BLEND_SRC, dst:cc.Macro.BLEND_DST}; this._particles = []; this._sourcePosition = cc.p(0, 0); @@ -1128,7 +1128,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ * dest blend function = GL_ONE; */ isBlendAdditive:function () { - return (( this._blendFunc.src === cc.SRC_ALPHA && this._blendFunc.dst === cc.ONE) || (this._blendFunc.src === cc.ONE && this._blendFunc.dst === cc.ONE)); + return (( this._blendFunc.src === cc.Macro.SRC_ALPHA && this._blendFunc.dst === cc.Macro.ONE) || + (this._blendFunc.src === cc.Macro.ONE && this._blendFunc.dst === cc.Macro.ONE)); }, /** @@ -1140,8 +1141,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ setBlendAdditive:function (isBlendAdditive) { var locBlendFunc = this._blendFunc; if (isBlendAdditive) { - locBlendFunc.src = cc.SRC_ALPHA; - locBlendFunc.dst = cc.ONE; + locBlendFunc.src = cc.Macro.SRC_ALPHA; + locBlendFunc.dst = cc.Macro.ONE; } else { this._renderCmd._setBlendAdditive(); } @@ -1388,13 +1389,13 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ var imageFormat = cc.getImageFormatByData(buffer); - if(imageFormat !== cc.FMT_TIFF && imageFormat !== cc.FMT_PNG){ + if(imageFormat !== cc.ImageFormat.TIFF && imageFormat !== cc.ImageFormat.PNG){ cc.log("_ccsg.ParticleSystem: unknown image format with Data"); return false; } var canvasObj = document.createElement("canvas"); - if(imageFormat === cc.FMT_PNG){ + if(imageFormat === cc.ImageFormat.PNG){ var myPngObj = new cc.PNGReader(buffer); myPngObj.render(canvasObj); } else { @@ -1444,8 +1445,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ this._isActive = true; // default blend function - this._blendFunc.src = cc.BLEND_SRC; - this._blendFunc.dst = cc.BLEND_DST; + this._blendFunc.src = cc.Macro.BLEND_SRC; + this._blendFunc.dst = cc.Macro.BLEND_DST; // default movement type; this.positionType = _ccsg.ParticleSystem.Type.FREE; @@ -1830,12 +1831,12 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ if (locTexture && locTexture instanceof cc.Texture2D) { this._opacityModifyRGB = false; var locBlendFunc = this._blendFunc; - if (locBlendFunc.src === cc.BLEND_SRC && locBlendFunc.dst === cc.BLEND_DST) { + if (locBlendFunc.src === cc.Macro.BLEND_SRC && locBlendFunc.dst === cc.Macro.BLEND_DST) { if (locTexture.hasPremultipliedAlpha()) { this._opacityModifyRGB = true; } else { - locBlendFunc.src = cc.SRC_ALPHA; - locBlendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + locBlendFunc.src = cc.Macro.SRC_ALPHA; + locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } } } diff --git a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js index c7732cd793..b206c2a3ff 100644 --- a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js +++ b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js @@ -182,8 +182,8 @@ proto._setBlendAdditive = function(){ var locBlendFunc = this._node._blendFunc; - locBlendFunc.src = cc.BLEND_SRC; - locBlendFunc.dst = cc.BLEND_DST; + locBlendFunc.src = cc.Macro.BLEND_SRC; + locBlendFunc.dst = cc.Macro.BLEND_DST; }; proto._initWithTotalParticles = function(totalParticles){}; diff --git a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js index 945f4cb6e4..48c7834c18 100644 --- a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js +++ b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js @@ -195,12 +195,12 @@ // // Using VBO without VAO // - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]); gl.drawElements(gl.TRIANGLES, node._particleIdx * 6, gl.UNSIGNED_SHORT, 0); @@ -219,7 +219,7 @@ } var left, bottom, right, top; - if (cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { + if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) { left = (pointRect.x * 2 + 1) / (wide * 2); bottom = (pointRect.y * 2 + 1) / (high * 2); right = left + (pointRect.width * 2 - 2) / (wide * 2); @@ -365,11 +365,11 @@ proto._setBlendAdditive = function(){ var locBlendFunc = this._node._blendFunc; if (this._texture && !this._texture.hasPremultipliedAlpha()) { - locBlendFunc.src = cc.SRC_ALPHA; - locBlendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + locBlendFunc.src = cc.Macro.SRC_ALPHA; + locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } else { - locBlendFunc.src = cc.BLEND_SRC; - locBlendFunc.dst = cc.BLEND_DST; + locBlendFunc.src = cc.Macro.BLEND_SRC; + locBlendFunc.dst = cc.Macro.BLEND_DST; } }; @@ -381,7 +381,7 @@ this.initIndices(totalParticles); this._setupVBO(); - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; proto._updateDeltaColor = function (selParticle, dt) { diff --git a/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js b/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js index 4c829203c2..47406e3808 100644 --- a/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js +++ b/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js @@ -51,7 +51,7 @@ var blendFunc = node._sprite._blendFunc; cc.glBlendFunc(blendFunc.src, blendFunc.dst); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); cc.glBindTexture2D(node._sprite.texture); @@ -61,9 +61,9 @@ this._vertexDataDirty = false; } var locVertexDataLen = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT; - context.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, locVertexDataLen, 0); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, locVertexDataLen, 8); - context.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, context.FLOAT, false, locVertexDataLen, 12); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, locVertexDataLen, 0); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, locVertexDataLen, 8); + context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, context.FLOAT, false, locVertexDataLen, 12); if (node._type === cc.ProgressTimer.Type.RADIAL) context.drawArrays(context.TRIANGLE_FAN, 0, this._vertexDataCount); @@ -169,7 +169,7 @@ this._vertexDataCount = 0; //shader program - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; proto._updateProgress = function(){ @@ -316,7 +316,7 @@ var i, locMidPoint = node._midPoint; var alpha = node._percentage / 100; - var angle = 2 * (cc.PI) * ( node._reverseDirection ? alpha : 1.0 - alpha); + var angle = 2 * (Math.PI) * ( node._reverseDirection ? alpha : 1.0 - alpha); // We find the vector to do a hit detection based on the percentage // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate @@ -342,7 +342,7 @@ // intersection point // We loop through five points since the top is split in half - var min_t = cc.FLT_MAX; + var min_t = cc.Macro.FLT_MAX; var locProTextCoordsCount = cc.ProgressTimer.TEXTURE_COORDS_COUNT; for (i = 0; i <= locProTextCoordsCount; ++i) { var pIndex = (i + (locProTextCoordsCount - 1)) % locProTextCoordsCount; diff --git a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js index 5a5f1ca9ea..7172765279 100644 --- a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js @@ -59,7 +59,7 @@ texture.handleLoadedTexture(); var locSprite = node.sprite = new _ccsg.Sprite(texture); - locSprite.setBlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA); + locSprite.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_ALPHA); // Disabled by default. node.autoDraw = false; // add sprite for backward compatibility diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js index 70eae0eb69..0cd2f84931 100644 --- a/cocos2d/shaders/CCGLProgram.js +++ b/cocos2d/shaders/CCGLProgram.js @@ -261,27 +261,27 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ /** * It will create 4 uniforms: - * cc.UNIFORM_PMATRIX - * cc.UNIFORM_MVMATRIX - * cc.UNIFORM_MVPMATRIX - * cc.UNIFORM_SAMPLER + * cc.Macro.UNIFORM_PMATRIX + * cc.Macro.UNIFORM_MVMATRIX + * cc.Macro.UNIFORM_MVPMATRIX + * cc.Macro.UNIFORM_SAMPLER */ updateUniforms: function () { - this._uniforms[cc.UNIFORM_PMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_PMATRIX_S); - this._uniforms[cc.UNIFORM_MVMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_MVMATRIX_S); - this._uniforms[cc.UNIFORM_MVPMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_MVPMATRIX_S); - this._uniforms[cc.UNIFORM_TIME] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_TIME_S); - this._uniforms[cc.UNIFORM_SINTIME] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_SINTIME_S); - this._uniforms[cc.UNIFORM_COSTIME] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_COSTIME_S); + this._uniforms[cc.Macro.UNIFORM_PMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_PMATRIX_S); + this._uniforms[cc.Macro.UNIFORM_MVMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_MVMATRIX_S); + this._uniforms[cc.Macro.UNIFORM_MVPMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_MVPMATRIX_S); + this._uniforms[cc.Macro.UNIFORM_TIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_TIME_S); + this._uniforms[cc.Macro.UNIFORM_SINTIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_SINTIME_S); + this._uniforms[cc.Macro.UNIFORM_COSTIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_COSTIME_S); - this._usesTime = (this._uniforms[cc.UNIFORM_TIME] != null || this._uniforms[cc.UNIFORM_SINTIME] != null || this._uniforms[cc.UNIFORM_COSTIME] != null); + this._usesTime = (this._uniforms[cc.Macro.UNIFORM_TIME] != null || this._uniforms[cc.Macro.UNIFORM_SINTIME] != null || this._uniforms[cc.Macro.UNIFORM_COSTIME] != null); - this._uniforms[cc.UNIFORM_RANDOM01] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_RANDOM01_S); - this._uniforms[cc.UNIFORM_SAMPLER] = this._glContext.getUniformLocation(this._programObj, cc.UNIFORM_SAMPLER_S); + this._uniforms[cc.Macro.UNIFORM_RANDOM01] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_RANDOM01_S); + this._uniforms[cc.Macro.UNIFORM_SAMPLER] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_SAMPLER_S); this.use(); // Since sample most probably won't change, set it to 0 now. - this.setUniformLocationWith1i(this._uniforms[cc.UNIFORM_SAMPLER], 0); + this.setUniformLocationWith1i(this._uniforms[cc.Macro.UNIFORM_SAMPLER], 0); }, /** @@ -303,7 +303,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ * @returns {WebGLUniformLocation} */ getUniformMVPMatrix: function () { - return this._uniforms[cc.UNIFORM_MVPMATRIX]; + return this._uniforms[cc.Macro.UNIFORM_MVPMATRIX]; }, /** @@ -311,7 +311,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ * @returns {WebGLUniformLocation} */ getUniformSampler: function () { - return this._uniforms[cc.UNIFORM_SAMPLER]; + return this._uniforms[cc.Macro.UNIFORM_SAMPLER]; }, /** @@ -552,9 +552,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ cc.kmMat4Multiply(matrixMVP, matrixP, matrixMV); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX], matrixP.mat, 1); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], matrixMV.mat, 1); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVPMATRIX], matrixMVP.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], matrixP.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], matrixMV.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1); if (this._usesTime) { var director = cc.director; @@ -563,13 +563,13 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ // Getting Mach time per frame per shader using time could be extremely expensive. var time = director.getTotalFrames() * director.getAnimationInterval(); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time)); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time)); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time)); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time)); } - if (this._uniforms[cc.UNIFORM_RANDOM01] !== -1) - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random()); + if (this._uniforms[cc.Macro.UNIFORM_RANDOM01] !== -1) + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random()); }, _setUniformsForBuiltinsForRenderer: function (node) { @@ -585,9 +585,9 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ cc.kmMat4Multiply(matrixMVP, matrixP, node._renderCmd._stackMatrix); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX], matrixP.mat, 1); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], node._renderCmd._stackMatrix.mat, 1); - this.setUniformLocationWithMatrix4fv(this._uniforms[cc.UNIFORM_MVPMATRIX], matrixMVP.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], matrixP.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], node._renderCmd._stackMatrix.mat, 1); + this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1); if (this._usesTime) { var director = cc.director; @@ -596,38 +596,38 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{ // Getting Mach time per frame per shader using time could be extremely expensive. var time = director.getTotalFrames() * director.getAnimationInterval(); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time)); - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time)); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time)); + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time)); } - if (this._uniforms[cc.UNIFORM_RANDOM01] !== -1) - this.setUniformLocationWith4f(this._uniforms[cc.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random()); + if (this._uniforms[cc.Macro.UNIFORM_RANDOM01] !== -1) + this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random()); }, /** * will update the MVP matrix on the MVP uniform if it is different than the previous call for this same shader program. */ setUniformForModelViewProjectionMatrix: function () { - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_MVPMATRIX], false, + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], false, cc.getMat4MultiplyValue(cc.projection_matrix_stack.top, cc.modelview_matrix_stack.top)); }, setUniformForModelViewProjectionMatrixWithMat4: function (swapMat4) { cc.kmMat4Multiply(swapMat4, cc.projection_matrix_stack.top, cc.modelview_matrix_stack.top); - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_MVPMATRIX], false, swapMat4.mat); + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], false, swapMat4.mat); }, setUniformForModelViewAndProjectionMatrixWithMat4: function () { - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], false, cc.modelview_matrix_stack.top.mat); - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat); + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], false, cc.modelview_matrix_stack.top.mat); + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat); }, _setUniformForMVPMatrixWithMat4: function(modelViewMatrix){ if(!modelViewMatrix) throw new Error("modelView matrix is undefined."); - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_MVMATRIX], false, modelViewMatrix.mat); - this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat); + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat); + this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat); }, /** @@ -753,7 +753,7 @@ cc.GLProgram._isHighpSupported = function(){ * @param {_ccsg.Node} node * @param {cc.GLProgram} program The shader program which fetches from CCShaderCache. * @example - * cc.setGLProgram(node, cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR)); + * cc.setGLProgram(node, cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR)); */ cc.setProgram = function (node, program) { node.shaderProgram = program; diff --git a/cocos2d/shaders/CCGLStateCache.js b/cocos2d/shaders/CCGLStateCache.js index 4523cc468d..70b1387591 100644 --- a/cocos2d/shaders/CCGLStateCache.js +++ b/cocos2d/shaders/CCGLStateCache.js @@ -29,7 +29,9 @@ cc._vertexAttribPosition = false; cc._vertexAttribColor = false; cc._vertexAttribTexCoords = false; -if (cc.ENABLE_GL_STATE_CACHE) { +var ENABLE_GL_STATE_CACHE = cc.Macro.ENABLE_GL_STATE_CACHE; + +if (ENABLE_GL_STATE_CACHE) { cc.MAX_ACTIVETEXTURE = 16; cc._currentShaderProgram = -1; @@ -37,7 +39,7 @@ if (cc.ENABLE_GL_STATE_CACHE) { cc._blendingSource = -1; cc._blendingDest = -1; cc._GLServerState = 0; - if(cc.TEXTURE_ATLAS_USE_VAO) + if(cc.Macro.TEXTURE_ATLAS_USE_VAO) cc._uVAO = 0; } @@ -45,7 +47,7 @@ if (cc.ENABLE_GL_STATE_CACHE) { /** * Invalidates the GL state cache.
- * If CC_ENABLE_GL_STATE_CACHE it will reset the GL state cache. + * If cc.Macro.ENABLE_GL_STATE_CACHE it will reset the GL state cache. * @function */ cc.glInvalidateStateCache = function () { @@ -54,7 +56,7 @@ cc.glInvalidateStateCache = function () { cc._vertexAttribPosition = false; cc._vertexAttribColor = false; cc._vertexAttribTexCoords = false; - if (cc.ENABLE_GL_STATE_CACHE) { + if (ENABLE_GL_STATE_CACHE) { cc._currentShaderProgram = -1; for (var i = 0; i < cc.MAX_ACTIVETEXTURE; i++) { cc._currentBoundTexture[i] = -1; @@ -67,7 +69,7 @@ cc.glInvalidateStateCache = function () { /** * Uses the GL program in case program is different than the current one.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly. * @function * @param {WebGLProgram} program */ @@ -78,7 +80,7 @@ cc.glUseProgram = function (program) { } }; -if(!cc.ENABLE_GL_STATE_CACHE){ +if(!ENABLE_GL_STATE_CACHE){ cc.glUseProgram = function (program) { cc._renderContext.useProgram(program); } @@ -86,12 +88,12 @@ if(!cc.ENABLE_GL_STATE_CACHE){ /** * Deletes the GL program. If it is the one that is being used, it invalidates it.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly. * @function * @param {WebGLProgram} program */ cc.glDeleteProgram = function (program) { - if (cc.ENABLE_GL_STATE_CACHE) { + if (ENABLE_GL_STATE_CACHE) { if (program === cc._currentShaderProgram) cc._currentShaderProgram = -1; } @@ -100,7 +102,7 @@ cc.glDeleteProgram = function (program) { /** * Uses a blending function in case it not already used.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly. * @function * @param {Number} sfactor * @param {Number} dfactor @@ -150,19 +152,19 @@ cc.glBlendFuncForParticle = function(sfactor, dfactor) { } }; -if(!cc.ENABLE_GL_STATE_CACHE){ +if(!ENABLE_GL_STATE_CACHE){ cc.glBlendFunc = cc.setBlending; }; /** * Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD. * @function */ cc.glBlendResetToCache = function () { var ctx = cc._renderContext; ctx.blendEquation(ctx.FUNC_ADD); - if (cc.ENABLE_GL_STATE_CACHE) + if (ENABLE_GL_STATE_CACHE) cc.setBlending(cc._blendingSource, cc._blendingDest); else cc.setBlending(ctx.BLEND_SRC, ctx.BLEND_DST); @@ -180,51 +182,51 @@ cc.setProjectionMatrixDirty = function () { *

* Will enable the vertex attribs that are passed as flags.
* Possible flags:
- * cc.VERTEX_ATTRIB_FLAG_POSITION
- * cc.VERTEX_ATTRIB_FLAG_COLOR
- * cc.VERTEX_ATTRIB_FLAG_TEX_COORDS
+ * cc.Macro.VERTEX_ATTRIB_FLAG_POSITION
+ * cc.Macro.VERTEX_ATTRIB_FLAG_COLOR
+ * cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS
*
* These flags can be ORed. The flags that are not present, will be disabled. *

* @function - * @param {cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR | cc.VERTEX_ATTRIB_FLAG_TEX_OORDS} flags + * @param {cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_OORDS} flags */ cc.glEnableVertexAttribs = function (flags) { /* Position */ var ctx = cc._renderContext; - var enablePosition = ( flags & cc.VERTEX_ATTRIB_FLAG_POSITION ); + var enablePosition = ( flags & cc.Macro.VERTEX_ATTRIB_FLAG_POSITION ); if (enablePosition !== cc._vertexAttribPosition) { if (enablePosition) - ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION); + ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_POSITION); else - ctx.disableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION); + ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_POSITION); cc._vertexAttribPosition = enablePosition; } /* Color */ - var enableColor = (flags & cc.VERTEX_ATTRIB_FLAG_COLOR); + var enableColor = (flags & cc.Macro.VERTEX_ATTRIB_FLAG_COLOR); if (enableColor !== cc._vertexAttribColor) { if (enableColor) - ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_COLOR); + ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_COLOR); else - ctx.disableVertexAttribArray(cc.VERTEX_ATTRIB_COLOR); + ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_COLOR); cc._vertexAttribColor = enableColor; } /* Tex Coords */ - var enableTexCoords = (flags & cc.VERTEX_ATTRIB_FLAG_TEX_COORDS); + var enableTexCoords = (flags & cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS); if (enableTexCoords !== cc._vertexAttribTexCoords) { if (enableTexCoords) - ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS); + ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_TEX_COORDS); else - ctx.disableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS); + ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_TEX_COORDS); cc._vertexAttribTexCoords = enableTexCoords; } }; /** * If the texture is not already bound, it binds it.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly. * @function * @param {cc.Texture2D} textureId */ @@ -234,7 +236,7 @@ cc.glBindTexture2D = function (textureId) { /** * If the texture is not already bound to a given unit, it binds it.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly. * @function * @param {Number} textureUnit * @param {cc.Texture2D} textureId @@ -251,7 +253,7 @@ cc.glBindTexture2DN = function (textureUnit, textureId) { else ctx.bindTexture(ctx.TEXTURE_2D, null); }; -if (!cc.ENABLE_GL_STATE_CACHE){ +if (!ENABLE_GL_STATE_CACHE){ cc.glBindTexture2DN = function (textureUnit, textureId) { var ctx = cc._renderContext; ctx.activeTexture(ctx.TEXTURE0 + textureUnit); @@ -264,7 +266,7 @@ if (!cc.ENABLE_GL_STATE_CACHE){ /** * It will delete a given texture. If the texture was bound, it will invalidate the cached.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly. * @function * @param {cc.Texture2D} textureId */ @@ -274,13 +276,13 @@ cc.glDeleteTexture2D = function (textureId) { /** * It will delete a given texture. If the texture was bound, it will invalidate the cached for the given texture unit.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly. * @function * @param {Number} textureUnit * @param {cc.Texture2D} textureId */ cc.glDeleteTexture2DN = function (textureUnit, textureId) { - if (cc.ENABLE_GL_STATE_CACHE) { + if (ENABLE_GL_STATE_CACHE) { if (textureId === cc._currentBoundTexture[ textureUnit ]) cc._currentBoundTexture[ textureUnit ] = -1; } @@ -289,15 +291,15 @@ cc.glDeleteTexture2DN = function (textureUnit, textureId) { /** * If the vertex array is not already bound, it binds it.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly. * @function * @param {Number} vaoId */ cc.glBindVAO = function (vaoId) { - if (!cc.TEXTURE_ATLAS_USE_VAO) + if (!cc.Macro.TEXTURE_ATLAS_USE_VAO) return; - if (cc.ENABLE_GL_STATE_CACHE) { + if (ENABLE_GL_STATE_CACHE) { if (cc._uVAO !== vaoId) { cc._uVAO = vaoId; //TODO need fixed @@ -310,12 +312,12 @@ cc.glBindVAO = function (vaoId) { /** * It will enable / disable the server side GL states.
- * If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly. + * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly. * @function * @param {Number} flags */ cc.glEnable = function (flags) { - if (cc.ENABLE_GL_STATE_CACHE) { + if (ENABLE_GL_STATE_CACHE) { /*var enabled; */ diff --git a/cocos2d/shaders/CCShaderCache.js b/cocos2d/shaders/CCShaderCache.js index f78780ddb6..6183feeca9 100644 --- a/cocos2d/shaders/CCShaderCache.js +++ b/cocos2d/shaders/CCShaderCache.js @@ -96,54 +96,54 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ _loadDefaultShader: function (program, type) { switch (type) { case this.TYPE_POSITION_TEXTURECOLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_COLOR_VERT, cc.SHADER_POSITION_TEXTURE_COLOR_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Shaders.POSITION_TEXTURE_COLOR_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); break; case this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_COLOR_VERT, cc.SHADER_POSITION_TEXTURE_COLOR_ALPHATEST_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Shaders.POSITION_TEXTURE_COLOR_ALPHATEST_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); break; case this.TYPE_POSITION_COLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_COLOR_VERT, cc.SHADER_POSITION_COLOR_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_COLOR_VERT, cc.Shaders.POSITION_COLOR_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); break; case this.TYPE_POSITION_TEXTURE: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_VERT, cc.SHADER_POSITION_TEXTURE_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_VERT, cc.Shaders.POSITION_TEXTURE_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); break; case this.TYPE_POSITION_TEXTURE_UCOLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_UCOLOR_VERT, cc.SHADER_POSITION_TEXTURE_UCOLOR_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_UCOLOR_VERT, cc.Shaders.POSITION_TEXTURE_UCOLOR_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); break; case this.TYPE_POSITION_TEXTURE_A8COLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_TEXTURE_A8COLOR_VERT, cc.SHADER_POSITION_TEXTURE_A8COLOR_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_A8COLOR_VERT, cc.Shaders.POSITION_TEXTURE_A8COLOR_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); break; case this.TYPE_POSITION_UCOLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_UCOLOR_VERT, cc.SHADER_POSITION_UCOLOR_FRAG); - program.addAttribute("aVertex", cc.VERTEX_ATTRIB_POSITION); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_UCOLOR_VERT, cc.Shaders.POSITION_UCOLOR_FRAG); + program.addAttribute("aVertex", cc.Macro.VERTEX_ATTRIB_POSITION); break; case this.TYPE_POSITION_LENGTH_TEXTURECOLOR: - program.initWithVertexShaderByteArray(cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_VERT, cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_FRAG); + program.initWithVertexShaderByteArray(cc.Shaders.POSITION_COLOR_LENGTH_TEXTURE_VERT, cc.Shaders.POSITION_COLOR_LENGTH_TEXTURE_FRAG); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); break; default: cc.log("cocos2d: cc.shaderCache._loadDefaultShader, error shader type"); @@ -163,13 +163,13 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // Position Texture Color shader var program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR); - this._programs[cc.SHADER_POSITION_TEXTURECOLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_TEXTURECOLOR] = program; this._programs["ShaderPositionTextureColor"] = program; // Position Texture Color alpha test program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST); - this._programs[cc.SHADER_POSITION_TEXTURECOLORALPHATEST] = program; + this._programs[cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST] = program; this._programs["ShaderPositionTextureColorAlphaTest"] = program; // @@ -177,7 +177,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_COLOR); - this._programs[cc.SHADER_POSITION_COLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_COLOR] = program; this._programs["ShaderPositionColor"] = program; // @@ -185,7 +185,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE); - this._programs[cc.SHADER_POSITION_TEXTURE] = program; + this._programs[cc.Macro.SHADER_POSITION_TEXTURE] = program; this._programs["ShaderPositionTexture"] = program; // @@ -193,7 +193,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_UCOLOR); - this._programs[cc.SHADER_POSITION_TEXTURE_UCOLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR] = program; this._programs["ShaderPositionTextureUColor"] = program; // @@ -201,7 +201,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_A8COLOR); - this._programs[cc.SHADER_POSITION_TEXTUREA8COLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_TEXTUREA8COLOR] = program; this._programs["ShaderPositionTextureA8Color"] = program; // @@ -209,7 +209,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_UCOLOR); - this._programs[cc.SHADER_POSITION_UCOLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_UCOLOR] = program; this._programs["ShaderPositionUColor"] = program; // @@ -217,7 +217,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // program = new cc.GLProgram(); this._loadDefaultShader(program, this.TYPE_POSITION_LENGTH_TEXTURECOLOR); - this._programs[cc.SHADER_POSITION_LENGTHTEXTURECOLOR] = program; + this._programs[cc.Macro.SHADER_POSITION_LENGTHTEXTURECOLOR] = program; this._programs["ShaderPositionLengthTextureColor"] = program; }, @@ -228,47 +228,47 @@ cc.shaderCache = /** @lends cc.shaderCache# */{ // reset all programs and reload them // Position Texture Color shader - var program = this.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + var program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR); // Position Texture Color alpha test - program = this.programForKey(cc.SHADER_POSITION_TEXTURECOLORALPHATEST); + program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST); // // Position, Color shader // - program = this.programForKey(cc.SHADER_POSITION_COLOR); + program = this.programForKey(cc.Macro.SHADER_POSITION_COLOR); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_COLOR); // // Position Texture shader // - program = this.programForKey(cc.SHADER_POSITION_TEXTURE); + program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURE); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE); // // Position, Texture attribs, 1 Color as uniform shader // - program = this.programForKey(cc.SHADER_POSITION_TEXTURE_UCOLOR); + program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_UCOLOR); // // Position Texture A8 Color shader // - program = this.programForKey(cc.SHADER_POSITION_TEXTUREA8COLOR); + program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTUREA8COLOR); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_A8COLOR); // // Position and 1 color passed as a uniform (to similate glColor4ub ) // - program = this.programForKey(cc.SHADER_POSITION_UCOLOR); + program = this.programForKey(cc.Macro.SHADER_POSITION_UCOLOR); program.reset(); this._loadDefaultShader(program, this.TYPE_POSITION_UCOLOR); }, diff --git a/cocos2d/shaders/CCShaders.js b/cocos2d/shaders/CCShaders.js index 437ce589aa..393e6b7c56 100644 --- a/cocos2d/shaders/CCShaders.js +++ b/cocos2d/shaders/CCShaders.js @@ -25,256 +25,254 @@ ****************************************************************************/ //-----------------------Shader_Position_uColor Shader Source-------------------------- + /** - * @constant - * @type {String} + * Predefined constants + * @property Shaders + * @readonly + * @type {Object} + * @static + * @namespace cc */ -cc.SHADER_POSITION_UCOLOR_FRAG = - "precision lowp float;\n" +cc.Shaders = { + /** + * @property POSITION_UCOLOR_FRAG + * @type {String} + */ + POSITION_UCOLOR_FRAG : "precision lowp float;\n" + "varying vec4 v_fragmentColor;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_fragmentColor; \n" - + "}\n"; -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_UCOLOR_VERT = - "attribute vec4 a_position;\n" - + "uniform vec4 u_color;\n" - + "uniform float u_pointSize;\n" - + "varying lowp vec4 v_fragmentColor; \n" - + "void main(void) \n" - + "{\n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " gl_PointSize = u_pointSize; \n" - + " v_fragmentColor = u_color; \n" - + "}"; + + "}\n", -//---------------------Shader_PositionColor Shader Source----------------------- -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_COLOR_FRAG = - "precision lowp float; \n" - + "varying vec4 v_fragmentColor; \n" - + "void main() \n" - + "{ \n" - + " gl_FragColor = v_fragmentColor; \n" - + "} "; + /** + * @property POSITION_UCOLOR_VERT + * @type {String} + */ + POSITION_UCOLOR_VERT : + "attribute vec4 a_position;\n" + + "uniform vec4 u_color;\n" + + "uniform float u_pointSize;\n" + + "varying lowp vec4 v_fragmentColor; \n" + + "void main(void) \n" + + "{\n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " gl_PointSize = u_pointSize; \n" + + " v_fragmentColor = u_color; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_COLOR_VERT = - "attribute vec4 a_position;\n" - + "attribute vec4 a_color;\n" - + "varying lowp vec4 v_fragmentColor;\n" - + "void main()\n" - + "{\n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " v_fragmentColor = a_color; \n" - + "}"; + //---------------------Shader_PositionColor Shader Source----------------------- + /** + * @property POSITION_COLOR_FRAG + * @type {String} + */ + POSITION_COLOR_FRAG : "precision lowp float; \n" + + "varying vec4 v_fragmentColor; \n" + + "void main() \n" + + "{ \n" + + " gl_FragColor = v_fragmentColor; \n" + + "} ", -// --------------------- Shader_PositionColorLengthTexture Shader source------------------------ -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_FRAG = - "// #extension GL_OES_standard_derivatives : enable\n" - + "varying mediump vec4 v_color;\n" - + "varying mediump vec2 v_texcoord;\n" - + "void main() \n" - + "{ \n" - + "// #if defined GL_OES_standard_derivatives \n" - + "// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord)); \n" - + "// #else \n" - + "gl_FragColor = v_color * step(0.0, 1.0 - length(v_texcoord)); \n" - + "// #endif \n" - + "}"; + /** + * @property POSITION_COLOR_VERT + * @type {String} + */ + POSITION_COLOR_VERT : "attribute vec4 a_position;\n" + + "attribute vec4 a_color;\n" + + "varying lowp vec4 v_fragmentColor;\n" + + "void main()\n" + + "{\n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " v_fragmentColor = a_color; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_VERT = - "attribute mediump vec4 a_position; \n" - + "attribute mediump vec2 a_texcoord; \n" - + "attribute mediump vec4 a_color; \n" - + "varying mediump vec4 v_color; \n" - + "varying mediump vec2 v_texcoord; \n" - + "void main() \n" - + "{ \n" - + " v_color = a_color;//vec4(a_color.rgb * a_color.a, a_color.a); \n" - + " v_texcoord = a_texcoord; \n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + "}"; + // --------------------- Shader_PositionColorLengthTexture Shader source------------------------ + /** + * @constant + * @type {String} + */ + POSITION_COLOR_LENGTH_TEXTURE_FRAG : "// #extension GL_OES_standard_derivatives : enable\n" + + "varying mediump vec4 v_color;\n" + + "varying mediump vec2 v_texcoord;\n" + + "void main() \n" + + "{ \n" + + "// #if defined GL_OES_standard_derivatives \n" + + "// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord)); \n" + + "// #else \n" + + "gl_FragColor = v_color * step(0.0, 1.0 - length(v_texcoord)); \n" + + "// #endif \n" + + "}", -// ----------------------Shader_PositionTexture Shader Source------------------------------------- -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_FRAG = - "precision lowp float; \n" - + "varying vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - + " gl_FragColor = texture2D(CC_Texture0, v_texCoord); \n" - + "}"; + /** + * @constant + * @type {String} + */ + POSITION_COLOR_LENGTH_TEXTURE_VERT : "attribute mediump vec4 a_position; \n" + + "attribute mediump vec2 a_texcoord; \n" + + "attribute mediump vec4 a_color; \n" + + "varying mediump vec4 v_color; \n" + + "varying mediump vec2 v_texcoord; \n" + + "void main() \n" + + "{ \n" + + " v_color = a_color;//vec4(a_color.rgb * a_color.a, a_color.a); \n" + + " v_texcoord = a_texcoord; \n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_VERT = - "attribute vec4 a_position; \n" - + "attribute vec2 a_texCoord; \n" - + "varying mediump vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " v_texCoord = a_texCoord; \n" - + "}"; + // ----------------------Shader_PositionTexture Shader Source------------------------------------- + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_FRAG : "precision lowp float; \n" + + "varying vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + + " gl_FragColor = texture2D(CC_Texture0, v_texCoord); \n" + + "}", -// ------------------------Shader_PositionTexture_uColor Shader Source------------------------------- -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_UCOLOR_FRAG = - "precision lowp float; \n" - + "uniform vec4 u_color; \n" - + "varying vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - + " gl_FragColor = texture2D(CC_Texture0, v_texCoord) * u_color; \n" - + "}"; + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_VERT : "attribute vec4 a_position; \n" + + "attribute vec2 a_texCoord; \n" + + "varying mediump vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " v_texCoord = a_texCoord; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_UCOLOR_VERT = - "attribute vec4 a_position;\n" - + "attribute vec2 a_texCoord; \n" - + "varying mediump vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " v_texCoord = a_texCoord; \n" - + "}"; + // ------------------------Shader_PositionTexture_uColor Shader Source------------------------------- + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_UCOLOR_FRAG : "precision lowp float; \n" + + "uniform vec4 u_color; \n" + + "varying vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + + " gl_FragColor = texture2D(CC_Texture0, v_texCoord) * u_color; \n" + + "}", -//---------------------Shader_PositionTextureA8Color Shader source------------------------------- -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_A8COLOR_FRAG = - "precision lowp float; \n" - + "varying vec4 v_fragmentColor; \n" - + "varying vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - + " gl_FragColor = vec4( v_fragmentColor.rgb, \n" // RGB from uniform - + " v_fragmentColor.a * texture2D(CC_Texture0, v_texCoord).a \n" // A from texture and uniform - + " ); \n" - + "}"; + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_UCOLOR_VERT : "attribute vec4 a_position;\n" + + "attribute vec2 a_texCoord; \n" + + "varying mediump vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " v_texCoord = a_texCoord; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_A8COLOR_VERT = - "attribute vec4 a_position; \n" - + "attribute vec2 a_texCoord; \n" - + "attribute vec4 a_color; \n" - + "varying lowp vec4 v_fragmentColor; \n" - + "varying mediump vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " v_fragmentColor = a_color; \n" - + " v_texCoord = a_texCoord; \n" - + "}"; + //---------------------Shader_PositionTextureA8Color Shader source------------------------------- + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_A8COLOR_FRAG : "precision lowp float; \n" + + "varying vec4 v_fragmentColor; \n" + + "varying vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + + " gl_FragColor = vec4( v_fragmentColor.rgb, \n" // RGB from uniform + + " v_fragmentColor.a * texture2D(CC_Texture0, v_texCoord).a \n" // A from texture and uniform + + " ); \n" + + "}", -// ------------------------Shader_PositionTextureColor Shader source------------------------------------ -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_COLOR_FRAG = - "precision lowp float;\n" - + "varying vec4 v_fragmentColor; \n" - + "varying vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - + " gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n" - + "}"; + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_A8COLOR_VERT : "attribute vec4 a_position; \n" + + "attribute vec2 a_texCoord; \n" + + "attribute vec4 a_color; \n" + + "varying lowp vec4 v_fragmentColor; \n" + + "varying mediump vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " v_fragmentColor = a_color; \n" + + " v_texCoord = a_texCoord; \n" + + "}", -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_COLOR_VERT = - "attribute vec4 a_position; \n" - + "attribute vec2 a_texCoord; \n" - + "attribute vec4 a_color; \n" - + "varying lowp vec4 v_fragmentColor; \n" - + "varying mediump vec2 v_texCoord; \n" - + "void main() \n" - + "{ \n" - //+ " gl_Position = CC_MVPMatrix * a_position; \n" - + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" - + " v_fragmentColor = a_color; \n" - + " v_texCoord = a_texCoord; \n" - + "}"; + // ------------------------Shader_PositionTextureColor Shader source------------------------------------ + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_COLOR_FRAG : "precision lowp float;\n" + + "varying vec4 v_fragmentColor; \n" + + "varying vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + + " gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n" + + "}", -//-----------------------Shader_PositionTextureColorAlphaTest_frag Shader Source---------------------------- -/** - * @constant - * @type {String} - */ -cc.SHADER_POSITION_TEXTURE_COLOR_ALPHATEST_FRAG = - "precision lowp float; \n" - + "varying vec4 v_fragmentColor; \n" - + "varying vec2 v_texCoord; \n" - + "uniform float CC_alpha_value; \n" - + "void main() \n" - + "{ \n" - + " vec4 texColor = texture2D(CC_Texture0, v_texCoord); \n" - // mimic: glAlphaFunc(GL_GREATER) - //pass if ( incoming_pixel >= CC_alpha_value ) => fail if incoming_pixel < CC_alpha_value - + " if ( texColor.a <= CC_alpha_value ) \n" - + " discard; \n" - + " gl_FragColor = texColor * v_fragmentColor; \n" - + "}"; + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_COLOR_VERT : "attribute vec4 a_position; \n" + + "attribute vec2 a_texCoord; \n" + + "attribute vec4 a_color; \n" + + "varying lowp vec4 v_fragmentColor; \n" + + "varying mediump vec2 v_texCoord; \n" + + "void main() \n" + + "{ \n" + //+ " gl_Position = CC_MVPMatrix * a_position; \n" + + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" + + " v_fragmentColor = a_color; \n" + + " v_texCoord = a_texCoord; \n" + + "}", -//-----------------------ShaderEx_SwitchMask_frag Shader Source---------------------------- -/** - * @constant - * @type {String} - */ -cc.SHADEREX_SWITCHMASK_FRAG = - "precision lowp float; \n" - + "varying vec4 v_fragmentColor; \n" - + "varying vec2 v_texCoord; \n" - + "uniform sampler2D u_texture; \n" - + "uniform sampler2D u_mask; \n" - + "void main() \n" - + "{ \n" - + " vec4 texColor = texture2D(u_texture, v_texCoord); \n" - + " vec4 maskColor = texture2D(u_mask, v_texCoord); \n" - + " vec4 finalColor = vec4(texColor.r, texColor.g, texColor.b, maskColor.a * texColor.a); \n" - + " gl_FragColor = v_fragmentColor * finalColor; \n" - + "}"; \ No newline at end of file + //-----------------------Shader_PositionTextureColorAlphaTest_frag Shader Source---------------------------- + /** + * @constant + * @type {String} + */ + POSITION_TEXTURE_COLOR_ALPHATEST_FRAG : "precision lowp float; \n" + + "varying vec4 v_fragmentColor; \n" + + "varying vec2 v_texCoord; \n" + + "uniform float CC_alpha_value; \n" + + "void main() \n" + + "{ \n" + + " vec4 texColor = texture2D(CC_Texture0, v_texCoord); \n" + // mimic: glAlphaFunc(GL_GREATER) + //pass if ( incoming_pixel >= CC_alpha_value ) => fail if incoming_pixel < CC_alpha_value + + " if ( texColor.a <= CC_alpha_value ) \n" + + " discard; \n" + + " gl_FragColor = texColor * v_fragmentColor; \n" + + "}", + + //-----------------------ShaderEx_SwitchMask_frag Shader Source---------------------------- + /** + * @constant + * @type {String} + */ + EX_SWITCHMASK_FRAG : "precision lowp float; \n" + + "varying vec4 v_fragmentColor; \n" + + "varying vec2 v_texCoord; \n" + + "uniform sampler2D u_texture; \n" + + "uniform sampler2D u_mask; \n" + + "void main() \n" + + "{ \n" + + " vec4 texColor = texture2D(u_texture, v_texCoord); \n" + + " vec4 maskColor = texture2D(u_mask, v_texCoord); \n" + + " vec4 finalColor = vec4(texColor.r, texColor.g, texColor.b, maskColor.a * texColor.a); \n" + + " gl_FragColor = v_fragmentColor * finalColor; \n" + + "}" + +}; \ No newline at end of file diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js index 4c1294d9bb..ee4a0febf4 100644 --- a/cocos2d/shape-nodes/CCDrawNode.js +++ b/cocos2d/shape-nodes/CCDrawNode.js @@ -198,7 +198,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { var locCmd = this._renderCmd; locCmd._buffer = this._buffer = []; locCmd._drawColor = this._drawColor = cc.color(255, 255, 255, 255); - locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); + locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); this.init(); }, @@ -527,7 +527,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { ctor:function () { _ccsg.Node.prototype.ctor.call(this); this._buffer = []; - this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); + this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); this._drawColor = new cc.WebGLColor(255,255,255,255); this.init(); @@ -535,7 +535,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { init:function () { if (_ccsg.Node.prototype.init.call(this)) { - this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_LENGTHTEXTURECOLOR); + this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_LENGTHTEXTURECOLOR); this._ensureCapacity(64); this._trianglesWebBuffer = cc._renderContext.createBuffer(); this._dirty = true; @@ -649,7 +649,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { _render:function () { var gl = cc._renderContext; - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._trianglesWebBuffer); if (this._dirty) { gl.bufferData(gl.ARRAY_BUFFER, this._trianglesArrayBuffer, gl.STREAM_DRAW); @@ -658,11 +658,11 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { var triangleSize = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT; // vertex - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0); // color - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8); // texcood - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12); gl.drawArrays(gl.TRIANGLES, 0, this._buffer.length * 3); cc.incrementGLDraws(1); diff --git a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js b/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js index 02bc6ce7d4..eb3af4bd14 100644 --- a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js +++ b/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js @@ -45,7 +45,7 @@ //context.save(); wrapper.setGlobalAlpha(alpha); - if ((this._blendFunc && (this._blendFunc.src === cc.SRC_ALPHA) && (this._blendFunc.dst === cc.ONE))) + if ((this._blendFunc && (this._blendFunc.src === cc.Macro.SRC_ALPHA) && (this._blendFunc.dst === cc.Macro.ONE))) wrapper.setCompositeOperation('lighter'); //todo: need refactor var locBuffer = this._buffer; for (var i = 0, len = locBuffer.length; i < len; i++) { diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 508797625f..54ab7da302 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -766,8 +766,8 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ alphaFuncValue = parseFloat(alphaFuncVal); if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { //todo: need move to WebGL render cmd - this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLORALPHATEST); - var alphaValueLocation = cc._renderContext.getUniformLocation(this.shaderProgram.getProgram(), cc.UNIFORM_ALPHA_TEST_VALUE_S); + this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST); + var alphaValueLocation = cc._renderContext.getUniformLocation(this.shaderProgram.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S); // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison this.shaderProgram.use(); this.shaderProgram.setUniformLocationWith1f(alphaValueLocation, alphaFuncValue); diff --git a/cocos2d/tilemap/CCSGTMXTiledMap.js b/cocos2d/tilemap/CCSGTMXTiledMap.js index 89126fd712..ddf28b0e3c 100644 --- a/cocos2d/tilemap/CCSGTMXTiledMap.js +++ b/cocos2d/tilemap/CCSGTMXTiledMap.js @@ -47,7 +47,7 @@ cc.TMX_ORIENTATION_HEX = 1; cc.TMX_ORIENTATION_ISO = 2; /** - *

cc.TMXTiledMap knows how to parse and render a TMX map.

+ *

_ccsg.TMXTiledMap knows how to parse and render a TMX map.

* *

It adds support for the TMX tiled map format used by http://www.mapeditor.org
* It supports isometric, hexagonal and orthogonal tiles.
@@ -113,15 +113,15 @@ cc.TMX_ORIENTATION_ISO = 2; * //example * 1. * //create a TMXTiledMap with file name - * var tmxTiledMap = new cc.TMXTiledMap("res/orthogonal-test1.tmx"); + * var tmxTiledMap = new _ccsg.TMXTiledMap("res/orthogonal-test1.tmx"); * 2. * //create a TMXTiledMap with content string and resource path * var resources = "res/TileMaps"; * var filePath = "res/TileMaps/orthogonal-test1.tmx"; * var xmlStr = cc.loader.getRes(filePath); - * var tmxTiledMap = new cc.TMXTiledMap(xmlStr, resources); + * var tmxTiledMap = new _ccsg.TMXTiledMap(xmlStr, resources); */ -_ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends cc.TMXTiledMap# */{ +_ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ properties: null, mapOrientation: null, objectGroups: null, diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index 0a818196a9..b041faf0f3 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -1518,8 +1518,8 @@ cc.TransitionCrossFade = cc.TransitionScene.extend(/** @lends cc.TransitionCross this._outScene.visit(); outTexture.end(); - inTexture.sprite.setBlendFunc(cc.ONE, cc.ONE); // inScene will lay on background and will not be used with alpha - outTexture.sprite.setBlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha + inTexture.sprite.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE); // inScene will lay on background and will not be used with alpha + outTexture.sprite.setBlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha // add render textures to the layer layer.addChild(inTexture); diff --git a/extensions/ccui/layouts/UILayout.js b/extensions/ccui/layouts/UILayout.js index 9f833cdd18..de88174cc3 100644 --- a/extensions/ccui/layouts/UILayout.js +++ b/extensions/ccui/layouts/UILayout.js @@ -936,7 +936,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ var index = 0, locChildren = this.getChildren(); var count = locChildren.length, widgetPosition; - var distance = cc.FLT_MAX, found = 0; + var distance = cc.Macro.FLT_MAX, found = 0; if (direction === ccui.Widget.LEFT || direction === ccui.Widget.RIGHT || direction === ccui.Widget.DOWN || direction === ccui.Widget.UP) { widgetPosition = this._getWorldCenterPoint(baseWidget); while (index < count) { @@ -972,7 +972,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ var index = 0, locChildren = this.getChildren(); var count = locChildren.length; - var distance = -cc.FLT_MAX, found = 0; + var distance = -cc.Macro.FLT_MAX, found = 0; if (direction === ccui.Widget.LEFT || direction === ccui.Widget.RIGHT || direction === ccui.Widget.DOWN || direction === ccui.Widget.UP) { var widgetPosition = this._getWorldCenterPoint(baseWidget); while (index < count) { @@ -1000,7 +1000,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ * @private */ _calculateNearestDistance: function(baseWidget){ - var distance = cc.FLT_MAX; + var distance = cc.Macro.FLT_MAX; var widgetPosition = this._getWorldCenterPoint(baseWidget); var locChildren = this._children; @@ -1027,7 +1027,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ * @private */ _calculateFarthestDistance:function(baseWidget){ - var distance = -cc.FLT_MAX; + var distance = -cc.Macro.FLT_MAX; var widgetPosition = this._getWorldCenterPoint(baseWidget); var locChildren = this._children; diff --git a/extensions/cocostudio/action/CCActionObject.js b/extensions/cocostudio/action/CCActionObject.js index d87e8f9e71..a78f0f7b41 100644 --- a/extensions/cocostudio/action/CCActionObject.js +++ b/extensions/cocostudio/action/CCActionObject.js @@ -200,7 +200,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{ locActionNodeList[i].playAction(fun); } if (this._loop) - this._scheduler.schedule(this.simulationActionUpdate, this, 0, cc.REPEAT_FOREVER, 0, false, this.__instanceId + ""); + this._scheduler.schedule(this.simulationActionUpdate, this, 0, cc.Macro.REPEAT_FOREVER, 0, false, this.__instanceId + ""); if(fun !== undefined) this._callback = fun; }, diff --git a/extensions/cocostudio/armature/CCArmature.js b/extensions/cocostudio/armature/CCArmature.js index 8f9525718a..8030a42a5c 100644 --- a/extensions/cocostudio/armature/CCArmature.js +++ b/extensions/cocostudio/armature/CCArmature.js @@ -68,7 +68,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{ this._armatureIndexDic = {}; this._offsetPoint = cc.p(0, 0); this._armatureTransformDirty = true; - this._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST}; + this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST}; name && ccs.Armature.prototype.init.call(this, name, parentBone); }, diff --git a/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js b/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js index 67dc48c3eb..9f4e8f6aaa 100644 --- a/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js +++ b/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js @@ -92,7 +92,7 @@ }; proto.initShaderCache = function(){ - this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); }; proto.setShaderProgram = function(shaderProgram){ diff --git a/extensions/cocostudio/armature/CCBone.js b/extensions/cocostudio/armature/CCBone.js index dd3149b8b9..38c5f123a7 100644 --- a/extensions/cocostudio/armature/CCBone.js +++ b/extensions/cocostudio/armature/CCBone.js @@ -78,7 +78,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{ this._worldTransform = cc.affineTransformMake(1, 0, 0, 1, 0, 0); this._boneTransformDirty = true; - this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + this._blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST); this.blendDirty = false; this._worldInfo = null; diff --git a/extensions/cocostudio/armature/animation/CCTween.js b/extensions/cocostudio/armature/animation/CCTween.js index 5706d1d595..c7d86e1134 100644 --- a/extensions/cocostudio/armature/animation/CCTween.js +++ b/extensions/cocostudio/armature/animation/CCTween.js @@ -212,7 +212,7 @@ ccs.Tween = ccs.ProcessBase.extend(/** @lends ccs.Tween# */{ } if (locCurrentPercent < 1 && locLoopType < ccs.ANIMATION_TYPE_TO_LOOP_BACK) - locCurrentPercent = Math.sin(locCurrentPercent * cc.PI / 2); + locCurrentPercent = Math.sin(locCurrentPercent * Math.PI / 2); this._currentPercent = locCurrentPercent; this._loopType = locLoopType; diff --git a/extensions/cocostudio/armature/datas/CCDatas.js b/extensions/cocostudio/armature/datas/CCDatas.js index 79c0de812a..5bd84bf0a1 100644 --- a/extensions/cocostudio/armature/datas/CCDatas.js +++ b/extensions/cocostudio/armature/datas/CCDatas.js @@ -557,7 +557,7 @@ ccs.FrameData = ccs.BaseData.extend(/** @lends ccs.FrameData# */{ this.event = ""; this.sound = ""; this.soundEffect = ""; - this.blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + this.blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST); this.frameID = 0; this.isTween = true; }, diff --git a/extensions/cocostudio/armature/display/CCBatchNode.js b/extensions/cocostudio/armature/display/CCBatchNode.js index c0ef12b7fe..504678a179 100644 --- a/extensions/cocostudio/armature/display/CCBatchNode.js +++ b/extensions/cocostudio/armature/display/CCBatchNode.js @@ -40,7 +40,7 @@ ccs.BatchNode = _ccsg.Node.extend(/** @lends ccs.BatchNode# */{ init:function () { var ret = _ccsg.Node.prototype.init.call(this); - this.setShaderProgram(cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE_UCOLOR)); + this.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR)); return ret; }, diff --git a/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js b/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js index a4586fdc41..f804e6a3aa 100644 --- a/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js +++ b/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js @@ -65,7 +65,7 @@ var dy = x1 * sr + y2 * cr2 + y; var locVertexZ = node._vertexZ; - if(!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) { + if(!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) { ax = 0 | ax; ay = 0 | ay; bx = 0 | bx; @@ -106,25 +106,25 @@ cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst); //optimize performance for javascript cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture); - cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); + cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer); if (this._quadDirty) { gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW); this._quadDirty = false; } - gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.VERTEX_ATTRIB_POSITION - gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.VERTEX_ATTRIB_COLOR - gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.VERTEX_ATTRIB_TEX_COORDS + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION + gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR + gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } cc.g_NumberOfDraws++; - if (cc.SPRITE_DEBUG_DRAW === 0 && !node._showNode) + if (cc.Macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode) return; - if (cc.SPRITE_DEBUG_DRAW === 1 || node._showNode) { + if (cc.Macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) { // draw bounding box var locQuad = this._quad; var verticesG1 = [ @@ -134,7 +134,7 @@ cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y) ]; cc._drawingUtil.drawPoly(verticesG1, 4, true); - } else if (cc.SPRITE_DEBUG_DRAW === 2) { + } else if (cc.Macro.SPRITE_DEBUG_DRAW === 2) { // draw texture box var drawRectG2 = node.getTextureRect(); var offsetPixG2 = node.getOffsetPosition(); diff --git a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js index 77cd0333c9..99c837dde9 100644 --- a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js +++ b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js @@ -847,24 +847,24 @@ ccs.dataReaderHelper = /** @lends ccs.dataReaderHelper# */{ var blendFunc = frameData.blendFunc; switch (blendType) { case ccs.BLEND_TYPE_NORMAL: - blendFunc.src = cc.BLEND_SRC; - blendFunc.dst = cc.BLEND_DST; + blendFunc.src = cc.Macro.BLEND_SRC; + blendFunc.dst = cc.Macro.BLEND_DST; break; case ccs.BLEND_TYPE_ADD: - blendFunc.src = cc.SRC_ALPHA; - blendFunc.dst = cc.ONE; + blendFunc.src = cc.Macro.SRC_ALPHA; + blendFunc.dst = cc.Macro.ONE; break; case ccs.BLEND_TYPE_MULTIPLY: - blendFunc.src = cc.DST_COLOR; - blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + blendFunc.src = cc.Macro.DST_COLOR; + blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; break; case ccs.BLEND_TYPE_SCREEN: - blendFunc.src = cc.ONE; - blendFunc.dst = cc.ONE_MINUS_DST_COLOR; + blendFunc.src = cc.Macro.ONE; + blendFunc.dst = cc.Macro.ONE_MINUS_DST_COLOR; break; default: - frameData.blendFunc.src = cc.BLEND_SRC; - frameData.blendFunc.dst = cc.BLEND_DST; + frameData.blendFunc.src = cc.Macro.BLEND_SRC; + frameData.blendFunc.dst = cc.Macro.BLEND_DST; break; } } @@ -937,8 +937,8 @@ ccs.dataReaderHelper = /** @lends ccs.dataReaderHelper# */{ frameData.tweenEasing = json[ccs.CONST_A_TWEEN_EASING] || ccs.TweenType.LINEAR; frameData.displayIndex = json[ccs.CONST_A_DISPLAY_INDEX]; - var bd_src = json[ccs.CONST_A_BLEND_SRC] == null ? cc.BLEND_SRC : json[ccs.CONST_A_BLEND_SRC]; - var bd_dst = json[ccs.CONST_A_BLEND_DST] == null ? cc.BLEND_DST : json[ccs.CONST_A_BLEND_DST]; + var bd_src = json[ccs.CONST_A_BLEND_SRC] == null ? cc.Macro.BLEND_SRC : json[ccs.CONST_A_BLEND_SRC]; + var bd_dst = json[ccs.CONST_A_BLEND_DST] == null ? cc.Macro.BLEND_DST : json[ccs.CONST_A_BLEND_DST]; frameData.blendFunc.src = bd_src; frameData.blendFunc.dst = bd_dst; frameData.isTween = json[ccs.CONST_A_TWEEN_FRAME] == null ? true : json[ccs.CONST_A_TWEEN_FRAME]; diff --git a/extensions/gui/control-extension/CCControlStepper.js b/extensions/gui/control-extension/CCControlStepper.js index c529b75ae0..fb0e8c97eb 100644 --- a/extensions/gui/control-extension/CCControlStepper.js +++ b/extensions/gui/control-extension/CCControlStepper.js @@ -221,7 +221,7 @@ cc.ControlStepper = cc.Control.extend(/** @lends cc.ControlStepper# */{ startAutorepeat:function () { this._autorepeatCount = -1; - this.schedule(this.update, cc.AUTOREPEAT_DELTATIME, cc.REPEAT_FOREVER, cc.AUTOREPEAT_DELTATIME * 3); + this.schedule(this.update, cc.AUTOREPEAT_DELTATIME, cc.Macro.REPEAT_FOREVER, cc.AUTOREPEAT_DELTATIME * 3); }, /** Stop the autorepeat. */ diff --git a/extensions/gui/scrollview/CCSorting.js b/extensions/gui/scrollview/CCSorting.js index 7902018171..d9e43b88c1 100644 --- a/extensions/gui/scrollview/CCSorting.js +++ b/extensions/gui/scrollview/CCSorting.js @@ -108,7 +108,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting# } var idx = this.indexOfSortedObject(delObject); - if (idx < this.count() && idx !== cc.INVALID_INDEX) { + if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) { var foundObj = this.objectAtIndex(idx); if (foundObj.getObjectID() === delObject.getObjectID()) { this.removeObjectAtIndex(idx); @@ -129,7 +129,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting# */ setObjectID_ofSortedObject:function (tag, setObject) { var idx = this.indexOfSortedObject(setObject); - if (idx < this.count() && idx !== cc.INVALID_INDEX) { + if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) { var foundObj = this.objectAtIndex(idx); if (foundObj.getObjectID() === setObject.getObjectID()) { this.removeObjectAtIndex(idx); @@ -147,7 +147,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting# foundObj.setObjectID(tag); var idx = this.indexOfSortedObject(foundObj); - if (idx < this.count() && idx !== cc.INVALID_INDEX) { + if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) { foundObj = this.objectAtIndex(idx); if (foundObj.getObjectID() !== tag) foundObj = null; @@ -201,7 +201,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting# idx++; } } else { - idx = cc.INVALID_INDEX; + idx = cc.Macro.INVALID_INDEX; } return idx; }, diff --git a/extensions/gui/scrollview/CCTableView.js b/extensions/gui/scrollview/CCTableView.js index ee312132ef..f3992593e5 100644 --- a/extensions/gui/scrollview/CCTableView.js +++ b/extensions/gui/scrollview/CCTableView.js @@ -65,7 +65,7 @@ cc.TableViewCell = _ccsg.Node.extend(/** @lends cc.TableViewCell# */{ * Cleans up any resources linked to this cell and resets idx property. */ reset:function () { - this._idx = cc.INVALID_INDEX; + this._idx = cc.Macro.INVALID_INDEX; }, setObjectID:function (idx) { @@ -257,7 +257,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ if (index !== -1) { index = Math.max(0, index); if (index > maxIdx) - index = cc.INVALID_INDEX; + index = cc.Macro.INVALID_INDEX; } return index; }, @@ -428,7 +428,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ * @param idx index to find a cell */ updateCellAtIndex:function (idx) { - if (idx === cc.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) + if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) return; var cell = this.cellAtIndex(idx); @@ -446,7 +446,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ * @param idx location to insert */ insertCellAtIndex:function (idx) { - if (idx === cc.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) + if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) return; var newIdx, locCellsUsed = this._cellsUsed; @@ -474,7 +474,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ * @param idx index to find a cell */ removeCellAtIndex:function (idx) { - if (idx === cc.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) + if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1) return; var cell = this.cellAtIndex(idx); @@ -569,7 +569,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ if (this._vOrdering === cc.TABLEVIEW_FILL_TOPDOWN) offset.y = offset.y + locViewSize.height/locContainer.getScaleY(); var startIdx = this._indexFromOffset(offset); - if (startIdx === cc.INVALID_INDEX) + if (startIdx === cc.Macro.INVALID_INDEX) startIdx = countOfItems - 1; if (this._vOrdering === cc.TABLEVIEW_FILL_TOPDOWN) @@ -579,7 +579,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ offset.x += locViewSize.width/locContainer.getScaleX(); var endIdx = this._indexFromOffset(offset); - if (endIdx === cc.INVALID_INDEX) + if (endIdx === cc.Macro.INVALID_INDEX) endIdx = countOfItems - 1; var cell, locCellsUsed = this._cellsUsed; @@ -656,7 +656,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{ point = this.getContainer().convertTouchToNodeSpace(touch); index = this._indexFromOffset(point); - if (index === cc.INVALID_INDEX) + if (index === cc.Macro.INVALID_INDEX) this._touchedCell = null; else this._touchedCell = this.cellAtIndex(index); diff --git a/extensions/spine/SGSkeleton.js b/extensions/spine/SGSkeleton.js index 5d2ca1a7b0..d96a50c93a 100644 --- a/extensions/spine/SGSkeleton.js +++ b/extensions/spine/SGSkeleton.js @@ -40,7 +40,7 @@ sp._SGSkeleton = _ccsg.Node.extend({ ctor: function(skeletonDataFile, atlasFile, scale) { _ccsg.Node.prototype.ctor.call(this); - this._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST}; + this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST}; if(arguments.length === 0) this.init(); @@ -58,8 +58,8 @@ sp._SGSkeleton = _ccsg.Node.extend({ init: function () { _ccsg.Node.prototype.init.call(this); //this.setOpacityModifyRGB(true); - this._blendFunc.src = cc.ONE; - this._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; + this._blendFunc.src = cc.Macro.ONE; + this._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA; this.scheduleUpdate(); }, @@ -148,7 +148,7 @@ sp._SGSkeleton = _ccsg.Node.extend({ * @returns {cc.Rect} */ getBoundingBox: function () { - var minX = cc.FLT_MAX, minY = cc.FLT_MAX, maxX = cc.FLT_MIN, maxY = cc.FLT_MIN; + var minX = cc.Macro.FLT_MAX, minY = cc.Macro.FLT_MAX, maxX = cc.Macro.FLT_MIN, maxY = cc.Macro.FLT_MIN; var scaleX = this.getScaleX(), scaleY = this.getScaleY(), vertices = [], slots = this._skeleton.slots, VERTEX = sp.VERTEX_INDEX; diff --git a/extensions/spine/SGSkeletonWebGLRenderCmd.js b/extensions/spine/SGSkeletonWebGLRenderCmd.js index 11355a9b92..524065302e 100644 --- a/extensions/spine/SGSkeletonWebGLRenderCmd.js +++ b/extensions/spine/SGSkeletonWebGLRenderCmd.js @@ -28,7 +28,7 @@ var spine = sp.spine; sp._SGSkeleton.WebGLRenderCmd = function (renderableObject) { _ccsg.Node.WebGLRenderCmd.call(this, renderableObject); this._needDraw = true; - this.setShaderProgram(cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR)); + this.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR)); this._tmpQuad = new cc.V3F_C4B_T2F_Quad(); }; @@ -86,13 +86,13 @@ proto.rendering = function (ctx) { blendMode = slot.data.blendMode; switch (blendMode) { case spine.BlendMode.additive: - cc.glBlendFunc(premultiAlpha ? cc.ONE : cc.SRC_ALPHA, cc.ONE); + cc.glBlendFunc(premultiAlpha ? cc.Macro.ONE : cc.Macro.SRC_ALPHA, cc.Macro.ONE); break; case spine.BlendMode.multiply: - cc.glBlendFunc(cc.DST_COLOR, cc.ONE_MINUS_SRC_ALPHA); + cc.glBlendFunc(cc.Macro.DST_COLOR, cc.Macro.ONE_MINUS_SRC_ALPHA); break; case spine.BlendMode.screen: - cc.glBlendFunc(cc.ONE, cc.ONE_MINUS_SRC_COLOR); + cc.glBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_COLOR); break; default: cc.glBlendFunc(locBlendFunc.src, locBlendFunc.dst); diff --git a/external/gaf/Library/GAFShaderManager.js b/external/gaf/Library/GAFShaderManager.js index 49b7ffba0f..4bb314ce0a 100644 --- a/external/gaf/Library/GAFShaderManager.js +++ b/external/gaf/Library/GAFShaderManager.js @@ -14,9 +14,9 @@ gaf._glShaderInit = function() { var program = new cc.GLProgram(); var result = program.initWithVertexShaderByteArray(vs, fs); cc.assert(result, "Shader init error"); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); result = program.link(); cc.assert(result, "Shader linking error"); program.updateUniforms(); @@ -24,7 +24,7 @@ gaf._glShaderInit = function() { }; gaf._shaderCreateAlpha = function () { - var program = gaf._shaderCreate(gaf.SHADER_COLOR_MATRIX_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT); + var program = gaf._shaderCreate(gaf.SHADER_COLOR_MATRIX_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT); gaf._Uniforms.ColorTransformMult = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_MULT); gaf._Uniforms.ColorTransformOffset = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_OFFSET); gaf._Uniforms.ColorMatrixBody = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_COLOR_MATRIX_BODY); @@ -33,14 +33,14 @@ gaf._glShaderInit = function() { }; gaf._shaderCreateBlur = function () { - var program = gaf._shaderCreate(gaf.SHADER_GAUSSIAN_BLUR_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT); + var program = gaf._shaderCreate(gaf.SHADER_GAUSSIAN_BLUR_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT); gaf._Uniforms.BlurTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_BLUR_TEXEL_OFFSET); return program; }; gaf._shaderCreateGlow = function () { - var program = gaf._shaderCreate(gaf.SHADER_GLOW_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT); + var program = gaf._shaderCreate(gaf.SHADER_GLOW_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT); gaf._Uniforms.GlowTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_TEXEL_OFFSET); gaf._Uniforms.GlowColor = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_COLOR); return program; diff --git a/external/gaf/Library/GAFSpriteWebGLRenderCmd.js b/external/gaf/Library/GAFSpriteWebGLRenderCmd.js index 58a48b8c02..127d2a7f6a 100644 --- a/external/gaf/Library/GAFSpriteWebGLRenderCmd.js +++ b/external/gaf/Library/GAFSpriteWebGLRenderCmd.js @@ -2,7 +2,7 @@ (function(){ gaf.Sprite.WebGLRenderCmd = function (renderable) { _ccsg.Sprite.WebGLRenderCmd.call(this, renderable); - this._defualtShader = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR); + this._defualtShader = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR); this._customShader = gaf._Shaders.Alpha; //this._shaderProgram = this._defualtShader; diff --git a/gulp/tasks/build-cocos2d.js b/gulp/tasks/build-cocos2d.js index eb14e7b6e1..b2b9ff65bd 100644 --- a/gulp/tasks/build-cocos2d.js +++ b/gulp/tasks/build-cocos2d.js @@ -35,9 +35,7 @@ var srcs = [ './Base64Images.js', './CCBoot.js', - './cocos2d/core/platform/CCCommon.js', './cocos2d/core/platform/CCSAXParser.js', - './cocos2d/core/platform/CCConfig.js', './cocos2d/core/platform/miniFramework.js', './cocos2d/core/platform/CCEGLView.js', './cocos2d/core/platform/CCScreen.js', diff --git a/jsb/index.js b/jsb/index.js index c514fe4d40..2168ae876b 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -39,7 +39,7 @@ cc.initEngine = function (config, cb) { try { var originLog = console.log; console.log = function () { - originLog.call(console, cc.formatStr.apply(null, arguments)); + originLog.call(console, cc.js.formatStr.apply(null, arguments)); }; } catch (e) { diff --git a/predefine.js b/predefine.js index 56ba694d85..da92d6de01 100644 --- a/predefine.js +++ b/predefine.js @@ -57,6 +57,7 @@ require('./cocos2d/core/platform/CCInputManager'); require('./cocos2d/core/platform/CCInputExtension'); require('./cocos2d/core/event'); require('./cocos2d/core/platform/CCSys'); +require('./cocos2d/core/platform/CCMacro'); require('./cocos2d/core/load-pipeline'); require('./cocos2d/core/CCDirector'); require('./cocos2d/core/CCDirectorWebGL'); diff --git a/test/visual-tests/main.js b/test/visual-tests/main.js index ffb7e4f6ff..3bd1dbc8e9 100644 --- a/test/visual-tests/main.js +++ b/test/visual-tests/main.js @@ -110,6 +110,8 @@ cc.game.run({ "../../cocos2d/labels/CCLabelBMFontCanvasRenderCmd.js", "../../cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js", + "../../cocos2d/actions/CCActionCatmullRom.js", + "src/BaseTestLayer/BaseTestLayer.js", "src/tests_resources.js", diff --git a/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js b/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js index 3aefcee7a8..e6b4d72a31 100644 --- a/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js +++ b/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js @@ -620,8 +620,8 @@ var RawStencilBufferTest4 = RawStencilBufferTest.extend({ this._super(plane); gl.depthMask(false); - 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); cc.glUseProgram(program.getProgram()); program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold); this._sprite.shaderProgram = program; @@ -644,8 +644,8 @@ var RawStencilBufferTest5 = RawStencilBufferTest.extend({ gl.disable(gl.DEPTH_TEST); gl.depthMask(false); - 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); cc.glUseProgram(program.getProgram()); program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold); this._sprite.shaderProgram = program; @@ -680,8 +680,8 @@ var RawStencilBufferTest6 = RawStencilBufferTest.extend({ gl.disable(gl.DEPTH_TEST); gl.depthMask(false); - 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); cc.glUseProgram(program.getProgram()); program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold); this._sprite.shaderProgram = program; diff --git a/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js b/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js index eb636e5a76..f11089f687 100644 --- a/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js +++ b/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js @@ -740,7 +740,7 @@ var NodeOpaqueTest = TestNodeDemo.extend({ var background; for (var i = 0; i < 50; i++) { background = new _ccsg.Sprite(s_back1); - background.setBlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA); + background.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_ALPHA); background.x = winSize.width / 2; background.y = winSize.height / 2; this.addChild(background); @@ -765,7 +765,7 @@ var NodeNonOpaqueTest = TestNodeDemo.extend({ var background; for (var i = 0; i < 50; i++) { background = new _ccsg.Sprite(s_back1); - background.setBlendFunc(cc.ONE, cc.ZERO); + background.setBlendFunc(cc.Macro.ONE, cc.Macro.ZERO); background.x = winSize.width / 2; background.y = winSize.height / 2; this.addChild(background); diff --git a/test/visual-tests/src/ExtensionsTest/S9SpriteTest/S9SpriteTest.js b/test/visual-tests/src/ExtensionsTest/S9SpriteTest/S9SpriteTest.js index 29b589c714..c52b6ef46b 100644 --- a/test/visual-tests/src/ExtensionsTest/S9SpriteTest/S9SpriteTest.js +++ b/test/visual-tests/src/ExtensionsTest/S9SpriteTest/S9SpriteTest.js @@ -219,11 +219,11 @@ var S9Actiontest = S9SpriteTestDemo.extend({ this.addChild(s9sprite1); var actionArray = []; - actionArray.push(cc.DelayTime.create(1)); - actionArray.push(cc.MoveBy.create(1,x/2, 0)); - actionArray.push(cc.RotateBy.create(2,360)); - actionArray.push(cc.ScaleBy.create(1,2)); - s9sprite1.runAction(cc.Sequence.create(actionArray)); + actionArray.push(cc.delayTime(1)); + actionArray.push(cc.moveBy(1,x/2, 0)); + actionArray.push(cc.rotateBy(2,360)); + actionArray.push(cc.scaleBy(1,2)); + s9sprite1.runAction(cc.sequence(actionArray)); } }); @@ -245,11 +245,11 @@ var S9ChangeFiletest = S9SpriteTestDemo.extend({ this.addChild(_s9sprite1); var actionArray = []; - actionArray.push(cc.DelayTime.create(1)); - actionArray.push(cc.CallFunc.create(this.changeFile1,this)); - actionArray.push(cc.DelayTime.create(2)); - actionArray.push(cc.CallFunc.create(this.changeFile2,this)); - _s9sprite1.runAction(cc.Sequence.create(actionArray)); + actionArray.push(cc.delayTime(1)); + actionArray.push(cc.callFunc(this.changeFile1,this)); + actionArray.push(cc.delayTime(2)); + actionArray.push(cc.callFunc(this.changeFile2,this)); + _s9sprite1.runAction(cc.sequence(actionArray)); }, changeFile1: function() { this.changeFile("res/Images/btn-highscores-normal.png"); diff --git a/test/visual-tests/src/LabelTest/LabelTest.js b/test/visual-tests/src/LabelTest/LabelTest.js index 02fb0fe84f..883fa2fe37 100644 --- a/test/visual-tests/src/LabelTest/LabelTest.js +++ b/test/visual-tests/src/LabelTest/LabelTest.js @@ -2006,11 +2006,11 @@ var WrapAlgorithmTest = AtlasDemo.extend({ }, onEnter: function(){ this._super(); - cc.SPRITE_DEBUG_DRAW = 1; + cc.Macro.SPRITE_DEBUG_DRAW = 1; }, onExit: function(){ this._super(); - cc.SPRITE_DEBUG_DRAW = 0; + cc.Macro.SPRITE_DEBUG_DRAW = 0; } }); diff --git a/test/visual-tests/src/LayerTest/LayerTest.js b/test/visual-tests/src/LayerTest/LayerTest.js index 3213630316..e73f979a73 100644 --- a/test/visual-tests/src/LayerTest/LayerTest.js +++ b/test/visual-tests/src/LayerTest/LayerTest.js @@ -428,11 +428,11 @@ var LayerTestBlend = LayerTest.extend({ var dst; if (this._blend) { - src = cc.SRC_ALPHA; - dst = cc.ONE_MINUS_SRC_ALPHA; + src = cc.Macro.SRC_ALPHA; + dst = cc.Macro.ONE_MINUS_SRC_ALPHA; } else { - src = cc.ONE_MINUS_DST_COLOR; - dst = cc.ZERO; + src = cc.Macro.ONE_MINUS_DST_COLOR; + dst = cc.Macro.ZERO; } layer.setBlendFunc( src, dst ); this._blend = ! this._blend; diff --git a/test/visual-tests/src/OpenGLTest/OpenGLTest.js b/test/visual-tests/src/OpenGLTest/OpenGLTest.js index a942e8813a..ba5eba2b31 100644 --- a/test/visual-tests/src/OpenGLTest/OpenGLTest.js +++ b/test/visual-tests/src/OpenGLTest/OpenGLTest.js @@ -458,23 +458,23 @@ var GLNodeCCAPITest = OpenGLTestLayer.extend({ this.shader.use(); this.shader.setUniformsForBuiltins(); - cc.glEnableVertexAttribs( cc.VERTEX_ATTRIB_FLAG_COLOR | cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_COLOR | cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); // Draw fullscreen Square gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexColorBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); // Draw fullscreen Triangle gl.bindBuffer(gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, this.triangleVertexColorBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 3); @@ -574,7 +574,7 @@ var ShaderNode = cc.GLNode.extend({ this.shader = cc.GLProgram.create(vertexShader, framentShader); this.shader.retain(); - this.shader.addAttribute("aVertex", cc.VERTEX_ATTRIB_POSITION); + this.shader.addAttribute("aVertex", cc.Macro.VERTEX_ATTRIB_POSITION); this.shader.link(); this.shader.updateUniforms(); @@ -604,11 +604,11 @@ var ShaderNode = cc.GLNode.extend({ this.shader.setUniformLocationF32( this.uniformCenter, centerx, centery); this.shader.setUniformLocationF32( this.uniformResolution, 256, 256); - cc.glEnableVertexAttribs( cc.VERTEX_ATTRIB_FLAG_POSITION ); + cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_POSITION ); // Draw fullscreen Square gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); gl.bindBuffer(gl.ARRAY_BUFFER, null); @@ -879,9 +879,9 @@ var ShaderOutlineEffect = OpenGLTestLayer.extend({ } else{ this.shader = new cc.GLProgram("res/Shaders/example_Outline.vsh", "res/Shaders/example_Outline.fsh"); - this.shader.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - this.shader.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); - this.shader.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR); + this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); + this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR); this.shader.link(); this.shader.updateUniforms(); @@ -950,8 +950,8 @@ var ShaderRetroEffect = OpenGLTestLayer.extend({ if( 'opengl' in cc.sys.capabilities ) { var program = new cc.GLProgram("res/Shaders/example_ColorBars.vsh", "res/Shaders/example_ColorBars.fsh"); - program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION); - program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION); + program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS); program.link(); program.updateUniforms(); @@ -1088,14 +1088,14 @@ var TexImage2DTest = OpenGLTestLayer.extend({ this.shader.setUniformsForBuiltins(); gl.bindTexture(gl.TEXTURE_2D, this.my_texture); - cc.glEnableVertexAttribs( cc.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.VERTEX_ATTRIB_FLAG_POSITION); + cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.Macro.VERTEX_ATTRIB_FLAG_POSITION); // Draw fullscreen Square gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexTextureBuffer); - gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0); + gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); diff --git a/test/visual-tests/src/ParallaxTest/ParallaxTest.js b/test/visual-tests/src/ParallaxTest/ParallaxTest.js index c9ac3661f5..f74d4429e8 100644 --- a/test/visual-tests/src/ParallaxTest/ParallaxTest.js +++ b/test/visual-tests/src/ParallaxTest/ParallaxTest.js @@ -84,7 +84,7 @@ var Parallax1 = ParallaxDemo.extend({ // Middle layer: a Tile map atlas //var tilemap = cc.TileMapAtlas.create(s_tilesPng, s_levelMapTga, 16, 16); - this._tilemap = new cc.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); + this._tilemap = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); // change the transform anchor to 0,0 (optional) this._tilemap.anchorX = 0; @@ -197,7 +197,7 @@ var Parallax2 = ParallaxDemo.extend({ // Middle layer: a Tile map atlas //var tilemap = cc.TileMapAtlas.create(s_tilesPng, s_levelMapTga, 16, 16); - var tilemap = new cc.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); + var tilemap = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); // change the transform anchor to 0,0 (optional) tilemap.anchorX = 0; diff --git a/test/visual-tests/src/SchedulerTest/SchedulerTest.js b/test/visual-tests/src/SchedulerTest/SchedulerTest.js index 69104d3fab..050f7be692 100644 --- a/test/visual-tests/src/SchedulerTest/SchedulerTest.js +++ b/test/visual-tests/src/SchedulerTest/SchedulerTest.js @@ -496,7 +496,7 @@ var ScheduleUsingSchedulerTest = SchedulerTestLayer.extend({ scheduler.scheduleUpdateForTarget(this, priority, paused); var interval = 0.25; // every 1/4 of second - var repeat = cc.REPEAT_FOREVER; // how many repeats. cc.REPEAT_FOREVER means forever + var repeat = cc.Macro.REPEAT_FOREVER; // how many repeats. cc.Macro.REPEAT_FOREVER means forever var delay = 2; // start after 2 seconds; paused = false; // not paused. queue it now. scheduler.scheduleCallbackForTarget(this, this.onSchedUpdate, interval, repeat, delay, paused); diff --git a/test/visual-tests/src/SpriteTest/SpriteTest.js b/test/visual-tests/src/SpriteTest/SpriteTest.js index d5d765b266..ef6e0606bf 100644 --- a/test/visual-tests/src/SpriteTest/SpriteTest.js +++ b/test/visual-tests/src/SpriteTest/SpriteTest.js @@ -994,7 +994,7 @@ var SpriteZVertex = SpriteTestDemo.extend({ // var alphaTestShader = cc.shaderCache.getProgram("ShaderPositionTextureColorAlphaTest"); var glprogram = alphaTestShader.getProgram(); - var alphaValueLocation = gl.getUniformLocation(glprogram, cc.UNIFORM_ALPHA_TEST_VALUE_S); + var alphaValueLocation = gl.getUniformLocation(glprogram, cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S); // set alpha test value // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison @@ -1118,7 +1118,7 @@ var SpriteBatchNodeZVertex = SpriteTestDemo.extend({ // var alphaTestShader = cc.shaderCache.getProgram("ShaderPositionTextureColorAlphaTest"); var glprogram = alphaTestShader.getProgram(); - var alphaValueLocation = gl.getUniformLocation(glprogram, cc.UNIFORM_ALPHA_TEST_VALUE_S); + var alphaValueLocation = gl.getUniformLocation(glprogram, cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S); // set alpha test value // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison @@ -5200,7 +5200,7 @@ var TextureRotatedSpriteFrame = SpriteTestDemo.extend({ var SpriteWithRepeatingTexture = SpriteTestDemo.extend({ _title:"Sprite with Repeating texture", - _subtitle:"aTexture.setTexParameters(cc.LINEAR, cc.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);", + _subtitle:"aTexture.setTexParameters(cc.Macro.LINEAR, cc.Macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);", ctor:function () { //----start58----ctor @@ -5212,7 +5212,7 @@ var SpriteWithRepeatingTexture = SpriteTestDemo.extend({ block.setTextureRect(cc.rect(0,0, 320,240)); block.setPosition(x, y); - block.getTexture().setTexParameters(cc.LINEAR, cc.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT); + block.getTexture().setTexParameters(cc.Macro.LINEAR, cc.Macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT); this.addChild(block); //----end58---- } @@ -5227,8 +5227,8 @@ var SpriteBlendFuncTest = SpriteTestDemo.extend({ //----start59----ctor this._super(); - var destFactors = [cc.ZERO, cc.ONE, cc.DST_COLOR, cc.ONE_MINUS_DST_COLOR, cc.DST_ALPHA, cc.ONE_MINUS_DST_ALPHA], - srcFactors = [cc.ZERO, cc.ONE, cc.SRC_COLOR, cc.ONE_MINUS_SRC_COLOR, cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA]; + var destFactors = [cc.Macro.ZERO, cc.Macro.ONE, cc.Macro.DST_COLOR, cc.Macro.ONE_MINUS_DST_COLOR, cc.Macro.DST_ALPHA, cc.Macro.ONE_MINUS_DST_ALPHA], + srcFactors = [cc.Macro.ZERO, cc.Macro.ONE, cc.Macro.SRC_COLOR, cc.Macro.ONE_MINUS_SRC_COLOR, cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA]; var destTitles = ["ZERO", "ONE", "DST_COLOR", "ONE_MINUS_DST_COLOR", "DST_ALPHA", "ONE_MINUS_DST_ALPHA"], srcTitles = ["ZERO", "ONE", "SRC_COLOR", "ONE_MINUS_SRC_COLOR", "SRC_ALPHA", "ONE_MINUS_SRC_ALPHA"]; @@ -5359,7 +5359,7 @@ var arrayOfSpriteTest = [ NodeSort, SpriteSkewNegativeScaleChildren, SpriteBatchNodeSkewNegativeScaleChildren, - SpriteDoubleResolution, + // SpriteDoubleResolution, SpriteBatchBug1217, SpriteFrameAnimationCacheFile, TextureColorCacheIssue, diff --git a/test/visual-tests/src/TileMapTest/TileMapTest.js b/test/visual-tests/src/TileMapTest/TileMapTest.js index 11e4e48b71..e83833d7bf 100644 --- a/test/visual-tests/src/TileMapTest/TileMapTest.js +++ b/test/visual-tests/src/TileMapTest/TileMapTest.js @@ -175,7 +175,7 @@ var TileMapEditTest = TileDemo.extend({ var TMXOrthoTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test1.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test1.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.runAction(new cc.ScaleBy(2, 0.5)); @@ -217,7 +217,7 @@ var TMXOrthoTest2 = TileDemo.extend({ // // it should not flicker. No artifacts should appear // - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); this.addChild(map, 0, TAG_TILE_MAP); }, title:function () { @@ -260,7 +260,7 @@ var TMXOrthoTest2 = TileDemo.extend({ var TMXOrthoTest3 = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test3.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test3.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.scale = 0.2; @@ -298,7 +298,7 @@ var TMXOrthoTest3 = TileDemo.extend({ var TMXOrthoTest4 = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test4.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test4.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.anchorX = 0; @@ -368,7 +368,7 @@ var TMXReadWriteTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test2.tmx"); this.addChild(map, 0, TAG_TILE_MAP); var layer = map.getLayer("Layer 0"); @@ -490,7 +490,7 @@ var TMXHexTest = TileDemo.extend({ var color = new cc.LayerColor(cc.color(64, 64, 64, 255)); this.addChild(color, -1); - var map = new cc.TMXTiledMap("res/TileMaps/hexa-test.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/hexa-test.tmx"); this.addChild(map, 0, TAG_TILE_MAP); }, title:function () { @@ -526,7 +526,7 @@ var TMXIsoTest = TileDemo.extend({ var color = new cc.LayerColor(cc.color(64, 64, 64, 255)); this.addChild(color, -1); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test.tmx"); this.addChild(map, 0, TAG_TILE_MAP); // move map to the center of the screen @@ -570,7 +570,7 @@ var TMXIsoTest1 = TileDemo.extend({ var color = new cc.LayerColor(cc.color(64, 64, 64, 255)); this.addChild(color, -1); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test1.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test1.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.anchorX = 0.5; @@ -612,7 +612,7 @@ var TMXIsoTest2 = TileDemo.extend({ var color = new cc.LayerColor(cc.color(64, 64, 64, 255)); this.addChild(color, -1); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test2.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test2.tmx"); this.addChild(map, 0, TAG_TILE_MAP); // move map to the center of the screen @@ -657,7 +657,7 @@ var TMXUncompressedTest = TileDemo.extend({ var color = new cc.LayerColor(cc.color(64, 64, 64, 255)); this.addChild(color, -1); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test2-uncompressed.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test2-uncompressed.tmx"); this.addChild(map, 0, TAG_TILE_MAP); // move map to the center of the screen @@ -710,7 +710,7 @@ var TMXUncompressedTest = TileDemo.extend({ var TMXTilesetTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test5.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test5.tmx"); this.addChild(map, 0, TAG_TILE_MAP); if ("opengl" in cc.sys.capabilities) { @@ -760,7 +760,7 @@ var TMXOrthoObjectsTest = TileDemo.extend({ drawNode.setLineWidth(3); drawNode.setDrawColor(cc.color(255,255,255,255)); - var map = new cc.TMXTiledMap("res/TileMaps/ortho-objects.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/ortho-objects.tmx"); this.addChild(map, 0, TAG_TILE_MAP); var group = map.getObjectGroup("Object Group 1"); @@ -835,7 +835,7 @@ var TMXIsoObjectsTest = TileDemo.extend({ drawNode.setDrawColor(cc.color(255,255,255,255)); this.addChild(drawNode); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test-objectgroup.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test-objectgroup.tmx"); this.addChild(map, 0, TAG_TILE_MAP); var group = map.getObjectGroup("Object Group 1"); @@ -906,7 +906,7 @@ var TMXIsoObjectsTest = TileDemo.extend({ var TMXResizeTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test5.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test5.tmx"); this.addChild(map, 0, TAG_TILE_MAP); var layer; @@ -950,7 +950,7 @@ var TMXIsoZorder = TileDemo.extend({ tamara:null, ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test-zorder.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test-zorder.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.x = -map.width / 2; @@ -1019,7 +1019,7 @@ var TMXOrthoZorder = TileDemo.extend({ tamara:null, ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test-zorder.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test-zorder.tmx"); this.addChild(map, 0, TAG_TILE_MAP); this.tamara = new _ccsg.Sprite(s_pathSister1); @@ -1082,7 +1082,7 @@ var TMXIsoVertexZ = TMXFixBugLayer.extend({ tamara:null, ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test-vertexz.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test-vertexz.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.x = -map.width / 2; @@ -1157,7 +1157,7 @@ var TMXOrthoVertexZ = TMXFixBugLayer.extend({ tamara:null, ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test-vertexz.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test-vertexz.tmx"); this.addChild(map, 0, TAG_TILE_MAP); // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you @@ -1231,7 +1231,7 @@ var TMXOrthoVertexZ = TMXFixBugLayer.extend({ var TMXIsoMoveLayer = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test-movelayer.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test-movelayer.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.x = -700; map.y = -50; @@ -1252,7 +1252,7 @@ var TMXIsoMoveLayer = TileDemo.extend({ var TMXOrthoMoveLayer = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test-movelayer.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test-movelayer.tmx"); this.addChild(map, 0, TAG_TILE_MAP); }, title:function () { @@ -1271,7 +1271,7 @@ var TMXOrthoMoveLayer = TileDemo.extend({ var TMXTilePropertyTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/ortho-tile-property.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/ortho-tile-property.tmx"); this.addChild(map, 0, TAG_TILE_MAP); for (var i = 1; i <= 6; i++) { @@ -1314,7 +1314,7 @@ var TMXTilePropertyTest = TileDemo.extend({ var TMXOrthoFlipTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/ortho-rotation-test.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/ortho-rotation-test.tmx"); this.addChild(map, 0, TAG_TILE_MAP); this.log("ContentSize:" + map.width + "," + map.height); @@ -1350,7 +1350,7 @@ var TMXOrthoFlipTest = TileDemo.extend({ var TMXOrthoFlipRunTimeTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/ortho-rotation-test.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/ortho-rotation-test.tmx"); this.addChild(map, 0, TAG_TILE_MAP); this.log("ContentSize:" + map.width + "," + map.height); @@ -1438,7 +1438,7 @@ var TMXOrthoFromXMLTest = TileDemo.extend({ var resources = "res/TileMaps"; var filePath = "res/TileMaps/orthogonal-test1.tmx"; var xmlStr = cc.loader.getRes(filePath); - var map = new cc.TMXTiledMap(xmlStr, resources); + var map = new _ccsg.TMXTiledMap(xmlStr, resources); this.addChild(map, 0, TAG_TILE_MAP); cc.log("ContentSize: " + map.width + ", " + map.height); @@ -1485,7 +1485,7 @@ var TMXOrthoFromXMLTest = TileDemo.extend({ var TMXBug987 = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/orthogonal-test6.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/orthogonal-test6.tmx"); this.addChild(map, 0, TAG_TILE_MAP); this.log("ContentSize:" + map.width + "," + map.height); @@ -1540,7 +1540,7 @@ var TMXBug987 = TileDemo.extend({ var TMXBug787 = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/iso-test-bug787.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/iso-test-bug787.tmx"); this.addChild(map, 0, TAG_TILE_MAP); map.scale = 0.25; @@ -1576,7 +1576,7 @@ var TMXGIDObjectsTest = TileDemo.extend({ drawNode.setDrawColor(cc.color(255,255,255,255)); this.addChild(drawNode); - var map = new cc.TMXTiledMap("res/TileMaps/test-object-layer.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/test-object-layer.tmx"); this.addChild(map, 0, TAG_TILE_MAP); this.log("ContentSize:" + map.width + "," + map.height); @@ -1639,7 +1639,7 @@ var TMXGIDObjectsTest = TileDemo.extend({ var TMXIsoOffsetTest = TileDemo.extend({ ctor:function () { this._super(); - var map = new cc.TMXTiledMap("res/TileMaps/tile_iso_offset.tmx"); + var map = new _ccsg.TMXTiledMap("res/TileMaps/tile_iso_offset.tmx"); this.addChild(map, 0, TAG_TILE_MAP); },