mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge remote-tracking branch 'fireball/master' into optimize-bmfont-load-speed
This commit is contained in:
@@ -20,6 +20,8 @@ if (CC_DEBUG) {
|
||||
"1016": "cc.RotateTo.reverse(): it should be overridden in subclass.", //RotateTo.reverse
|
||||
"1017": "cc.GridAction.getGrid(): it should be overridden in subclass.", //ActionGrid.getGrid
|
||||
"1018": "Grid size must be (1,1)", //ActionGrid3D.initWithSize
|
||||
"1019": "Failed to construct, Sequence construction needs two or more actions", //ActionInterval.sequence
|
||||
"1020": "Failed to construct, Spawn construction needs two or more actions", //ActionInterval.spawn
|
||||
//configuration: 1100
|
||||
"1100": "Expected 'data' dict, but not found. Config file: %s", //loadConfigFile
|
||||
"1101": "Please load the resource first : %s", //loadConfigFile_2
|
||||
|
||||
@@ -313,6 +313,10 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
this._actions = [];
|
||||
|
||||
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
|
||||
if (paramArray.length === 1) {
|
||||
cc.errorID(1019);
|
||||
return;
|
||||
}
|
||||
var last = paramArray.length - 1;
|
||||
if ((last >= 0) && (paramArray[last] == null))
|
||||
cc.logID(1015);
|
||||
@@ -444,6 +448,10 @@ cc.Sequence = cc.ActionInterval.extend({
|
||||
// todo: It should be use new
|
||||
cc.sequence = function (/*Multiple Arguments*/tempArray) {
|
||||
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
|
||||
if (paramArray.length === 1) {
|
||||
cc.errorID(1019);
|
||||
return null;
|
||||
}
|
||||
var last = paramArray.length - 1;
|
||||
if ((last >= 0) && (paramArray[last] == null))
|
||||
cc.logID(1015);
|
||||
@@ -731,6 +739,10 @@ cc.Spawn = cc.ActionInterval.extend({
|
||||
this._two = null;
|
||||
|
||||
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
|
||||
if (paramArray.length === 1) {
|
||||
cc.errorID(1020);
|
||||
return;
|
||||
}
|
||||
var last = paramArray.length - 1;
|
||||
if ((last >= 0) && (paramArray[last] == null))
|
||||
cc.logID(1015);
|
||||
@@ -825,6 +837,10 @@ cc.Spawn = cc.ActionInterval.extend({
|
||||
*/
|
||||
cc.spawn = function (/*Multiple Arguments*/tempArray) {
|
||||
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
|
||||
if (paramArray.length === 1) {
|
||||
cc.errorID(1020);
|
||||
return null;
|
||||
}
|
||||
if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null))
|
||||
cc.logID(1015);
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
You can choose between MIT and BSD-3-Clause license. License file will be added later.
|
||||
--*/
|
||||
|
||||
var Misc = require('../core/utils/misc');
|
||||
var strValue = Misc.BASE64_VALUES;
|
||||
|
||||
/**
|
||||
* mixin cc.Codec.Base64
|
||||
*/
|
||||
var Base64 = {name:'Jacob__Codec__Base64'};
|
||||
|
||||
Base64._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* cc.Codec.Base64.decode(input[, unicode=false]) -> String (http://en.wikipedia.org/wiki/Base64).
|
||||
@@ -31,10 +32,10 @@ Base64.decode = function Jacob__Codec__Base64__decode(input) {
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
while (i < input.length) {
|
||||
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc1 = strValue[input.charCodeAt(i++)];
|
||||
enc2 = strValue[input.charCodeAt(i++)];
|
||||
enc3 = strValue[input.charCodeAt(i++)];
|
||||
enc4 = strValue[input.charCodeAt(i++)];
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
|
||||
+10
-10
@@ -252,11 +252,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* @return {Vec2}
|
||||
*/
|
||||
convertToGL: function (uiPoint) {
|
||||
var docElem = document.documentElement;
|
||||
var container = cc.game.container;
|
||||
var view = cc.view;
|
||||
var box = docElem.getBoundingClientRect();
|
||||
var left = box.left + window.pageXOffset - docElem.clientLeft;
|
||||
var top = box.top + window.pageYOffset - docElem.clientTop;
|
||||
var box = container.getBoundingClientRect();
|
||||
var left = box.left + window.pageXOffset - container.clientLeft;
|
||||
var top = box.top + window.pageYOffset - container.clientTop;
|
||||
var x = view._devicePixelRatio * (uiPoint.x - left);
|
||||
var y = view._devicePixelRatio * (top + box.height - uiPoint.y);
|
||||
return view._isRotated ? {x: view._viewPortRect.width - y, y: x} : {x: x, y: y};
|
||||
@@ -273,19 +273,19 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* @return {Vec2}
|
||||
*/
|
||||
convertToUI: function (glPoint) {
|
||||
var docElem = document.documentElement;
|
||||
var container = cc.game.container;
|
||||
var view = cc.view;
|
||||
var box = docElem.getBoundingClientRect();
|
||||
var left = box.left + window.pageXOffset - docElem.clientLeft;
|
||||
var top = box.top + window.pageYOffset - docElem.clientTop;
|
||||
var box = container.getBoundingClientRect();
|
||||
var left = box.left + window.pageXOffset - container.clientLeft;
|
||||
var top = box.top + window.pageYOffset - container.clientTop;
|
||||
var uiPoint = {x: 0, y: 0};
|
||||
if (view._isRotated) {
|
||||
uiPoint.x = left + glPoint.y / view._devicePixelRatio;
|
||||
uiPoint.y = top + box.height - (view._viewPortRect.width - glPoint.x) / view._devicePixelRatio;
|
||||
}
|
||||
else {
|
||||
uiPoint.x = left + glPoint.x / view._devicePixelRatio;
|
||||
uiPoint.y = top + box.height - glPoint.y / view._devicePixelRatio;
|
||||
uiPoint.x = left + glPoint.x * view._devicePixelRatio;
|
||||
uiPoint.y = top + box.height - glPoint.y * view._devicePixelRatio;
|
||||
}
|
||||
return uiPoint;
|
||||
},
|
||||
|
||||
@@ -1306,7 +1306,7 @@ var Node = cc.Class({
|
||||
var rect = cc.rect(0, 0, w, h);
|
||||
|
||||
var trans;
|
||||
if (cc.Camera.main) {
|
||||
if (cc.Camera && cc.Camera.main) {
|
||||
trans = cc.Camera.main.getNodeToCameraTransform(this);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -60,7 +60,7 @@ cc.Asset = cc.Class({
|
||||
get: function () {
|
||||
if (this._rawFiles) {
|
||||
if (cc.AssetLibrary) {
|
||||
return cc.AssetLibrary.getImportedDir(this._uuid) + '/' + this._uuid + '/' + this._rawFiles[0];
|
||||
return cc.AssetLibrary.getImportedDir(this._uuid) + '/' + this._rawFiles[0];
|
||||
}
|
||||
else {
|
||||
cc.errorID(6400);
|
||||
@@ -84,7 +84,7 @@ cc.Asset = cc.Class({
|
||||
get: function () {
|
||||
if (this._rawFiles) {
|
||||
if (cc.AssetLibrary) {
|
||||
var dir = cc.AssetLibrary.getImportedDir(this._uuid) + '/' + this._uuid + '/';
|
||||
var dir = cc.AssetLibrary.getImportedDir(this._uuid) + '/';
|
||||
return this._rawFiles.map(function (filename) {
|
||||
return dir + filename;
|
||||
});
|
||||
|
||||
@@ -279,11 +279,12 @@ _ccsg.Node.RenderCmd.prototype = {
|
||||
this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.DirtyDouble);
|
||||
}
|
||||
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
|
||||
var Camera = cc.Camera;
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL && Camera) {
|
||||
// check if node is in camera
|
||||
var camera = cc.Camera.main;
|
||||
if (parentCmd && this._cameraFlag != cc.Camera.flags.InCamera) {
|
||||
this._cameraFlag = parentCmd._cameraFlag > 0 ? cc.Camera.flags.ParentInCamera : 0;
|
||||
var camera = Camera.main;
|
||||
if (parentCmd && this._cameraFlag != Camera.flags.InCamera) {
|
||||
this._cameraFlag = parentCmd._cameraFlag > 0 ? Camera.flags.ParentInCamera : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var transformDirtyFlag;
|
||||
|
||||
if (!CC_JSB) {
|
||||
transformDirtyFlag = _ccsg.Node._dirtyFlags.transformDirty;
|
||||
require('./CCSGCameraNode');
|
||||
}
|
||||
|
||||
@@ -45,6 +48,8 @@ let Camera = cc.Class({
|
||||
this.viewMatrix = cc.affineTransformMake();
|
||||
this.invertViewMatrix = cc.affineTransformMake();
|
||||
|
||||
this._lastViewMatrix = cc.affineTransformMake();
|
||||
|
||||
this._sgTarges = [];
|
||||
|
||||
this.visibleRect = {
|
||||
@@ -123,7 +128,7 @@ let Camera = cc.Class({
|
||||
|
||||
if (!CC_JSB) {
|
||||
var cmd = sgNode._renderCmd;
|
||||
cmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
cmd.setDirtyFlag(transformDirtyFlag);
|
||||
cmd._cameraFlag = Camera.flags.InCamera;
|
||||
|
||||
cc.renderer.childrenOrderDirty = true;
|
||||
@@ -146,7 +151,7 @@ let Camera = cc.Class({
|
||||
|
||||
if (!CC_JSB) {
|
||||
var cmd = sgNode._renderCmd;
|
||||
cmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
|
||||
cmd.setDirtyFlag(transformDirtyFlag);
|
||||
cmd._cameraFlag = 0;
|
||||
|
||||
cc.renderer.childrenOrderDirty = true;
|
||||
@@ -281,6 +286,18 @@ let Camera = cc.Class({
|
||||
return false;
|
||||
},
|
||||
|
||||
_setSgNodesTransformDirty: function () {
|
||||
let sgTarges = this._sgTarges;
|
||||
for (let i = 0; i < sgTarges.length; i++) {
|
||||
if (CC_JSB) {
|
||||
sgTarges[i].markTransformUpdated();
|
||||
}
|
||||
else {
|
||||
sgTarges[i]._renderCmd.setDirtyFlag(transformDirtyFlag);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
lateUpdate: !CC_EDITOR && function () {
|
||||
let m = this.viewMatrix;
|
||||
let im = this.invertViewMatrix;
|
||||
@@ -335,6 +352,25 @@ let Camera = cc.Class({
|
||||
selfVisibleRect.top.y = viewPort.yMax;
|
||||
|
||||
this._sgNode.setTransform(a, b, c, d, m.tx, m.ty);
|
||||
|
||||
// if view transform changed, then need recalculate whether targets need culling
|
||||
var lvm = this._lastViewMatrix;
|
||||
if (lvm.a !== m.a ||
|
||||
lvm.b !== m.b ||
|
||||
lvm.c !== m.c ||
|
||||
lvm.d !== m.d ||
|
||||
lvm.tx !== m.tx ||
|
||||
lvm.ty !== m.ty
|
||||
) {
|
||||
this._setSgNodesTransformDirty();
|
||||
|
||||
lvm.a = m.a;
|
||||
lvm.b = m.b;
|
||||
lvm.c = m.c;
|
||||
lvm.d = m.d;
|
||||
lvm.tx = m.tx;
|
||||
lvm.ty = m.ty;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -531,19 +531,19 @@ var Label = cc.Class({
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string, JSON.stringify(font._fntConfig), font.spriteFrame);
|
||||
} else {
|
||||
cc.warnID(4012, font.name);
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string);
|
||||
sgNode = this._sgNode = _ccsg.Label.pool.get(this.string);
|
||||
}
|
||||
} else {
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string, "", font.spriteFrame, font);
|
||||
sgNode = this._sgNode = _ccsg.Label.pool.get(this.string, "", font.spriteFrame, font);
|
||||
}
|
||||
} else {
|
||||
cc.warnID(4011, font.name);
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string);
|
||||
sgNode = this._sgNode = _ccsg.Label.pool.get(this.string);
|
||||
}
|
||||
} else {
|
||||
var isAsset = font instanceof cc.Font;
|
||||
var ttfName = isAsset ? font.rawUrl : '';
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string, ttfName);
|
||||
sgNode = this._sgNode = _ccsg.Label.pool.get(this.string, ttfName);
|
||||
}
|
||||
|
||||
if (CC_JSB) {
|
||||
@@ -592,6 +592,15 @@ var Label = cc.Class({
|
||||
this.node.setContentSize(this._sgNode.getContentSize());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy: function () {
|
||||
var sgNode = this._sgNode;
|
||||
//FIXME:: call order matters
|
||||
this._super();
|
||||
if (sgNode) {
|
||||
_ccsg.Label.pool.put(sgNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ var RichText = cc.Class({
|
||||
},
|
||||
|
||||
_createFontLabel: function (string) {
|
||||
return new _ccsg.Label(string, this._getFontRawUrl());
|
||||
return _ccsg.Label.pool.get(string, this._getFontRawUrl());
|
||||
},
|
||||
|
||||
_getFontRawUrl: function() {
|
||||
@@ -427,7 +427,6 @@ var RichText = cc.Class({
|
||||
|
||||
this._addLabelSegment(labelString, styleIndex);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_isLastComponentCR: function(stringToken) {
|
||||
@@ -764,8 +763,16 @@ var RichText = cc.Class({
|
||||
label._clickHandler = textStyle.event.click;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy: function () {
|
||||
this._super();
|
||||
|
||||
for (var i = 0; i < this._labelSegments.length; ++i) {
|
||||
_ccsg.Label.pool.put(this._labelSegments[i]);
|
||||
}
|
||||
this._resetState();
|
||||
}
|
||||
});
|
||||
|
||||
cc.RichText = module.exports = RichText;
|
||||
|
||||
@@ -853,14 +853,14 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
|
||||
proto._createLabels = function () {
|
||||
var editBoxSize = this._editBox.getContentSize();
|
||||
if(!this._textLabel) {
|
||||
this._textLabel = new _ccsg.Label();
|
||||
this._textLabel = _ccsg.Label.pool.get();
|
||||
this._textLabel.setAnchorPoint(cc.p(0, 1));
|
||||
this._textLabel.setOverflow(_ccsg.Label.Overflow.CLAMP);
|
||||
this._editBox.addChild(this._textLabel, 100);
|
||||
}
|
||||
|
||||
if(!this._placeholderLabel) {
|
||||
this._placeholderLabel = new _ccsg.Label();
|
||||
this._placeholderLabel = _ccsg.Label.pool.get();
|
||||
this._placeholderLabel.setAnchorPoint(cc.p(0, 1));
|
||||
this._placeholderLabel.setColor(cc.Color.GRAY);
|
||||
this._editBox.addChild(this._placeholderLabel, 100);
|
||||
|
||||
@@ -330,7 +330,13 @@ var EventTouch = function (touchArr, bubbles) {
|
||||
cc.Event.call(this, cc.Event.TOUCH, bubbles);
|
||||
this._eventCode = 0;
|
||||
this._touches = touchArr || [];
|
||||
this.currentTouch = null;
|
||||
/**
|
||||
* !#en The current touch object
|
||||
* !#zh 当前触点对象
|
||||
* @property touch
|
||||
* @type {Touch}
|
||||
*/
|
||||
this.touch = null;
|
||||
};
|
||||
|
||||
JS.extend(EventTouch, cc.Event);
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Shader = require('./shader');
|
||||
|
||||
var LineCap = require('./types').LineCap;
|
||||
var LineJoin = require('./types').LineJoin;
|
||||
|
||||
@@ -38,8 +36,10 @@ var Js = cc.js;
|
||||
// Math
|
||||
var INIT_VERTS_SIZE = 32;
|
||||
|
||||
var VERTS_FLOAT_LENGTH = 2;
|
||||
var VERTS_BYTE_LENGTH = 8;
|
||||
var VERTS_FLOAT_LENGTH = 3;
|
||||
var VERTS_BYTE_LENGTH = 12;
|
||||
|
||||
var MAX_BUFFER_SIZE = 65535;
|
||||
|
||||
var PI = Math.PI;
|
||||
var min = Math.min;
|
||||
@@ -102,6 +102,81 @@ Path.prototype.reset = function () {
|
||||
}
|
||||
};
|
||||
|
||||
// GraphicsBuffer
|
||||
function GraphicsBuffer () {
|
||||
this.vertsOffset = 0;
|
||||
this.vertsVBO = gl.createBuffer();
|
||||
this.vertsBuffer = null;
|
||||
this.uint32VertsBuffer = null;
|
||||
this.vertsDirty = false;
|
||||
|
||||
this.indicesOffset = 0;
|
||||
this.indicesVBO = gl.createBuffer();
|
||||
this.indicesBuffer = null;
|
||||
this.indicesDirty = false;
|
||||
}
|
||||
|
||||
GraphicsBuffer.prototype.clear = function () {
|
||||
this.vertsOffset = 0;
|
||||
this.indicesOffset = 0;
|
||||
}
|
||||
|
||||
GraphicsBuffer.prototype.alloc = function (cverts, cindices) {
|
||||
var dnverts = this.vertsOffset + cverts;
|
||||
if (dnverts > MAX_BUFFER_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var verts = this.vertsBuffer;
|
||||
var nverts = verts ? verts.length / VERTS_FLOAT_LENGTH : 0;
|
||||
|
||||
if (dnverts > nverts) {
|
||||
if (nverts === 0) {
|
||||
nverts = INIT_VERTS_SIZE;
|
||||
}
|
||||
|
||||
while (dnverts > nverts) {
|
||||
nverts *= 2;
|
||||
}
|
||||
|
||||
var newBuffer = new Float32Array(nverts * VERTS_FLOAT_LENGTH);
|
||||
|
||||
if (verts) {
|
||||
for (var i = 0, l = verts.length; i < l; i++) {
|
||||
newBuffer[i] = verts[i];
|
||||
}
|
||||
}
|
||||
|
||||
this.vertsBuffer = newBuffer;
|
||||
this.uint32VertsBuffer = new Uint32Array(this.vertsBuffer.buffer);
|
||||
}
|
||||
|
||||
var indices = this.indicesBuffer;
|
||||
var dnindices = this.indicesOffset + cindices;
|
||||
var nindices = indices ? indices.length : 0;
|
||||
|
||||
if (dnindices > nindices) {
|
||||
if (nindices === 0) {
|
||||
nindices = INIT_VERTS_SIZE * 3;
|
||||
}
|
||||
|
||||
while (dnindices > nindices) {
|
||||
nindices *= 2;
|
||||
}
|
||||
|
||||
var newIndices = new Uint16Array(nindices);
|
||||
|
||||
if (indices) {
|
||||
for (var i = 0, l = indices.length; i < l; i++) {
|
||||
newIndices[i] = indices[i];
|
||||
}
|
||||
}
|
||||
this.indicesBuffer = newIndices;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// webgl render command
|
||||
function WebGLRenderCmd (renderable) {
|
||||
this._rootCtor(renderable);
|
||||
@@ -109,15 +184,9 @@ function WebGLRenderCmd (renderable) {
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
this._vertsOffset = 0;
|
||||
this._vertsVBO = gl.createBuffer();
|
||||
this._vertsBuffer = null;
|
||||
this._vertsDirty = false;
|
||||
|
||||
this._indicesOffset = 0;
|
||||
this._indicesVBO = gl.createBuffer();
|
||||
this._indicesBuffer = null;
|
||||
this._indicesDirty = false;
|
||||
this._buffers = [];
|
||||
this._buffer = null;
|
||||
this._allocBuffer();
|
||||
|
||||
this._matrix = new cc.math.Matrix4();
|
||||
this._matrix.identity();
|
||||
@@ -125,17 +194,20 @@ function WebGLRenderCmd (renderable) {
|
||||
this._paths = [];
|
||||
this._points = [];
|
||||
|
||||
this._cmds = [];
|
||||
this._curColorValue = 0;
|
||||
|
||||
this._blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
|
||||
|
||||
// init shader
|
||||
this._shader = new cc.GLProgram();
|
||||
this._shader.initWithVertexShaderByteArray(Shader.vert, Shader.frag);
|
||||
this._shader.retain();
|
||||
this._shader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.link();
|
||||
this._shader.updateUniforms();
|
||||
var shader = new cc.GLProgram();
|
||||
shader.initWithVertexShaderByteArray(cc.PresetShaders.POSITION_COLOR_VERT, cc.PresetShaders.POSITION_COLOR_FRAG);
|
||||
shader.retain();
|
||||
shader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
|
||||
shader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
|
||||
shader.link();
|
||||
shader.updateUniforms();
|
||||
|
||||
this._shaderProgram = shader;
|
||||
|
||||
this._allocVerts(INIT_VERTS_SIZE);
|
||||
}
|
||||
@@ -244,18 +316,22 @@ _p.close = function () {
|
||||
_p.stroke = function () {
|
||||
this._flattenPaths();
|
||||
|
||||
var color = this._strokeColor;
|
||||
this._curColorValue = ((color.a<<24) >>> 0) + (color.b<<16) + (color.g<<8) + color.r;
|
||||
|
||||
this._expandStroke();
|
||||
|
||||
this._vertsDirty = true;
|
||||
this._updatePathOffset = true;
|
||||
};
|
||||
|
||||
_p.fill = function () {
|
||||
// this._flattenPaths();
|
||||
|
||||
var color = this._fillColor;
|
||||
this._curColorValue = ((color.a<<24) >>> 0) + (color.b<<16) + (color.g<<8) + color.r;
|
||||
|
||||
this._expandFill();
|
||||
|
||||
this._vertsDirty = true;
|
||||
this._updatePathOffset = true;
|
||||
this._filling = false;
|
||||
};
|
||||
@@ -303,46 +379,36 @@ Js.getset(_p, 'strokeColor', _p.getStrokeColor, _p.setStrokeColor);
|
||||
Js.getset(_p, 'fillColor', _p.getFillColor, _p.setFillColor);
|
||||
|
||||
_p._render = function () {
|
||||
var vertsBuffer = this._vertsBuffer;
|
||||
if (!vertsBuffer || vertsBuffer.length === 0 || this._cmds.length === 0) return;
|
||||
let buffers = this._buffers;
|
||||
if (buffers.length === 0) return;
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertsVBO);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesVBO);
|
||||
|
||||
if (this._vertsDirty) {
|
||||
gl.bufferData(gl.ARRAY_BUFFER, vertsBuffer, gl.STREAM_DRAW);
|
||||
this._vertsDirty = false;
|
||||
}
|
||||
|
||||
if (this._indicesDirty && this._indicesBuffer) {
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer, gl.STREAM_DRAW);
|
||||
this._indicesDirty = false;
|
||||
}
|
||||
|
||||
if (this._vertsOffset > 65536) {
|
||||
cc.warnID(2401);
|
||||
}
|
||||
|
||||
gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_POSITION);
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, VERTS_BYTE_LENGTH, 0);
|
||||
|
||||
var shader = this._shader;
|
||||
var colorLocation = shader.getUniformLocationForName('color');
|
||||
let gl = cc._renderContext;
|
||||
|
||||
// draw paths
|
||||
var cmds = this._cmds;
|
||||
for (var i = 0, l = cmds.length; i < l; i++) {
|
||||
var cmd = cmds[i];
|
||||
for (let i = 0, l = buffers.length; i < l; i++) {
|
||||
let buffer = buffers[i];
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.vertsVBO);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer.indicesVBO);
|
||||
|
||||
if (cmd.nIndices) {
|
||||
var color = cmd.color;
|
||||
gl.uniform4f(colorLocation, color.r / 255, color.g / 255, color.b / 255, color.a / 255);
|
||||
gl.drawElements(gl.TRIANGLES, cmd.nIndices, gl.UNSIGNED_SHORT, cmd.indicesOffset * 2);
|
||||
|
||||
cc.incrementGLDraws(cmd.nverts);
|
||||
if (buffer.vertsDirty) {
|
||||
gl.bufferData(gl.ARRAY_BUFFER, buffer.vertsBuffer, gl.STREAM_DRAW);
|
||||
buffer.vertsDirty = false;
|
||||
}
|
||||
|
||||
if (buffer.indicesDirty && buffer.indicesBuffer) {
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, buffer.indicesBuffer, gl.STREAM_DRAW);
|
||||
buffer.indicesDirty = false;
|
||||
}
|
||||
|
||||
gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_POSITION);
|
||||
gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_COLOR);
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, VERTS_BYTE_LENGTH, 0);
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, VERTS_BYTE_LENGTH, 8);
|
||||
|
||||
gl.drawElements(gl.TRIANGLES, buffer.indicesOffset, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
cc.g_NumberOfDraws++;
|
||||
}
|
||||
|
||||
cc.checkGLErrorDebug();
|
||||
@@ -351,7 +417,7 @@ _p._render = function () {
|
||||
_p.rendering = function () {
|
||||
cc.gl.blendFunc(this._blendFunc.src, this._blendFunc.dst);
|
||||
|
||||
var wt = this._worldTransform, mat = this._matrix.mat;
|
||||
let wt = this._worldTransform, mat = this._matrix.mat;
|
||||
mat[0] = wt.a;
|
||||
mat[4] = wt.c;
|
||||
mat[12] = wt.tx;
|
||||
@@ -359,7 +425,7 @@ _p.rendering = function () {
|
||||
mat[5] = wt.d;
|
||||
mat[13] = wt.ty;
|
||||
|
||||
var shader = this._shader;
|
||||
let shader = this._shaderProgram;
|
||||
shader.use();
|
||||
shader._setUniformForMVPMatrixWithMat4(this._matrix);
|
||||
|
||||
@@ -368,23 +434,26 @@ _p.rendering = function () {
|
||||
|
||||
// clear
|
||||
_p.clear = function (clean) {
|
||||
this._vertsOffset = 0;
|
||||
this._indicesOffset = 0;
|
||||
|
||||
this._pathLength = 0;
|
||||
this._pathOffset = 0;
|
||||
this._pointsOffset = 0;
|
||||
|
||||
this._curPath = null;
|
||||
|
||||
this._cmds.length = 0;
|
||||
|
||||
if (clean) {
|
||||
this._paths.length = 0;
|
||||
this._points.length = 0;
|
||||
|
||||
this._vertsBuffer = null;
|
||||
this._indicesBuffer = null;
|
||||
this._buffer = null;
|
||||
this._buffers = [];
|
||||
}
|
||||
else {
|
||||
var buffers = this._buffers;
|
||||
for(var i = 0; i < buffers.length; i++) {
|
||||
buffers[i].clear();
|
||||
}
|
||||
|
||||
this._buffer = buffers[0];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -473,80 +542,31 @@ _p._flattenPaths = function () {
|
||||
}
|
||||
};
|
||||
|
||||
_p._allocBuffer = function () {
|
||||
if (this._buffer) {
|
||||
var index = this._buffers.indexOf(this._buffer);
|
||||
if (index < (this._buffers.length - 1)) {
|
||||
this._buffer = this._buffers[index + 1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var buffer = new GraphicsBuffer();
|
||||
this._buffers.push(buffer);
|
||||
this._buffer = buffer;
|
||||
};
|
||||
|
||||
_p._allocVerts = function (cverts) {
|
||||
var dnverts = this._vertsOffset + cverts;
|
||||
var buffer = this._vertsBuffer;
|
||||
var nverts = buffer ? buffer.length / VERTS_FLOAT_LENGTH : 0;
|
||||
|
||||
if (dnverts > nverts) {
|
||||
if (nverts === 0) {
|
||||
nverts = INIT_VERTS_SIZE;
|
||||
}
|
||||
|
||||
while (dnverts > nverts) {
|
||||
nverts *= 2;
|
||||
}
|
||||
|
||||
var newBuffer = new Float32Array(nverts * VERTS_FLOAT_LENGTH);
|
||||
|
||||
if (buffer) {
|
||||
for (var i = 0, l = buffer.length; i < l; i++) {
|
||||
newBuffer[i] = buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
this._vertsBuffer = newBuffer;
|
||||
if (!this._buffer) {
|
||||
this._allocBuffer();
|
||||
}
|
||||
};
|
||||
|
||||
_p._allocIndices = function (cindices) {
|
||||
var indices = this._indicesBuffer;
|
||||
var dnindices = this._indicesOffset + cindices;
|
||||
var nindices = indices ? indices.length : 0;
|
||||
|
||||
if (dnindices > nindices) {
|
||||
if (nindices === 0) {
|
||||
nindices = INIT_VERTS_SIZE * 3;
|
||||
}
|
||||
|
||||
while (dnindices > nindices) {
|
||||
nindices *= 2;
|
||||
}
|
||||
|
||||
var newIndices = new Uint16Array(nindices);
|
||||
|
||||
if (indices) {
|
||||
for (var i = 0, l = indices.length; i < l; i++) {
|
||||
newIndices[i] = indices[i];
|
||||
}
|
||||
}
|
||||
this._indicesBuffer = newIndices;
|
||||
}
|
||||
};
|
||||
|
||||
_p._pushCmd = function (cmd) {
|
||||
var cmds = this._cmds;
|
||||
var lastCmd = cmds[cmds.length - 1];
|
||||
|
||||
if (lastCmd) {
|
||||
var lastColor = lastCmd.color;
|
||||
var color = cmd.color;
|
||||
|
||||
if (lastColor.r === color.r &&
|
||||
lastColor.g === color.g &&
|
||||
lastColor.b === color.b &&
|
||||
lastColor.a === color.a &&
|
||||
(lastCmd.indicesOffset + lastCmd.nIndices === cmd.indicesOffset)) {
|
||||
lastCmd.nIndices += cmd.nIndices;
|
||||
lastCmd.nverts += cmd.nverts;
|
||||
}
|
||||
else {
|
||||
cmds.push(cmd);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cmds.push(cmd);
|
||||
var nIndices = (cverts - 2*(this._pathLength-this._pathOffset)) * 3;
|
||||
if (!this._buffer.alloc(cverts, nIndices)) {
|
||||
this._allocBuffer();
|
||||
this._buffer.alloc(cverts, nIndices);
|
||||
}
|
||||
this._buffer.vertsDirty = true;
|
||||
};
|
||||
|
||||
_p._expandStroke = function () {
|
||||
@@ -580,8 +600,8 @@ _p._expandStroke = function () {
|
||||
}
|
||||
|
||||
this._allocVerts(cverts);
|
||||
this._allocIndices((cverts - 2*(this._pathLength-this._pathOffset)) * 3);
|
||||
|
||||
var buffer = this._buffer;
|
||||
for (var i = this._pathOffset, l = this._pathLength; i < l; i++) {
|
||||
var path = paths[i];
|
||||
var pts = path.points;
|
||||
@@ -591,7 +611,7 @@ _p._expandStroke = function () {
|
||||
var s, e, loop;
|
||||
|
||||
loop = path.closed;
|
||||
var offset = this._vertsOffset;
|
||||
var offset = buffer.vertsOffset;
|
||||
|
||||
if (loop) {
|
||||
// Looping
|
||||
@@ -640,11 +660,11 @@ _p._expandStroke = function () {
|
||||
}
|
||||
|
||||
if (loop) {
|
||||
var v0 = this._vget(offset);
|
||||
var v1 = this._vget(offset + 1);
|
||||
let vertsBuffer = buffer.vertsBuffer;
|
||||
|
||||
// Loop it
|
||||
this._vset(v0.x, v0.y);
|
||||
this._vset(v1.x, v1.y);
|
||||
this._vset(vertsBuffer[offset*VERTS_FLOAT_LENGTH], vertsBuffer[offset*VERTS_FLOAT_LENGTH+1]);
|
||||
this._vset(vertsBuffer[(offset+1)*VERTS_FLOAT_LENGTH], vertsBuffer[(offset+1)*VERTS_FLOAT_LENGTH+1]);
|
||||
} else {
|
||||
// Add cap
|
||||
var dPos = p1.sub(p0);
|
||||
@@ -662,25 +682,17 @@ _p._expandStroke = function () {
|
||||
}
|
||||
|
||||
// stroke indices
|
||||
var indicesOffset = this._indicesOffset;
|
||||
var indicesBuffer = this._indicesBuffer;
|
||||
var indicesOffset = buffer.indicesOffset;
|
||||
var indicesBuffer = buffer.indicesBuffer;
|
||||
|
||||
for (var start = offset+2, end = this._vertsOffset; start < end; start++) {
|
||||
for (var start = offset+2, end = buffer.vertsOffset; start < end; start++) {
|
||||
indicesBuffer[indicesOffset++] = start - 2;
|
||||
indicesBuffer[indicesOffset++] = start - 1;
|
||||
indicesBuffer[indicesOffset++] = start;
|
||||
}
|
||||
|
||||
this._pushCmd({
|
||||
color: this._strokeColor,
|
||||
indicesOffset: this._indicesOffset,
|
||||
nIndices: indicesOffset - this._indicesOffset,
|
||||
vertsOffset: offset,
|
||||
nverts: this._vertsOffset - offset
|
||||
});
|
||||
|
||||
this._indicesOffset = indicesOffset;
|
||||
this._indicesDirty = true;
|
||||
buffer.indicesOffset = indicesOffset;
|
||||
buffer.indicesDirty = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -699,8 +711,8 @@ _p._expandFill = function () {
|
||||
}
|
||||
|
||||
this._allocVerts(cverts);
|
||||
this._allocIndices((cverts - 2*(this._pathLength-this._pathOffset)) * 3);
|
||||
|
||||
var buffer = this._buffer;
|
||||
for (var i = this._pathOffset, l = this._pathLength; i < l; i++) {
|
||||
var path = paths[i];
|
||||
var pts = path.points;
|
||||
@@ -711,18 +723,24 @@ _p._expandFill = function () {
|
||||
}
|
||||
|
||||
// Calculate shape vertices.
|
||||
var offset = this._vertsOffset;
|
||||
var offset = buffer.vertsOffset;
|
||||
|
||||
for (var j = 0; j < pointsLength; ++j) {
|
||||
this._vset(pts[j].x, pts[j].y, 0.5, 1);
|
||||
}
|
||||
|
||||
var indicesOffset = path.indicesOffset = this._indicesOffset;
|
||||
var indicesBuffer = this._indicesBuffer;
|
||||
var indicesOffset = path.indicesOffset = buffer.indicesOffset;
|
||||
var indicesBuffer = buffer.indicesBuffer;
|
||||
var nIndices = 0;
|
||||
|
||||
if (path.complex) {
|
||||
var data = new Float32Array(this._vertsBuffer.buffer, offset * 8, (this._vertsOffset - offset) * 2);
|
||||
var data = [];
|
||||
var start = offset*VERTS_FLOAT_LENGTH, end = buffer.vertsOffset*VERTS_FLOAT_LENGTH;
|
||||
for (var i = start; i < end; i+=VERTS_FLOAT_LENGTH) {
|
||||
data.push(buffer.vertsBuffer[i]);
|
||||
data.push(buffer.vertsBuffer[i+1]);
|
||||
}
|
||||
|
||||
var newIndices = Earcut(data, null, 2);
|
||||
|
||||
if (!newIndices || newIndices.length === 0) {
|
||||
@@ -737,25 +755,17 @@ _p._expandFill = function () {
|
||||
}
|
||||
else {
|
||||
var first = offset;
|
||||
for (var start = offset+2, end = this._vertsOffset; start < end; start++) {
|
||||
for (var start = offset+2, end = buffer.vertsOffset; start < end; start++) {
|
||||
indicesBuffer[indicesOffset++] = first;
|
||||
indicesBuffer[indicesOffset++] = start - 1;
|
||||
indicesBuffer[indicesOffset++] = start;
|
||||
}
|
||||
|
||||
nIndices = indicesOffset - this._indicesOffset;
|
||||
nIndices = indicesOffset - buffer.indicesOffset;
|
||||
}
|
||||
|
||||
this._pushCmd({
|
||||
color: this._fillColor,
|
||||
indicesOffset: this._indicesOffset,
|
||||
nIndices: nIndices,
|
||||
vertsOffset: offset,
|
||||
nverts: this._vertsOffset - offset
|
||||
});
|
||||
|
||||
this._indicesOffset += nIndices;
|
||||
this._indicesDirty = true;
|
||||
buffer.indicesOffset += nIndices;
|
||||
buffer.indicesDirty = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -838,24 +848,18 @@ _p._calculateJoins = function (w, lineJoin, miterLimit) {
|
||||
};
|
||||
|
||||
_p._vset = function (x, y) {
|
||||
var offset = this._vertsOffset * VERTS_FLOAT_LENGTH;
|
||||
var buffer = this._vertsBuffer;
|
||||
let buffer = this._buffer;
|
||||
let offset = buffer.vertsOffset * VERTS_FLOAT_LENGTH;
|
||||
let vertsBuffer = buffer.vertsBuffer;
|
||||
|
||||
buffer[offset] = x;
|
||||
buffer[offset + 1] = y;
|
||||
vertsBuffer[offset] = x;
|
||||
vertsBuffer[offset + 1] = y;
|
||||
|
||||
this._vertsOffset++;
|
||||
buffer.uint32VertsBuffer[offset + 2] = this._curColorValue;
|
||||
|
||||
buffer.vertsOffset++;
|
||||
};
|
||||
|
||||
_p._vget = function (index) {
|
||||
var buffer = this._vertsBuffer;
|
||||
var offset = index * VERTS_FLOAT_LENGTH;
|
||||
return {
|
||||
x: buffer[offset],
|
||||
y: buffer[offset + 1]
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
_p._chooseBevel = function (bevel, p0, p1, w) {
|
||||
var x = p1.x;
|
||||
|
||||
@@ -317,9 +317,10 @@ var Graphics = cc.Class({
|
||||
* !#en Erasing any previously drawn content.
|
||||
* !#zh 擦除之前绘制的所有内容的方法。
|
||||
* @method clear
|
||||
* @param {Boolean} [clean] Whether to clean the graphics inner cache.
|
||||
*/
|
||||
clear: function () {
|
||||
this._sgNode.clear();
|
||||
clear: function (clean) {
|
||||
this._sgNode.clear(clean);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
****************************************************************************/
|
||||
require('./CCTextUtils.js');
|
||||
var EventTarget = require("../event/event-target");
|
||||
var JS = require("../platform/js");
|
||||
|
||||
|
||||
var FontLetterDefinition = function() {
|
||||
@@ -155,33 +156,41 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
this._string = string;
|
||||
|
||||
_ccsg.Node.prototype.ctor.call(this);
|
||||
this.setAnchorPoint(cc.p(0.5, 0.5));
|
||||
_ccsg.Node.prototype.setContentSize.call(this, cc.size(128, 128));
|
||||
this.setAnchorPoint(0.5, 0.5);
|
||||
_ccsg.Node.prototype.setContentSize.call(this, 128, 128);
|
||||
this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
|
||||
|
||||
this._imageOffset = cc.p(0, 0);
|
||||
this._numberOfLines = 0;
|
||||
this._lettersInfo = [];
|
||||
this._linesWidth = [];
|
||||
this._linesOffsetX = [];
|
||||
this._horizontalKernings = [];
|
||||
this._reusedRect = cc.rect(0, 0, 0, 0);
|
||||
|
||||
this.setFontFileOrFamily(fontHandle, spriteFrame, fontAsset);
|
||||
this.setString(this._string);
|
||||
},
|
||||
|
||||
_resetBMFont: function() {
|
||||
this._imageOffset = cc.p(0, 0);
|
||||
this._imageOffset.x = this._imageOffset.y = 0;
|
||||
this._cascadeColorEnabled = true;
|
||||
this._cascadeOpacityEnabled = true;
|
||||
this._fontAtlas = null;
|
||||
this._config = null;
|
||||
this._numberOfLines = 0;
|
||||
this._lettersInfo = [];
|
||||
this._linesWidth = [];
|
||||
this._linesOffsetX = [];
|
||||
this._lettersInfo.length = 0;
|
||||
this._linesWidth.length = 0;
|
||||
this._linesOffsetX.length = 0;
|
||||
this._textDesiredHeight = 0;
|
||||
this._letterOffsetY = 0;
|
||||
this._tailoredTopY = 0;
|
||||
this._tailoredBottomY = 0;
|
||||
this._bmfontScale = 1.0;
|
||||
this._horizontalKernings = [];
|
||||
this._horizontalKernings.length = 0;
|
||||
this._lineBreakWithoutSpaces = false;
|
||||
|
||||
this._reusedRect = cc.rect(0, 0, 0, 0);
|
||||
this._reusedRect.x = this._reusedRect.y = this._reusedRect.width = this._reusedRect.height = 0;
|
||||
this._textureLoaded = false;
|
||||
|
||||
if (this._spriteBatchNode) {
|
||||
@@ -580,7 +589,7 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
}
|
||||
return _ccsg.Node.prototype._getHeight.call(this);
|
||||
},
|
||||
_alignText: function() {
|
||||
_alignText: function() {
|
||||
var ret = true;
|
||||
|
||||
do {
|
||||
@@ -1237,6 +1246,60 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
}
|
||||
});
|
||||
|
||||
_ccsg.Label.pool = new JS.Pool(function (label) {
|
||||
if (!(label instanceof _ccsg.Label)) {
|
||||
return false;
|
||||
}
|
||||
label._string = "";
|
||||
label._fontAsset = null;
|
||||
label._fontHandle = "";
|
||||
label._labelType = 0;
|
||||
label._resetBMFont();
|
||||
label._renderCmd._labelCanvas.width = 1;
|
||||
label._renderCmd._labelCanvas.height = 1;
|
||||
label.removeFromParent(true);
|
||||
// label._parent = null;
|
||||
label._updateLabel();
|
||||
return true;
|
||||
}, 20);
|
||||
|
||||
_ccsg.Label.pool.get = function (string, fontHandle, spriteFrame, fontAsset) {
|
||||
var label = this._get();
|
||||
if (label) {
|
||||
fontHandle = fontHandle || "";
|
||||
label._fontHandle = fontHandle;
|
||||
if (typeof string !== 'string') {
|
||||
string = '' + string;
|
||||
}
|
||||
label._string = string;
|
||||
|
||||
label._position.x = 0;
|
||||
label._position.y = 0;
|
||||
label.setAnchorPoint(0.5, 0.5);
|
||||
_ccsg.Node.prototype.setContentSize.call(label, 128, 128);
|
||||
|
||||
label.setFontFileOrFamily(fontHandle, spriteFrame, fontAsset);
|
||||
label.setString(string);
|
||||
label.setHorizontalAlign(cc.TextAlignment.LEFT);
|
||||
label.setVerticalAlign(cc.VerticalTextAlignment.TOP);
|
||||
label.setFontSize(40);
|
||||
label.setOverflow(0);
|
||||
label.enableWrapText(true);
|
||||
label.setVisible(true);
|
||||
label.setLineHeight(40);
|
||||
label.setOutlined(false);
|
||||
label.enableBold(false);
|
||||
label.enableItalics(false);
|
||||
label.enableUnderline(false);
|
||||
label.setBlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
return label;
|
||||
}
|
||||
else {
|
||||
return new _ccsg.Label(string, fontHandle, spriteFrame, fontAsset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var _p = _ccsg.Label.prototype;
|
||||
cc.js.addon(_p, EventTarget.prototype);
|
||||
|
||||
@@ -59,8 +59,6 @@ function getResWithUrl (res) {
|
||||
id = res;
|
||||
}
|
||||
isUuid = result.type ? result.type === 'uuid' : cc.AssetLibrary._getAssetUrl(id);
|
||||
_info.url = null;
|
||||
_info.raw = false;
|
||||
cc.AssetLibrary._getAssetInfoInRuntime(id, _info);
|
||||
result.url = !isUuid ? id : _info.url;
|
||||
if (_info.url && result.type === 'uuid' && _info.raw) {
|
||||
@@ -261,10 +259,6 @@ proto.load = function(resources, progressCallback, completeCallback) {
|
||||
};
|
||||
|
||||
proto.flowInDeps = function (owner, urlList, callback) {
|
||||
if (owner && !owner.deps) {
|
||||
owner.deps = [];
|
||||
}
|
||||
|
||||
_sharedList.length = 0;
|
||||
for (var i = 0; i < urlList.length; ++i) {
|
||||
var res = getResWithUrl(urlList[i]);
|
||||
@@ -273,8 +267,6 @@ proto.flowInDeps = function (owner, urlList, callback) {
|
||||
var item = this.getItem(res.url);
|
||||
if (item) {
|
||||
_sharedList.push(item);
|
||||
// Collect deps to avoid circle reference
|
||||
owner && owner.deps.push(item);
|
||||
}
|
||||
else {
|
||||
_sharedList.push(res);
|
||||
@@ -289,7 +281,7 @@ proto.flowInDeps = function (owner, urlList, callback) {
|
||||
callback(errors, items);
|
||||
// Clear deps because it's already done
|
||||
// Each item will only flowInDeps once, so it's still safe here
|
||||
owner && (owner.deps.length = 0);
|
||||
owner && owner.deps && (owner.deps.length = 0);
|
||||
items.destroy();
|
||||
});
|
||||
if (owner) {
|
||||
@@ -338,8 +330,6 @@ proto._getReferenceKey = function (assetOrUrlOrUuid) {
|
||||
cc.warnID(4800, assetOrUrlOrUuid);
|
||||
return key;
|
||||
}
|
||||
_info.url = null;
|
||||
_info.raw = false;
|
||||
cc.AssetLibrary._getAssetInfoInRuntime(key, _info);
|
||||
return this._cache[_info.url] ? _info.url : key;
|
||||
};
|
||||
|
||||
@@ -413,7 +413,7 @@ LoadingItems.initQueueDeps = function (queue) {
|
||||
}
|
||||
};
|
||||
|
||||
LoadingItems.registerDep = function (owner, depId) {
|
||||
LoadingItems.registerQueueDep = function (owner, depId) {
|
||||
var queueId = owner.queueId || owner;
|
||||
if (!queueId) {
|
||||
return false;
|
||||
@@ -463,6 +463,9 @@ proto.append = function (urlList, owner) {
|
||||
if (!this.active) {
|
||||
return [];
|
||||
}
|
||||
if (owner && !owner.deps) {
|
||||
owner.deps = [];
|
||||
}
|
||||
|
||||
this._appending = true;
|
||||
var accepted = [], i, url, item;
|
||||
@@ -472,6 +475,8 @@ proto.append = function (urlList, owner) {
|
||||
// Already queued in another items queue, url is actually the item
|
||||
if (url.queueId && !this.map[url.id]) {
|
||||
this.map[url.id] = url;
|
||||
// Register item deps for circle reference check
|
||||
owner && owner.deps.push(url);
|
||||
// Queued and completed or Owner circle referenced by dependency
|
||||
if (url.complete || checkCircleReference(owner, url)) {
|
||||
this.totalCount++;
|
||||
@@ -485,7 +490,7 @@ proto.append = function (urlList, owner) {
|
||||
var queue = _queues[url.queueId];
|
||||
if (queue) {
|
||||
this.totalCount++;
|
||||
LoadingItems.registerDep(owner || this._id, url.id);
|
||||
LoadingItems.registerQueueDep(owner || this._id, url.id);
|
||||
// console.log('+++++ Waited ' + url.id);
|
||||
queue.addListener(url.id, function (item) {
|
||||
// console.log('----- Completed by waiting ' + item.id + ', rest: ' + (self.totalCount - self.completedCount-1));
|
||||
@@ -503,7 +508,9 @@ proto.append = function (urlList, owner) {
|
||||
if (!this.map[key]) {
|
||||
this.map[key] = item;
|
||||
this.totalCount++;
|
||||
LoadingItems.registerDep(owner || this._id, key);
|
||||
// Register item deps for circle reference check
|
||||
owner && owner.deps.push(item);
|
||||
LoadingItems.registerQueueDep(owner || this._id, key);
|
||||
accepted.push(item);
|
||||
// console.log('+++++ Appended ' + item.id);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ module.exports = {
|
||||
|
||||
_loadNewPack: function (uuid, packUuid, callback) {
|
||||
var self = this;
|
||||
var packUrl = cc.AssetLibrary.getImportedDir(packUuid) + '/' + packUuid + '.json';
|
||||
var packUrl = cc.AssetLibrary.getImportedDir(packUuid) + '.json';
|
||||
cc.loader.load({ url: packUrl, ignoreMaxConcurrency: true }, function (err, packJson) {
|
||||
if (err) {
|
||||
cc.errorID(4916, uuid);
|
||||
|
||||
@@ -137,7 +137,7 @@ var RigidBody = cc.Class({
|
||||
* 碰撞回调。
|
||||
* 如果你的脚本中实现了这个函数,那么它将会在接触更新完后被调用。
|
||||
* 你可以在这个回调中从接触信息中获取到冲量信息。
|
||||
* @method onEndSolve
|
||||
* @method onPostSolve
|
||||
* @param {PhysicsContact} contact - contact information
|
||||
* @param {PhysicsCollider} selfCollider - the collider belong to this rigidbody
|
||||
* @param {PhysicsCollider} otherCollider - the collider belong to another rigidbody
|
||||
|
||||
@@ -222,7 +222,7 @@ var MouseJoint = cc.Class({
|
||||
var manager = cc.director.getPhysicsManager();
|
||||
var target = this._pressPoint = event.touch.getLocation();
|
||||
|
||||
if (cc.Camera.main) {
|
||||
if (cc.Camera && cc.Camera.main) {
|
||||
target = cc.Camera.main.getCameraToWorldPoint(target);
|
||||
}
|
||||
|
||||
@@ -259,9 +259,16 @@ var MouseJoint = cc.Class({
|
||||
},
|
||||
|
||||
update: function () {
|
||||
if (cc.Camera.main && this._pressPoint) {
|
||||
if (!this._pressPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc.Camera && cc.Camera.main) {
|
||||
this.target = cc.Camera.main.getCameraToWorldPoint(this._pressPoint);
|
||||
}
|
||||
else {
|
||||
this.target = this._pressPoint;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ var callInNextTick = require('./utils').callInNextTick;
|
||||
var Loader = require('../load-pipeline/CCLoader');
|
||||
var PackDownloader = require('../load-pipeline/pack-downloader');
|
||||
var AutoReleaseUtils = require('../load-pipeline/auto-release-utils');
|
||||
var decodeUuid = require('../utils/decode-uuid');
|
||||
|
||||
/**
|
||||
* The asset library which managing loading/unloading assets in project.
|
||||
@@ -111,7 +112,10 @@ var AssetLibrary = {
|
||||
},
|
||||
|
||||
getImportedDir: function (uuid) {
|
||||
return _libraryBase + uuid.slice(0, 2)/* + cc.path.sep + uuid*/;
|
||||
if (CC_BUILD) {
|
||||
uuid = decodeUuid(uuid);
|
||||
}
|
||||
return _libraryBase + uuid.slice(0, 2) + '/' + uuid;
|
||||
},
|
||||
|
||||
_queryAssetInfoInEditor: function (uuid, callback) {
|
||||
@@ -138,16 +142,15 @@ var AssetLibrary = {
|
||||
},
|
||||
|
||||
_getAssetInfoInRuntime: function (uuid, result) {
|
||||
if (!result) {
|
||||
result = {url: null, raw: false};
|
||||
}
|
||||
result = result || {url: null, raw: false};
|
||||
var info = _uuidToRawAsset[uuid];
|
||||
if (info && !cc.isChildClassOf(info.type, cc.Asset)) {
|
||||
result.url = _rawAssetsBase + info.url;
|
||||
result.raw = true;
|
||||
}
|
||||
else {
|
||||
result.url = this.getImportedDir(uuid) + '/' + uuid + '.json';
|
||||
result.url = this.getImportedDir(uuid) + '.json';
|
||||
result.raw = false;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
@@ -742,8 +742,8 @@ function declareProperties (cls, className, properties, baseClass, mixins, es6)
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en Defines a CCClass using the given specification, please see [Class](/docs/editors_and_tools/creator-chapters/scripting/class-es5/) for details.
|
||||
* !#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/docs/creator/scripting/class-es5/)。
|
||||
* !#en Defines a CCClass using the given specification, please see [Class](/docs/editors_and_tools/creator-chapters/scripting/class.html) for details.
|
||||
* !#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/docs/creator/scripting/class.html)。
|
||||
*
|
||||
* @method Class
|
||||
*
|
||||
|
||||
@@ -574,7 +574,7 @@ cc.js.unregisterClass to remove the id of unused class';
|
||||
* @param {Boolean} [writable=false]
|
||||
*/
|
||||
js.obsolete = function (obj, obsoleted, newPropName, writable) {
|
||||
var oldName = obsoleted.split('.').slice(-1);
|
||||
var oldName = obsoleted.split('.').slice(-1)[0];
|
||||
function get () {
|
||||
if (CC_DEV) {
|
||||
cc.warnID(5400, obsoleted, newPropName);
|
||||
@@ -688,7 +688,7 @@ js.shiftArguments = function () {
|
||||
var len = arguments.length - 1;
|
||||
var args = new Array(len);
|
||||
for(var i = 0; i < len; ++i) {
|
||||
args[i] = arguments[i + i];
|
||||
args[i] = arguments[i + 1];
|
||||
}
|
||||
return args;
|
||||
};
|
||||
@@ -988,6 +988,20 @@ Pool.prototype.put = function (obj) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en Resize the pool.
|
||||
* !#zh 设置对象池容量。
|
||||
* @method resize
|
||||
*/
|
||||
Pool.prototype.resize = function (length) {
|
||||
if (length >= 0) {
|
||||
this._pool.length = length;
|
||||
if (this.count > length) {
|
||||
this.count = length;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
js.Pool = Pool;
|
||||
|
||||
//
|
||||
|
||||
@@ -492,6 +492,9 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
else {
|
||||
uuid = Editor.Utils.UuidCache.urlToUuid(url);
|
||||
}
|
||||
if (exporting) {
|
||||
uuid = Editor.Utils.UuidUtils.compressUuid(uuid, true);
|
||||
}
|
||||
}
|
||||
var capInsets;
|
||||
if (this.insetLeft !== 0 ||
|
||||
|
||||
@@ -22,29 +22,32 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var vert = [
|
||||
'attribute vec4 a_position;',
|
||||
'',
|
||||
'void main()',
|
||||
'{',
|
||||
'gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;',
|
||||
'}'
|
||||
];
|
||||
|
||||
var frag = [
|
||||
'#ifdef GL_ES',
|
||||
'precision mediump float;',
|
||||
'#endif',
|
||||
'',
|
||||
'uniform vec4 color;',
|
||||
'',
|
||||
'void main(void) {',
|
||||
'gl_FragColor = color;',
|
||||
'}'
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
vert: vert.join(' \n'),
|
||||
frag: frag.join(' \n')
|
||||
var Base64Values = require('./misc').BASE64_VALUES;
|
||||
|
||||
var HexChars = '0123456789abcdef'.split('');
|
||||
|
||||
var _t = ['', '', '', ''];
|
||||
var UuidTemplate = _t.concat(_t, '-', _t, '-', _t, '-', _t, '-', _t, _t, _t);
|
||||
var Indices = UuidTemplate.map(function (x, i) { return x === '-' ? NaN : i; }).filter(isFinite);
|
||||
|
||||
// fcmR3XADNLgJ1ByKhqcC5Z -> fc991dd7-0033-4b80-9d41-c8a86a702e59
|
||||
module.exports = function (base64) {
|
||||
if (base64.length !== 22) {
|
||||
return base64;
|
||||
}
|
||||
UuidTemplate[0] = base64[0];
|
||||
UuidTemplate[1] = base64[1];
|
||||
for (var i = 2, j = 2; i < 22; i += 2) {
|
||||
var lhs = Base64Values[base64.charCodeAt(i)];
|
||||
var rhs = Base64Values[base64.charCodeAt(i + 1)];
|
||||
UuidTemplate[Indices[j++]] = HexChars[lhs >> 2];
|
||||
UuidTemplate[Indices[j++]] = HexChars[((lhs & 3) << 2) | rhs >> 4];
|
||||
UuidTemplate[Indices[j++]] = HexChars[rhs & 0xF];
|
||||
}
|
||||
return UuidTemplate.join('');
|
||||
};
|
||||
|
||||
if (CC_TEST) {
|
||||
cc._Test.decodeUuid = module.exports;
|
||||
}
|
||||
@@ -128,3 +128,11 @@ misc.isBuiltinClassId = function (id) {
|
||||
return id.startsWith('cc.') || id.startsWith('dragonBones.') || id.startsWith('sp.') || id.startsWith('ccsg.');
|
||||
};
|
||||
|
||||
|
||||
var BASE64_KEYS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
var BASE64_VALUES = new Array(123); // max char code in base64Keys
|
||||
for (let i = 0; i < 123; ++i) BASE64_VALUES[i] = 64; // fill with placeholder('=') index
|
||||
for (let i = 0; i < 64; ++i) BASE64_VALUES[BASE64_KEYS.charCodeAt(i)] = i;
|
||||
|
||||
// decoded value indexed by base64 char code
|
||||
misc.BASE64_VALUES = BASE64_VALUES;
|
||||
|
||||
@@ -105,9 +105,9 @@ Rect.fromMinMax = function (v1, v2) {
|
||||
* @param b {Rect} Rect b
|
||||
* @return {Number} The contains result, 1 is a contains b, -1 is b contains a, 0 is no contains.
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(5, 5, 5, 5);
|
||||
* var c = new cc.rect(20, 20, 10, 10);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(5, 5, 5, 5);
|
||||
* var c = new cc.Rect(20, 20, 10, 10);
|
||||
* cc.Rect.contain(a, b); // 1;
|
||||
* cc.Rect.contain(b, a); // -1;
|
||||
* cc.Rect.contain(a, c); // 0;
|
||||
@@ -138,7 +138,7 @@ var proto = Rect.prototype;
|
||||
* @method clone
|
||||
* @return {Rect}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* a.clone();// Rect {x: 0, y: 0, width: 10, height: 10}
|
||||
*/
|
||||
proto.clone = function () {
|
||||
@@ -152,8 +152,8 @@ proto.clone = function () {
|
||||
* @param {Rect} other
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(0, 0, 10, 10);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(0, 0, 10, 10);
|
||||
* a.equals(b);// true;
|
||||
*/
|
||||
proto.equals = function (other) {
|
||||
@@ -173,8 +173,8 @@ proto.equals = function (other) {
|
||||
* @param {Rect} [out] - optional, the receiving vector.
|
||||
* @return {Rect}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(50, 50, 100, 100);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(50, 50, 100, 100);
|
||||
* update (dt) {
|
||||
* // method 1;
|
||||
* var c = a.lerp(b, dt * 0.1);
|
||||
@@ -201,7 +201,7 @@ proto.lerp = function (to, ratio, out) {
|
||||
* @method toString
|
||||
* @return {String}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* a.toString();// "(0.00, 0.00, 10.00, 10.00)";
|
||||
*/
|
||||
proto.toString = function () {
|
||||
@@ -312,8 +312,8 @@ JS.getset(proto, 'size',
|
||||
* @param {Rect} rect
|
||||
* @type {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(0, 0, 20, 20);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(0, 0, 20, 20);
|
||||
* a.intersects(b);// true
|
||||
*/
|
||||
proto.intersects = function (rect) {
|
||||
@@ -328,15 +328,15 @@ proto.intersects = function (rect) {
|
||||
* @param {Vec2} point
|
||||
* @type {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.v2(0, 5);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Vec2(0, 5);
|
||||
* a.contains(b);// true
|
||||
*/
|
||||
proto.contains = function (point) {
|
||||
return (this.x < point.x &&
|
||||
this.x + this.width > point.x &&
|
||||
this.y < point.y &&
|
||||
this.y + this.height > point.y);
|
||||
return (this.x <= point.x &&
|
||||
this.x + this.width >= point.x &&
|
||||
this.y <= point.y &&
|
||||
this.y + this.height >= point.y);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -346,15 +346,15 @@ proto.contains = function (point) {
|
||||
* @param {Rect} rect
|
||||
* @type {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(0, 0, 20, 20);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(0, 0, 20, 20);
|
||||
* a.containsRect(b);// true
|
||||
*/
|
||||
proto.containsRect = function (rect) {
|
||||
return (this.x < rect.x &&
|
||||
this.x + this.width > rect.x + rect.width &&
|
||||
this.y < rect.y &&
|
||||
this.y + this.height > rect.y + rect.height);
|
||||
return (this.x <= rect.x &&
|
||||
this.x + this.width >= rect.x + rect.width &&
|
||||
this.y <= rect.y &&
|
||||
this.y + this.height >= rect.y + rect.height);
|
||||
};
|
||||
|
||||
cc.Rect = Rect;
|
||||
@@ -376,7 +376,7 @@ cc.Rect = Rect;
|
||||
* @param {Number} [h=0]
|
||||
* @return {Rect}
|
||||
* @example
|
||||
* var a = new cc.rect(0 , 0, 10, 0);
|
||||
* var a = new cc.Rect(0 , 0, 10, 0);
|
||||
*/
|
||||
cc.rect = function rect (x, y, w, h) {
|
||||
return new Rect(x, y, w, h);
|
||||
@@ -393,10 +393,10 @@ cc.rect = function rect (x, y, w, h) {
|
||||
* @param {Rect} rect2
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 10, 10);
|
||||
* var b = new cc.rect(0, 0, 5, 5);
|
||||
* var a = new cc.Rect(0, 0, 10, 10);
|
||||
* var b = new cc.Rect(0, 0, 5, 5);
|
||||
* cc.rectEqualToRect(a, b); // false;
|
||||
* var c = new cc.rect(0, 0, 5, 5);
|
||||
* var c = new cc.Rect(0, 0, 5, 5);
|
||||
* cc.rectEqualToRect(b, c); // true;
|
||||
*/
|
||||
cc.rectEqualToRect = function (rect1, rect2) {
|
||||
@@ -417,8 +417,8 @@ cc._rectEqualToZero = function(rect){
|
||||
* @param {Rect} rect2
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 0, 20, 20);
|
||||
* var b = new cc.rect(10, 10, 20, 20);
|
||||
* var a = new cc.Rect(0, 0, 20, 20);
|
||||
* var b = new cc.Rect(10, 10, 20, 20);
|
||||
* cc.rectContainsRect(a, b); // true;
|
||||
*/
|
||||
cc.rectContainsRect = function (rect1, rect2) {
|
||||
@@ -436,7 +436,7 @@ cc.rectContainsRect = function (rect1, rect2) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The rightmost x value.
|
||||
* @example
|
||||
* var a = new cc.rect(10, 0, 20, 20);
|
||||
* var a = new cc.Rect(10, 0, 20, 20);
|
||||
* cc.rectGetMaxX(a); // 30;
|
||||
*/
|
||||
cc.rectGetMaxX = function (rect) {
|
||||
@@ -450,7 +450,7 @@ cc.rectGetMaxX = function (rect) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The midpoint x value.
|
||||
* @example
|
||||
* var a = new cc.rect(10, 0, 20, 20);
|
||||
* var a = new cc.Rect(10, 0, 20, 20);
|
||||
* cc.rectGetMidX(a); // 20;
|
||||
*/
|
||||
cc.rectGetMidX = function (rect) {
|
||||
@@ -463,7 +463,7 @@ cc.rectGetMidX = function (rect) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The leftmost x value.
|
||||
* @example
|
||||
* var a = new cc.rect(10, 0, 20, 20);
|
||||
* var a = new cc.Rect(10, 0, 20, 20);
|
||||
* cc.rectGetMinX(a); // 10;
|
||||
*/
|
||||
cc.rectGetMinX = function (rect) {
|
||||
@@ -477,7 +477,7 @@ cc.rectGetMinX = function (rect) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The topmost y value.
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* cc.rectGetMaxY(a); // 30;
|
||||
*/
|
||||
cc.rectGetMaxY = function (rect) {
|
||||
@@ -491,7 +491,7 @@ cc.rectGetMaxY = function (rect) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The midpoint y value.
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* cc.rectGetMidY(a); // 20;
|
||||
*/
|
||||
cc.rectGetMidY = function (rect) {
|
||||
@@ -505,7 +505,7 @@ cc.rectGetMidY = function (rect) {
|
||||
* @param {Rect} rect
|
||||
* @return {Number} The bottommost y value.
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* cc.rectGetMinY(a); // 10;
|
||||
*/
|
||||
cc.rectGetMinY = function (rect) {
|
||||
@@ -520,8 +520,8 @@ cc.rectGetMinY = function (rect) {
|
||||
* @param {Vec2} point
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var b = cc.v2(0, 10, 10, 10);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* var b = new cc.Vec2(0, 10, 10, 10);
|
||||
* cc.rectContainsPoint(a, b); // true;
|
||||
*/
|
||||
cc.rectContainsPoint = function (rect, point) {
|
||||
@@ -537,8 +537,8 @@ cc.rectContainsPoint = function (rect, point) {
|
||||
* @param {Rect} rectB
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var b = new cc.rect(0, 10, 10, 10);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* var b = new cc.Rect(0, 10, 10, 10);
|
||||
* cc.rectIntersectsRect(a, b); // true;
|
||||
*/
|
||||
cc.rectIntersectsRect = function (ra, rb) {
|
||||
@@ -557,8 +557,8 @@ cc.rectIntersectsRect = function (ra, rb) {
|
||||
* @param {Rect} rectB
|
||||
* @return {Boolean}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var b = new cc.rect(0, 10, 10, 10);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* var b = new cc.Rect(0, 10, 10, 10);
|
||||
* cc.rectOverlapsRect(a, b); // true;
|
||||
*/
|
||||
cc.rectOverlapsRect = function (rectA, rectB) {
|
||||
@@ -576,8 +576,8 @@ cc.rectOverlapsRect = function (rectA, rectB) {
|
||||
* @param {Rect} rectB
|
||||
* @return {Rect}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var b = new cc.rect(0, 10, 10, 10);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* var b = new cc.Rect(0, 10, 10, 10);
|
||||
* cc.rectUnion(a, b); // Rect {x: 0, y: 10, width: 20, height: 20};
|
||||
*/
|
||||
cc.rectUnion = function (rectA, rectB) {
|
||||
@@ -597,8 +597,8 @@ cc.rectUnion = function (rectA, rectB) {
|
||||
* @param {Rect} rectB
|
||||
* @return {Rect}
|
||||
* @example
|
||||
* var a = new cc.rect(0, 10, 20, 20);
|
||||
* var b = new cc.rect(0, 10, 10, 10);
|
||||
* var a = new cc.Rect(0, 10, 20, 20);
|
||||
* var b = new cc.Rect(0, 10, 10, 10);
|
||||
* cc.rectIntersection(a, b); // Rect {x: 0, y: 10, width: 10, height: 10};
|
||||
*/
|
||||
cc.rectIntersection = function (rectA, rectB) {
|
||||
|
||||
@@ -356,7 +356,7 @@ _ccsg.WebView.EventType = {
|
||||
this._div.style.height = contentSize.height + "px";
|
||||
this._div.style.width = contentSize.width + "px";
|
||||
this._div.style.overflow = "scroll";
|
||||
this._div.style.border = "none";
|
||||
this._iframe.style.border = "none";
|
||||
cc.game.container.appendChild(this._div);
|
||||
this.updateVisibility();
|
||||
};
|
||||
|
||||
@@ -1478,16 +1478,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
this._renderCmd._initWithTotalParticles(numberOfParticles);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unschedules the "update" method.
|
||||
* @function
|
||||
* @see scheduleUpdate();
|
||||
*/
|
||||
destroyParticleSystem:function () {
|
||||
this.unscheduleUpdate();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Add a particle to the emitter
|
||||
* @return {Boolean}
|
||||
|
||||
+67
-15
@@ -53,8 +53,6 @@ var actionArr = [
|
||||
'Place',
|
||||
'CallFunc',
|
||||
'DelayTime',
|
||||
'Sequence',
|
||||
'Spawn',
|
||||
'Speed',
|
||||
'Repeat',
|
||||
'RepeatForever',
|
||||
@@ -79,6 +77,12 @@ var actionArr = [
|
||||
'TintBy',
|
||||
];
|
||||
|
||||
cc.Action.prototype._getSgTarget = cc.Action.prototype.getTarget;
|
||||
cc.Action.prototype.getTarget = function () {
|
||||
var sgNode = this._getSgTarget();
|
||||
return sgNode._owner || sgNode;
|
||||
};
|
||||
|
||||
function setCtorReplacer (proto) {
|
||||
var ctor = proto._ctor;
|
||||
proto._ctor = function (...args) {
|
||||
@@ -111,6 +115,54 @@ if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
|
||||
}
|
||||
}
|
||||
|
||||
cc.Sequence.prototype._ctor = function (...args) {
|
||||
var paramArray = (args[0] instanceof Array) ? args[0] : args;
|
||||
if (paramArray.length === 1) {
|
||||
cc.errorID(1019);
|
||||
return;
|
||||
}
|
||||
var last = paramArray.length - 1;
|
||||
if ((last >= 0) && (paramArray[last] == null))
|
||||
cc.logID(1015);
|
||||
|
||||
if (last >= 0) {
|
||||
this.init(paramArray);
|
||||
}
|
||||
|
||||
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
|
||||
this.retain();
|
||||
this._retained = true;
|
||||
}
|
||||
};
|
||||
|
||||
cc.sequence = function (...args) {
|
||||
var paramArray = (args[0] instanceof Array) ? args[0] : args;
|
||||
return new cc.Sequence(paramArray);
|
||||
}
|
||||
|
||||
cc.Spawn.prototype._ctor = function (...args) {
|
||||
var paramArray = (args[0] instanceof Array) ? args[0] : args;
|
||||
if (paramArray.length === 1)
|
||||
cc.errorID(1020);
|
||||
var last = paramArray.length - 1;
|
||||
if ((last >= 0) && (paramArray[last] == null))
|
||||
cc.logID(1015);
|
||||
|
||||
if (last >= 0) {
|
||||
this.init(paramArray);
|
||||
}
|
||||
|
||||
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
|
||||
this.retain();
|
||||
this._retained = true;
|
||||
}
|
||||
};
|
||||
|
||||
cc.spawn = function (...args) {
|
||||
var paramArray = (args[0] instanceof Array) ? args[0] : args;
|
||||
return new cc.Spawn(paramArray);
|
||||
}
|
||||
|
||||
cc.targetedAction = function (target, action) {
|
||||
return new cc.TargetedAction(target, action);
|
||||
};
|
||||
@@ -126,7 +178,7 @@ cc.follow = function (followedNode, rect) {
|
||||
};
|
||||
|
||||
cc.Follow.prototype.update = function(dt) {
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.setPosition(target.getPosition());
|
||||
}
|
||||
@@ -147,7 +199,7 @@ cc.FlipX = _FlipX.extend({
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
target.scaleX = Math.abs(target.scaleX) * (this._flippedX ? -1 : 1);
|
||||
},
|
||||
|
||||
@@ -179,7 +231,7 @@ cc.FlipY = _FlipY.extend({
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
target.scaleY = Math.abs(target.scaleY) * (this._flippedY ? -1 : 1);
|
||||
},
|
||||
|
||||
@@ -206,15 +258,15 @@ function setRendererVisibility (sgNode, toggleVisible, visible) {
|
||||
}
|
||||
|
||||
cc.Show.prototype.update = function (dt) {
|
||||
setRendererVisibility(this.getTarget(), false, true);
|
||||
setRendererVisibility(this._getSgTarget(), false, true);
|
||||
};
|
||||
|
||||
cc.Hide.prototype.update = function (dt) {
|
||||
setRendererVisibility(this.getTarget(), false, false);
|
||||
setRendererVisibility(this._getSgTarget(), false, false);
|
||||
};
|
||||
|
||||
cc.ToggleVisibility.prototype.update = function (dt) {
|
||||
setRendererVisibility(this.getTarget(), true);
|
||||
setRendererVisibility(this._getSgTarget(), true);
|
||||
};
|
||||
|
||||
// Special call func
|
||||
@@ -359,7 +411,7 @@ cc.ActionManager.prototype.pauseTargets = function (targetsToPause) {
|
||||
|
||||
function syncPositionUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.x = target.getPositionX();
|
||||
target._owner.y = target.getPositionY();
|
||||
@@ -368,7 +420,7 @@ function syncPositionUpdate (dt) {
|
||||
|
||||
function syncRotationUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.rotationX = target.getRotationX();
|
||||
target._owner.rotationY = target.getRotationY();
|
||||
@@ -377,7 +429,7 @@ function syncRotationUpdate (dt) {
|
||||
|
||||
function syncScaleUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.scaleX = target.getScaleX();
|
||||
target._owner.scaleY = target.getScaleY();
|
||||
@@ -386,7 +438,7 @@ function syncScaleUpdate (dt) {
|
||||
|
||||
function syncRemoveSelfUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.removeFromParent();
|
||||
}
|
||||
@@ -394,7 +446,7 @@ function syncRemoveSelfUpdate (dt) {
|
||||
|
||||
function syncSkewUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.skewX = target.getSkewX();
|
||||
target._owner.skewY = target.getSkewY();
|
||||
@@ -403,7 +455,7 @@ function syncSkewUpdate (dt) {
|
||||
|
||||
function syncOpacityUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.opacity = target.getOpacity();
|
||||
}
|
||||
@@ -411,7 +463,7 @@ function syncOpacityUpdate (dt) {
|
||||
|
||||
function syncColorUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.color = target.getColor();
|
||||
}
|
||||
|
||||
@@ -225,6 +225,8 @@ jsbLabel.prototype.getOutlineColor = function() {
|
||||
return this._outlineColor || cc.color(255,255,255,255);
|
||||
};
|
||||
|
||||
jsbLabel.pool = new JS.Pool(0);
|
||||
|
||||
|
||||
cc.Label = function (string, fontHandle, spriteFrame) {
|
||||
fontHandle = fontHandle || "Arial";
|
||||
|
||||
@@ -232,5 +232,11 @@
|
||||
"entries": [
|
||||
"./cocos2d/core/camera/CCCamera.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Intersection",
|
||||
"entries": [
|
||||
"./cocos2d/core/collider/CCIntersection.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"__type__": "TestDependency",
|
||||
"name": "Prefab A",
|
||||
"dependency": {
|
||||
"__uuid__": "749417"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"__type__": "TestDependency",
|
||||
"name": "Prefab B",
|
||||
"dependency": {
|
||||
"__uuid__": "65535"
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,17 @@ var TestScript = cc.Class({
|
||||
}
|
||||
});
|
||||
|
||||
var TestDependency = cc.Class({
|
||||
name: 'TestDependency',
|
||||
extends: cc.Asset,
|
||||
properties: {
|
||||
dependency: {
|
||||
default: '',
|
||||
url: TestDependency,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// mocks to test engine extends
|
||||
|
||||
cc.engine = new (cc.Class({
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
var grossini_uuid = '748321';
|
||||
var grossiniSprite_uuid = '1232218';
|
||||
var selfReferenced_uuid = '123200';
|
||||
var circleReferenced_uuid = '65535';
|
||||
|
||||
largeModule('AssetLibrary', {
|
||||
setup: function () {
|
||||
@@ -81,4 +82,21 @@
|
||||
}, 200);
|
||||
});
|
||||
|
||||
asyncTest('load asset with circle referenced dependencies', function () {
|
||||
AssetLibrary.loadAsset(circleReferenced_uuid, function (err, asset) {
|
||||
if (err) {
|
||||
ok(false, err.errorMessage);
|
||||
return start();
|
||||
}
|
||||
clearTimeout(timerId);
|
||||
ok(asset.dependency, 'can load circle referenced asset');
|
||||
strictEqual(asset.dependency.dependency, asset, 'circle referenced asset should have dependency which equal to self');
|
||||
start();
|
||||
});
|
||||
var timerId = setTimeout(function () {
|
||||
ok(false, 'time out!');
|
||||
start();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module('decode uuid');
|
||||
|
||||
test('decode uuid', function () {
|
||||
var encoded = 'fcmR3XADNLgJ1ByKhqcC5Z';
|
||||
var decoded = 'fc991dd7-0033-4b80-9d41-c8a86a702e59';
|
||||
var uuid = cc._Test.decodeUuid(encoded);
|
||||
strictEqual(uuid, decoded, 'uuid could be decoded');
|
||||
});
|
||||
Reference in New Issue
Block a user