60 | * Converts an input string encoded in base64 to an array of integers whose
61 | * values represent the decoded string's characters' bytes.
62 | *
63 | * @function
64 | * @param {String} input The String to convert to an array of Integers
65 | * @param {Number} bytes
66 | * @return {Array}
67 | * @example
68 | * //decode string to array
69 | * var decodeArr = cc.Codec.Base64.decodeAsArray("U29tZSBTdHJpbmc=");
70 | */
71 | cc.Codec.Base64.decodeAsArray = function Jacob__Codec__Base64___decodeAsArray(input, bytes) {
72 | var dec = this.decode(input),
73 | ar = [], i, j, len;
74 | for (i = 0, len = dec.length / bytes; i < len; i++) {
75 | ar[i] = 0;
76 | for (j = bytes - 1; j >= 0; --j) {
77 | ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
78 | }
79 | }
80 |
81 | return ar;
82 | };
83 |
84 | cc.uint8ArrayToUint32Array = function(uint8Arr){
85 | if(uint8Arr.length % 4 !== 0)
86 | return null;
87 |
88 | var arrLen = uint8Arr.length /4;
89 | var retArr = window.Uint32Array? new Uint32Array(arrLen) : [];
90 | for(var i = 0; i < arrLen; i++){
91 | var offset = i * 4;
92 | retArr[i] = uint8Arr[offset] + uint8Arr[offset + 1] * (1 << 8) + uint8Arr[offset + 2] * (1 << 16) + uint8Arr[offset + 3] * (1<<24);
93 | }
94 | return retArr;
95 | };
96 |
--------------------------------------------------------------------------------
/cocos2d/core/CCDirectorCanvas.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
28 |
29 | if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
30 | var _p = cc.Director.prototype;
31 |
32 | _p.getProjection = function (projection) {
33 | return this._projection;
34 | };
35 |
36 | _p.setProjection = function (projection) {
37 | this._projection = projection;
38 | cc.eventManager.dispatchEvent(this._eventProjectionChanged);
39 | };
40 |
41 | _p.setDepthTest = function () {
42 | };
43 |
44 | _p.setClearColor = function (clearColor) {
45 | cc.renderer._clearColor = clearColor;
46 | cc.renderer._clearFillStyle = 'rgb(' + clearColor.r + ',' + clearColor.g + ',' + clearColor.b +')' ;
47 | };
48 |
49 | _p.setOpenGLView = function (openGLView) {
50 | // set size
51 | this._winSizeInPoints.width = cc._canvas.width; //this._openGLView.getDesignResolutionSize();
52 | this._winSizeInPoints.height = cc._canvas.height;
53 | this._openGLView = openGLView || cc.view;
54 | if (cc.eventManager)
55 | cc.eventManager.setEnabled(true);
56 | };
57 |
58 | _p.getVisibleSize = function () {
59 | //if (this._openGLView) {
60 | //return this._openGLView.getVisibleSize();
61 | //} else {
62 | return this.getWinSize();
63 | //}
64 | };
65 |
66 | _p.getVisibleOrigin = function () {
67 | //if (this._openGLView) {
68 | //return this._openGLView.getVisibleOrigin();
69 | //} else {
70 | return cc.p(0, 0);
71 | //}
72 | };
73 | } else {
74 | cc.Director._fpsImage = new Image();
75 | cc.Director._fpsImage.addEventListener("load", function () {
76 | cc.Director._fpsImageLoaded = true;
77 | });
78 | if (cc._fpsImage) {
79 | cc.Director._fpsImage.src = cc._fpsImage;
80 | }
81 | }
82 | });
83 |
--------------------------------------------------------------------------------
/cocos2d/core/base-nodes/CCAtlasNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.AtlasNode's rendering objects of Canvas
27 | */
28 | (function () {
29 | cc.AtlasNode.CanvasRenderCmd = function (renderableObject) {
30 | this._rootCtor(renderableObject);
31 | this._needDraw = false;
32 | this._colorUnmodified = cc.color.WHITE;
33 | this._textureToRender = null;
34 | };
35 |
36 | var proto = cc.AtlasNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
37 | proto.constructor = cc.AtlasNode.CanvasRenderCmd;
38 |
39 | proto.initWithTexture = function (texture, tileWidth, tileHeight, itemsToRender) {
40 | var node = this._node;
41 | node._itemWidth = tileWidth;
42 | node._itemHeight = tileHeight;
43 |
44 | node._opacityModifyRGB = true;
45 | node._texture = texture;
46 | if (!node._texture) {
47 | cc.log(cc._LogInfos.AtlasNode__initWithTexture);
48 | return false;
49 | }
50 | this._textureToRender = texture;
51 | this._calculateMaxItems();
52 |
53 | node.quadsToDraw = itemsToRender;
54 | return true;
55 | };
56 |
57 | proto.setColor = function (color3) {
58 | var node = this._node;
59 | var locRealColor = node._realColor;
60 | if ((locRealColor.r === color3.r) && (locRealColor.g === color3.g) && (locRealColor.b === color3.b))
61 | return;
62 | this._colorUnmodified = color3;
63 | this._changeTextureColor();
64 | };
65 |
66 | proto._changeTextureColor = function () {
67 | var node = this._node;
68 | var texture = node._texture,
69 | color = this._colorUnmodified,
70 | element = texture.getHtmlElementObj();
71 | var textureRect = cc.rect(0, 0, element.width, element.height);
72 | if (texture === this._textureToRender)
73 | this._textureToRender = texture._generateColorTexture(color.r, color.g, color.b, textureRect);
74 | else
75 | texture._generateColorTexture(color.r, color.g, color.b, textureRect, this._textureToRender.getHtmlElementObj());
76 | };
77 |
78 | proto.setOpacity = function (opacity) {
79 | var node = this._node;
80 | cc.Node.prototype.setOpacity.call(node, opacity);
81 | };
82 |
83 | proto._calculateMaxItems = function () {
84 | var node = this._node;
85 | var selTexture = node._texture;
86 | var size = selTexture.getContentSize();
87 |
88 | node._itemsPerColumn = 0 | (size.height / node._itemHeight);
89 | node._itemsPerRow = 0 | (size.width / node._itemWidth);
90 | };
91 | })();
92 |
--------------------------------------------------------------------------------
/cocos2d/core/base-nodes/CCNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 | // ------------------------------ The cc.Node's render command for WebGL ----------------------------------
25 | (function () {
26 | cc.Node.WebGLRenderCmd = function (renderable) {
27 | this._node = renderable;
28 | this._anchorPointInPoints = {x: 0, y: 0};
29 | this._displayedColor = cc.color(255, 255, 255, 255);
30 | this._glProgramState = null;
31 | };
32 |
33 | var proto = cc.Node.WebGLRenderCmd.prototype = Object.create(cc.Node.RenderCmd.prototype);
34 | proto.constructor = cc.Node.WebGLRenderCmd;
35 | proto._rootCtor = cc.Node.WebGLRenderCmd;
36 |
37 | proto._updateColor = function () {
38 | };
39 |
40 | proto.setShaderProgram = function (shaderProgram) {
41 | this._glProgramState = cc.GLProgramState.getOrCreateWithGLProgram(shaderProgram);
42 | };
43 |
44 | proto.getShaderProgram = function () {
45 | return this._glProgramState ? this._glProgramState.getGLProgram() : null;
46 | };
47 |
48 | proto.getGLProgramState = function () {
49 | return this._glProgramState;
50 | };
51 |
52 | proto.setGLProgramState = function (glProgramState) {
53 | this._glProgramState = glProgramState;
54 | };
55 |
56 | // Use a property getter/setter for backwards compatability, and
57 | // to ease the transition from using glPrograms directly, to
58 | // using glProgramStates.
59 | Object.defineProperty(proto, '_shaderProgram', {
60 | set: function (value) { this.setShaderProgram(value); },
61 | get: function () { return this.getShaderProgram(); }
62 | });
63 | /** @expose */
64 | proto._shaderProgram;
65 | })();
66 |
--------------------------------------------------------------------------------
/cocos2d/core/cocos2d_externs.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Java Script Builtins for windows properties.
3 | *
4 | * @externs
5 | */
6 |
7 | /**
8 | * @see https://cocos2d-x.org
9 | */
10 |
11 | /**
12 | * cocos2d-html5-only.
13 | * @type {string}
14 | */
15 | CSSProperties.prototype._super;
16 |
17 | /**
18 | * cocos2d-html5-only. We need this because the cc.Class.extend's new
19 | * infrastructure requires it.
20 | * @type {string}
21 | */
22 | CSSProperties.prototype.ctor;
23 |
24 | /**
25 | * cocos2d-html5-only.
26 | * @type {string}
27 | */
28 | CSSProperties.prototype.Inflate;
29 |
30 | /**
31 | * cocos2d-html5-only.
32 | * @type {string}
33 | */
34 | CSSProperties.prototype.decompress;
35 |
36 | /**
37 | * Accelerometer api
38 | * cocos2d-html5-only.
39 | * @type {string}
40 | */
41 | CSSProperties.prototype.DeviceOrientationEvent;
42 | CSSProperties.prototype.DeviceMotionEvent;
43 | CSSProperties.prototype.accelerationIncludingGravity;
44 | CSSProperties.prototype.gamma;
45 | CSSProperties.prototype.beta;
46 | CSSProperties.prototype.alpha;
47 |
48 |
49 | var gl = gl || {};
50 | CSSProperties.prototype.gl;
51 |
52 | CSSProperties.prototype.AudioContext;
53 | CSSProperties.prototype.webkitAudioContext;
54 | CSSProperties.prototype.mozAudioContext;
55 | CSSProperties.prototype.createBufferSource;
56 | CSSProperties.prototype.createGain;
57 | CSSProperties.prototype.createGainNode;
58 | CSSProperties.prototype.destination;
59 | CSSProperties.prototype.decodeAudioData;
60 | CSSProperties.prototype.gain;
61 | CSSProperties.prototype.connect;
62 | CSSProperties.prototype.playbackState;
63 | CSSProperties.prototype.noteGrainOn;
64 | CSSProperties.prototype.noteOn;
65 |
66 |
67 |
--------------------------------------------------------------------------------
/cocos2d/core/labelttf/CCLabelTTFWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | // ----------------------------------- LabelTTF WebGL render cmd ----------------------------
26 | (function () {
27 | cc.LabelTTF.WebGLRenderCmd = function (renderable) {
28 | this._spriteCmdCtor(renderable);
29 | this._cacheCmdCtor();
30 | };
31 | var proto = cc.LabelTTF.WebGLRenderCmd.prototype = Object.create(cc.Sprite.WebGLRenderCmd.prototype);
32 |
33 | cc.inject(cc.LabelTTF.CacheRenderCmd.prototype, proto);
34 | proto.constructor = cc.LabelTTF.WebGLRenderCmd;
35 | proto._updateColor = function () {
36 | };
37 | })();
38 |
--------------------------------------------------------------------------------
/cocos2d/core/scenes/CCScene.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 |
28 | /**
29 | *
cc.Scene is a subclass of cc.Node that is used only as an abstract concept.
30 | *
cc.Scene an cc.Node are almost identical with the difference that cc.Scene has it's
31 | * anchor point (by default) at the center of the screen.
32 | *
33 | *
For the moment cc.Scene has no other logic than that, but in future releases it might have
34 | * additional logic.
35 | *
36 | *
It is a good practice to use and cc.Scene as the parent of all your nodes.
37 | * @class
38 | * @extends cc.Node
39 | * @example
40 | * var scene = new cc.Scene();
41 | */
42 | cc.Scene = cc.Node.extend(/** @lends cc.Scene# */{
43 | /**
44 | * Constructor of cc.Scene
45 | */
46 | _className:"Scene",
47 | ctor:function () {
48 | cc.Node.prototype.ctor.call(this);
49 | this._ignoreAnchorPointForPosition = true;
50 | this.setAnchorPoint(0.5, 0.5);
51 | this.setContentSize(cc.director.getWinSize());
52 | }
53 | });
54 |
55 | /**
56 | * creates a scene
57 | * @deprecated since v3.0,please use new cc.Scene() instead.
58 | * @return {cc.Scene}
59 | */
60 | cc.Scene.create = function () {
61 | return new cc.Scene();
62 | };
63 |
--------------------------------------------------------------------------------
/cocos2d/core/sprites/CCBakeSprite.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of _t software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.BakeSprite is a type of sprite that will be cached.
27 | * @class
28 | * @extend cc.Sprite
29 | */
30 | cc.BakeSprite = cc.Sprite.extend(/** @lends cc.BakeSprite# */{
31 | _cacheCanvas: null,
32 | _cacheContext: null,
33 |
34 | ctor: function(){
35 | cc.Sprite.prototype.ctor.call(this);
36 | var canvasElement = document.createElement("canvas");
37 | canvasElement.width = canvasElement.height = 10;
38 | this._cacheCanvas = canvasElement;
39 | this._cacheContext = new cc.CanvasContextWrapper(canvasElement.getContext("2d"));
40 |
41 | var texture = new cc.Texture2D();
42 | texture.initWithElement(canvasElement);
43 | texture.handleLoadedTexture();
44 | this.setTexture(texture);
45 | },
46 |
47 | getCacheContext: function(){
48 | return this._cacheContext;
49 | },
50 |
51 | getCacheCanvas: function(){
52 | return this._cacheCanvas;
53 | },
54 |
55 | /**
56 | * reset the cache canvas size
57 | * @param {cc.Size|Number} sizeOrWidth size or width
58 | * @param {Number} [height]
59 | */
60 | resetCanvasSize: function(sizeOrWidth, height){
61 | var locCanvas = this._cacheCanvas,
62 | locContext = this._cacheContext,
63 | strokeStyle = locContext._context.strokeStyle,
64 | fillStyle = locContext._context.fillStyle;
65 | if(height === undefined){
66 | height = sizeOrWidth.height;
67 | sizeOrWidth = sizeOrWidth.width;
68 | }
69 | locCanvas.width = sizeOrWidth;
70 | locCanvas.height = height; //TODO note baidu browser reset the context after set width or height
71 | if(strokeStyle !== locContext._context.strokeStyle)
72 | locContext._context.strokeStyle = strokeStyle;
73 | if(fillStyle !== locContext._context.fillStyle)
74 | locContext._context.fillStyle = fillStyle;
75 | this.getTexture().handleLoadedTexture();
76 | this.setTextureRect(cc.rect(0,0, sizeOrWidth, height), false, null, false);
77 | }
78 | });
79 |
--------------------------------------------------------------------------------
/cocos2d/core/sprites/SpritesPropertyDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc._tmp.PrototypeSprite = function () {
28 | var _p = cc.Sprite.prototype;
29 |
30 | // Override properties
31 | cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB);
32 | cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
33 | cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
34 |
35 | // Extended properties
36 | /** @expose */
37 | _p.dirty;
38 | /** @expose */
39 | _p.flippedX;
40 | cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX);
41 | /** @expose */
42 | _p.flippedY;
43 | cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY);
44 | /** @expose */
45 | _p.offsetX;
46 | cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX);
47 | /** @expose */
48 | _p.offsetY;
49 | cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY);
50 | /** @expose */
51 | _p.atlasIndex;
52 | /** @expose */
53 | _p.texture;
54 | cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
55 | /** @expose */
56 | _p.textureRectRotated;
57 | cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated);
58 | /** @expose */
59 | _p.textureAtlas;
60 | /** @expose */
61 | _p.batchNode;
62 | cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode);
63 | /** @expose */
64 | _p.quad;
65 | cc.defineGetterSetter(_p, "quad", _p.getQuad);
66 |
67 | };
68 |
--------------------------------------------------------------------------------
/cocos2d/core/support/TransformUtils.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2009 Valentin Milea
6 |
7 | http://www.cocos2d-x.org
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in
17 | all copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | THE SOFTWARE.
26 | ****************************************************************************/
27 |
28 | /**
29 | * convert an affine transform object to a kmMat4 object
30 | * @param {cc.AffineTransform} trans
31 | * @param {cc.kmMat4} mat
32 | * @function
33 | */
34 | cc.CGAffineToGL = function (trans, mat) {
35 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx |
36 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty |
37 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 |
38 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 |
39 | mat[2] = mat[3] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[14] = 0.0;
40 | mat[10] = mat[15] = 1.0;
41 | mat[0] = trans.a;
42 | mat[4] = trans.c;
43 | mat[12] = trans.tx;
44 | mat[1] = trans.b;
45 | mat[5] = trans.d;
46 | mat[13] = trans.ty;
47 | };
48 |
49 | /**
50 | * Convert a kmMat4 object to an affine transform object
51 | * @param {cc.kmMat4} mat
52 | * @param {cc.AffineTransform} trans
53 | * @function
54 | */
55 | cc.GLToCGAffine = function (mat, trans) {
56 | trans.a = mat[0];
57 | trans.c = mat[4];
58 | trans.tx = mat[12];
59 | trans.b = mat[1];
60 | trans.d = mat[5];
61 | trans.ty = mat[13];
62 | };
63 |
--------------------------------------------------------------------------------
/cocos2d/core/utils/CCSimplePool.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2016 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | cc.SimplePool = function () {
26 | this._pool = [];
27 | };
28 | cc.SimplePool.prototype = {
29 | constructor: cc.SimplePool,
30 |
31 | size: function () {
32 | return this._pool.length;
33 | },
34 |
35 | put: function (obj) {
36 | if (obj && this._pool.indexOf(obj) === -1) {
37 | this._pool.unshift(obj);
38 | }
39 | },
40 |
41 | get: function () {
42 | var last = this._pool.length-1;
43 | if (last < 0) {
44 | return null;
45 | }
46 | else {
47 | var obj = this._pool[last];
48 | this._pool.length = last;
49 | return obj;
50 | }
51 | },
52 |
53 | find: function (finder, end) {
54 | var found, i, obj, pool = this._pool, last = pool.length-1;
55 | for (i = pool.length; i >= 0; --i) {
56 | obj = pool[i];
57 | found = finder(i, obj);
58 | if (found) {
59 | pool[i] = pool[last];
60 | pool.length = last;
61 | return obj;
62 | }
63 | }
64 | if (end) {
65 | var index = end();
66 | if (index >= 0) {
67 | pool[index] = pool[last];
68 | pool.length = last;
69 | return obj;
70 | }
71 | }
72 | return null;
73 | }
74 | };
--------------------------------------------------------------------------------
/cocos2d/kazmath/SIMDPolyfill.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | * Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | * Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc) {
30 | var _useSIMD = false;
31 |
32 | var mat4Proto = cc.math.Matrix4.prototype;
33 | var mat4Inverse = mat4Proto.inverse;
34 | var mat4IsIdentity = mat4Proto.isIdentity;
35 | var mat4Transpose = mat4Proto.transpose;
36 | var mat4Multiply = mat4Proto.multiply;
37 | var mat4GetMat4MultiplyValue = mat4Proto.getMat4MultiplyValue;
38 | var mat4AssignFrom = mat4Proto.assignFrom;
39 | var mat4Equals = mat4Proto.equals;
40 | var mat4LookAt = mat4Proto.lookAt;
41 |
42 | var vec3Proto = cc.math.Vec3.prototype;
43 | var vec3TransformCoord = vec3Proto.transformCoord;
44 |
45 | function _isEnabledSIMD () {
46 | return _useSIMD;
47 | }
48 |
49 | function _enableSIMD (enable) {
50 | if(typeof(SIMD) === 'undefined')
51 | return;
52 |
53 | if (enable) {
54 | mat4Proto.inverse = mat4Proto.inverseSIMD;
55 | mat4Proto.isIdentity = mat4Proto.isIdentitySIMD;
56 | mat4Proto.transpose = mat4Proto.transposeSIMD;
57 | mat4Proto.multiply = mat4Proto.multiplySIMD;
58 | mat4Proto.getMat4MultiplyValue = mat4Proto.getMat4MultiplyValueSIMD;
59 | mat4Proto.assignFrom = mat4Proto.assignFromSIMD;
60 | mat4Proto.equals = mat4Proto.equalsSIMD;
61 | mat4Proto.lookAt = mat4Proto.lookAtSIMD;
62 | vec3Proto.transformCoord = vec3Proto.transformCoordSIMD;
63 | } else {
64 | mat4Proto.inverse = mat4Inverse;
65 | mat4Proto.isIdentity = mat4IsIdentity;
66 | mat4Proto.transpose = mat4Transpose;
67 | mat4Proto.multiply = mat4Multiply;
68 | mat4Proto.getMat4MultiplyValue = mat4GetMat4MultiplyValue;
69 | mat4Proto.assignFrom = mat4AssignFrom;
70 | mat4Proto.equals = mat4Equals;
71 | mat4Proto.lookAt = mat4LookAt;
72 | vec3Proto.transformCoord = vec3TransformCoord;
73 | }
74 | _useSIMD = enable;
75 | }
76 |
77 | cc.defineGetterSetter(cc.sys, "useSIMD", _isEnabledSIMD, _enableSIMD);
78 | })(cc);
--------------------------------------------------------------------------------
/cocos2d/kazmath/aabb.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | /**
30 | * A structure that represents an axis-aligned bounding box.
31 | * cc.kmAABB => cc.math.AABB
32 | */
33 | cc.math.AABB = function (min, max) {
34 | /** The max corner of the box */
35 | this.min = min || new cc.math.Vec3();
36 | /** The min corner of the box */
37 | this.max = max || new cc.math.Vec3();
38 | };
39 |
40 | /**
41 | * Returns true if point is in the specified AABB, returns false otherwise.
42 | * @param {cc.math.Vec3} point
43 | * @returns {boolean}
44 | */
45 | cc.math.AABB.prototype.containsPoint = function (point) {
46 | return (point.x >= this.min.x && point.x <= this.max.x &&
47 | point.y >= this.min.y && point.y <= this.max.y &&
48 | point.z >= this.min.z && point.z <= this.max.z);
49 | };
50 |
51 | /**
52 | * Returns true if point is in the specified AABB, returns
53 | * false otherwise.
54 | */
55 | cc.math.AABB.containsPoint = function (pPoint, pBox) {
56 | return (pPoint.x >= pBox.min.x && pPoint.x <= pBox.max.x &&
57 | pPoint.y >= pBox.min.y && pPoint.y <= pBox.max.y &&
58 | pPoint.z >= pBox.min.z && pPoint.z <= pBox.max.z);
59 | };
60 |
61 | /**
62 | * Assigns aabb to current AABB object
63 | * @param {cc.math.AABB} aabb
64 | */
65 | cc.math.AABB.prototype.assignFrom = function(aabb){
66 | this.min.assignFrom(aabb.min);
67 | this.max.assignFrom(aabb.max);
68 | };
69 |
70 | /**
71 | * Assigns pIn to pOut, returns pOut.
72 | */
73 | cc.math.AABB.assign = function (pOut, pIn) { //cc.kmAABBAssign
74 | pOut.min.assignFrom(pIn.min);
75 | pOut.max.assignFrom(pIn.max);
76 | return pOut;
77 | };
78 |
79 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/gl/mat4stack.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function (cc) {
30 | /**
31 | * The stack of cc.math.Matrix4
32 | * @param {cc.math.Matrix4} [top]
33 | * @param {Array} [stack]
34 | * @constructor
35 | */
36 | cc.math.Matrix4Stack = function (top, stack) {
37 | this.top = top;
38 | this.stack = stack || [];
39 | this.lastUpdated = 0;
40 | //this._matrixPool = []; // use pool in next version
41 | };
42 | cc.km_mat4_stack = cc.math.Matrix4Stack;
43 | var proto = cc.math.Matrix4Stack.prototype;
44 |
45 | proto.initialize = function () { //cc.km_mat4_stack_initialize
46 | this.stack.length = 0;
47 | this.top = null;
48 | };
49 |
50 | //for compatibility
51 | cc.km_mat4_stack_push = function (stack, item) {
52 | stack.stack.push(stack.top);
53 | stack.top = new cc.math.Matrix4(item);
54 | };
55 |
56 | cc.km_mat4_stack_pop = function (stack, pOut) {
57 | stack.top = stack.stack.pop();
58 | };
59 |
60 | cc.km_mat4_stack_release = function (stack) {
61 | stack.stack = null;
62 | stack.top = null;
63 | };
64 |
65 | proto.push = function (item) {
66 | item = item || this.top;
67 | this.stack.push(this.top);
68 | this.top = new cc.math.Matrix4(item);
69 | //this.top = this._getFromPool(item);
70 | };
71 |
72 | proto.pop = function () {
73 | //this._putInPool(this.top);
74 | this.top = this.stack.pop();
75 | };
76 |
77 | proto.release = function () {
78 | this.stack = null;
79 | this.top = null;
80 | this._matrixPool = null;
81 | };
82 |
83 | proto._getFromPool = function (item) {
84 | var pool = this._matrixPool;
85 | if (pool.length === 0)
86 | return new cc.math.Matrix4(item);
87 | var ret = pool.pop();
88 | ret.assignFrom(item);
89 | return ret;
90 | };
91 |
92 | proto._putInPool = function (matrix) {
93 | this._matrixPool.push(matrix);
94 | };
95 | })(cc);
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Kazmath SIMD benchmarks
6 |
7 |
8 |
9 |
Running benchmarks...
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kernel-template.js:
--------------------------------------------------------------------------------
1 | // Kernel template
2 | // Author: Peter Jensen
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "Test",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 100000000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add (new Benchmark (kernelConfig));
17 |
18 | // Kernel Initializer
19 | function init () {
20 | // Do initial sanity check and initialize data for the kernels.
21 | // The sanity check should verify that the simd and nonSimd results
22 | // are the same.
23 | // It is recommended to do minimal object creation in the kernels
24 | // themselves. If global data needs to be initialized, here would
25 | // be the place to do it.
26 | // If the sanity checks fails the kernels will not be executed
27 | // Returns:
28 | // true: First run (unoptimized) of the kernels passed
29 | // false: First run (unoptimized) of the kernels failed
30 | return simd (1) === nonSimd (1);
31 | }
32 |
33 | // Kernel Cleanup
34 | function cleanup () {
35 | // Do final sanity check and perform cleanup.
36 | // This function is called when all the kernel iterations have been
37 | // executed, so they should be in their final optimized version. The
38 | // sanity check done during initialization will probably be of the
39 | // initial unoptimized version.
40 | // Returns:
41 | // true: Last run (optimized) of the kernels passed
42 | // false: last run (optimized) of the kernels failed
43 | return simd (1) === nonSimd (1);
44 | }
45 |
46 | // SIMD version of the kernel
47 | function simd (n) {
48 | var s = 0;
49 | for (var i = 0; i < n; ++i) {
50 | s += i;
51 | }
52 | return s;
53 | }
54 |
55 | // Non SIMD version of the kernel
56 | function nonSimd (n) {
57 | var s = 0;
58 | for (var i = 0; i < n; ++i) {
59 | s += i;
60 | }
61 | return s;
62 | }
63 |
64 | } ());
65 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js:
--------------------------------------------------------------------------------
1 | // kmMat4AreEqual
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4AreEqual",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var T1 = new cc.kmMat4();
20 | var T2 = new cc.kmMat4();
21 | var T1x4 = new cc.kmMat4();
22 | var T2x4 = new cc.kmMat4();
23 | var areEqual, areEqualSIMD;
24 |
25 | function equals(A, B) {
26 | for (var i = 0; i < 16; ++i) {
27 | if (A[i] != B[i])
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | function init() {
34 | T1.mat[0] = 1.0;
35 | T1.mat[5] = 1.0;
36 | T1.mat[10] = 1.0;
37 | T1.mat[15] = 1.0;
38 |
39 | T2.mat[0] = 1.0;
40 | T2.mat[5] = 1.0;
41 | T2.mat[10] = 1.0;
42 | T2.mat[15] = 1.0;
43 |
44 | T1x4.mat[0] = 1.0;
45 | T1x4.mat[5] = 1.0;
46 | T1x4.mat[10] = 1.0;
47 | T1x4.mat[15] = 1.0;
48 |
49 | T2x4.mat[0] = 1.0;
50 | T2x4.mat[5] = 1.0;
51 | T2x4.mat[10] = 1.0;
52 | T2x4.mat[15] = 1.0;
53 |
54 | nonSimd(1);
55 | simd(1);
56 |
57 | return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat) && (areEqual === areEqualSIMD);
58 |
59 | }
60 |
61 | function cleanup() {
62 | return init(); // Sanity checking before and after are the same
63 | }
64 |
65 | function nonSimd(n) {
66 | for (var i = 0; i < n; i++) {
67 | areEqual = T1.equals(T2);
68 | }
69 | }
70 |
71 | function simd(n) {
72 | for (var i = 0; i < n; i++) {
73 | areEqualSIMD = T1x4.equalsSIMD(T2x4);
74 | }
75 | }
76 |
77 | } ());
78 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js:
--------------------------------------------------------------------------------
1 | // kmMat4Assign
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4Assign",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var T1 = new cc.kmMat4();
20 | var T2 = new cc.kmMat4();
21 | var T1x4 = new cc.kmMat4();
22 | var T2x4 = new cc.kmMat4();
23 |
24 | function equals(A, B) {
25 | for (var i = 0; i < 16; ++i) {
26 | if (A[i] != B[i])
27 | return false;
28 | }
29 | return true;
30 | }
31 |
32 | function init() {
33 | T1.mat[0] = 1.0;
34 | T1.mat[5] = 1.0;
35 | T1.mat[10] = 1.0;
36 | T1.mat[15] = 1.0;
37 |
38 | T1x4.mat[0] = 1.0;
39 | T1x4.mat[5] = 1.0;
40 | T1x4.mat[10] = 1.0;
41 | T1x4.mat[15] = 1.0;
42 |
43 | nonSimd(1);
44 | simd(1);
45 |
46 | return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
47 |
48 | }
49 |
50 | function cleanup() {
51 | return init(); // Sanity checking before and after are the same
52 | }
53 |
54 | function nonSimd(n) {
55 | for (var i = 0; i < n; i++) {
56 | //cc.kmMat4Assign(T2, T1);
57 | T2.assignFrom(T1);
58 | }
59 | }
60 |
61 | function simd(n) {
62 | for (var i = 0; i < n; i++) {
63 | //cc.kmMat4AssignSIMD(T2x4, T1x4);
64 | T2x4.assignFromSIMD(T1x4);
65 | }
66 | }
67 |
68 | } ());
69 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js:
--------------------------------------------------------------------------------
1 | // kmMat4Inverse
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4Inverse",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var src = new cc.kmMat4();
20 | var dst = new cc.kmMat4();
21 | var srcx4 = new cc.kmMat4();
22 | var dstx4 = new cc.kmMat4();
23 | var ident = new Float32Array(
24 | [1,0,0,0,
25 | 0,1,0,0,
26 | 0,0,1,0,
27 | 0,0,0,1]);
28 |
29 | function equals(A, B) {
30 | for (var i = 0; i < 16; ++i) {
31 | if (Math.abs (A[i] - B[i]) > 5)
32 | return false;
33 | }
34 | return true;
35 | }
36 |
37 | function initMatrix(matrix) {
38 | // These values were chosen somewhat randomly, but they will at least yield a solution.
39 | matrix [0] = 0; matrix[1] = 1; matrix[2] = 2; matrix[3] = 3;
40 | matrix [4] = -1; matrix[5] = -2; matrix[6] = -3; matrix[7] = -4;
41 | matrix [8] = 0; matrix[9] = 0; matrix[10] = 2; matrix[11] = 3;
42 | matrix [12] = -1; matrix[13] = -2; matrix[14] = 0; matrix[15] = -4;
43 | }
44 |
45 | function mulMatrix(dst, op1, op2) {
46 | for (var r = 0; r < 4; ++r) {
47 | for (var c = 0; c < 4; ++c) {
48 | var ri = 4*r;
49 | dst[ri + c] = op1[ri]*op2[c] + op1[ri+1]*op2[c+4] + op1[ri+2]*op2[c+8] + op1[ri+3]*op2[c+12];
50 | }
51 | }
52 | }
53 |
54 | function printMatrix(matrix, str) {
55 | print('--------matrix ' + str + '----------');
56 | for (var r = 0; r < 4; ++r) {
57 | var str = "";
58 | var ri = r*4;
59 | for (var c = 0; c < 4; ++c) {
60 | var value = matrix[ri + c];
61 | str += " " + value.toFixed(2);
62 | }
63 | print(str);
64 | }
65 | }
66 |
67 | function checkMatrix(src, dst) {
68 | // when multiplied with the src matrix it should yield the identity matrix
69 | var tmp = new Float32Array(16);
70 | mulMatrix(tmp, src, dst);
71 | for (var i = 0; i < 16; ++i) {
72 | if (Math.abs (tmp[i] - ident[i]) > 0.00001) {
73 | return false;
74 | }
75 | }
76 | return true;
77 | }
78 |
79 | function init() {
80 | initMatrix(src.mat);
81 | // printMatrix(src);
82 | nonSimd(1);
83 | // printMatrix(dst);
84 | if (!checkMatrix(src.mat, dst.mat)) {
85 | return false;
86 | }
87 |
88 | initMatrix(srcx4.mat);
89 | simd(1);
90 | // printMatrix(dst);
91 | if (!checkMatrix(srcx4.mat, dstx4.mat)) {
92 | return false;
93 | }
94 |
95 | return true;
96 | }
97 |
98 | function cleanup() {
99 | return init(); // Sanity checking before and after are the same
100 | }
101 |
102 | function nonSimd(n) {
103 | for (var i = 0; i < n; i++) {
104 | //cc.kmMat4Inverse(dst, src);
105 | dst = src.inverse();
106 | }
107 | }
108 |
109 | function simd(n) {
110 | for (var i = 0; i < n; i++) {
111 | //cc.kmMat4InverseSIMD(dstx4, srcx4);
112 | dstx4 = srcx4.inverseSIMD();
113 | }
114 | }
115 |
116 | } ());
117 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js:
--------------------------------------------------------------------------------
1 | // kmMat4IsIdentity
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4IsIdentity",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var T1 = new cc.kmMat4();
20 | var T1x4 = new cc.kmMat4();
21 | var isIdentity, isIdentitySIMD;
22 |
23 | function equals(A, B) {
24 | for (var i = 0; i < 16; ++i) {
25 | if (A[i] != B[i])
26 | return false;
27 | }
28 | return true;
29 | }
30 |
31 | function init() {
32 | T1.mat[0] = 1.0;
33 | T1.mat[5] = 1.0;
34 | T1.mat[10] = 1.0;
35 | T1.mat[15] = 1.0;
36 |
37 | T1x4.mat[0] = 1.0;
38 | T1x4.mat[5] = 1.0;
39 | T1x4.mat[10] = 1.0;
40 | T1x4.mat[15] = 1.0;
41 |
42 | nonSimd(1);
43 | simd(1);
44 |
45 | return equals(T1.mat, T1x4.mat) && (isIdentity === isIdentitySIMD);
46 |
47 | }
48 |
49 | function cleanup() {
50 | return init(); // Sanity checking before and after are the same
51 | }
52 |
53 | function nonSimd(n) {
54 | for (var i = 0; i < n; i++) {
55 | isIdentity = T1.isIdentity();
56 | }
57 | }
58 |
59 | function simd(n) {
60 | for (var i = 0; i < n; i++) {
61 | isIdentitySIMD = T1x4.isIdentitySIMD();
62 | }
63 | }
64 |
65 | } ());
66 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js:
--------------------------------------------------------------------------------
1 | // kmMat4LookAt
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4LookAt",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var eye = new cc.kmVec3(), center = new cc.kmVec3(), up = new cc.kmVec3();
20 | var T1 = new cc.kmMat4();
21 | var eye1 = new cc.kmVec3(), center1 = new cc.kmVec3(), up1 = new cc.kmVec3();
22 | var T1x4 = new cc.kmMat4();
23 |
24 | function printMatrix(matrix) {
25 | print('--------matrix----------');
26 | for (var r = 0; r < 4; ++r) {
27 | var str = "";
28 | var ri = r*4;
29 | for (var c = 0; c < 4; ++c) {
30 | var value = matrix[ri + c];
31 | str += " " + value.toFixed(2);
32 | }
33 | print(str);
34 | }
35 | }
36 |
37 | function equals(A, B) {
38 | for (var i = 0; i < 16; ++i) {
39 | if (Math.abs (A[i] - B[i]) > 0.001) {
40 | return false;
41 | }
42 | }
43 | return true;
44 | }
45 |
46 | function init() {
47 |
48 | eye.fill(0, 1, 2);
49 | center.fill(2, 1, 0);
50 | up.fill(1, 1, 1);
51 |
52 | eye1.fill(0, 1, 2);
53 | center1.fill(2, 1, 0);
54 | up1.fill(1, 1, 1);
55 | /*
56 | eye1.data[0] = 0;
57 | eye1.data[1] = 1;
58 | eye1.data[2] = 2;
59 |
60 | center1.data[0] = 2;
61 | center1.data[1] = 1;
62 | center1.data[2] = 0;
63 |
64 | up1.data[0] = 1;
65 | up1.data[1] = 1;
66 | up1.data[2] = 1;
67 | */
68 | nonSimd(1);
69 | //printMatrix(T1.mat);
70 | simd(1);
71 | //printMatrix(T1x4.mat);
72 |
73 | return equals(T1.mat, T1x4.mat);
74 | }
75 |
76 | function cleanup() {
77 | return init(); // Sanity checking before and after are the same
78 | }
79 |
80 | function nonSimd(n) {
81 | for (var i = 0; i < n; i++) {
82 | //cc.kmMat4LookAt(T1, eye, center, up);
83 | T1.lookAt(eye, center, up);
84 | }
85 | }
86 |
87 | function simd(n) {
88 | for (var i = 0; i < n; i++) {
89 | //cc.kmMat4LookAtSIMD(T1x4, eye1, center1, up1);
90 | T1x4.lookAtSIMD(eye1, center1, up1);
91 | }
92 | }
93 |
94 | } ());
95 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js:
--------------------------------------------------------------------------------
1 | // kmMat4Multiply
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4Multiply",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var T1 = new cc.kmMat4();
20 | var T2 = new cc.kmMat4();
21 | var T1x4 = new cc.kmMat4();
22 | var T2x4 = new cc.kmMat4();
23 |
24 | function equals(A, B) {
25 | for (var i = 0; i < 16; ++i) {
26 | if (A[i] != B[i])
27 | return false;
28 | }
29 | return true;
30 | }
31 |
32 | function init() {
33 | T1.mat[0] = 1.0;
34 | T1.mat[5] = 1.0;
35 | T1.mat[10] = 1.0;
36 | T1.mat[15] = 1.0;
37 |
38 | T2.mat[0] = 1.0;
39 | T2.mat[5] = 1.0;
40 | T2.mat[10] = 1.0;
41 | T2.mat[15] = 1.0;
42 |
43 | T1x4.mat[0] = 1.0;
44 | T1x4.mat[5] = 1.0;
45 | T1x4.mat[10] = 1.0;
46 | T1x4.mat[15] = 1.0;
47 |
48 | T2x4.mat[0] = 1.0;
49 | T2x4.mat[5] = 1.0;
50 | T2x4.mat[10] = 1.0;
51 | T2x4.mat[15] = 1.0;
52 |
53 | nonSimd(1);
54 | simd(1);
55 | return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
56 | }
57 |
58 | function cleanup() {
59 | return init(); // Sanity checking before and after are the same
60 | }
61 |
62 | function nonSimd(n) {
63 | for (var i = 0; i < n; i++) {
64 | T1.multiply(T2);
65 | }
66 | }
67 |
68 | function simd(n) {
69 | for (var i = 0; i < n; i++) {
70 | T1x4.multiplySIMD(T2x4);
71 | }
72 | }
73 |
74 | } ());
75 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js:
--------------------------------------------------------------------------------
1 | // kmMat4Transpose
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmMat4Transpose",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var T1 = new cc.kmMat4();
20 | var T2 = new cc.kmMat4();
21 | var T1x4 = new cc.kmMat4();
22 | var T2x4 = new cc.kmMat4();
23 |
24 | function equals(A, B) {
25 | for (var i = 0; i < 16; ++i) {
26 | if (A[i] != B[i])
27 | return false;
28 | }
29 | return true;
30 | }
31 |
32 | function printMatrix(matrix) {
33 | print('--------matrix----------');
34 | for (var r = 0; r < 4; ++r) {
35 | var str = "";
36 | var ri = r*4;
37 | for (var c = 0; c < 4; ++c) {
38 | var value = matrix[ri + c];
39 | str += " " + value.toFixed(2);
40 | }
41 | print(str);
42 | }
43 | }
44 |
45 | function init() {
46 | T1.mat [0] = 0; T1.mat[1] = 1; T1.mat[2] = 2; T1.mat[3] = 3;
47 | T1.mat [4] = -1; T1.mat[5] = -2; T1.mat[6] = -3; T1.mat[7] = -4;
48 | T1.mat [8] = 0; T1.mat[9] = 0; T1.mat[10] = 2; T1.mat[11] = 3;
49 | T1.mat [12] = -1; T1.mat[13] = -2; T1.mat[14] = 0; T1.mat[15] = -4;
50 |
51 | T1x4.mat [0] = 0; T1x4.mat[1] = 1; T1x4.mat[2] = 2; T1x4.mat[3] = 3;
52 | T1x4.mat [4] = -1; T1x4.mat[5] = -2; T1x4.mat[6] = -3; T1x4.mat[7] = -4;
53 | T1x4.mat [8] = 0; T1x4.mat[9] = 0; T1x4.mat[10] = 2; T1x4.mat[11] = 3;
54 | T1x4.mat [12] = -1; T1x4.mat[13] = -2; T1x4.mat[14] = 0; T1x4.mat[15] = -4;
55 |
56 | nonSimd(1);
57 | //printMatrix(T2.mat);
58 | simd(1);
59 | //printMatrix(T2x4.mat);
60 | return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
61 |
62 | }
63 |
64 | function cleanup() {
65 | return init(); // Sanity checking before and after are the same
66 | }
67 |
68 | function nonSimd(n) {
69 | for (var i = 0; i < n; i++) {
70 | T2 = T1.transpose();
71 | //T1.transpose();
72 | }
73 | }
74 |
75 | function simd(n) {
76 | for (var i = 0; i < n; i++) {
77 | T2x4 = T1x4.transposeSIMD();
78 | //T1x4.transposeSIMD();
79 | }
80 | }
81 |
82 | } ());
83 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js:
--------------------------------------------------------------------------------
1 | // kmVec3TransformCoord
2 |
3 | (function () {
4 |
5 | // Kernel configuration
6 | var kernelConfig = {
7 | kernelName: "kmVec3TransformCoord",
8 | kernelInit: init,
9 | kernelCleanup: cleanup,
10 | kernelSimd: simd,
11 | kernelNonSimd: nonSimd,
12 | kernelIterations: 10000
13 | };
14 |
15 | // Hook up to the harness
16 | benchmarks.add(new Benchmark(kernelConfig));
17 |
18 | // Benchmark data, initialization and kernel functions
19 | var V = new cc.kmVec3();
20 | var T = new cc.kmMat4();
21 | var Out = new cc.kmVec3();
22 | var Vx4 = new cc.kmVec3();
23 | var Tx4 = new cc.kmMat4();
24 | var Outx4 = new cc.kmVec3();
25 |
26 | function init() {
27 | T.mat[0] = 1.0;
28 | T.mat[5] = 1.0;
29 | T.mat[10] = 1.0;
30 | T.mat[15] = 1.0;
31 |
32 | V.fill(0.0, 1.0, 0.0);
33 |
34 | Tx4.mat[0] = 1.0;
35 | Tx4.mat[5] = 1.0;
36 | Tx4.mat[10] = 1.0;
37 | Tx4.mat[15] = 1.0;
38 |
39 | Vx4.fill(0.0, 1.0, 0.0);
40 |
41 | nonSimd(1);
42 | simd(1);
43 | //console.log(V);
44 | //console.log(Vx4);
45 | return V.equals(Vx4);
46 |
47 | }
48 |
49 | function cleanup() {
50 | return init(); // Sanity checking before and after are the same
51 | }
52 |
53 | function nonSimd(n) {
54 | for (var i = 0; i < n; i++) {
55 | V.transformCoord(T);
56 | }
57 | }
58 |
59 | function simd(n) {
60 | for (var i = 0; i < n; i++) {
61 | Vx4.transformCoordSIMD(Tx4);
62 | }
63 | }
64 |
65 | } ());
66 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/run.js:
--------------------------------------------------------------------------------
1 | "use strict"
2 |
3 | var cc = {};
4 |
5 | load ('base.js');
6 |
7 | load ('../utility.js');
8 | load ('../vec3.js');
9 | load ('../vec4.js');
10 | load ('../mat4.js');
11 | load ('../vec3SIMD.js');
12 | load ('../mat4SIMD.js');
13 |
14 | // load individual benchmarks
15 | load ('kernel-template.js');
16 | load ('kmMat4Multiply.js');
17 | load ('kmMat4Assign.js');
18 | load ('kmMat4AreEqual.js');
19 | load ('kmMat4Inverse.js');
20 | load ('kmMat4IsIdentity.js');
21 | load ('kmMat4Transpose.js');
22 | load ('kmMat4LookAt.js');
23 | load ('kmVec3TransformCoord.js');
24 |
25 | function printResult (str) {
26 | print (str);
27 | }
28 |
29 | function printError (str) {
30 | print (str);
31 | }
32 |
33 | function printScore (str) {
34 | print (str);
35 | }
36 |
37 | benchmarks.runAll ({notifyResult: printResult,
38 | notifyError: printError,
39 | notifyScore: printScore},
40 | true);
41 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/simd_benchmark/run_browser.js:
--------------------------------------------------------------------------------
1 | var echo = document.getElementById('echo');
2 |
3 | function printResult(str) {
4 | console.log(str);
5 | echo.innerHTML += str + ' ';
6 | }
7 |
8 | function printError(str) {
9 | console.log(str);
10 | echo.innerHTML += str + ' ';
11 | }
12 |
13 | function printScore(str) {
14 | console.log(str);
15 | echo.innerHTML += str + ' ';
16 | }
17 |
18 | var timeData = {
19 | labels: [],
20 | datasets: [
21 | {
22 | labels: 'Non-SIMD',
23 | fillColor: "rgba(220,220,220,0.5)",
24 | strokeColor: "rgba(220,220,220,0.8)",
25 | highlightFill: "rgba(220,220,220,0.75)",
26 | highlightStroke: "rgba(220,220,220,1)",
27 | data: []
28 | },
29 | {
30 | labels: 'SIMD',
31 | fillColor: "rgba(151,187,205,0.5)",
32 | strokeColor: "rgba(151,187,205,0.8)",
33 | highlightFill: "rgba(151,187,205,0.75)",
34 | highlightStroke: "rgba(151,187,205,1)",
35 | data: []
36 | }
37 | ]
38 | };
39 |
40 | var speedupData ={
41 | labels: [],
42 | datasets: [
43 | {
44 | labels: 'SIMD',
45 | fillColor: "rgba(151,187,205,0.5)",
46 | strokeColor: "rgba(151,187,205,0.8)",
47 | highlightFill: "rgba(151,187,205,0.75)",
48 | highlightStroke: "rgba(151,187,205,1)",
49 | data: []
50 | }
51 | ]
52 | };
53 |
54 | window.onload = function() {
55 | if (typeof(SIMD) === 'undefined') {
56 | var head = document.getElementById('head');
57 | head.innerHTML = 'SIMD is not implemented in your browser, stops.';
58 | return;
59 | }
60 | console.log('Running benchmarks.');
61 | benchmarks.runAll({notifyResult: printResult,
62 | notifyError: printError,
63 | notifyScore: printScore,
64 | timeData: timeData,
65 | speedupData: speedupData}, true);
66 | document.getElementById('head').innerHTML = 'Results';
67 | document.getElementById('time').innerHTML = 'Time';
68 | document.getElementById('speedup').innerHTML = 'Speedup';
69 | var ctx1 = document.getElementById("canvasTime").getContext("2d");
70 | window.Bar1 = new Chart(ctx1).Bar(timeData, {
71 | scaleLabel: "<%=value%>ms",
72 | responsive: true
73 | });
74 | var ctx2 = document.getElementById("canvasSpeedup").getContext("2d");
75 | window.Bar2 = new Chart(ctx2).Bar(speedupData, {
76 | scaleLabel: " <%=value%>",
77 | responsive: true
78 | });
79 | console.log('Benchmarks completed.');
80 | };
81 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/utility.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 |
30 | /**
31 | *
The main namespace of Cocos2d-html5's math library,
32 | * all math core classes, functions, properties and constants are defined in this namespace
33 | * @namespace
34 | * @name cc.math
35 | */
36 | cc.math = cc.math || {};
37 |
38 | //cc.kmPIOver180 = 0.017453; please use cc.RAD
39 |
40 | //cc.kmPIUnder180 = 57.295779; please use cc.DEG
41 |
42 | cc.math.EPSILON = 1.0 / 64.0; //cc.kmEpsilon
43 |
44 | /**
45 | * Returns the square of s (e.g. s*s)
46 | * @param {Number} s
47 | */
48 | cc.math.square = function(s){
49 | return s*s;
50 | };
51 |
52 | cc.math.almostEqual = function(lhs,rhs){
53 | return (lhs + cc.math.EPSILON > rhs && lhs - cc.math.EPSILON < rhs);
54 | };
55 |
--------------------------------------------------------------------------------
/cocos2d/kazmath/vec3SIMD.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc) {
30 | var proto = cc.math.Vec3.prototype;
31 |
32 | proto.transformCoordSIMD = function(mat4){
33 | var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0);
34 | var mat0 = SIMD.float32x4.load(mat4.mat, 0);
35 | var mat1 = SIMD.float32x4.load(mat4.mat, 4);
36 | var mat2 = SIMD.float32x4.load(mat4.mat, 8);
37 | var mat3 = SIMD.float32x4.load(mat4.mat, 12);
38 |
39 | //cc.kmVec4Transform(v, inV,pM);
40 | var out = SIMD.float32x4.add(
41 | SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)),
42 | SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))),
43 | SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)),
44 | mat3));
45 |
46 | out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3));
47 | this.fill(out);
48 |
49 | return this;
50 | };
51 | })(cc);
52 |
--------------------------------------------------------------------------------
/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
26 | Use any of these editors to generate BMFonts:
27 | http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
28 | http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
29 | http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
30 | http://www.angelcode.com/products/bmfont/ (Free, Windows only)
31 | ****************************************************************************/
32 |
33 | (function () {
34 | cc.LabelBMFont.WebGLRenderCmd = function (renderableObject) {
35 | this._rootCtor(renderableObject);
36 | };
37 |
38 | var proto = cc.LabelBMFont.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
39 | proto.constructor = cc.LabelBMFont.WebGLRenderCmd;
40 |
41 | proto.setTexture = function (texture) {
42 | this._node.setOpacityModifyRGB(this._node._texture.hasPremultipliedAlpha());
43 | };
44 |
45 | proto._updateCharTexture = function(fontChar, rect, key, isRotated){
46 | // updating previous sprite
47 | fontChar.setTextureRect(rect, isRotated);
48 | // restore to default in case they were modified
49 | fontChar.visible = true;
50 | };
51 |
52 | proto._changeTextureColor = function () {
53 | };
54 |
55 | proto._updateCharColorAndOpacity = function () {
56 | };
57 | })();
58 |
--------------------------------------------------------------------------------
/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | cc.MotionStreak.WebGLRenderCmd = function (renderableObject) {
26 | this._rootCtor(renderableObject);
27 | this._needDraw = true;
28 | this._matrix = new cc.math.Matrix4();
29 | this._matrix.identity();
30 | this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR);
31 | };
32 |
33 | cc.MotionStreak.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
34 | cc.MotionStreak.WebGLRenderCmd.prototype.constructor = cc.Sprite.WebGLRenderCmd;
35 |
36 | cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function (ctx) {
37 | var node = this._node;
38 | if (node._nuPoints <= 1)
39 | return;
40 |
41 | if (node.texture && node.texture.isLoaded()) {
42 | ctx = ctx || cc._renderContext;
43 |
44 | var wt = this._worldTransform;
45 | this._matrix.mat[0] = wt.a;
46 | this._matrix.mat[4] = wt.c;
47 | this._matrix.mat[12] = wt.tx;
48 | this._matrix.mat[1] = wt.b;
49 | this._matrix.mat[5] = wt.d;
50 | this._matrix.mat[13] = wt.ty;
51 |
52 | this._glProgramState.apply(this._matrix);
53 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
54 |
55 | cc.glBindTexture2D(node.texture);
56 |
57 | ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION);
58 | ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_COLOR);
59 | ctx.enableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS);
60 |
61 | //position
62 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._verticesBuffer);
63 | ctx.bufferData(ctx.ARRAY_BUFFER, node._vertices, ctx.DYNAMIC_DRAW);
64 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
65 |
66 | //texcoords
67 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._texCoordsBuffer);
68 | ctx.bufferData(ctx.ARRAY_BUFFER, node._texCoords, ctx.DYNAMIC_DRAW);
69 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
70 |
71 | //colors
72 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._colorPointerBuffer);
73 | ctx.bufferData(ctx.ARRAY_BUFFER, node._colorPointer, ctx.DYNAMIC_DRAW);
74 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
75 |
76 | ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, node._nuPoints * 2);
77 | cc.g_NumberOfDraws++;
78 | }
79 | };
80 |
--------------------------------------------------------------------------------
/cocos2d/node-grid/CCNodeGrid.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | *
NodeGrid class is a class serves as a decorator of cc.Node,
29 | * Grid node can run grid actions over all its children (WebGL only)
30 | *
31 | * @type {Class}
32 | *
33 | * @property {cc.GridBase} grid - Grid object that is used when applying effects
34 | * @property {cc.Node} target - <@writeonly>Target
35 | */
36 | cc.NodeGrid = cc.Node.extend(/** @lends cc.NodeGrid# */{
37 | grid: null,
38 | _target: null,
39 | _gridRect:null,
40 |
41 | ctor: function (rect) {
42 | cc.Node.prototype.ctor.call(this);
43 | if(rect === undefined) rect = cc.rect();
44 | this._gridRect = rect;
45 | },
46 | /**
47 | * Gets the grid object.
48 | * @returns {cc.GridBase}
49 | */
50 | getGrid: function () {
51 | return this.grid;
52 | },
53 |
54 | /**
55 | * Set the grid object.
56 | * @param {cc.GridBase} grid
57 | */
58 | setGrid: function (grid) {
59 | this.grid = grid;
60 | },
61 |
62 | /**
63 | * @brief Set the effect grid rect.
64 | * @param {cc.Rect} rect
65 | */
66 | setGridRect: function (rect) {
67 | this._gridRect = rect;
68 | },
69 | /**
70 | * @brief Get the effect grid rect.
71 | * @return {cc.Rect} rect.
72 | */
73 | getGridRect: function () {
74 | return this._gridRect;
75 | },
76 |
77 | /**
78 | * Set the target
79 | * @param {cc.Node} target
80 | */
81 | setTarget: function (target) {
82 | this._target = target;
83 | },
84 |
85 | _createRenderCmd: function(){
86 | if (cc._renderType === cc.game.RENDER_TYPE_WEBGL)
87 | return new cc.NodeGrid.WebGLRenderCmd(this);
88 | else
89 | return new cc.Node.CanvasRenderCmd(this); // cc.NodeGrid doesn't support Canvas mode.
90 | }
91 | });
92 |
93 | var _p = cc.NodeGrid.prototype;
94 | // Extended property
95 | /** @expose */
96 | _p.grid;
97 | /** @expose */
98 | _p.target;
99 | cc.defineGetterSetter(_p, "target", null, _p.setTarget);
100 |
101 |
102 | /**
103 | * Creates a NodeGrid.
104 | * Implementation cc.NodeGrid
105 | * @deprecated since v3.0 please new cc.NodeGrid instead.
106 | * @return {cc.NodeGrid}
107 | */
108 | cc.NodeGrid.create = function () {
109 | return new cc.NodeGrid();
110 | };
111 |
--------------------------------------------------------------------------------
/cocos2d/parallax/CCParallaxNodeRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | //TODO find a way to simple these code.
26 |
27 | (function () {
28 | cc.ParallaxNode.CanvasRenderCmd = function (renderable) {
29 | this._rootCtor(renderable);
30 | this._needDraw = false;
31 | };
32 |
33 | var proto = cc.ParallaxNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
34 | proto.constructor = cc.ParallaxNode.CanvasRenderCmd;
35 |
36 | proto.updateStatus = function () {
37 | this._node._updateParallaxPosition();
38 | this.originUpdateStatus();
39 | };
40 |
41 | proto._syncStatus = function (parentCmd) {
42 | this._node._updateParallaxPosition();
43 | this._originSyncStatus(parentCmd);
44 | };
45 | })();
46 |
47 | cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
48 | if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL)
49 | return;
50 |
51 | cc.ParallaxNode.WebGLRenderCmd = function (renderable) {
52 | this._rootCtor(renderable);
53 | this._needDraw = false;
54 | };
55 |
56 | var proto = cc.ParallaxNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
57 | proto.constructor = cc.ParallaxNode.WebGLRenderCmd;
58 |
59 | proto.updateStatus = function () {
60 | this._node._updateParallaxPosition();
61 | this.originUpdateStatus();
62 | };
63 |
64 | proto._syncStatus = function (parentCmd) {
65 | this._node._updateParallaxPosition();
66 | this._originSyncStatus(parentCmd);
67 | };
68 | });
69 |
70 |
--------------------------------------------------------------------------------
/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | /**
27 | * cc.ParticleBatchNode's rendering objects of Canvas
28 | */
29 | cc.ParticleBatchNode.CanvasRenderCmd = function (renderable) {
30 | this._rootCtor(renderable);
31 | this._needDraw = false;
32 | };
33 |
34 | var proto = cc.ParticleBatchNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
35 | proto.constructor = cc.ParticleBatchNode.CanvasRenderCmd;
36 |
37 | proto._initWithTexture = function () {
38 | };
39 | })();
40 |
--------------------------------------------------------------------------------
/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | /**
27 | * cc.ParticleBatchNode's rendering objects of WebGL
28 | */
29 | cc.ParticleBatchNode.WebGLRenderCmd = function (renderable) {
30 | this._rootCtor(renderable);
31 | this._needDraw = true;
32 | this._matrix = new cc.math.Matrix4();
33 | this._matrix.identity();
34 | };
35 |
36 | var proto = cc.ParticleBatchNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
37 | proto.constructor = cc.ParticleBatchNode.WebGLRenderCmd;
38 |
39 | proto.rendering = function (ctx) {
40 | var _t = this._node;
41 | if (_t.textureAtlas.totalQuads === 0)
42 | return;
43 |
44 | var wt = this._worldTransform;
45 | this._matrix.mat[0] = wt.a;
46 | this._matrix.mat[4] = wt.c;
47 | this._matrix.mat[12] = wt.tx;
48 | this._matrix.mat[1] = wt.b;
49 | this._matrix.mat[5] = wt.d;
50 | this._matrix.mat[13] = wt.ty;
51 |
52 | this._glProgramState.apply(this._matrix);
53 | cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
54 | _t.textureAtlas.drawQuads();
55 | };
56 |
57 | proto._initWithTexture = function () {
58 | this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR);
59 | };
60 | })();
61 |
--------------------------------------------------------------------------------
/cocos2d/physics/CCPhysicsDebugNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsDebugNode's rendering objects of Canvas
27 | */
28 | (function () {
29 | cc.PhysicsDebugNode.CanvasRenderCmd = function (renderableObject) {
30 | this._rootCtor(renderableObject);
31 | this._buffer = renderableObject._buffer;
32 | this._needDraw = true;
33 | };
34 |
35 | var proto = cc.PhysicsDebugNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
36 | proto.constructor = cc.PhysicsDebugNode.CanvasRenderCmd;
37 |
38 | proto.rendering = function (ctx, scaleX, scaleY) {
39 | var node = this._node;
40 | if (!node._space)
41 | return;
42 | node._space.eachShape(cc.DrawShape.bind(node));
43 | node._space.eachConstraint(cc.DrawConstraint.bind(node));
44 | cc.DrawNode.CanvasRenderCmd.prototype.rendering.call(this, ctx, scaleX, scaleY);
45 | node.clear();
46 | };
47 |
48 | proto._drawDot = cc.DrawNode.CanvasRenderCmd.prototype._drawDot;
49 | proto._drawSegment = cc.DrawNode.CanvasRenderCmd.prototype._drawSegment;
50 | proto._drawPoly = cc.DrawNode.CanvasRenderCmd.prototype._drawPoly;
51 |
52 | })();
53 |
--------------------------------------------------------------------------------
/cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsDebugNode's rendering objects of WebGL
27 | */
28 | (function () {
29 | cc.PhysicsDebugNode.WebGLRenderCmd = function (renderableObject) {
30 | this._rootCtor(renderableObject);
31 | this._needDraw = true;
32 | this._matrix = new cc.math.Matrix4();
33 | this._matrix.identity();
34 | };
35 |
36 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
37 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype.constructor = cc.PhysicsDebugNode.WebGLRenderCmd;
38 |
39 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
40 | var node = this._node;
41 | if (!node._space)
42 | return;
43 |
44 | node._space.eachShape(cc.DrawShape.bind(node));
45 | node._space.eachConstraint(cc.DrawConstraint.bind(node));
46 |
47 | var wt = this._worldTransform;
48 | this._matrix.mat[0] = wt.a;
49 | this._matrix.mat[4] = wt.c;
50 | this._matrix.mat[12] = wt.tx;
51 | this._matrix.mat[1] = wt.b;
52 | this._matrix.mat[5] = wt.d;
53 | this._matrix.mat[13] = wt.ty;
54 |
55 | //cc.DrawNode.prototype.draw.call(node);
56 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
57 | this._glProgramState.apply(this._matrix);
58 | node._render();
59 |
60 | node.clear();
61 | };
62 | })();
63 |
--------------------------------------------------------------------------------
/cocos2d/physics/CCPhysicsSpriteCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsSprite's rendering objects of Canvas
27 | */
28 | (function () {
29 | cc.PhysicsSprite.CanvasRenderCmd = function (renderableObject) {
30 | this._spriteCmdCtor(renderableObject);
31 | this._needDraw = true;
32 | };
33 |
34 | var proto = cc.PhysicsSprite.CanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);
35 | proto.constructor = cc.PhysicsSprite.CanvasRenderCmd;
36 |
37 | proto.rendering = function (ctx, scaleX, scaleY) {
38 | // This is a special class
39 | // Sprite can not obtain sign
40 | // So here must to calculate of each frame
41 | var node = this._node;
42 | node._syncPosition();
43 | if (!node._ignoreBodyRotation)
44 | node._syncRotation();
45 | this.transform(this.getParentRenderCmd());
46 |
47 | cc.Sprite.CanvasRenderCmd.prototype.rendering.call(this, ctx, scaleX, scaleY);
48 | };
49 |
50 | })();
51 |
--------------------------------------------------------------------------------
/cocos2d/physics/CCPhysicsSpriteWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsSprite's rendering objects of WebGL
27 | */
28 | (function () {
29 | cc.PhysicsSprite.WebGLRenderCmd = function (renderableObject) {
30 | this._spriteCmdCtor(renderableObject);
31 | this._needDraw = true;
32 | };
33 |
34 | var proto = cc.PhysicsSprite.WebGLRenderCmd.prototype = Object.create(cc.Sprite.WebGLRenderCmd.prototype);
35 | proto.constructor = cc.PhysicsSprite.WebGLRenderCmd;
36 |
37 | proto.spUploadData = cc.Sprite.WebGLRenderCmd.prototype.uploadData;
38 |
39 | proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
40 | // This is a special class
41 | // Sprite can not obtain sign
42 | // So here must to calculate of each frame
43 | var node = this._node;
44 | node._syncPosition();
45 | if (!node._ignoreBodyRotation)
46 | node._syncRotation();
47 | this.transform(this.getParentRenderCmd(), true);
48 |
49 | return this.spUploadData(f32buffer, ui32buffer, vertexDataOffset);
50 | };
51 | })();
52 |
--------------------------------------------------------------------------------
/cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | cc.DrawNode.WebGLRenderCmd = function (renderableObject) {
27 | this._rootCtor(renderableObject);
28 | this._needDraw = true;
29 | this._matrix = new cc.math.Matrix4();
30 | this._matrix.identity();
31 | };
32 |
33 | cc.DrawNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
34 | cc.DrawNode.WebGLRenderCmd.prototype.constructor = cc.DrawNode.WebGLRenderCmd;
35 |
36 | cc.DrawNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
37 | var node = this._node;
38 | if (node._vertexCount > 0) {
39 | var wt = this._worldTransform;
40 | this._matrix.mat[0] = wt.a;
41 | this._matrix.mat[4] = wt.c;
42 | this._matrix.mat[12] = wt.tx;
43 | this._matrix.mat[1] = wt.b;
44 | this._matrix.mat[5] = wt.d;
45 | this._matrix.mat[13] = wt.ty;
46 |
47 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
48 | this._glProgramState.apply(this._matrix);
49 | node._render();
50 | }
51 | };
52 | })();
53 |
--------------------------------------------------------------------------------
/extensions/ccb-reader/CCBKeyframe.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.BuilderKeyframe = cc.Class.extend({
28 | _value:null,
29 | _time:0,
30 | _easingType:0,
31 | _easingOpt:0,
32 |
33 | getValue:function(){
34 | return this._value;
35 | },
36 | setValue:function(value){
37 | this._value = value;
38 | },
39 |
40 | getTime:function(){
41 | return this._time;
42 | },
43 | setTime:function(time){
44 | this._time = time;
45 | },
46 |
47 | getEasingType:function(){
48 | return this._easingType;
49 | },
50 | setEasingType:function(easingType){
51 | this._easingType = easingType;
52 | },
53 |
54 | getEasingOpt:function(){
55 | return this._easingOpt;
56 | },
57 | setEasingOpt:function(easingOpt){
58 | this._easingOpt = easingOpt;
59 | }
60 | });
61 |
--------------------------------------------------------------------------------
/extensions/ccb-reader/CCBReaderUtil.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.NodeLoaderListener = cc.Class.extend({
28 | onNodeLoaded: function (node, nodeLoader) {
29 | }
30 | });
31 |
32 | cc.BuilderSelectorResolver = cc.Class.extend({
33 | onResolveCCBCCMenuItemSelector: function (target, selectorName) {
34 | },
35 | onResolveCCBCCCallFuncSelector: function (target, selectorName) {
36 | },
37 | onResolveCCBCCControlSelector: function (target, selectorName) {
38 | }
39 | });
40 |
41 | cc.BuilderScriptOwnerProtocol = cc.Class.extend({
42 | createNew: function () {
43 | }
44 | });
45 |
46 | cc.BuilderMemberVariableAssigner = cc.Class.extend({
47 | /**
48 | * The callback function of assigning member variable.
49 | * @note The member variable must be CCNode or its subclass.
50 | * @param {Object} target The custom class
51 | * @param {string} memberVariableName The name of the member variable.
52 | * @param {cc.Node} node The member variable.
53 | * @return {Boolean} Whether the assignment was successful.
54 | */
55 | onAssignCCBMemberVariable: function (target, memberVariableName, node) {
56 | return false;
57 | },
58 |
59 | /**
60 | * The callback function of assigning custom properties.
61 | * @note The member variable must be Integer, Float, Boolean or String.
62 | * @param {Object} target The custom class.
63 | * @param {string} memberVariableName The name of the member variable.
64 | * @param {*} value The value of the property.
65 | * @return {Boolean} Whether the assignment was successful.
66 | */
67 | onAssignCCBCustomProperty: function (target, memberVariableName, value) {
68 | return false;
69 | }
70 | });
71 |
--------------------------------------------------------------------------------
/extensions/ccb-reader/CCBRelativePositioning.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.getAbsolutePosition = function (x, y, type, containerSize, propName, out) {
28 | var absPt = out || cc.p(0, 0);
29 | if (type === CCB_POSITIONTYPE_RELATIVE_BOTTOM_LEFT) {
30 | absPt.x = x;
31 | absPt.y = y;
32 | } else if (type === CCB_POSITIONTYPE_RELATIVE_TOP_LEFT) {
33 | absPt.x = x;
34 | absPt.y = containerSize.height - y;
35 | } else if (type === CCB_POSITIONTYPE_RELATIVE_TOP_RIGHT) {
36 | absPt.x = containerSize.width - x;
37 | absPt.y = containerSize.height - y;
38 | } else if (type === CCB_POSITIONTYPE_RELATIVE_BOTTOM_RIGHT) {
39 | absPt.x = containerSize.width - x;
40 | absPt.y = y;
41 | } else if (type === CCB_POSITIONTYPE_PERCENT) {
42 | absPt.x = (containerSize.width * x / 100.0);
43 | absPt.y = (containerSize.height * y / 100.0);
44 | } else if (type === CCB_POSITIONTYPE_MULTIPLY_RESOLUTION) {
45 | var resolutionScale = cc.BuilderReader.getResolutionScale();
46 | absPt.x = x * resolutionScale;
47 | absPt.y = y * resolutionScale;
48 | }
49 | return absPt;
50 | };
51 |
52 | cc.setRelativeScale = function (node, scaleX, scaleY, type, propName) {
53 | if (!node)
54 | throw new Error("cc.setRelativeScale(): node should be non-null");
55 |
56 | if (type === CCB_POSITIONTYPE_MULTIPLY_RESOLUTION) {
57 | var resolutionScale = cc.BuilderReader.getResolutionScale();
58 |
59 | scaleX *= resolutionScale;
60 | scaleY *= resolutionScale;
61 | }
62 |
63 | node.setScale(scaleX, scaleY);
64 | };
65 |
--------------------------------------------------------------------------------
/extensions/ccb-reader/CCBSequence.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.BuilderSequence = cc.Class.extend({
28 | _duration:0,
29 | _name:"",
30 | _sequenceId:0,
31 | _chainedSequenceId:0,
32 | _callbackChannel:null,
33 | _soundChannel:null,
34 |
35 | ctor:function(){
36 | this._name = "";
37 | },
38 |
39 | getDuration:function(){
40 | return this._duration;
41 | },
42 | setDuration:function(duration){
43 | this._duration = duration;
44 | },
45 |
46 | getName:function(){
47 | return this._name;
48 | },
49 | setName:function(name){
50 | this._name = name;
51 | },
52 |
53 | getSequenceId:function(){
54 | return this._sequenceId;
55 | },
56 | setSequenceId:function(sequenceId){
57 | this._sequenceId = sequenceId;
58 | },
59 |
60 | getChainedSequenceId:function(){
61 | return this._chainedSequenceId;
62 | },
63 | setChainedSequenceId:function(chainedSequenceId){
64 | this._chainedSequenceId = chainedSequenceId;
65 | },
66 |
67 | getCallbackChannel:function() {
68 | return this._callbackChannel;
69 | },
70 | setCallbackChannel:function(channel) {
71 | this._callbackChannel = channel;
72 | },
73 |
74 | getSoundChannel:function() {
75 | return this._soundChannel;
76 | },
77 | setSoundChannel:function(channel) {
78 | this._soundChannel = channel;
79 | }
80 | });
81 |
82 | cc.BuilderSequenceProperty = cc.Class.extend({
83 | _name : null,
84 | _type:0,
85 | _keyFrames:null,
86 |
87 | ctor:function(){
88 | this.init();
89 | },
90 |
91 | init:function(){
92 | this._keyFrames = [];
93 | this._name = "";
94 | },
95 |
96 | getName:function(){
97 | return this._name;
98 | },
99 |
100 | setName :function(name){
101 | this._name = name;
102 | },
103 |
104 | getType:function(){
105 | return this._type;
106 | },
107 | setType :function(type){
108 | this._type = type;
109 | },
110 |
111 | getKeyframes:function(){
112 | return this._keyFrames;
113 | }
114 | });
--------------------------------------------------------------------------------
/extensions/ccb-reader/CCBValue.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc.INT_VALUE = 0;
28 |
29 | cc.FLOAT_VALUE = 1;
30 |
31 | cc.POINTER_VALUE = 2;
32 |
33 | cc.BOOL_VALUE = 3;
34 |
35 | cc.UNSIGNEDCHAR_VALUE = 4;
36 |
37 | cc.BuilderValue = cc.Class.extend({
38 | _value: null,
39 | _type: 0,
40 |
41 | getIntValue: function () {
42 | },
43 | getFloatValue: function () {
44 | },
45 | getBoolValue: function () {
46 | },
47 | getByteValue: function () {
48 | },
49 | getPointer: function () {
50 | },
51 |
52 | getValue: function () {
53 | return this._value;
54 | }
55 | });
56 |
57 | cc.BuilderValue.create = function (value) {
58 | return new cc.BuilderValue();
59 | };
60 |
61 |
--------------------------------------------------------------------------------
/extensions/ccui/base-classes/CCProtectedNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | if (!cc.Node.WebGLRenderCmd)
27 | return;
28 | cc.ProtectedNode.WebGLRenderCmd = function (renderable) {
29 | this._rootCtor(renderable);
30 | };
31 |
32 | var proto = cc.ProtectedNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
33 | cc.inject(cc.ProtectedNode.RenderCmd, proto);
34 | proto.constructor = cc.ProtectedNode.WebGLRenderCmd;
35 | proto._pNodeCmdCtor = cc.ProtectedNode.WebGLRenderCmd;
36 |
37 | proto.transform = function (parentCmd, recursive) {
38 | this.originTransform(parentCmd, recursive);
39 |
40 | var i, len,
41 | locChildren = this._node._protectedChildren;
42 | if (recursive && locChildren && locChildren.length !== 0) {
43 | for (i = 0, len = locChildren.length; i < len; i++) {
44 | locChildren[i]._renderCmd.transform(this, recursive);
45 | }
46 | }
47 | };
48 |
49 | proto.pNodeTransform = proto.transform;
50 | })();
51 |
--------------------------------------------------------------------------------
/extensions/ccui/layouts/UIHBox.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The horizontal box of Cocos UI. Its layout type is ccui.Layout.LINEAR_HORIZONTAL.
28 | * @class
29 | * @extends ccui.Layout
30 | */
31 | ccui.HBox = ccui.Layout.extend(/** @lends ccui.HBox# */{
32 | /**
33 | * The constructor of ccui.HBox
34 | * @function
35 | * @param {cc.Size} [size]
36 | */
37 | ctor: function(size){
38 | ccui.Layout.prototype.ctor.call(this);
39 | this.setLayoutType(ccui.Layout.LINEAR_HORIZONTAL);
40 |
41 | if(size) {
42 | this.setContentSize(size);
43 | }
44 | }
45 | });
46 |
47 | /**
48 | * Creates a HBox object
49 | * @deprecated since v3.0, please use new ccui.HBox(size) instead.
50 | * @param {cc.Size} size
51 | * @returns {ccui.HBox}
52 | */
53 | ccui.HBox.create = function(size){
54 | return new ccui.HBox(size);
55 | };
--------------------------------------------------------------------------------
/extensions/ccui/layouts/UIRelativeBox.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The Relative box for Cocos UI layout. Its layout type is ccui.Layout.RELATIVE.
28 | * @class
29 | * @extends ccui.Layout
30 | */
31 | ccui.RelativeBox = ccui.Layout.extend(/** @lends ccui.RelativeBox# */{
32 | /**
33 | * The constructor of ccui.RelativeBox
34 | * @function
35 | * @param {cc.Size} [size]
36 | */
37 | ctor: function(size){
38 | ccui.Layout.prototype.ctor.call(this);
39 | this.setLayoutType(ccui.Layout.RELATIVE);
40 |
41 | if(size) {
42 | this.setContentSize(size);
43 | }
44 | }
45 | });
46 |
47 | /**
48 | * Creates a relative box
49 | * @deprecated since v3.0, please use new ccui.RelativeBox(size) instead.
50 | * @param {cc.Size} size
51 | * @returns {ccui.RelativeBox}
52 | */
53 | ccui.RelativeBox.create = function(size){
54 | return new ccui.RelativeBox(size);
55 | };
--------------------------------------------------------------------------------
/extensions/ccui/layouts/UIVBox.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The vertical box of Cocos UI. Its layout type is ccui.Layout.LINEAR_VERTICAL.
28 | * @class
29 | * @extends ccui.Layout
30 | */
31 | ccui.VBox = ccui.Layout.extend(/** @lends ccui.VBox# */{
32 | /**
33 | * The constructor of ccui.VBox
34 | * @function
35 | * @param {cc.Size} size
36 | */
37 | ctor: function(size){
38 | ccui.Layout.prototype.ctor.call(this);
39 | this.setLayoutType(ccui.Layout.LINEAR_VERTICAL);
40 |
41 | if (size) {
42 | this.setContentSize(size);
43 | }
44 | },
45 |
46 | /**
47 | * Initializes a VBox with size.
48 | * @param {cc.Size} size
49 | * @returns {boolean}
50 | */
51 | initWithSize: function(size){
52 | if(this.init()){
53 |
54 | return true;
55 | }
56 | return false;
57 | }
58 | });
59 |
60 | /**
61 | * Creates a VBox
62 | * @param {cc.Size} size
63 | * @returns {ccui.VBox}
64 | */
65 | ccui.VBox.create = function(size){
66 | return new ccui.VBox(size);
67 | };
--------------------------------------------------------------------------------
/extensions/ccui/system/CocosGUI.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The namespace of Cocos UI
28 | * @namespace
29 | * @name ccui
30 | */
31 | var ccui = ccui || {};
32 |
33 | //These classes defines are use for jsDoc
34 | /**
35 | * The same as cc.Class
36 | * @class
37 | */
38 | ccui.Class = ccui.Class || cc.Class;
39 | ccui.Class.extend = ccui.Class.extend || cc.Class.extend;
40 |
41 | /**
42 | * that same as cc.Node
43 | * @class
44 | * @extends ccui.Class
45 | */
46 | ccui.Node = ccui.Node || cc.Node;
47 | ccui.Node.extend = ccui.Node.extend || cc.Node.extend;
48 |
49 |
50 | /**
51 | * that same as cc.Node
52 | * @class
53 | * @extends ccui.Node
54 | */
55 | ccui.ProtectedNode = ccui.ProtectedNode || cc.ProtectedNode;
56 | ccui.ProtectedNode.extend = ccui.ProtectedNode.extend || cc.ProtectedNode.extend;
57 |
58 | /**
59 | * Cocos UI version
60 | * @type {String}
61 | */
62 | ccui.cocosGUIVersion = "CocosGUI v1.0.0.0";
--------------------------------------------------------------------------------
/extensions/ccui/uiwidgets/scroll-widget/UIScrollViewCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | if (!ccui.ProtectedNode.CanvasRenderCmd)
3 | return;
4 | ccui.ScrollView.CanvasRenderCmd = function (renderable) {
5 | this._layoutCmdCtor(renderable);
6 | //this._needDraw = true;
7 | this._dirty = false;
8 | };
9 |
10 | var proto = ccui.ScrollView.CanvasRenderCmd.prototype = Object.create(ccui.Layout.CanvasRenderCmd.prototype);
11 | proto.constructor = ccui.ScrollView.CanvasRenderCmd;
12 |
13 | proto.rendering = function (ctx) {
14 | var currentID = this._node.__instanceId;
15 | var i, locCmds = cc.renderer._cacheToCanvasCmds[currentID], len,
16 | scaleX = cc.view.getScaleX(),
17 | scaleY = cc.view.getScaleY();
18 | var context = ctx || cc._renderContext;
19 | context.computeRealOffsetY();
20 |
21 | this._node.updateChildren();
22 |
23 | for (i = 0, len = locCmds.length; i < len; i++) {
24 | var checkNode = locCmds[i]._node;
25 | if (checkNode instanceof ccui.ScrollView)
26 | continue;
27 | if (checkNode && checkNode._parent && checkNode._parent._inViewRect === false)
28 | continue;
29 | locCmds[i].rendering(context, scaleX, scaleY);
30 | }
31 | };
32 | })();
33 |
--------------------------------------------------------------------------------
/extensions/ccui/uiwidgets/scroll-widget/UIScrollViewWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | if (!ccui.ProtectedNode.WebGLRenderCmd)
3 | return;
4 | ccui.ScrollView.WebGLRenderCmd = function (renderable) {
5 | this._layoutCmdCtor(renderable);
6 | this._needDraw = true;
7 | this._dirty = false;
8 | };
9 |
10 | var proto = ccui.ScrollView.WebGLRenderCmd.prototype = Object.create(ccui.Layout.WebGLRenderCmd.prototype);
11 | proto.constructor = ccui.ScrollView.WebGLRenderCmd;
12 |
13 | proto.rendering = function (ctx) {
14 | var currentID = this._node.__instanceId,
15 | locCmds = cc.renderer._cacheToBufferCmds[currentID],
16 | i, len, checkNode, cmd,
17 | context = ctx || cc._renderContext;
18 | if (!locCmds) {
19 | return;
20 | }
21 |
22 | this._node.updateChildren();
23 |
24 | // Reset buffer for rendering
25 | context.bindBuffer(gl.ARRAY_BUFFER, null);
26 |
27 | for (i = 0, len = locCmds.length; i < len; i++) {
28 | cmd = locCmds[i];
29 | checkNode = cmd._node;
30 | if (checkNode && checkNode._parent && checkNode._parent._inViewRect === false)
31 | continue;
32 |
33 | if (cmd.uploadData) {
34 | cc.renderer._uploadBufferData(cmd);
35 | }
36 | else {
37 | if (cmd._batchingSize > 0) {
38 | cc.renderer._batchRendering();
39 | }
40 | cmd.rendering(context);
41 | }
42 | cc.renderer._batchRendering();
43 | }
44 | };
45 | })();
46 |
--------------------------------------------------------------------------------
/extensions/cocostudio/CocoStudio.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 | /**
26 | * The main namespace of Cocostudio, all classes, functions, properties and constants of Spine are defined in this namespace
27 | * @namespace
28 | * @name ccs
29 | */
30 | var ccs = ccs || {};
31 |
32 | /**
33 | * The same as cc.Class
34 | * @class
35 | */
36 | ccs.Class = ccs.Class || cc.Class;
37 | ccs.Class.extend = ccs.Class.extend || cc.Class.extend;
38 |
39 | /**
40 | * The same as cc.Node
41 | * @class
42 | * @extends ccs.Class
43 | */
44 | ccs.Node = ccs.Node || cc.Node;
45 | ccs.Node.extend = ccs.Node.extend || cc.Node.extend;
46 |
47 | /**
48 | * The same as cc.Sprite
49 | * @class
50 | * @extends ccs.Class
51 | */
52 | ccs.Sprite = ccs.Sprite || cc.Sprite;
53 | ccs.Sprite.extend = ccs.Sprite.extend || cc.Sprite.extend;
54 |
55 | /**
56 | * The same as cc.Component
57 | * @class
58 | * @extends ccs.Class
59 | */
60 | ccs.Component = ccs.Component || cc.Component;
61 | ccs.Component.extend = ccs.Component.extend || cc.Component.extend;
62 |
63 | /**
64 | * CocoStudio version
65 | * @constant
66 | * @type {string}
67 | */
68 | ccs.cocostudioVersion = "v1.3.0.0";
--------------------------------------------------------------------------------
/extensions/cocostudio/armature/display/CCDecorativeDisplay.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * Decorative a display node for Cocos Armature
28 | * @class
29 | * @extends ccs.Class
30 | */
31 | ccs.DecorativeDisplay = ccs.Class.extend(/** @lends ccs.DecorativeDisplay# */{
32 | _display: null,
33 | _colliderDetector: null,
34 | _displayData: null,
35 |
36 | ctor:function () {
37 | this._display = null;
38 | this._colliderDetector = null;
39 | this._displayData = null;
40 |
41 | //ccs.DecorativeDisplay.prototype.init.call(this);
42 | },
43 |
44 | /**
45 | * Initializes a ccs.DecorativeDisplay
46 | * @returns {boolean}
47 | */
48 | init:function () {
49 | return true;
50 | },
51 |
52 | /**
53 | * Sets display node to decorative
54 | * @param {cc.Node} display
55 | */
56 | setDisplay:function (display) {
57 | if(display._parent){
58 | display._parent.removeChild(display);
59 | delete display._parent;
60 | }
61 | this._display = display;
62 | },
63 |
64 | /**
65 | * Returns the display node
66 | * @returns {cc.Node}
67 | */
68 | getDisplay:function () {
69 | return this._display;
70 | },
71 |
72 | /**
73 | * Sets collide detector
74 | * @param {ccs.ColliderDetector} colliderDetector
75 | */
76 | setColliderDetector:function (colliderDetector) {
77 | this._colliderDetector = colliderDetector;
78 | },
79 |
80 | /**
81 | * Returns collide detector
82 | * @returns {ccs.ColliderDetector}
83 | */
84 | getColliderDetector:function () {
85 | return this._colliderDetector;
86 | },
87 |
88 | /**
89 | * Sets display data
90 | * @param {ccs.DisplayData} displayData
91 | */
92 | setDisplayData:function (displayData) {
93 | this._displayData = displayData;
94 | },
95 |
96 | /**
97 | * Returns display data
98 | * @returns {ccs.DisplayData}
99 | */
100 | getDisplayData:function () {
101 | return this._displayData;
102 | },
103 |
104 | release:function () {
105 | this._display = null;
106 | this._displayData = null;
107 | this._colliderDetector = null;
108 | }
109 | });
110 |
111 | /**
112 | * Allocates and initializes a decorative display.
113 | * @return {ccs.DecorativeDisplay}
114 | * @deprecated since v3.1, please use new construction instead
115 | */
116 | ccs.DecorativeDisplay.create = function () {
117 | return new ccs.DecorativeDisplay();
118 | };
--------------------------------------------------------------------------------
/extensions/cocostudio/armature/utils/CCArmatureDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 | /**
26 | * @ignore
27 | */
28 | ccs.VERSION_COMBINED = 0.30;
29 | ccs.VERSION_CHANGE_ROTATION_RANGE = 1.0;
30 | ccs.VERSION_COLOR_READING = 1.1;
31 | ccs.MAX_VERTEXZ_VALUE = 5000000.0;
32 | ccs.ARMATURE_MAX_CHILD = 50.0;
33 | ccs.ARMATURE_MAX_ZORDER = 100;
34 | ccs.ARMATURE_MAX_COUNT = ((ccs.MAX_VERTEXZ_VALUE) / (ccs.ARMATURE_MAX_CHILD) / ccs.ARMATURE_MAX_ZORDER);
35 | ccs.AUTO_ADD_SPRITE_FRAME_NAME_PREFIX = false;
36 | ccs.ENABLE_PHYSICS_CHIPMUNK_DETECT = false;
37 | ccs.ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX = false;
38 |
39 | /**
40 | * Returns the version of Armature.
41 | * @returns {string}
42 | */
43 | ccs.armatureVersion = function(){
44 | return "v1.1.0.0";
45 | };
46 |
--------------------------------------------------------------------------------
/extensions/cocostudio/armature/utils/CCSpriteFrameCacheHelper.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * ccs.spriteFrameCacheHelper is a singleton object, it's a sprite frame cache helper
28 | * @class
29 | * @name ccs.spriteFrameCacheHelper
30 | */
31 | ccs.spriteFrameCacheHelper = /** @lends ccs.spriteFrameCacheHelper# */ {
32 | _textureAtlasDic:{},
33 | _imagePaths:[],
34 |
35 | /**
36 | * Adds sprite frame from file
37 | * @param plistPath
38 | * @param imagePath
39 | */
40 | addSpriteFrameFromFile:function (plistPath, imagePath) {
41 | cc.spriteFrameCache.addSpriteFrames(plistPath, imagePath);
42 | },
43 |
44 | /**
45 | * Returns texture atlas with texture.
46 | * @param texture
47 | * @returns {*}
48 | */
49 | getTextureAtlasWithTexture:function (texture) {
50 | //todo
51 | return null;
52 | var textureName = texture.getName();
53 | var atlas = this._textureAtlasDic[textureName];
54 | if (atlas == null) {
55 | atlas = new cc.TextureAtlas(texture, 20);
56 | this._textureAtlasDic[textureName] = atlas;
57 | }
58 | return atlas;
59 | },
60 |
61 | /**
62 | * Clear the sprite frame cache's data.
63 | */
64 | clear: function () {
65 | this._textureAtlasDic = {};
66 | this._imagePaths = [];
67 | }
68 | };
--------------------------------------------------------------------------------
/extensions/cocostudio/armature/utils/CCUtilMath.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | var ENABLE_PHYSICS_DETECT = false;
27 | ccs.fmodf = function (x, y) {
28 | while (x > y) {
29 | x -= y;
30 | }
31 | return x;
32 | };
33 | var CC_SAFE_RELEASE = function (obj) {
34 | if (obj && obj.release) {
35 | obj.release();
36 | }
37 | };
38 |
39 | ccs.isSpriteContainPoint = function (sprite, point, outPoint) {
40 | var p = sprite.convertToNodeSpace(point);
41 | if (outPoint) {
42 | outPoint.x = p.x;
43 | outPoint.y = p.y;
44 | }
45 | var s = sprite.getContentSize();
46 | return cc.rectContainsPoint(cc.rect(0, 0, s.width, s.height), p);
47 | };
48 | ccs.SPRITE_CONTAIN_POINT = ccs.isSpriteContainPoint;
49 | ccs.SPRITE_CONTAIN_POINT_WITH_RETURN = ccs.isSpriteContainPoint;
50 |
51 | ccs.extBezierTo = function (t, point1, point2, point3, point4) {
52 | var p = cc.p(0, 0);
53 | if (point3 && !point4) {
54 | p.x = Math.pow((1 - t), 2) * point1.x + 2 * t * (1 - t) * point2.x + Math.pow(t, 2) * point3.x;
55 | p.y = Math.pow((1 - t), 2) * point1.y + 2 * t * (1 - t) * point2.y + Math.pow(t, 2) * point3.y;
56 | }
57 | if (point4) {
58 | p.x = point1.x * Math.pow((1 - t), 3) + 3 * t * point2.x * Math.pow((1 - t), 2) + 3 * point3.x * Math.pow(t, 2) * (1 - t) + point4.x * Math.pow(t, 3);
59 | p.y = point1.y * Math.pow((1 - t), 3) + 3 * t * point2.y * Math.pow((1 - t), 2) + 3 * point3.y * Math.pow(t, 2) * (1 - t) + point4.y * Math.pow(t, 3);
60 | }
61 | return p;
62 | };
63 |
64 | ccs.extCircleTo = function (t, center, radius, fromRadian, radianDif) {
65 | var p = cc.p(0, 0);
66 | p.x = center.x + radius * Math.cos(fromRadian + radianDif * t);
67 | p.y = center.y + radius * Math.sin(fromRadian + radianDif * t);
68 | return p;
69 | };
--------------------------------------------------------------------------------
/extensions/cocostudio/components/CCComController.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The controller component for Cocostudio.
28 | * @class
29 | * @extends ccs.Component
30 | */
31 | ccs.ComController = ccs.Component.extend(/** @lends ccs.ComController# */{
32 | /**
33 | * Construction of ccs.ComController.
34 | */
35 | ctor: function () {
36 | cc.Component.prototype.ctor.call(this);
37 | this._name = "ComController";
38 | ccs.ComController.prototype.init.call(this);
39 | },
40 |
41 | /**
42 | * The callback calls when controller component enter stage.
43 | * @override
44 | */
45 | onEnter: function () {
46 | if (this._owner !== null)
47 | this._owner.scheduleUpdate();
48 | },
49 |
50 | /**
51 | * Returns controller component whether is enabled
52 | * @returns {Boolean}
53 | */
54 | isEnabled: function () {
55 | return this._enabled;
56 | },
57 |
58 | /**
59 | * Sets controller component whether is enabled
60 | * @param {Boolean} bool
61 | */
62 | setEnabled: function (bool) {
63 | this._enabled = bool;
64 | }
65 | });
66 | /**
67 | * Allocates and initializes a ComController.
68 | * @deprecated since v3.0, please use new construction instead.
69 | * @return {ccs.ComController}
70 | * @example
71 | * // example
72 | * var com = ccs.ComController.create();
73 | */
74 | ccs.ComController.create = function () {
75 | return new ccs.ComController();
76 | };
--------------------------------------------------------------------------------
/extensions/cocostudio/components/CCComRender.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The render component for Cocostudio.
28 | * @class
29 | * @extends ccs.Component
30 | */
31 | ccs.ComRender = ccs.Component.extend(/** @lends ccs.ComRender# */{
32 | _render: null,
33 | /**
34 | * Construction of ccs.ComRender
35 | * @param {cc.Node} node
36 | * @param {String} comName
37 | */
38 | ctor: function (node, comName) {
39 | cc.Component.prototype.ctor.call(this);
40 | this._render = node;
41 | this._name = comName;
42 | this.isRenderer = true;
43 | ccs.ComRender.prototype.init.call(this);
44 | },
45 |
46 | /**
47 | * The callback calls when a render component enter stage.
48 | */
49 | onEnter: function () {
50 | if (this._owner)
51 | this._owner.addChild(this._render);
52 | },
53 |
54 | /**
55 | * The callback calls when a render component exit stage.
56 | */
57 | onExit: function () {
58 | if (this._owner) {
59 | this._owner.removeChild(this._render, true);
60 | this._render = null;
61 | }
62 | },
63 |
64 | /**
65 | * Returns a render node
66 | * @returns {cc.Node}
67 | */
68 | getNode: function () {
69 | return this._render;
70 | },
71 |
72 | /**
73 | * Sets a render node to component.
74 | * @param {cc.Node} node
75 | */
76 | setNode: function (node) {
77 | this._render = node;
78 | }
79 | });
80 |
81 | /**
82 | * allocates and initializes a ComRender.
83 | * @deprecated since v3.0, please use new construction instead.
84 | * @return {ccs.ComRender}
85 | * @example
86 | * // example
87 | * var com = ccs.ComRender.create();
88 | */
89 | ccs.ComRender.create = function (node, comName) {
90 | return new ccs.ComRender(node, comName);
91 | };
92 |
--------------------------------------------------------------------------------
/extensions/cocostudio/components/CCComponent.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The base class of component in CocoStudio
28 | * @class
29 | * @extends cc.Class
30 | */
31 | cc.Component = cc.Class.extend(/** @lends cc.Component# */{
32 | _owner: null,
33 | _name: "",
34 | _enabled: true,
35 |
36 | /**
37 | * Construction of cc.Component
38 | */
39 | ctor:function(){
40 | this._owner = null;
41 | this._name = "";
42 | this._enabled = true;
43 | },
44 |
45 | /**
46 | * Initializes a cc.Component.
47 | * @returns {boolean}
48 | */
49 | init:function(){
50 | return true;
51 | },
52 |
53 | /**
54 | * The callback when a component enter stage.
55 | */
56 | onEnter:function(){
57 | },
58 |
59 | /**
60 | * The callback when a component exit stage.
61 | */
62 | onExit:function(){
63 | },
64 |
65 | /**
66 | * The callback per every frame if it schedules update.
67 | * @param delta
68 | */
69 | update:function(delta){
70 | },
71 |
72 | /**
73 | * Serialize a component object.
74 | * @param reader
75 | */
76 | serialize:function( reader){
77 | },
78 |
79 | /**
80 | * Returns component whether is enabled.
81 | * @returns {boolean}
82 | */
83 | isEnabled:function(){
84 | return this._enabled;
85 | },
86 |
87 | /**
88 | * Sets component whether is enabled.
89 | * @param enable
90 | */
91 | setEnabled:function(enable){
92 | this._enabled = enable;
93 | },
94 |
95 | /**
96 | * Returns the name of cc.Component.
97 | * @returns {string}
98 | */
99 | getName:function(){
100 | return this._name;
101 | } ,
102 |
103 | /**
104 | * Sets the name to cc.Component.
105 | * @param {String} name
106 | */
107 | setName:function(name){
108 | this._name = name;
109 | } ,
110 |
111 | /**
112 | * Sets the owner to cc.Component.
113 | * @param owner
114 | */
115 | setOwner:function(owner){
116 | this._owner = owner;
117 | },
118 |
119 | /**
120 | * Returns the owner of cc.Component.
121 | * @returns {*}
122 | */
123 | getOwner:function(){
124 | return this._owner;
125 | }
126 | });
127 |
128 | /**
129 | * Allocates and initializes a component.
130 | * @deprecated since v3.0, please use new construction instead.
131 | * @return {cc.Component}
132 | */
133 | cc.Component.create = function(){
134 | return new cc.Component();
135 | };
136 |
137 |
--------------------------------------------------------------------------------
/extensions/cocostudio/timeline/CCSkinNode.js:
--------------------------------------------------------------------------------
1 | ccs.SkinNode = (function () {
2 |
3 | var Node = cc.Node;
4 |
5 | var proto = {};
6 |
7 | var SkinNode = Node.extend(proto);
8 |
9 | SkinNode.create = function () {
10 | };
11 |
12 | return SkinNode;
13 |
14 | })();
15 |
--------------------------------------------------------------------------------
/extensions/cocostudio/trigger/ObjectFactory.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The singleton object that creating object factory, it creates object with class name, and manager the type mapping.
28 | * @class
29 | * @name ccs.objectFactory
30 | */
31 | ccs.objectFactory = /** @lends ccs.objectFactory# */{
32 | _typeMap: {},
33 |
34 | /**
35 | * Creates object with class name. if the the class name without register in type map, it returns null.
36 | * @param {String} className
37 | * @returns {*}
38 | */
39 | createObject: function (className) {
40 | var o = null;
41 | var t = this._typeMap[className];
42 | if (t) {
43 | if(cc.isFunction(t._fun))
44 | o = new t._fun();
45 | else
46 | o = t._fun;
47 | }
48 | return o;
49 | },
50 |
51 | /**
52 | * Registers class type in type map.
53 | * @param {ccs.TInfo} t
54 | */
55 | registerType: function (t) {
56 | this._typeMap[t._className] = t;
57 | },
58 |
59 | /**
60 | * Creates ccui widget object.
61 | * @param {String} name widget name
62 | * @returns {ccui.Widget|null}
63 | */
64 | createGUI: function(name){
65 | var object = null;
66 | if(name === "Panel")
67 | name = "Layout";
68 | else if(name === "TextArea")
69 | name = "Label";
70 | else if(name === "TextButton")
71 | name = "Button";
72 |
73 | var t = this._typeMap[name];
74 | if(t && t._fun)
75 | object = t._fun;
76 |
77 | return object;
78 | },
79 |
80 | removeAll: function(){
81 | this._typeMap = {};
82 | }
83 | };
84 |
85 | ccs.TInfo = ccs.Class.extend({
86 | _className: "",
87 | _fun: null,
88 |
89 | ctor: function (c, f) {
90 | if (f) {
91 | this._className = c;
92 | this._fun = f;
93 | } else {
94 | this._className = c._className;
95 | this._fun = c._fun;
96 | }
97 | ccs.objectFactory.registerType(this);
98 | }
99 | });
100 |
--------------------------------------------------------------------------------
/extensions/cocostudio/trigger/TriggerBase.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * Sends event by trigger manager.
28 | * @function
29 | * @param {Number} event
30 | */
31 | ccs.sendEvent = function (event) {
32 | var triggerObjArr = ccs.triggerManager.get(event);
33 | if (triggerObjArr == null)
34 | return;
35 | for (var i = 0; i < triggerObjArr.length; i++) {
36 | var triObj = triggerObjArr[i];
37 | if (triObj != null && triObj.detect())
38 | triObj.done();
39 | }
40 | };
41 |
42 | /**
43 | * Registers a trigger class to objectFactory type map.
44 | * @param {String} className
45 | * @param {function} func
46 | */
47 | ccs.registerTriggerClass = function (className, func) {
48 | new ccs.TInfo(className, func);
49 | };
--------------------------------------------------------------------------------
/extensions/gui/control-extension/CCInvocation.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * An Invocation class
29 | * @class
30 | * @extends cc.Class
31 | */
32 | cc.Invocation = cc.Class.extend(/** @lends cc.Invocation# */{
33 | _action:null,
34 | _target:null,
35 | _controlEvent:null,
36 |
37 | ctor:function(target,action,controlEvent){
38 | this._target=target;
39 | this._action=action;
40 | this._controlEvent=controlEvent;
41 | },
42 |
43 | getAction:function(){
44 | return this._action;
45 | },
46 |
47 | getTarget:function(){
48 | return this._target ;
49 | },
50 |
51 | getControlEvent:function(){
52 | return this._controlEvent;
53 | },
54 |
55 | invoke:function(sender){
56 | if (this._target && this._action) {
57 | if (cc.isString(this._action)) {
58 | this._target[this._action](sender, this._controlEvent);
59 | } else{
60 | this._action.call(this._target, sender, this._controlEvent);
61 | }
62 | }
63 | }
64 | });
65 |
66 |
--------------------------------------------------------------------------------
/extensions/gui/scrollview/CCScrollViewCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | cc.ScrollView.CanvasRenderCmd = function (renderable) {
27 | this._layerCmdCtor(renderable);
28 | this._needDraw = false;
29 |
30 | this.startCmd = new cc.CustomRenderCmd(this, this._startCmd);
31 | this.startCmd._canUseDirtyRegion = true;
32 | this.endCmd = new cc.CustomRenderCmd(this, this._endCmd);
33 | this.endCmd._canUseDirtyRegion = true;
34 | };
35 |
36 | var proto = cc.ScrollView.CanvasRenderCmd.prototype = Object.create(cc.Layer.CanvasRenderCmd.prototype);
37 | proto.constructor = cc.ScrollView.CanvasRenderCmd;
38 |
39 | proto._startCmd = function (ctx, scaleX, scaleY) {
40 | var node = this._node;
41 | var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
42 | wrapper.save();
43 |
44 | if (node._clippingToBounds) {
45 | this._scissorRestored = false;
46 | wrapper.setTransform(this._worldTransform, scaleX, scaleY);
47 |
48 | var locScaleX = node.getScaleX(), locScaleY = node.getScaleY();
49 |
50 | var getWidth = (node._viewSize.width * locScaleX);
51 | var getHeight = (node._viewSize.height * locScaleY);
52 |
53 | context.beginPath();
54 | context.rect(0, 0, getWidth, -getHeight);
55 | context.closePath();
56 | context.clip();
57 | }
58 | };
59 |
60 | proto._endCmd = function (wrapper) {
61 | wrapper = wrapper || cc._renderContext;
62 | wrapper.restore();
63 | };
64 | })();
65 |
--------------------------------------------------------------------------------
/extensions/gui/scrollview/CCScrollViewWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function () {
26 | cc.ScrollView.WebGLRenderCmd = function (renderable) {
27 | this._layerCmdCtor(renderable);
28 | this._needDraw = false;
29 |
30 | this.startCmd = new cc.CustomRenderCmd(this, this._startCmd);
31 | this.endCmd = new cc.CustomRenderCmd(this, this._endCmd);
32 | };
33 |
34 | var proto = cc.ScrollView.WebGLRenderCmd.prototype = Object.create(cc.Layer.WebGLRenderCmd.prototype);
35 | proto.constructor = cc.ScrollView.WebGLRenderCmd;
36 |
37 | proto._startCmd = function () {
38 | var node = this._node;
39 | var EGLViewer = cc.view;
40 | var frame = node._getViewRect();
41 | if (EGLViewer.isScissorEnabled()) {
42 | node._scissorRestored = true;
43 | node._parentScissorRect = EGLViewer.getScissorRect();
44 | //set the intersection of m_tParentScissorRect and frame as the new scissor rect
45 | if (cc.rectIntersection(frame, node._parentScissorRect)) {
46 | var locPSRect = node._parentScissorRect;
47 | var x = Math.max(frame.x, locPSRect.x);
48 | var y = Math.max(frame.y, locPSRect.y);
49 | var xx = Math.min(frame.x + frame.width, locPSRect.x + locPSRect.width);
50 | var yy = Math.min(frame.y + frame.height, locPSRect.y + locPSRect.height);
51 | EGLViewer.setScissorInPoints(x, y, xx - x, yy - y);
52 | }
53 | } else {
54 | var ctx = cc._renderContext;
55 | ctx.enable(ctx.SCISSOR_TEST);
56 | //clip
57 | EGLViewer.setScissorInPoints(frame.x, frame.y, frame.width, frame.height);
58 | }
59 | };
60 |
61 | proto._endCmd = function () {
62 | var node = this._node;
63 | if (node._scissorRestored) { //restore the parent's scissor rect
64 | var rect = node._parentScissorRect;
65 | cc.view.setScissorInPoints(rect.x, rect.y, rect.width, rect.height);
66 | } else {
67 | var ctx = cc._renderContext;
68 | ctx.disable(ctx.SCISSOR_TEST);
69 | }
70 | };
71 | })();
72 |
--------------------------------------------------------------------------------
/extensions/spine/CCSkeletonTexture.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2017 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | sp.SkeletonTexture = function (image) {
26 | sp.spine.Texture.call(this, image);
27 | };
28 | cc.inherits(sp.SkeletonTexture, sp.spine.Texture);
29 | cc.extend(sp.SkeletonTexture.prototype, {
30 | name: 'sp.SkeletonTexture',
31 | _texture: null,
32 |
33 | setRealTexture: function(tex) {
34 | this._texture = tex;
35 | },
36 |
37 | getRealTexture: function() {
38 | return this._texture;
39 | },
40 |
41 | setFilters: function(minFilter, magFilter) {
42 | if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
43 | var gl = cc._renderContext;
44 | this.bind();
45 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
46 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
47 | }
48 | },
49 |
50 | setWraps: function(uWrap, vWrap) {
51 | if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
52 | var gl = cc._renderContext;
53 | this.bind();
54 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
55 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
56 | }
57 | },
58 |
59 | dispose: function() {
60 | },
61 |
62 | bind: function() {
63 | if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
64 | cc.glBindTexture2D(this._texture);
65 | }
66 | }
67 | });
--------------------------------------------------------------------------------
/extensions/spine/LICENSE:
--------------------------------------------------------------------------------
1 | Spine Runtimes Software License v2.5
2 |
3 | Copyright (c) 2013-2016, Esoteric Software
4 | All rights reserved.
5 |
6 | You are granted a perpetual, non-exclusive, non-sublicensable, and
7 | non-transferable license to use, install, execute, and perform the Spine
8 | Runtimes software and derivative works solely for personal or internal
9 | use. Without the written permission of Esoteric Software (see Section 2 of
10 | the Spine Software License Agreement), you may not (a) modify, translate,
11 | adapt, or develop new applications using the Spine Runtimes or otherwise
12 | create derivative works or improvements of the Spine Runtimes or (b) remove,
13 | delete, alter, or obscure any trademarks or any copyright, trademark, patent,
14 | or other intellectual property or proprietary rights notices on or in the
15 | Software, including any copy thereof. Redistributions in binary or source
16 | form must include this license and terms.
17 |
18 | THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21 | EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
24 | USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/external/gaf/GAFBoot.js:
--------------------------------------------------------------------------------
1 | var gaf = gaf || {};
2 | gaf._tmp = gaf._tmp || {};
3 | gaf._initialized = false;
4 |
5 | gaf.CCGAFLoader = function()
6 | {
7 | this.load = function(realUrl, url, item, cb)
8 | {
9 | if(!gaf._initialized)
10 | {
11 | gaf._setup();
12 | }
13 | var loader = new gaf.Loader();
14 | loader.LoadFile(realUrl, function(data){cb(null, data)});
15 | };
16 | };
17 |
18 | gaf._setup = function()
19 | {
20 | gaf._setupShaders();
21 | gaf._initialized = true;
22 | };
23 |
24 | cc.loader.register('.gaf', new gaf.CCGAFLoader());
25 |
--------------------------------------------------------------------------------
/external/gaf/GAFMacros.js:
--------------------------------------------------------------------------------
1 | var gaf = gaf || {};
2 |
3 | gaf.COMPRESSION_NONE = 0x00474146;
4 | gaf.COMPRESSION_ZIP = 0x00474143;
5 |
6 | gaf.IDNONE = 0xffffffff;
7 | gaf.FIRST_FRAME_INDEX = 0;
8 |
9 | gaf.EFFECT_DROP_SHADOW = 0;
10 | gaf.EFFECT_BLUR = 1;
11 | gaf.EFFECT_GLOW = 2;
12 | gaf.EFFECT_COLOR_MATRIX = 6;
13 |
14 | gaf.ACTION_STOP = 0;
15 | gaf.ACTION_PLAY = 1;
16 | gaf.ACTION_GO_TO_AND_STOP = 2;
17 | gaf.ACTION_GO_TO_AND_PLAY = 3;
18 | gaf.ACTION_DISPATCH_EVENT = 4;
19 |
20 | gaf.PI_FRAME = 0;
21 | gaf.PI_EVENT_TYPE = 0;
22 |
23 | gaf.TYPE_TEXTURE = 0;
24 | gaf.TYPE_TEXT_FIELD = 1;
25 | gaf.TYPE_TIME_LINE = 2;
26 |
27 | gaf.UNIFORM_BLUR_TEXEL_OFFSET = "u_step";
28 | gaf.UNIFORM_GLOW_TEXEL_OFFSET = "u_step";
29 | gaf.UNIFORM_GLOW_COLOR = "u_glowColor";
30 | gaf.UNIFORM_ALPHA_TINT_MULT = "colorTransformMult";
31 | gaf.UNIFORM_ALPHA_TINT_OFFSET = "colorTransformOffsets";
32 | gaf.UNIFORM_ALPHA_COLOR_MATRIX_BODY = "colorMatrix";
33 | gaf.UNIFORM_ALPHA_COLOR_MATRIX_APPENDIX = "colorMatrix2";
34 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFAtlasLoader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by admiral on 19.02.2015.
3 | */
4 |
5 | gaf._AtlasLoader = {};
6 | gaf._AtlasLoader.execute = function(condition, success, fail)
7 | {
8 | condition() ? success() : fail();
9 | };
10 |
11 | gaf._AtlasLoader.checkAtlas = function(atlas) // curried function
12 | {
13 | return function(){return atlas && typeof atlas !== "string" && atlas.isLoaded()};
14 | };
15 |
16 | gaf._AtlasLoader.load = function(path, success, fail)
17 | {
18 | cc.textureCache.addImage(path, function(atlas){
19 | gaf._AtlasLoader.execute(
20 | gaf._AtlasLoader.checkAtlas(atlas),
21 | function(){success(atlas)},
22 | fail
23 | );
24 | });
25 | };
26 |
27 | gaf._AtlasLoader.loadFront = function(arr, success, fail)
28 | {
29 | // Call recursively this function for each element starting from the first
30 | // stops on first success, or fails after last element
31 | return function()
32 | {
33 | if (arr.length > 0){
34 | gaf._AtlasLoader.load(
35 | arr[0],
36 | success,
37 | gaf._AtlasLoader.loadFront(
38 | arr.slice(1),
39 | success,
40 | fail
41 | ));}
42 | else
43 | fail();
44 | }
45 | };
46 |
47 | gaf._AtlasLoader.loadArray = function(array, success, fail)
48 | {
49 | gaf._AtlasLoader.loadFront(array, success, fail)();
50 | };
51 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFLoader.js:
--------------------------------------------------------------------------------
1 | var gaf = gaf || {};
2 |
3 | //@Private class
4 | gaf.Loader = function(){
5 |
6 | var readHeaderBegin = function(stream, header){
7 | header.compression = stream.Uint();
8 | header.versionMajor = stream.Ubyte();
9 | header.versionMinor = stream.Ubyte();
10 | header.fileLength = stream.Uint();
11 | };
12 |
13 | var readHeaderEndV3 = function(stream, header) {
14 | header.framesCount = stream.Ushort();
15 | header.frameSize = stream.Rect();
16 | header.pivot = stream.Point();
17 | };
18 |
19 | var readHeaderEndV4 = function(stream, header){
20 | var scaleCount = stream.Uint();
21 | header.scaleValues = [];
22 | for(var i = 0; i < scaleCount; ++i){
23 | header.scaleValues.push(stream.Float());
24 | }
25 | var csfCount = stream.Uint();
26 | header.csfValues = [];
27 | for(var i = 0; i < csfCount; ++i){
28 | header.csfValues.push(stream.Float());
29 | }
30 | };
31 |
32 | this.LoadFile = function(filePath, onLoaded){
33 | var oReq = new XMLHttpRequest();
34 | oReq.open("GET", filePath, true);
35 | var self = this;
36 | oReq.responseType = "arraybuffer";
37 | oReq.onload = function(oEvent) {
38 | var gaf_data = new gaf.DataReader(oReq.response);
39 | var gafFile = self.LoadStream(gaf_data);
40 | if(onLoaded)
41 | onLoaded(gafFile);
42 | };
43 | oReq.send();
44 | };
45 |
46 | this.LoadStream = function(stream){
47 | var header = {};
48 | readHeaderBegin(stream, header);
49 | if(header.compression == gaf.COMPRESSION_NONE) { // GAF
50 | }
51 | else if(header.compression == gaf.COMPRESSION_ZIP){ // GAC
52 | var compressed = stream.dataRaw.slice(stream.tell());
53 |
54 | var inflate = new window.Zlib.Inflate(new Uint8Array(compressed));
55 | var decompressed = inflate.decompress();
56 | stream = new gaf.DataReader(decompressed.buffer);
57 | }
58 | else{
59 | throw new Error("GAF syntax error.");
60 | }
61 |
62 | if(header.versionMajor < 4){
63 | readHeaderEndV3(stream, header);
64 | }
65 | else{
66 | readHeaderEndV4(stream, header);
67 | }
68 |
69 | var tags = gaf.ReadTags(stream);
70 | return {
71 | header: header,
72 | tags: tags
73 | };
74 | };
75 | };
76 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFMask.js:
--------------------------------------------------------------------------------
1 |
2 | gaf.Mask = gaf.Object.extend
3 | ({
4 | _className: "GAFMask",
5 | _clippingNode: null,
6 |
7 | ctor : function(gafSpriteProto)
8 | {
9 | this._super();
10 | cc.assert(gafSpriteProto, "Error! Missing mandatory parameter.");
11 | this._gafproto = gafSpriteProto;
12 | },
13 |
14 | _init : function()
15 | {
16 | var maskNodeProto = this._gafproto.getMaskNodeProto();
17 | cc.assert(maskNodeProto, "Error. Mask node for id ref " + this._gafproto.getIdRef() + " not found.");
18 | this._maskNode = maskNodeProto._gafConstruct();
19 | this._clippingNode = cc.ClippingNode.create(this._maskNode);
20 | this._clippingNode.setAlphaThreshold(0.5);
21 | this.addChild(this._clippingNode);
22 | },
23 |
24 | setExternalTransform : function(affineTransform)
25 | {
26 | if(!cc.affineTransformEqualToTransform(this._maskNode._additionalTransform, affineTransform))
27 | {
28 | this._maskNode.setAdditionalTransform(affineTransform);
29 | }
30 | },
31 |
32 | _getNode : function()
33 | {
34 | return this._clippingNode;
35 | }
36 | });
--------------------------------------------------------------------------------
/external/gaf/Library/GAFMaskProto.js:
--------------------------------------------------------------------------------
1 |
2 | gaf._MaskProto = function(asset, mask, idRef)
3 | {
4 | this.getIdRef = function(){return idRef};
5 | this.getMaskNodeProto = function() {return mask};
6 |
7 | /*
8 | * Will construct GAFMask
9 | */
10 | this._gafConstruct = function()
11 | {
12 | var ret = new gaf.Mask(this);
13 | ret._init();
14 | return ret;
15 | };
16 | };
17 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFShaderManager.js:
--------------------------------------------------------------------------------
1 |
2 | gaf._glShaderInit = function() {
3 | gaf._Uniforms = {
4 | ColorTransformMult: -1,
5 | ColorTransformOffset: -1,
6 | ColorMatrixBody: -1,
7 | ColorMatrixAppendix: -1,
8 | BlurTexelOffset: -1,
9 | GlowTexelOffset: -1,
10 | GlowColor: -1
11 | };
12 |
13 | gaf._shaderCreate = function (fs, vs) {
14 | var program = new cc.GLProgram();
15 | var result = program.initWithVertexShaderByteArray(vs, fs);
16 | cc.assert(result, "Shader init error");
17 | program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
18 | program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR);
19 | program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
20 | result = program.link();
21 | cc.assert(result, "Shader linking error");
22 | program.updateUniforms();
23 | return program;
24 | };
25 |
26 | gaf._shaderCreateAlpha = function () {
27 | var program = gaf._shaderCreate(gaf.SHADER_COLOR_MATRIX_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT);
28 | gaf._Uniforms.ColorTransformMult = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_MULT);
29 | gaf._Uniforms.ColorTransformOffset = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_OFFSET);
30 | gaf._Uniforms.ColorMatrixBody = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_COLOR_MATRIX_BODY);
31 | gaf._Uniforms.ColorMatrixAppendix = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_COLOR_MATRIX_APPENDIX);
32 | return program;
33 | };
34 |
35 | gaf._shaderCreateBlur = function () {
36 | var program = gaf._shaderCreate(gaf.SHADER_GAUSSIAN_BLUR_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT);
37 | gaf._Uniforms.BlurTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_BLUR_TEXEL_OFFSET);
38 |
39 | return program;
40 | };
41 |
42 | gaf._shaderCreateGlow = function () {
43 | var program = gaf._shaderCreate(gaf.SHADER_GLOW_FRAG, cc.SHADER_POSITION_TEXTURE_COLOR_VERT);
44 | gaf._Uniforms.GlowTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_TEXEL_OFFSET);
45 | gaf._Uniforms.GlowColor = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_COLOR);
46 | return program;
47 | };
48 |
49 | gaf._Shaders = {
50 | Alpha: gaf._shaderCreateAlpha(),
51 | Blur: gaf._shaderCreateBlur(),
52 | Glow: gaf._shaderCreateGlow()
53 | };
54 | };
55 |
56 | gaf._setupShaders = function() {
57 | if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
58 | gaf._glShaderInit();
59 | }
60 | else {
61 | delete gaf._glShaderInit;
62 | }
63 | };
64 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFShaders.js:
--------------------------------------------------------------------------------
1 | gaf.SHADER_GAUSSIAN_BLUR_FRAG =
2 | "varying mediump vec2 v_texCoord;\n"
3 | + "uniform mediump vec2 u_step;\n"
4 | + "void main()\n"
5 | + "{ \n"
6 | + " mediump vec4 sum = vec4(0.0); \n"
7 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 4.0) * 0.05; \n"
8 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 3.0) * 0.09; \n"
9 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 2.0) * 0.12; \n"
10 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 1.0) * 0.15; \n"
11 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 0.0) * 0.18; \n"
12 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 1.0) * 0.15; \n"
13 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 2.0) * 0.12; \n"
14 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 3.0) * 0.09; \n"
15 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 4.0) * 0.05; \n"
16 | + " gl_FragColor = sum; \n"
17 | + "} \n";
18 |
19 | gaf.SHADER_GLOW_FRAG =
20 | "varying mediump vec2 v_texCoord;\n"
21 | + "uniform mediump vec2 u_step;\n"
22 | + "uniform mediump vec4 u_glowColor;\n"
23 | + "void main()\n"
24 | + "{ \n"
25 | + " mediump vec4 sum = vec4(0.0); \n"
26 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 4.0) * 0.05; \n"
27 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 3.0) * 0.09; \n"
28 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 2.0) * 0.12; \n"
29 | + " sum += texture2D(CC_Texture0, v_texCoord - u_step * 1.0) * 0.15; \n"
30 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 0.0) * 0.18; \n"
31 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 1.0) * 0.15; \n"
32 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 2.0) * 0.12; \n"
33 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 3.0) * 0.09; \n"
34 | + " sum += texture2D(CC_Texture0, v_texCoord + u_step * 4.0) * 0.05; \n"
35 | + " gl_FragColor = sum * u_glowColor; \n"
36 | + "} \n";
37 |
38 | gaf.SHADER_COLOR_MATRIX_FRAG =
39 | "varying mediump vec2 v_texCoord;\n"
40 | + "varying mediump vec4 v_fragmentColor;\n"
41 | + "uniform mediump vec4 colorTransformMult;\n"
42 | + "uniform mediump vec4 colorTransformOffsets;\n"
43 | + "uniform mediump mat4 colorMatrix;\n"
44 | + "uniform mediump vec4 colorMatrix2;\n"
45 | + "void main()\n"
46 | + "{ \n"
47 | + " vec4 texColor = texture2D(CC_Texture0, v_texCoord); \n"
48 | + " const float kMinimalAlphaAllowed = 1.0e-8; \n"
49 | + " if (texColor.a > kMinimalAlphaAllowed) \n"
50 | + " { \n"
51 | + " texColor = vec4(texColor.rgb / texColor.a, texColor.a); \n"
52 | + " vec4 ctxColor = texColor * colorTransformMult + colorTransformOffsets; \n"
53 | + " vec4 adjustColor = colorMatrix * ctxColor + colorMatrix2; \n"
54 | + " adjustColor *= v_fragmentColor; \n"
55 | + " texColor = vec4(adjustColor.rgb * adjustColor.a, adjustColor.a); \n"
56 | + " } \n"
57 | + " gl_FragColor = texColor; \n"
58 | + "}\n";
59 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFSprite.js:
--------------------------------------------------------------------------------
1 |
2 | gaf.Sprite = gaf.Object.extend
3 | ({
4 | _className: "GAFSprite",
5 |
6 | _hasCtx: false,
7 | _hasFilter: false,
8 |
9 | ctor : function(gafSpriteProto, usedScale)
10 | {
11 | this._super(usedScale);
12 | cc.assert(gafSpriteProto, "Error! Missing mandatory parameter.");
13 | this._gafproto = gafSpriteProto;
14 | },
15 |
16 | // Private
17 |
18 | _init : function()
19 | {
20 | var frame = this._gafproto.getFrame();
21 | cc.assert(frame instanceof cc.SpriteFrame, "Error. Wrong object type.");
22 |
23 | // Create sprite with custom render command from frame
24 | this._sprite = new cc.Sprite();
25 | this._sprite._renderCmd = this._gafCreateRenderCmd(this._sprite);
26 | this._sprite.initWithSpriteFrame(frame);
27 |
28 | this._sprite.setAnchorPoint(this._gafproto.getAnchor());
29 | this.addChild(this._sprite);
30 | //this._sprite.setCascadeColorEnabled(true);
31 | //this._sprite.setCascadeOpacityEnabled(true);
32 | this._sprite.setOpacityModifyRGB(true);
33 |
34 | if(cc._renderType === cc.game.RENDER_TYPE_WEBGL)
35 | this._sprite.setBlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
36 | },
37 |
38 | _applyState : function(state, parent)
39 | {
40 | this._applyStateSuper(state, parent);
41 | if(this._needsCtx)
42 | {
43 | // Enable ctx state if wasn't enabled
44 | if(!this._hasCtx)
45 | {
46 | this._enableCtx();
47 | this._hasCtx = true;
48 | }
49 | // Set ctx shader
50 | this._applyCtxState(state);
51 | }
52 | else
53 | {
54 | // Disable ctx state if was enabled
55 | if(this._hasCtx)
56 | {
57 | this._disableCtx();
58 | this._hasCtx = false;
59 | }
60 | // Apply color
61 | if(!cc.colorEqual(this._sprite._realColor, this._cascadeColorMult))
62 | {
63 | this._sprite.setColor(this._cascadeColorMult);
64 | }
65 | // Apply opacity
66 | if(this._sprite.getOpacity() != this._cascadeColorMult.a)
67 | {
68 | this._sprite.setOpacity(this._cascadeColorMult.a);
69 | }
70 |
71 | }
72 | },
73 |
74 | _enableCtx: function()
75 | {
76 | this._sprite._renderCmd._enableCtx();
77 | },
78 |
79 | _disableCtx: function()
80 | {
81 | this._sprite._renderCmd._disableCtx();
82 | },
83 |
84 | _applyCtxState: function(state){
85 | this._sprite._renderCmd._applyCtxState(this);
86 | },
87 |
88 | getBoundingBoxForCurrentFrame: function ()
89 | {
90 | var result = this._sprite.getBoundingBox();
91 | return cc._rectApplyAffineTransformIn(result, this.getNodeToParentTransform());
92 | },
93 |
94 | _gafCreateRenderCmd: function(item){
95 | if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
96 | return new gaf.Sprite.CanvasRenderCmd(item);
97 | else
98 | return new gaf.Sprite.WebGLRenderCmd(item);
99 | }
100 | });
101 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFSpriteProto.js:
--------------------------------------------------------------------------------
1 |
2 | gaf._SpriteProto = function(asset, atlasFrames, elementAtlasIdRef)
3 | {
4 | //this._anchor = atlasFrame._gafAnchor;
5 | //delete atlasFrame._gafAnchor;
6 |
7 | this.getFrames = function(){return atlasFrames};
8 | this.getIdRef = function(){return elementAtlasIdRef};
9 | //this.getAnchor = function() {return this._anchor};
10 | this.getAsset = function() {return asset};
11 |
12 | /*
13 | * Will construct GAFSprite
14 | */
15 | this._gafConstruct = function()
16 | {
17 | var usedScale = this.getAsset()._usedAtlasScale;
18 | var ret = new gaf.Sprite(this, usedScale);
19 | ret._init();
20 | return ret;
21 | };
22 | };
23 |
24 | gaf._SpriteProto.prototype.getFrame = function()
25 | {
26 | var usedScale = this.getAsset()._usedAtlasScale;
27 | cc.assert(usedScale, "Error. Atlas scale zero.");
28 | var frames = this.getFrames()[usedScale];
29 | cc.assert(frames, "Error. No frames found for used scale `"+usedScale+"`");
30 | return frames[this.getIdRef()];
31 | };
32 |
33 | gaf._SpriteProto.prototype.getAnchor = function()
34 | {
35 | return this.getFrame()._gafAnchor;
36 | };
37 |
--------------------------------------------------------------------------------
/external/gaf/Library/GAFTextField.js:
--------------------------------------------------------------------------------
1 |
2 | gaf.TextField = gaf.Object.extend
3 | ({
4 | _className: "GAFTextField"
5 |
6 | });
--------------------------------------------------------------------------------
/external/gaf/Library/GAFTimeLineProto.js:
--------------------------------------------------------------------------------
1 |
2 | gaf._TimeLineProto = function(asset, animationFrameCount, boundingBox, pivotPoint, id, linkageName)
3 | {
4 | id = typeof id != 'undefined' ? id : 0;
5 | linkageName = linkageName || "";
6 |
7 | this._objects = [];
8 |
9 | this.getTotalFrames = function(){return animationFrameCount};
10 | this.getBoundingBox = function() {return boundingBox};
11 | this.getId = function() {return id};
12 | this.getLinkageName = function() {return linkageName};
13 | this.getPivot = function(){return pivotPoint};
14 | this.getRect = function(){return boundingBox};
15 | this.getNamedParts = function() {return {}}; // Map name -> id
16 | this.getSequences = function() {return {}}; // Map name -> {start, end}
17 | this.getFrames = function(){return []}; // Array {states, actions}
18 | this.getFps = function(){return 60};
19 | this.getObjects = function(){return this._objects};
20 | this.getAsset = function(){return asset};
21 |
22 | /*
23 | * Will construct GAFTimeLine
24 | */
25 | this._gafConstruct = function()
26 | {
27 | var usedScale = this.getAsset()._usedAtlasScale;
28 | var ret = new gaf.TimeLine(this, usedScale);
29 | ret._init();
30 | return ret;
31 | };
32 | };
33 |
--------------------------------------------------------------------------------
/external/gaf/gaf_viewer.css:
--------------------------------------------------------------------------------
1 | #drop_zone {
2 | border: 2px dashed #bbb;
3 | -moz-border-radius: 5px;
4 | -webkit-border-radius: 5px;
5 | border-radius: 5px;
6 | padding: 25px;
7 | text-align: center;
8 | font: 20pt bold 'Vollkorn';
9 | color: #bbb;
10 |
11 | }
12 | .renderjson a {
13 | text-decoration: none;
14 | }
15 | .renderjson .disclosure {
16 | color: crimson;
17 | font-size: 150%;
18 | }
19 | .renderjson .syntax {
20 | color: grey;
21 | }
22 | .renderjson .string {
23 | color: darkred;
24 | }
25 | .renderjson .number {
26 | color: darkcyan;
27 | }
28 | .renderjson .boolean {
29 | color: blueviolet;
30 | }
31 | .renderjson .key {
32 | color: darkblue;
33 | }
34 | .renderjson .keyword {
35 | color: blue;
36 | }
37 | .renderjson .object.syntax {
38 | color: lightseagreen;
39 | }
40 | .renderjson .array.syntax {
41 | color: orange;
42 | }
43 |
--------------------------------------------------------------------------------
/external/gaf/gaf_viewer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Drop GAF here
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/external/socketio/socket.io.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/external/socketio/socket.io.js
--------------------------------------------------------------------------------
/licenses/LICENSE_cocos2d-html5.txt:
--------------------------------------------------------------------------------
1 | cocos2d-html5 http://www.cocos2d-x.org
2 |
3 | Copyright (c) 2010-2011 - cocos2d-x community
4 | (see each file to see the different copyright owners)
5 |
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
--------------------------------------------------------------------------------
/licenses/LICENSE_cocos2d-x.txt:
--------------------------------------------------------------------------------
1 | cocos2d-x http://www.cocos2d-x.org
2 |
3 | Copyright (c) 2010-2011 - cocos2d-x community
4 | (see each file to see the different copyright owners)
5 |
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
--------------------------------------------------------------------------------
/licenses/LICENSE_zlib.js.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * @license
3 | * zlib.js
4 | * JavaScript Zlib Library
5 | * https://github.com/imaya/zlib.js
6 | *
7 | * The MIT License
8 | *
9 | * Copyright (c) 2012 imaya
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in
19 | * all copies or substantial portions of the Software.
20 | *
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 | * THE SOFTWARE.
28 | */
29 |
--------------------------------------------------------------------------------
/template/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Cocos2d-html5 Hello World test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/template/main.js:
--------------------------------------------------------------------------------
1 | cc.game.onStart = function(){
2 | if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it
3 | document.body.removeChild(document.getElementById("cocosLoading"));
4 |
5 | var designSize = cc.size(480, 800);
6 | var screenSize = cc.view.getFrameSize();
7 |
8 | if(!cc.sys.isNative && screenSize.height < 800){
9 | designSize = cc.size(320, 480);
10 | cc.loader.resPath = "res/Normal";
11 | }else{
12 | cc.loader.resPath = "res/HD";
13 | }
14 | cc.view.setDesignResolutionSize(designSize.width, designSize.height, cc.ResolutionPolicy.SHOW_ALL);
15 |
16 | //load resources
17 | cc.LoaderScene.preload(g_resources, function () {
18 | cc.director.runScene(new MyScene());
19 | }, this);
20 | };
21 | cc.game.run();
--------------------------------------------------------------------------------
/template/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "debugMode" : 1,
3 | "noCache": false,
4 | "showFPS" : true,
5 | "frameRate" : 60,
6 | "id" : "gameCanvas",
7 | "renderMode" : 0,
8 | "engineDir":"../",
9 |
10 | "modules" : ["cocos2d"],
11 |
12 | "jsList" : [
13 | "src/resource.js",
14 | "src/myApp.js"
15 | ]
16 | }
--------------------------------------------------------------------------------
/template/res/HD/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/HD/CloseNormal.png
--------------------------------------------------------------------------------
/template/res/HD/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/HD/CloseSelected.png
--------------------------------------------------------------------------------
/template/res/HD/HelloWorld.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/HD/HelloWorld.jpg
--------------------------------------------------------------------------------
/template/res/Normal/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/Normal/CloseNormal.png
--------------------------------------------------------------------------------
/template/res/Normal/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/Normal/CloseSelected.png
--------------------------------------------------------------------------------
/template/res/Normal/HelloWorld.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/Normal/HelloWorld.jpg
--------------------------------------------------------------------------------
/template/res/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/template/res/favicon.ico
--------------------------------------------------------------------------------
/template/res/loading.js:
--------------------------------------------------------------------------------
1 | (function(){var createStyle=function(){return".cocosLoading{position:absolute;margin:-30px -60px;padding:0;top:50%;left:50%}"+".cocosLoading ul{margin:0;padding:0;}"+".cocosLoading span{color:#FFF;text-align:center;display:block;}"+".cocosLoading li{list-style:none;float:left;border-radius:15px;width:15px;height:15px;background:#FFF;margin:5px 0 0 10px}"+".cocosLoading li .ball,.cocosLoading li .unball{background-color:#2187e7;background-image:-moz-linear-gradient(90deg,#2187e7 25%,#a0eaff);background-image:-webkit-linear-gradient(90deg,#2187e7 25%,#a0eaff);width:15px;height:15px;border-radius:50px}"+".cocosLoading li .ball{transform:scale(0);-moz-transform:scale(0);-webkit-transform:scale(0);animation:showDot 1s linear forwards;-moz-animation:showDot 1s linear forwards;-webkit-animation:showDot 1s linear forwards}"+".cocosLoading li .unball{transform:scale(1);-moz-transform:scale(1);-webkit-transform:scale(1);animation:hideDot 1s linear forwards;-moz-animation:hideDot 1s linear forwards;-webkit-animation:hideDot 1s linear forwards}"+"@keyframes showDot{0%{transform:scale(0,0)}100%{transform:scale(1,1)}}"+"@-moz-keyframes showDot{0%{-moz-transform:scale(0,0)}100%{-moz-transform:scale(1,1)}}"+"@-webkit-keyframes showDot{0%{-webkit-transform:scale(0,0)}100%{-webkit-transform:scale(1,1)}}"+"@keyframes hideDot{0%{transform:scale(1,1)}100%{transform:scale(0,0)}}"+"@-moz-keyframes hideDot{0%{-moz-transform:scale(1,1)}100%{-moz-transform:scale(0,0)}}"+"@-webkit-keyframes hideDot{0%{-webkit-transform:scale(1,1)}100%{-webkit-transform:scale(0,0)}}"};var createDom=function(id,num){id=id||"cocosLoading";num=num||5;var i,item;var div=document.createElement("div");div.className="cocosLoading";div.id=id;var bar=document.createElement("ul");var list=[];for(i=0;i=list.length){direction=!direction;index=0;time=1000}else{time=300}animation()},time)};animation()};(function(){var bgColor=document.body.style.background;document.body.style.background="#000";var style=document.createElement("style");style.type="text/css";style.innerHTML=createStyle();document.head.appendChild(style);var list=createDom();startAnimation(list,function(){var div=document.getElementById("cocosLoading");if(!div){document.body.style.background=bgColor}return !!div})})()})();
--------------------------------------------------------------------------------
/template/src/myApp.js:
--------------------------------------------------------------------------------
1 | var MyLayer = cc.Layer.extend({
2 | helloLabel:null,
3 | sprite:null,
4 |
5 | init:function () {
6 |
7 | //////////////////////////////
8 | // 1. super init first
9 | this._super();
10 |
11 | /////////////////////////////
12 | // 2. add a menu item with "X" image, which is clicked to quit the program
13 | // you may modify it.
14 | // ask director the window size
15 | var size = cc.director.getWinSize();
16 |
17 | // add a "close" icon to exit the progress. it's an autorelease object
18 | var closeItem = new cc.MenuItemImage(
19 | s_CloseNormal,
20 | s_CloseSelected,
21 | function () {
22 | cc.log("close");
23 | },this);
24 | closeItem.setAnchorPoint(0.5, 0.5);
25 |
26 | var menu = new cc.Menu(closeItem);
27 | menu.setPosition(0, 0);
28 | this.addChild(menu, 1);
29 | closeItem.setPosition(size.width - 20, 20);
30 |
31 | /////////////////////////////
32 | // 3. add your codes below...
33 | // add a label shows "Hello World"
34 | // create and initialize a label
35 | this.helloLabel = new cc.LabelTTF("Hello World", "Impact", 38);
36 | // position the label on the center of the screen
37 | this.helloLabel.setPosition(size.width / 2, size.height - 40);
38 | // add the label as a child to this layer
39 | this.addChild(this.helloLabel, 5);
40 |
41 | // add "Helloworld" splash screen"
42 | this.sprite = new cc.Sprite(s_HelloWorld);
43 | this.sprite.setAnchorPoint(0.5, 0.5);
44 | this.sprite.setPosition(size.width / 2, size.height / 2);
45 | this.sprite.setScale(size.height / this.sprite.getContentSize().height);
46 | this.addChild(this.sprite, 0);
47 | }
48 | });
49 |
50 | var MyScene = cc.Scene.extend({
51 | onEnter:function () {
52 | this._super();
53 | var layer = new MyLayer();
54 | this.addChild(layer);
55 | layer.init();
56 | }
57 | });
58 |
--------------------------------------------------------------------------------
/template/src/resource.js:
--------------------------------------------------------------------------------
1 | var s_HelloWorld = "HelloWorld.jpg";
2 | var s_CloseNormal = "CloseNormal.png";
3 | var s_CloseSelected = "CloseSelected.png";
4 |
5 | var g_resources = [
6 | //image
7 | s_HelloWorld,
8 | s_CloseNormal,
9 | s_CloseSelected
10 |
11 | //plist
12 |
13 | //fnt
14 |
15 | //tmx
16 |
17 | //bgm
18 |
19 | //effect
20 | ];
--------------------------------------------------------------------------------
/tools/compiler/compiler.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cocos2d/cocos2d-html5/c0324ad511b7e327a597d9a0d27e5a7d9f4fbc07/tools/compiler/compiler.jar
--------------------------------------------------------------------------------
/tools/genBuildXml.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Put the `tools` in the root of your project, then run this script with nodejs.
3 | * @type {exports|*}
4 | */
5 |
6 | var fs = require("fs");
7 | var path = require("path");
8 |
9 |
10 | module.exports = function(projectDir, projectJson, buildOpt){
11 | var engineDir = projectJson.engineDir || "frameworks/cocos2d-html5";
12 | var realEngineDir = path.join(projectDir, engineDir);
13 | var realPublishDir = path.join(projectDir, "publish/html5");
14 | var realToolsDir = path.dirname(__filename);
15 | var moduleConfig = require(path.join(realEngineDir, "moduleConfig.json"));
16 | var ccModuleMap = moduleConfig.module;
17 | var modules = projectJson.modules || ["core"];
18 | var renderMode = projectJson.renderMode || 0;
19 | var mainJs = projectJson.main || "main.js";
20 |
21 |
22 | var ccJsList = [moduleConfig.bootFile];
23 | var userJsList = projectJson.jsList || [];
24 |
25 | if(renderMode != 1 && modules.indexOf("base4webgl") < 0){
26 | modules.splice(0, 0, "base4webgl");
27 | }
28 |
29 |
30 | //cache for js and module that has added into jsList to be loaded.
31 | var _jsAddedCache = {};
32 | function _getJsListOfModule(moduleMap, moduleName){
33 | var jsAddedCache = _jsAddedCache;
34 | if(jsAddedCache[moduleName]) return null;
35 | jsAddedCache[moduleName] = true;
36 | var jsList = [];
37 | var tempList = moduleMap[moduleName];
38 | if(!tempList) throw new Error("can not find module [" + moduleName + "]");
39 | for(var i = 0, li = tempList.length; i < li; i++){
40 | var item = tempList[i];
41 | if(jsAddedCache[item]) continue;
42 | var extname = path.extname(item);
43 | if(!extname) {
44 | var arr = _getJsListOfModule(moduleMap, item);
45 | if(arr) jsList = jsList.concat(arr);
46 | }else if(extname.toLowerCase() == ".js") jsList.push(item);
47 | jsAddedCache[item] = true;
48 | }
49 | return jsList;
50 | };
51 |
52 |
53 |
54 | for(var i = 0, li = modules.length; i < li; i++){
55 | var item = modules[i];
56 | var arr = _getJsListOfModule(ccModuleMap, item, "");
57 | if(arr) ccJsList = ccJsList.concat(arr);
58 | }
59 |
60 | var externalList = [];
61 | function getFileArrStr(jsList){
62 | var str = "";
63 | for(var i = 0, li = jsList.length; i < li; i++){
64 | if(/^external/.test(jsList[i]) && !/Plugin/.test(jsList[i])){
65 | externalList.push(jsList[i]);
66 | }else{
67 | str += ' ';
68 | if(i < li - 1) str += '\r\n';
69 | }
70 | }
71 | return str;
72 | }
73 |
74 | userJsList.push(mainJs);
75 |
76 | var buildContent = fs.readFileSync(path.join(realToolsDir, "template/build.xml")).toString();
77 | buildContent = buildContent.replace(/%projectDir%/gi, projectDir);
78 | buildContent = buildContent.replace(/%engineDir%/gi, realEngineDir);
79 | buildContent = buildContent.replace(/%publishDir%/gi, realPublishDir);
80 | buildContent = buildContent.replace(/%outputFileName%/gi, buildOpt.outputFileName);
81 | buildContent = buildContent.replace(/%toolsDir%/gi, realToolsDir);
82 | buildContent = buildContent.replace(/%compilationLevel%/gi, buildOpt.compilationLevel);
83 | buildContent = buildContent.replace(/%sourceMapCfg%/gi, buildOpt.sourceMapOpened ? 'sourceMapOutputFile="' + path.join(realPublishDir, "sourcemap") + '" sourceMapFormat="V3"' : "");
84 | buildContent = buildContent.replace(/%ccJsList%/gi, getFileArrStr(ccJsList));
85 | buildContent = buildContent.replace(/%userJsList%/gi, getFileArrStr(userJsList));
86 | fs.writeFileSync(path.join(realPublishDir, "build.xml"), buildContent);
87 |
88 | return externalList;
89 | };
90 |
--------------------------------------------------------------------------------
/tools/publish.js:
--------------------------------------------------------------------------------
1 | var exec = require("child_process").exec;
2 | var fs = require("fs");
3 | var path = require("path");
4 | var core4cc = require("./core4cc");
5 | console.log("Publishing...");
6 |
7 | var projectDir = path.join(__dirname, "../");
8 |
9 | var projectJson = require(path.join(projectDir, "project.json"));
10 | var engineDir = path.join(projectJson.engineDir || "frameworks/cocos2d-html5", "/");
11 | var realEngineDir = path.join(projectDir, engineDir, "/");
12 |
13 | var realPublishDir = path.join(projectDir, "publish/html5");
14 |
15 | var buildOpt = {
16 | outputFileName : "game.min.js",
17 | // compilationLevel : "simple",
18 | compilationLevel : "advanced",
19 | sourceMapOpened : true
20 | };
21 |
22 | if(!fs.existsSync(realPublishDir)) core4cc.mkdirSyncRecursive(realPublishDir);
23 |
24 | var externalList = require("./genBuildXml")(projectDir, projectJson, buildOpt);
25 |
26 | var outputJsPath = path.join(realPublishDir, buildOpt.outputFileName);
27 | if(fs.existsSync(outputJsPath)) fs.unlinkSync(outputJsPath);
28 |
29 | exec("cd " + realPublishDir + " && ant", function(err, data, info){
30 | console.log(info);
31 | console.log(data);
32 | if(err) {
33 | console.error(err);
34 | console.log(err[0]);
35 | return console.log("Failed!")
36 | }
37 | var sourceMapPath = path.join(realPublishDir, "sourcemap");
38 | if(fs.existsSync(sourceMapPath)){
39 | var smContent = fs.readFileSync(sourceMapPath).toString();
40 | smContent = smContent.replace(new RegExp(path.join(projectDir, "/").replace(/\\/g, "\\\\\\\\") , "gi"), path.join(path.relative(realPublishDir, projectDir), "/"));
41 | smContent = smContent.replace(new RegExp(path.join(realEngineDir, "/").replace(/\\/g, "\\\\\\\\"), "gi"), path.join(path.relative(realPublishDir, realEngineDir), "/"));
42 | fs.writeFileSync(sourceMapPath, smContent);
43 | }
44 |
45 | delete projectJson.engineDir;
46 | delete projectJson.modules;
47 | delete projectJson.jsList;
48 | fs.writeFileSync(path.join(realPublishDir, "project.json"), JSON.stringify(projectJson, null, 4));
49 |
50 | var publishResDir = path.join(realPublishDir, "res");
51 | core4cc.rmdirSyncRecursive(publishResDir);
52 | core4cc.copyFiles(path.join(projectDir, "res"), publishResDir);
53 |
54 | var indexContent = fs.readFileSync(path.join(projectDir, "index.html")).toString();
55 | var externalScript = "";
56 | externalList.forEach(function(external){
57 | externalScript += "\n";
58 | });
59 | indexContent = indexContent.replace(/";
68 | });
69 | indexContent += externalScript;
70 | fs.writeFileSync(path.join(realPublishDir, "index.html"), indexContent);
71 | console.log("Finished!")
72 | });
--------------------------------------------------------------------------------
/tools/readme for tools.txt:
--------------------------------------------------------------------------------
1 | Compiler:
2 |
3 | Default compiler is Google closure compiler. Please install Ant and Jre to build.
4 | The shell files and Closure Compiler which Ant needs are provided in tools folder and cocos2d folder.
5 |
6 | Reference wiki: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Closure_Compiler
7 | For more on Google closure: https://developers.google.com/closure/compiler
8 |
9 |
--------------------------------------------------------------------------------