Merge branch 'next' of https://github.com/cocos-creator/engine into optimize

This commit is contained in:
minggo
2018-04-11 11:16:16 +08:00
86 changed files with 12368 additions and 10952 deletions
+3 -3
View File
@@ -80,7 +80,7 @@ cc.Show = cc.Class({
extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
var _renderComps = this.target.getComponentsInChildren(cc.RenderComponent);
for (var i = 0; i < _renderComps.length; ++i) {
var render = _renderComps[i];
render.enabled = true;
@@ -119,7 +119,7 @@ cc.Hide = cc.Class({
extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
var _renderComps = this.target.getComponentsInChildren(cc.RenderComponent);
for (var i = 0; i < _renderComps.length; ++i) {
var render = _renderComps[i];
render.enabled = false;
@@ -158,7 +158,7 @@ cc.ToggleVisibility = cc.Class({
extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
var _renderComps = this.target.getComponentsInChildren(cc.RenderComponent);
for (var i = 0; i < _renderComps.length; ++i) {
var render = _renderComps[i];
render.enabled = !render.enabled;
+1 -2
View File
@@ -764,8 +764,7 @@ var game = {
if (!this._renderContext) {
game.renderType = game.RENDER_TYPE_CANVAS;
// Could be ignored by module settings
var canvasRenderer = require('./renderer/canvas');
renderer.initCanvas(localCanvas, canvasRenderer);
renderer.initCanvas(localCanvas);
this._renderContext = renderer.device._ctx;
}
cc.renderer = renderer;
+10 -4
View File
@@ -1009,10 +1009,7 @@ var Node = cc.Class({
// INTERNAL
/*
* The initializer for Node which will be called before all components onLoad
*/
_onBatchCreated () {
_upgrade_1x_to_2x () {
// Upgrade scaleX, scaleY from v1.x
// TODO: remove in future version, 3.0 ?
if (this._scaleX !== undefined) {
@@ -1051,6 +1048,13 @@ var Node = cc.Class({
if (this._opacity !== 255 && this._opacity !== undefined) {
this._color.a = this._opacity;
}
},
/*
* The initializer for Node which will be called before all components onLoad
*/
_onBatchCreated () {
this._upgrade_1x_to_2x();
this._updateOrderOfArrival();
@@ -1079,6 +1083,8 @@ var Node = cc.Class({
// the same as _onBatchCreated but untouch prefab
_onBatchRestored () {
this._upgrade_1x_to_2x();
if (!this._activeInHierarchy) {
// deactivate ActionManager and EventManager by default
if (ActionManagerExist) {
+34 -4
View File
@@ -153,6 +153,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
*/
this.insetRight = 0;
this.vertices = null;
this._texture = null;
this._textureFilename = '';
@@ -459,6 +461,18 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
}
},
_normalizeUV () {
let vertices = this.vertices;
let tw = this._texture.width;
let th = this._texture.height;
vertices.nu = [];
vertices.nv = [];
for (let i = 0; i < vertices.u.length; i++) {
vertices.nu[i] = vertices.u[i]/tw;
vertices.nv[i] = vertices.v[i]/th;
}
},
// SERIALIZATION
_serialize: CC_EDITOR && function (exporting) {
@@ -486,6 +500,18 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
this.insetBottom !== 0) {
capInsets = [this.insetLeft, this.insetTop, this.insetRight, this.insetBottom];
}
let vertices;
if (this.vertices) {
vertices = {
triangles: this.vertices.triangles,
x: this.vertices.x,
y: this.vertices.y,
u: this.vertices.u,
v: this.vertices.v
};
}
return {
name: this._name,
texture: uuid || undefined,
@@ -494,7 +520,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
offset: offset ? [offset.x, offset.y] : undefined,
originalSize: size ? [size.width, size.height] : undefined,
rotated: this._rotated ? 1 : undefined,
capInsets: capInsets
capInsets: capInsets,
vertices: vertices
};
},
@@ -522,6 +549,11 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
this._atlasUuid = data.atlas;
}
if (data.vertices) {
this.vertices = data.vertices;
this.on('load', this._normalizeUV, this);
}
// load texture via _textureSetter
var textureUuid = data.texture;
if (textureUuid) {
@@ -536,8 +568,6 @@ proto.copyWithZone = proto.clone;
proto.copy = proto.clone;
proto.initWithTexture = proto.setTexture;
if (!CC_JSB) {
cc.SpriteFrame = SpriteFrame;
}
cc.SpriteFrame = SpriteFrame;
module.exports = SpriteFrame;
+3
View File
@@ -362,6 +362,9 @@ var Texture2D = cc.Class({
this._image = options.images[0];
}
else if (options.image !== undefined) {
// Release previous gl texture if existed
this._texture.destroy();
this._image = options.image;
if (!options.images) {
_images.length = 0;
+1 -1
View File
@@ -417,7 +417,7 @@ let Camera = cc.Class({
* @return {Boolean}
*/
containsNode (node) {
return node._cullingMask === this.cullingMask;
return node._cullingMask & this.cullingMask;
},
/**
+67 -10
View File
@@ -147,6 +147,31 @@ function debounce (func, wait, immediate) {
};
}
let _canvasPool = {
pool: [],
get () {
let data = this.pool.pop();
if (!data) {
let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");
data = {
_canvas: canvas,
_context: context
}
}
data.width = data.height = 1;
return data;
},
put (canvas) {
if (this.pool.length >= 32) {
return;
}
this.pool.push(canvas);
}
};
/**
* !#en The Label Component.
@@ -164,6 +189,7 @@ var Label = cc.Class({
}
this._actualFontSize = 0;
this._assemblerData = null;
},
editor: CC_EDITOR && {
@@ -342,7 +368,6 @@ var Label = cc.Class({
if (value && this._isSystemFontUsed)
this._isSystemFontUsed = false;
if ( typeof value === 'string' ) {
cc.warnID(4000);
}
@@ -357,6 +382,7 @@ var Label = cc.Class({
}
this._fontAtlas = null;
this._material = null;
this._updateAssembler();
this._activateMaterial();
this._updateRenderData();
},
@@ -442,12 +468,41 @@ var Label = cc.Class({
onEnable: function () {
this._super();
this._updateAssembler();
this._activateMaterial();
},
onDestroy () {
this._resetAssemblerData();
},
_resetAssemblerData () {
if (this._assemblerData) {
_canvasPool.put(this._assemblerData);
}
this._assemblerData = null;
},
_updateAssembler () {
let assembler = Label._assembler.getAssembler(this);
if (this._assembler !== assembler) {
this._assembler = assembler;
this._renderData = null;
}
if (!this._renderData) {
this._renderData = this._assembler.createData(this);
this._renderData.worldMatDirty = true;
}
},
_activateMaterial: function () {
if (this._material) return;
this._resetAssemblerData();
let material;
let font = this.font;
if (font instanceof cc.BitmapFont) {
@@ -459,21 +514,23 @@ var Label = cc.Class({
material = new SpriteMaterial();
// TODO: old texture in material have been released by loader
material.texture = spriteFrame.getTexture();
material.texture = this._texture = spriteFrame._texture;
}
else {
material = new SpriteMaterial();
this._texture = new cc.Texture2D();
this._canvas = document.createElement("canvas");
// create canvas with size so that the default texture impl can be created and don't need activate material again
this._canvas.width = this._canvas.height = 1;
this._texture.initWithElement(this._canvas);
this._texture.handleLoadedTexture();
this._context = this._canvas.getContext("2d");
this._assemblerData = _canvasPool.get();
this._texture = new cc.Texture2D();
this._texture.initWithElement(this._assemblerData._canvas);
this._texture.handleLoadedTexture();
material = new SpriteMaterial();
material.texture = this._texture;
}
if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
this._texture.url = this.uuid + '_texture';
}
this.setMaterial(material);
},
@@ -24,9 +24,9 @@
THE SOFTWARE.
****************************************************************************/
const RenderComponent = require('../core/components/CCRenderComponent');
const renderer = require('../core/renderer');
const renderEngine = require('../core/renderer/render-engine');
const RenderComponent = require('../components/CCRenderComponent');
const renderer = require('../renderer');
const renderEngine = require('../renderer/render-engine');
const SpriteMaterial = renderEngine.SpriteMaterial;
/**
+3
View File
@@ -65,6 +65,9 @@ var pool = new js.Pool(function (node) {
if (CC_DEV) {
cc.assert(!node._parent, 'Recycling node\'s parent should be null!');
}
if (!cc.isValid(node)) {
return false;
}
if (node.getComponent(cc.LabelOutline)) {
return false;
}
+25 -13
View File
@@ -370,8 +370,10 @@ var Sprite = cc.Class({
set: function (value) {
if (this._isTrimmedMode !== value) {
this._isTrimmedMode = value;
if (this._type === SpriteType.SIMPLE && this._renderData) {
if ((this._type === SpriteType.SIMPLE || this._type === SpriteType.MESH) &&
this._renderData) {
this._renderData.uvDirty = true;
this._renderData.vertDirty = true;
}
}
},
@@ -480,12 +482,6 @@ var Sprite = cc.Class({
this._super();
this._updateAssembler();
let renderData = this._renderData;
if (!renderData) {
renderData = this._renderData = Sprite._assembler.createData(this);
renderData.worldMatDirty = true;
}
this._activateMaterial();
@@ -515,7 +511,18 @@ var Sprite = cc.Class({
},
_updateAssembler: function () {
this._assembler = Sprite._assembler.getAssembler(this);
let assembler = Sprite._assembler.getAssembler(this);
if (this._assembler !== assembler) {
this._assembler = assembler;
this._renderData = null;
}
if (!this._renderData) {
this._renderData = this._assembler.createData(this);
this._renderData.worldMatDirty = true;
this._renderData.material = this._material;
}
},
_activateMaterial: function () {
@@ -647,13 +654,18 @@ var Sprite = cc.Class({
}
var spriteFrame = this._spriteFrame;
if (spriteFrame && (!oldFrame || spriteFrame._texture !== oldFrame._texture)) {
if (spriteFrame.textureLoaded()) {
this._onTextureLoaded(null);
if (spriteFrame) {
if (!oldFrame || spriteFrame._texture !== oldFrame._texture) {
if (spriteFrame.textureLoaded()) {
this._onTextureLoaded(null);
}
else {
spriteFrame.once('load', this._onTextureLoaded, this);
spriteFrame.ensureLoadTexture();
}
}
else {
spriteFrame.once('load', this._onTextureLoaded, this);
spriteFrame.ensureLoadTexture();
this._applySpriteSize();
}
}
+1 -3
View File
@@ -51,9 +51,7 @@ var components = [
require('./CCToggleGroup'),
require('./CCToggle'),
require('./CCBlockInputEvents'),
require('./CCMotionStreak')
];
// Delay require render components assemblers
require('../renderer/assemblers');
module.exports = components;
+19 -163
View File
@@ -33,41 +33,6 @@ const Helper = require('./helper');
const Types = require('./types');
const LineCap = Types.LineCap;
const LineJoin = Types.LineJoin;
const PointFlags = Types.PointFlags;
// Point
function Point (x, y) {
cc.Vec2.call(this, x, y);
this.reset();
}
cc.js.extend(Point, cc.Vec2);
Point.prototype.reset = function () {
this.dx = 0;
this.dy = 0;
this.dmx = 0;
this.dmy = 0;
this.flags = 0;
this.len = 0;
};
// Path
function Path () {
this.reset();
}
Path.prototype.reset = function () {
this.closed = false;
this.nbevel = 0;
this.complex = true;
if (this.points) {
this.points.length = 0;
}
else {
this.points = [];
}
};
/**
* @class Graphics
@@ -82,25 +47,7 @@ let Graphics = cc.Class({
},
ctor () {
// inner properties
this._tessTol = 0.25;
this._distTol = 0.01;
this._updatePathOffset = false;
this._paths = null;
this._pathLength = 0;
this._pathOffset = 0;
this._points = null;
this._pointsOffset = 0;
this._commandx = 0;
this._commandy = 0;
this._paths = [];
this._points = [];
this._renderDatas = [];
this._impl = Graphics._assembler.createImpl();
},
properties: {
@@ -125,6 +72,7 @@ let Graphics = cc.Class({
},
set (value) {
this._lineWidth = value;
this._impl.lineWidth = value;
}
},
@@ -142,6 +90,7 @@ let Graphics = cc.Class({
},
set (value) {
this._lineJoin = value;
this._impl.lineJoin = value;
},
type: LineJoin
},
@@ -160,6 +109,7 @@ let Graphics = cc.Class({
},
set (value) {
this._lineCap = value;
this._impl.lineCap = value;
},
type: LineCap
},
@@ -178,6 +128,7 @@ let Graphics = cc.Class({
},
set (value) {
this._strokeColor = cc.color(value);
this._impl.strokeColor = value;
}
},
@@ -195,6 +146,7 @@ let Graphics = cc.Class({
},
set (value) {
this._fillColor = cc.color(value);
this._impl.fillColor = value;
}
},
@@ -212,6 +164,7 @@ let Graphics = cc.Class({
},
set (value) {
this._miterLimit = value;
this._impl.miterLimit = value;
}
}
},
@@ -228,8 +181,7 @@ let Graphics = cc.Class({
onDestroy () {
this._super();
// all requested render data will be destroyed by RenderComponent
this._renderDatas.length = 0;
this._impl = null;
},
_activateMaterial () {
@@ -248,16 +200,7 @@ let Graphics = cc.Class({
* @param {Number} [y] The y axis of the coordinate for the end point.
*/
moveTo (x, y) {
if (this._updatePathOffset) {
this._pathOffset = this._pathLength;
this._updatePathOffset = false;
}
this._addPath();
this._addPoint(x, y, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
this._impl.moveTo(x, y);
},
/**
@@ -268,10 +211,7 @@ let Graphics = cc.Class({
* @param {Number} [y] The y axis of the coordinate for the end point.
*/
lineTo (x, y) {
this._addPoint(x, y, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
this._impl.lineTo(x, y);
},
/**
@@ -286,18 +226,7 @@ let Graphics = cc.Class({
* @param {Number} [y] The y axis of the coordinate for the end point.
*/
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
var path = this._curPath;
var last = path.points[path.points.length - 1];
if (last.x === c1x && last.y === c1y && c2x === x && c2y === y) {
this.lineTo(x, y);
return;
}
Helper.tesselateBezier(this, last.x, last.y, c1x, c1y, c2x, c2y, x, y, 0, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
this._impl.bezierCurveTo(c1x, c1y, c2x, c2y, x, y);
},
/**
@@ -310,9 +239,7 @@ let Graphics = cc.Class({
* @param {Number} [y] The y axis of the coordinate for the end point.
*/
quadraticCurveTo (cx, cy, x, y) {
var x0 = this._commandx;
var y0 = this._commandy;
this.bezierCurveTo(x0 + 2.0 / 3.0 * (cx - x0), y0 + 2.0 / 3.0 * (cy - y0), x + 2.0 / 3.0 * (cx - x), y + 2.0 / 3.0 * (cy - y), x, y);
this._impl.quadraticCurveTo(cx, cy, x, y);
},
/**
@@ -327,7 +254,7 @@ let Graphics = cc.Class({
* @param {Number} [counterclockwise] An optional Boolean which, if true, causes the arc to be drawn counter-clockwise between the two angles. By default it is drawn clockwise.
*/
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
this._impl.arc(cx, cy, r, startAngle, endAngle, counterclockwise);
},
/**
@@ -340,8 +267,7 @@ let Graphics = cc.Class({
* @param {Number} [ry] The ellipse's y-axis radius.
*/
ellipse (cx, cy, rx, ry) {
Helper.ellipse(this, cx, cy, rx, ry);
this._curPath.complex = false;
this._impl.ellipse(cx, cy, rx, ry);
},
/**
@@ -353,8 +279,7 @@ let Graphics = cc.Class({
* @param {Number} [r] The circle's radius.
*/
circle (cx, cy, r) {
Helper.ellipse(this, cx, cy, r, r);
this._curPath.complex = false;
this._impl.circle(cx, cy, r);
},
/**
@@ -367,12 +292,7 @@ let Graphics = cc.Class({
* @param {Number} [h] The rectangle's height.
*/
rect (x, y, w, h) {
this.moveTo(x, y);
this.lineTo(x, y + h);
this.lineTo(x + w, y + h);
this.lineTo(x + w, y);
this.close();
this._curPath.complex = false;
this._impl.rect(x, y, w, h);
},
/**
@@ -386,8 +306,7 @@ let Graphics = cc.Class({
* @param {Number} [r] The radius of the rectangle.
*/
roundRect (x, y, w, h, r) {
Helper.roundRect(this, x, y, w, h, r);
this._curPath.complex = false;
this._impl.roundRect(x, y, w, h, r);
},
/**
@@ -411,29 +330,7 @@ let Graphics = cc.Class({
* @param {Boolean} [clean] Whether to clean the graphics inner cache.
*/
clear (clean) {
this._pathLength = 0;
this._pathOffset = 0;
this._pointsOffset = 0;
this._curPath = null;
let datas = this._renderDatas;
if (clean) {
this._paths.length = 0;
this._points.length = 0;
// manually destroy render datas
for (let i = 0, l = datas.length; i < l; i++) {
this.destroyRenderData(datas[i]);
}
datas.length = 0;
}
else {
for (let i = 0, l = datas.length; i < l; i++) {
let data = datas[i];
data.vertexCount = data.indiceCount = data.dataLength = 0;
data._indices.length = 0;
}
}
this._impl.clear(this, clean);
},
/**
@@ -442,7 +339,7 @@ let Graphics = cc.Class({
* @method close
*/
close () {
this._curPath.closed = true;
this._impl.close();
},
/**
@@ -461,47 +358,6 @@ let Graphics = cc.Class({
*/
fill () {
Graphics._assembler.fill(this);
},
_addPath () {
var offset = this._pathLength;
var path = this._paths[offset];
if (!path) {
path = new Path();
this._paths.push(path);
} else {
path.reset();
}
this._pathLength++;
this._curPath = path;
return path;
},
_addPoint (x, y, flags) {
var path = this._curPath;
if (!path) return;
var pt;
var points = this._points;
var pathPoints = path.points;
var offset = this._pointsOffset++;
pt = points[offset];
if (!pt) {
pt = new Point(x, y);
points.push(pt);
} else {
pt.x = x;
pt.y = y;
}
pt.flags = flags;
pathPoints.push(pt);
}
});
+1 -1
View File
@@ -162,7 +162,7 @@ function equalsToDefault (def, value) {
(def.constructor === Object && value.constructor === Object)
) {
try {
return JSON.stringify(def) === JSON.stringify(value);
return Array.isArray(def) && Array.isArray(value) && def.length === 0 && value.length === 0;
}
catch (e) {
}
@@ -0,0 +1,208 @@
const Helper = require('../../../graphics/helper');
const PointFlags = require('../../../graphics/types').PointFlags;
class Point extends cc.Vec2 {
constructor (x, y) {
super(x, y);
this.reset();
}
reset () {
this.dx = 0;
this.dy = 0;
this.dmx = 0;
this.dmy = 0;
this.flags = 0;
this.len = 0;
}
}
class Path {
constructor () {
this.reset();
}
reset () {
this.closed = false;
this.nbevel = 0;
this.complex = true;
if (this.points) {
this.points.length = 0;
}
else {
this.points = [];
}
}
}
class Impl {
constructor () {
// inner properties
this._tessTol = 0.25;
this._distTol = 0.01;
this._updatePathOffset = false;
this._paths = null;
this._pathLength = 0;
this._pathOffset = 0;
this._points = null;
this._pointsOffset = 0;
this._commandx = 0;
this._commandy = 0;
this._paths = [];
this._points = [];
this._renderDatas = [];
this._dataOffset = 0;
}
moveTo (x, y) {
if (this._updatePathOffset) {
this._pathOffset = this._pathLength;
this._updatePathOffset = false;
}
this._addPath();
this._addPoint(x, y, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
}
lineTo (x, y) {
this._addPoint(x, y, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
}
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
var path = this._curPath;
var last = path.points[path.points.length - 1];
if (last.x === c1x && last.y === c1y && c2x === x && c2y === y) {
this.lineTo(x, y);
return;
}
Helper.tesselateBezier(this, last.x, last.y, c1x, c1y, c2x, c2y, x, y, 0, PointFlags.PT_CORNER);
this._commandx = x;
this._commandy = y;
}
quadraticCurveTo (cx, cy, x, y) {
var x0 = this._commandx;
var y0 = this._commandy;
this.bezierCurveTo(x0 + 2.0 / 3.0 * (cx - x0), y0 + 2.0 / 3.0 * (cy - y0), x + 2.0 / 3.0 * (cx - x), y + 2.0 / 3.0 * (cy - y), x, y);
}
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
}
ellipse (cx, cy, rx, ry) {
Helper.ellipse(this, cx, cy, rx, ry);
this._curPath.complex = false;
}
circle (cx, cy, r) {
Helper.ellipse(this, cx, cy, r, r);
this._curPath.complex = false;
}
rect (x, y, w, h) {
this.moveTo(x, y);
this.lineTo(x, y + h);
this.lineTo(x + w, y + h);
this.lineTo(x + w, y);
this.close();
this._curPath.complex = false;
}
roundRect (x, y, w, h, r) {
Helper.roundRect(this, x, y, w, h, r);
this._curPath.complex = false;
}
clear (comp, clean) {
this._pathLength = 0;
this._pathOffset = 0;
this._pointsOffset = 0;
this._dataOffset = 0;
this._curPath = null;
let datas = this._renderDatas;
if (clean) {
this._paths.length = 0;
this._points.length = 0;
// manually destroy render datas
for (let i = 0, l = datas.length; i < l; i++) {
comp.destroyRenderData(datas[i]);
}
datas.length = 0;
}
else {
for (let i = 0, l = datas.length; i < l; i++) {
let data = datas[i];
data.indiceCount = data._indices.length = 0;
data.vertexCount = 0;
}
}
}
close () {
this._curPath.closed = true;
}
_addPath () {
var offset = this._pathLength;
var path = this._paths[offset];
if (!path) {
path = new Path();
this._paths.push(path);
} else {
path.reset();
}
this._pathLength++;
this._curPath = path;
return path;
}
_addPoint (x, y, flags) {
var path = this._curPath;
if (!path) return;
var pt;
var points = this._points;
var pathPoints = path.points;
var offset = this._pointsOffset++;
pt = points[offset];
if (!pt) {
pt = new Point(x, y);
points.push(pt);
} else {
pt.x = x;
pt.y = y;
}
pt.flags = flags;
pathPoints.push(pt);
}
}
module.exports = Impl;
@@ -28,6 +28,7 @@ const PointFlags = require('../../../graphics/types').PointFlags;
const LineJoin = Graphics.LineJoin;
const LineCap = Graphics.LineCap;
const Earcut = require('./earcut');
const Impl = require('./impl');
const macro = require('../../../platform/CCMacro');
const MAX_VERTEX = macro.BATCH_VERTEX_COUNT;
@@ -50,6 +51,7 @@ const abs = Math.abs;
let _matrix = math.mat4.create();
let _renderData = null;
let _impl = null;
let _curColor = 0;
function curveDivs (r, arc, tol) {
@@ -68,8 +70,12 @@ function clamp (v, min, max) {
}
let graphicsAssembler = js.addon({
createImpl () {
return new Impl();
},
updateRenderData (graphics) {
let datas = graphics._renderDatas;
let datas = graphics._impl._renderDatas;
if (datas.length === 0) {
datas.push(graphics.requestRenderData());
}
@@ -98,7 +104,7 @@ let graphicsAssembler = js.addon({
nodeG = nodeColor.g / 255,
nodeB = nodeColor.b / 255,
nodeA = nodeColor.a / 255;
for (let i = 0, l = data.length; i < l; i++) {
for (let i = 0, l = renderData.vertexCount; i < l; i++) {
vbuf[offset++] = data[i].x * a + data[i].y * c + tx;
vbuf[offset++] = data[i].x * b + data[i].y * d + ty;
vbuf[offset++] = z;
@@ -122,38 +128,55 @@ let graphicsAssembler = js.addon({
},
genRenderData (graphics, cverts) {
let renderDatas = graphics._renderDatas;
let renderData = renderDatas[renderDatas.length - 1];
let maxVertsCount = renderData.dataLength + cverts;
let renderDatas = _impl._renderDatas;
let renderData = renderDatas[_impl._dataOffset];
let maxVertsCount = renderData.vertexCount + cverts;
if (maxVertsCount > MAX_VERTEX ||
maxVertsCount * 3 > MAX_INDICE) {
renderData = graphics.requestRenderData();
++_impl._dataOffset;
maxVertsCount = cverts;
if (_impl._dataOffset < renderDatas.length) {
renderData = renderDatas[_impl._dataOffset];
}
else {
renderData = graphics.requestRenderData();
renderDatas[_impl._dataOffset] = renderData;
}
}
if (maxVertsCount > renderData.dataLength) {
renderData.dataLength = maxVertsCount;
}
return renderData;
},
stroke (graphics) {
if (graphics._renderDatas.length === 0) {
graphics._renderDatas.push(graphics.requestRenderData());
let renderDatas = graphics._impl._renderDatas;
if (renderDatas.length === 0) {
renderDatas.push(graphics.requestRenderData());
}
_curColor = graphics._strokeColor._val;
this._flattenPaths(graphics);
this._flattenPaths(graphics._impl);
this._expandStroke(graphics);
graphics._updatePathOffset = true;
graphics._impl._updatePathOffset = true;
},
fill (graphics) {
if (graphics._renderDatas.length === 0) {
graphics._renderDatas.push(graphics.requestRenderData());
let renderDatas = graphics._impl._renderDatas;
if (renderDatas.length === 0) {
renderDatas.push(graphics.requestRenderData());
}
_curColor = graphics._fillColor._val;
this._expandFill(graphics);
this._updatePathOffset = true;
graphics._impl._updatePathOffset = true;
},
_expandStroke (graphics) {
@@ -161,16 +184,18 @@ let graphicsAssembler = js.addon({
lineCap = graphics.lineCap,
lineJoin = graphics.lineJoin,
miterLimit = graphics.miterLimit;
_impl = graphics._impl;
let ncap = curveDivs(w, PI, graphics._tessTol);
let ncap = curveDivs(w, PI, _impl._tessTol);
this._calculateJoins(graphics, w, lineJoin, miterLimit);
this._calculateJoins(_impl, w, lineJoin, miterLimit);
let paths = graphics._paths;
let paths = _impl._paths;
// Calculate max vertex usage.
let cverts = 0;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
let path = paths[i];
let pointsLength = path.points.length;
@@ -186,16 +211,16 @@ let graphicsAssembler = js.addon({
}
}
}
let renderData = _renderData = this.genRenderData(graphics, cverts),
data = renderData._data,
indicesBuffer = renderData._indices;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
let path = paths[i];
let pts = path.points;
let pointsLength = pts.length;
let offset = data.length;
let offset = renderData.vertexCount;
let p0, p1;
let start, end, loop;
@@ -268,25 +293,27 @@ let graphicsAssembler = js.addon({
// stroke indices
let indicesOffset = indicesBuffer.length;
for (let start = offset+2, end = data.length; start < end; start++) {
for (let start = offset+2, end = renderData.vertexCount; start < end; start++) {
indicesBuffer[indicesOffset++] = start - 2;
indicesBuffer[indicesOffset++] = start - 1;
indicesBuffer[indicesOffset++] = start;
}
}
renderData.vertexCount = data.length;
renderData.indiceCount = indicesBuffer.length;
_renderData = null;
_impl = null;
},
_expandFill (graphics) {
let paths = graphics._paths;
_impl = graphics._impl;
let paths = _impl._paths;
// Calculate max vertex usage.
let cverts = 0;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
let path = paths[i];
let pointsLength = path.points.length;
@@ -297,7 +324,7 @@ let graphicsAssembler = js.addon({
data = renderData._data,
indicesBuffer = renderData._indices;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
let path = paths[i];
let pts = path.points;
let pointsLength = pts.length;
@@ -307,7 +334,7 @@ let graphicsAssembler = js.addon({
}
// Calculate shape vertices.
let offset = data.length;
let offset = renderData.vertexCount;
for (let j = 0; j < pointsLength; ++j) {
this._vset(pts[j].x, pts[j].y);
@@ -317,7 +344,7 @@ let graphicsAssembler = js.addon({
if (path.complex) {
let earcutData = [];
for (let j = offset, end = data.length; j < end; j++) {
for (let j = offset, end = renderData.vertexCount; j < end; j++) {
earcutData.push(data[j].x);
earcutData.push(data[j].y);
}
@@ -334,7 +361,7 @@ let graphicsAssembler = js.addon({
}
else {
let first = offset;
for (let start = offset+2, end = data.length; start < end; start++) {
for (let start = offset+2, end = renderData.vertexCount; start < end; start++) {
indicesBuffer[indicesOffset++] = first;
indicesBuffer[indicesOffset++] = start - 1;
indicesBuffer[indicesOffset++] = start;
@@ -342,13 +369,13 @@ let graphicsAssembler = js.addon({
}
}
renderData.vertexCount = data.length;
renderData.indiceCount = indicesBuffer.length;
_renderData = null;
_impl = null;
},
_calculateJoins (graphics, w, lineJoin, miterLimit) {
_calculateJoins (impl, w, lineJoin, miterLimit) {
let iw = 0.0;
if (w > 0.0) {
@@ -356,8 +383,8 @@ let graphicsAssembler = js.addon({
}
// Calculate which joins needs extra vertices to append, and gather vertex count.
let paths = graphics._paths;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
let paths = impl._paths;
for (let i = impl._pathOffset, l = impl._pathLength; i < l; i++) {
let path = paths[i];
let pts = path.points;
@@ -420,9 +447,9 @@ let graphicsAssembler = js.addon({
}
},
_flattenPaths (graphics) {
let paths = graphics._paths;
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
_flattenPaths (impl) {
let paths = impl._paths;
for (let i = impl._pathOffset, l = impl._pathLength; i < l; i++) {
let path = paths[i];
let pts = path.points;
@@ -613,13 +640,13 @@ let graphicsAssembler = js.addon({
_vset (x, y) {
let data = _renderData._data;
let offset = data.length;
_renderData.dataLength = offset + 1;
let offset = _renderData.vertexCount;
data[offset].x = x;
data[offset].y = y;
data[offset].color = _curColor;
_renderData.vertexCount ++;
}
}, assembler);
+4 -3
View File
@@ -23,7 +23,8 @@
THE SOFTWARE.
****************************************************************************/
require('./sprite/sprite-assembler');
require('./sprite');
require('./mask-assembler');
require('./graphics/graphics-assembler');
require('./label/label-assembler');
require('./graphics');
require('./label');
require('./motion-streak');
@@ -0,0 +1,135 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const macro = require('../../../platform/CCMacro');
const renderEngine = require('../../render-engine');
const js = require('../../../platform/js');
const bmfontUtls = require('../../utils/label/bmfont');
module.exports = js.addon({
createData (comp) {
return comp.requestRenderData();
},
fillVertexBuffer (comp, off, vbuf, uintbuf) {
let node = comp.node;
let renderData = comp._renderData;
let data = renderData._data;
let z = node._position.z;
let color = node.color._val;
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let a = matrix.m00,
b = matrix.m01,
c = matrix.m04,
d = matrix.m05,
tx = matrix.m12,
ty = matrix.m13;
let vert;
let length = renderData.dataLength;
for (let i = 0; i < length; i++) {
vert = data[i];
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
vbuf[off + 2] = z;
vbuf[off + 4] = vert.u;
vbuf[off + 5] = vert.v;
uintbuf[off + 3] = color;
off += 6;
}
},
fillIndexBuffer (comp, offset, vertexId, ibuf) {
let renderData = comp._renderData;
let length = renderData.indiceCount;
for (let i = 0; i < length; i+=6) {
ibuf[offset++] = vertexId;
ibuf[offset++] = vertexId+1;
ibuf[offset++] = vertexId+2;
ibuf[offset++] = vertexId+1;
ibuf[offset++] = vertexId+3;
ibuf[offset++] = vertexId+2;
vertexId += 4;
}
},
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
let dataOffset = renderData.dataLength;
renderData.dataLength += 4;
renderData.vertexCount = renderData.dataLength;
renderData.indiceCount = renderData.dataLength / 2 * 3;
let data = renderData._data;
let texw = texture.width,
texh = texture.height;
let rectWidth = rect.width,
rectHeight = rect.height;
let l, b, r, t;
if (!rotated) {
l = (rect.x) / texw;
r = (rect.x + rectWidth) / texw;
b = (rect.y + rectHeight) / texh;
t = (rect.y) / texh;
data[dataOffset].u = l;
data[dataOffset].v = b;
data[dataOffset+1].u = r;
data[dataOffset+1].v = b;
data[dataOffset+2].u = l;
data[dataOffset+2].v = t;
data[dataOffset+3].u = r;
data[dataOffset+3].v = t;
} else {
l = (rect.x) / texw;
r = (rect.x + rectHeight) / texw;
b = (rect.y + rectWidth) / texh;
t = (rect.y) / texh;
data[dataOffset].u = l;
data[dataOffset].v = t;
data[dataOffset+1].u = l;
data[dataOffset+1].v = b;
data[dataOffset+2].u = r;
data[dataOffset+2].v = t;
data[dataOffset+3].u = r;
data[dataOffset+3].v = b;
}
data[dataOffset].x = x;
data[dataOffset].y = y - rectHeight * scale;
data[dataOffset+1].x = x + rectWidth * scale;
data[dataOffset+1].y = y - rectHeight * scale;
data[dataOffset+2].x = x;
data[dataOffset+2].y = y;
data[dataOffset+3].x = x + rectWidth * scale;
data[dataOffset+3].y = y;
},
}, bmfontUtls);
@@ -26,57 +26,53 @@
const js = require('../../../platform/js');
const assembler = require('../assembler');
const Label = require('../../../components/CCLabel');
const ttfAssembler = require('./ttf-assembler');
const bmfontAssembler = require('./bmfont-assembler');
const ttfAssembler = require('./ttf');
const bmfontAssembler = require('./bmfont');
var labelAssembler = js.addon({
getAssembler (comp) {
let assembler = ttfAssembler;
if (comp.font instanceof cc.BitmapFont) {
assembler = bmfontAssembler;
}
return assembler;
},
updateRenderData (comp) {
this.datas.length = 0;
if (comp.string !== undefined && comp.string !== null && comp.string !== "") {
let assembler;
if (comp.font instanceof cc.BitmapFont) {
assembler = bmfontAssembler;
}
else {
assembler = ttfAssembler;
}
let renderData = comp._renderData;
if (!renderData) {
renderData = comp._renderData = assembler.createData(comp);
}
if (comp.string === undefined ||
comp.string === null ||
comp.string === "" ||
!comp._assembler) {
return this.datas;
}
let size = comp.node._contentSize;
let anchor = comp.node._anchorPoint;
renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
let renderData = comp._renderData;
assembler.update(comp);
// let size = comp.node._contentSize;
// let anchor = comp.node._anchorPoint;
// renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
renderData.material = comp.getMaterial();
this.datas.push(renderData);
}
comp._assembler.update(comp);
renderData.material = comp.getMaterial();
this.datas.push(renderData);
return this.datas;
},
fillBuffers (comp, batchData, vertexId, vbuf, uintbuf, ibuf) {
let assembler = comp._assembler;
if (!assembler) return;
let vertexOffset = batchData.byteOffset / 4,
indiceOffset = batchData.indiceOffset;
// vertex buffer
if (comp.font instanceof cc.BitmapFont) {
bmfontAssembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
}
else {
ttfAssembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
}
// index buffer
if (comp.font instanceof cc.BitmapFont) {
bmfontAssembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
}
else {
ttfAssembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
}
assembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
assembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
}
}, assembler);
@@ -0,0 +1,110 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const macro = require('../../../platform/CCMacro');
const renderEngine = require('../../render-engine');
const js = require('../../../platform/js');
const ttfUtls = require('../../utils/label/ttf');
module.exports = js.addon({
createData (comp) {
let renderData = comp.requestRenderData();
renderData.dataLength = 4;
renderData.vertexCount = 4;
renderData.indiceCount = 6;
let data = renderData._data;
data[0].u = 0;
data[0].v = 1;
data[1].u = 1;
data[1].v = 1;
data[2].u = 0;
data[2].v = 0;
data[3].u = 1;
data[3].v = 0;
return renderData;
},
fillVertexBuffer (comp, off, vbuf, uintbuf) {
let node = comp.node;
let renderData = comp._renderData;
let data = renderData._data;
let z = node._position.z;
let color = cc.Color.WHITE._val;
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let a = matrix.m00,
b = matrix.m01,
c = matrix.m04,
d = matrix.m05,
tx = matrix.m12,
ty = matrix.m13;
let vert;
let length = renderData.dataLength;
for (let i = 0; i < length; i++) {
vert = data[i];
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
vbuf[off + 2] = z;
vbuf[off + 4] = vert.u;
vbuf[off + 5] = vert.v;
uintbuf[off + 3] = color;
off += 6;
}
},
fillIndexBuffer (comp, offset, vertexId, ibuf) {
ibuf[offset + 0] = vertexId;
ibuf[offset + 1] = vertexId + 1;
ibuf[offset + 2] = vertexId + 2;
ibuf[offset + 3] = vertexId + 1;
ibuf[offset + 4] = vertexId + 3;
ibuf[offset + 5] = vertexId + 2;
},
_updateVerts (comp) {
let renderData = comp._renderData;
let node = comp.node,
width = node.width,
height = node.height,
appx = node.anchorX * width,
appy = node.anchorY * height;
let data = renderData._data;
data[0].x = -appx;
data[0].y = -appy;
data[1].x = width - appx;
data[1].y = -appy;
data[2].x = -appx;
data[2].y = height - appy;
data[3].x = width - appx;
data[3].y = height - appy;
}
}, ttfUtls);
@@ -32,7 +32,7 @@ const js = require('../../platform/js');
const assembler = require('./assembler');
const spriteAssembler = require('./sprite/simple');
const Graphics = require('../../graphics/graphics');
const graphicsAssembler = require('./graphics/graphics-assembler');
const graphicsAssembler = require('./graphics');
let _stencilMgr = StencilManager.sharedManager;
let _color = cc.color(255, 255, 255, 0);
@@ -94,7 +94,7 @@ let maskFrontAssembler = js.addon({
if (mask.spriteFrame) {
datas = mask._renderDatas;
datas.length = 0;
renderData.dataLength = 4;
renderData.dataLength = 8;
spriteAssembler.update(mask);
renderData.material = mask.getMaterial();
datas.push(renderData);
@@ -149,7 +149,7 @@ let maskEndAssembler = js.addon({
datas = mask._renderDatas;
}
else {
datas = mask._graphics._renderDatas;
datas = mask._graphics._impl._renderDatas;
}
let material = mask.getMaterial();
for (let i = 0; i < datas.length; i++) {
@@ -169,8 +169,7 @@ let maskEndAssembler = js.addon({
// vertex buffer
if (mask._type === Mask.Type.IMAGE_STENCIL) {
spriteAssembler.fillVertexBuffer(mask, batchData.byteOffset / 4, vbuf, uintbuf);
spriteAssembler.fillIndexBuffer(mask, batchData.indiceOffset, vertexId, ibuf);
spriteAssembler.fillBuffers(mask, batchData, vertexId, vbuf, uintbuf, ibuf);
}
else {
// Share node for correct global matrix
@@ -23,10 +23,11 @@
THE SOFTWARE.
****************************************************************************/
const js = require('../core/platform/js');
const assembler = require('../core/renderer/assemblers/assembler');
const MotionStreak = require('./CCMotionStreak');
const renderEngine = require('../core/renderer/render-engine');
const js = require('../../platform/js');
const assembler = require('../../renderer/assemblers/assembler');
const renderEngine = require('../../renderer/render-engine');
const MotionStreak = require('../../components/CCMotionStreak');
function Point (point, dir) {
this.point = point || cc.v2();
@@ -63,7 +63,7 @@ module.exports = {
if (vertDirty) {
this.updateVerts(sprite, fillStart, fillEnd);
}
if (renderData.worldMatDirty) {
if (vertDirty || renderData.worldMatDirty) {
this.updateWorldVerts(sprite);
}
},
@@ -35,6 +35,7 @@ const slicedRenderUtil = require('./sliced');
const tiledRenderUtil = require('./tiled');
const radialFilledRenderUtil = require('./radial-filled');
const barFilledRenderUtil = require('./bar-filled');
const meshRenderUtil = require('./mesh');
// Inline all type switch to avoid jit deoptimization during inlined function change
let spriteAssembler = js.addon({
@@ -58,18 +59,17 @@ let spriteAssembler = js.addon({
util = barFilledRenderUtil;
}
break;
case SpriteType.MESH:
util = meshRenderUtil;
break;
}
return util;
},
createData (sprite) {
return sprite._assembler.createData(sprite);
},
updateRenderData (sprite) {
let datas = sprite.__allocedDatas;
if (!sprite.spriteFrame) {
if (!sprite.spriteFrame || !sprite.getMaterial() || !sprite._renderData) {
return datas;
}
@@ -0,0 +1,170 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
module.exports = {
createData (sprite) {
return sprite.requestRenderData();
},
update (sprite) {
let renderData = sprite._renderData;
let frame = sprite.spriteFrame;
let vertices = frame.vertices;
if (!vertices) return;
if (renderData.vertexCount !== vertices.x.length) {
renderData.vertexCount = vertices.x.length;
renderData.indiceCount = vertices.triangles.length;
// 1 for world vertices, 2 for local vertices
renderData.dataLength = renderData.vertexCount * 2;
renderData.uvDirty = renderData.vertDirty = true;
}
if (renderData.uvDirty) {
this.updateUVs(sprite);
}
let vertDirty = renderData.vertDirty;
if (vertDirty) {
this.updateVerts(sprite);
}
if (vertDirty || renderData.worldMatDirty) {
this.updateWorldVerts(sprite);
}
},
updateUVs (sprite) {
let material = sprite.getMaterial();
let texture = material.effect.getProperty('texture');
let texw = texture._width,
texh = texture._height;
let vertices = sprite.spriteFrame.vertices,
u = vertices.nu,
v = vertices.nv;
let renderData = sprite._renderData;
let data = renderData._data;
for (let i = 0, l = u.length; i < l; i++) {
let vertice = data[i];
vertice.u = u[i];
vertice.v = v[i];
}
renderData.uvDirty = false;
},
updateVerts (sprite) {
let node = sprite.node,
contentWidth = Math.abs(node.width),
contentHeight = Math.abs(node.height),
appx = node.anchorX * contentWidth,
appy = node.anchorY * contentHeight;
let frame = sprite.spriteFrame,
vertices = frame.vertices,
x = vertices.x,
y = vertices.y,
originalWidth = frame._originalSize.width,
originalHeight = frame._originalSize.height,
rectWidth = frame._rect.width,
rectHeight = frame._rect.height,
offsetX = frame._offset.x,
offsetY = frame._offset.y;
trimX = offsetX + (originalWidth - rectWidth) / 2,
trimY = offsetY + (originalHeight - rectHeight) / 2;
let scaleX = contentWidth / (sprite.trim ? rectWidth : originalWidth),
scaleY = contentHeight / (sprite.trim ? rectHeight : originalHeight);
let renderData = sprite._renderData;
let data = renderData._data;
if (!sprite.trim) {
for (let i = 0, l = x.length; i < l; i++) {
let vertice = data[i+l];
vertice.x = (x[i]) * scaleX - appx;
vertice.y = (originalHeight - y[i]) * scaleY - appy;
}
}
else {
for (let i = 0, l = x.length; i < l; i++) {
let vertice = data[i+l];
vertice.x = (x[i] - trimX) * scaleX - appx;
vertice.y = (originalHeight - y[i] - trimY) * scaleY - appy;
}
}
renderData.vertDirty = false;
},
updateWorldVerts (sprite) {
let node = sprite.node,
renderData = sprite._renderData,
data = renderData._data,
matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
for (let i = 0, l = renderData.vertexCount; i < l; i++) {
let local = data[i+l];
let world = data[i];
world.x = local.x * a + local.y * c + tx;
world.y = local.x * b + local.y * d + ty;
}
renderData.worldMatDirty = false;
},
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
let vertexOffset = batchData.byteOffset / 4,
indiceOffset = batchData.indiceOffset;
// update verts
let node = sprite.node;
let renderData = sprite._renderData;
let data = renderData._data;
let z = node._position.z;
let color = node._color._val;
for (let i = 0, l = renderData.vertexCount; i < l; i++) {
let vertice = data[i];
vbuf[vertexOffset++] = vertice.x;
vbuf[vertexOffset++] = vertice.y;
vbuf[vertexOffset++] = z;
uintbuf[vertexOffset++] = color;
vbuf[vertexOffset++] = vertice.u;
vbuf[vertexOffset++] = vertice.v;
}
let triangles = sprite.spriteFrame.vertices.triangles;
for (let i = 0, l = triangles.length; i < l; i++) {
ibuf[indiceOffset++] = vertexId + triangles[i];
}
}
};
@@ -23,7 +23,6 @@
THE SOFTWARE.
****************************************************************************/
const Sprite = require('../../../components/CCSprite');
const simpleRenderUtil = require('./simple');
const PI_2 = Math.PI * 2;
@@ -23,8 +23,6 @@
THE SOFTWARE.
****************************************************************************/
const Sprite = require('../../../components/CCSprite');
const js = require('../../../platform/js');
const assembler = require('../assembler');
@@ -87,45 +85,43 @@ module.exports = js.addon({
updateUVs (sprite) {
let material = sprite.getMaterial();
let renderData = sprite._renderData;
if (material && renderData) {
let data = renderData._data;
let texture = material.effect.getProperty('texture');
let texw = texture._width,
texh = texture._height;
let frame = sprite.spriteFrame;
let rect = frame._rect;
if (frame._rotated) {
let l = texw === 0 ? 0 : rect.x / texw;
let r = texw === 0 ? 0 : (rect.x + rect.height) / texw;
let b = texh === 0 ? 0 : (rect.y + rect.width) / texh;
let t = texh === 0 ? 0 : rect.y / texh;
data[0].u = l;
data[0].v = t;
data[1].u = l;
data[1].v = b;
data[2].u = r;
data[2].v = t;
data[3].u = r;
data[3].v = b;
}
else {
let l = texw === 0 ? 0 : rect.x / texw;
let r = texw === 0 ? 0 : (rect.x + rect.width) / texw;
let b = texh === 0 ? 0 : (rect.y + rect.height) / texh;
let t = texh === 0 ? 0 : rect.y / texh;
data[0].u = l;
data[0].v = b;
data[1].u = r;
data[1].v = b;
data[2].u = l;
data[2].v = t;
data[3].u = r;
data[3].v = t;
}
renderData.uvDirty = false;
let data = renderData._data;
let texture = material.effect.getProperty('texture');
let texw = texture._width,
texh = texture._height;
let frame = sprite.spriteFrame;
let rect = frame._rect;
if (frame._rotated) {
let l = texw === 0 ? 0 : rect.x / texw;
let r = texw === 0 ? 0 : (rect.x + rect.height) / texw;
let b = texh === 0 ? 0 : (rect.y + rect.width) / texh;
let t = texh === 0 ? 0 : rect.y / texh;
data[0].u = l;
data[0].v = t;
data[1].u = l;
data[1].v = b;
data[2].u = r;
data[2].v = t;
data[3].u = r;
data[3].v = b;
}
else {
let l = texw === 0 ? 0 : rect.x / texw;
let r = texw === 0 ? 0 : (rect.x + rect.width) / texw;
let b = texh === 0 ? 0 : (rect.y + rect.height) / texh;
let t = texh === 0 ? 0 : rect.y / texh;
data[0].u = l;
data[0].v = b;
data[1].u = r;
data[1].v = b;
data[2].u = l;
data[2].v = t;
data[3].u = r;
data[3].v = t;
}
renderData.uvDirty = false;
},
updateWorldVerts (sprite) {
@@ -43,45 +43,43 @@ module.exports = {
updateUVs (sprite) {
let material = sprite.getMaterial();
let renderData = sprite._renderData;
if (material && renderData) {
let texture = material.effect.getProperty('texture');
let frame = sprite.spriteFrame;
let rect = frame._rect;
let atlasWidth = texture._width;
let atlasHeight = texture._height;
// caculate texture coordinate
let leftWidth = frame.insetLeft;
let rightWidth = frame.insetRight;
let centerWidth = rect.width - leftWidth - rightWidth;
let topHeight = frame.insetTop;
let bottomHeight = frame.insetBottom;
let centerHeight = rect.height - topHeight - bottomHeight;
// uv computation should take spritesheet into account.
let data = renderData._data;
if (frame._rotated) {
data[0].u = (rect.x) / atlasWidth;
data[0].v = (rect.y) / atlasHeight;
data[1].u = (bottomHeight + rect.x) / atlasWidth;
data[1].v = (leftWidth + rect.y) / atlasHeight;
data[2].u = (bottomHeight + centerHeight + rect.x) / atlasWidth;
data[2].v = (leftWidth + centerWidth + rect.y) / atlasHeight;
data[3].u = (rect.x + rect.height) / atlasWidth;
data[3].v = (rect.y + rect.width) / atlasHeight;
}
else {
data[0].u = (rect.x) / atlasWidth;
data[1].u = (leftWidth + rect.x) / atlasWidth;
data[2].u = (leftWidth + centerWidth + rect.x) / atlasWidth;
data[3].u = (rect.x + rect.width) / atlasWidth;
data[3].v = (rect.y) / atlasHeight;
data[2].v = (topHeight + rect.y) / atlasHeight;
data[1].v = (topHeight + centerHeight + rect.y) / atlasHeight;
data[0].v = (rect.y + rect.height) / atlasHeight;
}
renderData.uvDirty = false;
let texture = material.effect.getProperty('texture');
let frame = sprite.spriteFrame;
let rect = frame._rect;
let atlasWidth = texture._width;
let atlasHeight = texture._height;
// caculate texture coordinate
let leftWidth = frame.insetLeft;
let rightWidth = frame.insetRight;
let centerWidth = rect.width - leftWidth - rightWidth;
let topHeight = frame.insetTop;
let bottomHeight = frame.insetBottom;
let centerHeight = rect.height - topHeight - bottomHeight;
// uv computation should take spritesheet into account.
let data = renderData._data;
if (frame._rotated) {
data[0].u = (rect.x) / atlasWidth;
data[0].v = (rect.y) / atlasHeight;
data[1].u = (bottomHeight + rect.x) / atlasWidth;
data[1].v = (leftWidth + rect.y) / atlasHeight;
data[2].u = (bottomHeight + centerHeight + rect.x) / atlasWidth;
data[2].v = (leftWidth + centerWidth + rect.y) / atlasHeight;
data[3].u = (rect.x + rect.height) / atlasWidth;
data[3].v = (rect.y + rect.width) / atlasHeight;
}
else {
data[0].u = (rect.x) / atlasWidth;
data[1].u = (leftWidth + rect.x) / atlasWidth;
data[2].u = (leftWidth + centerWidth + rect.x) / atlasWidth;
data[3].u = (rect.x + rect.width) / atlasWidth;
data[3].v = (rect.y) / atlasHeight;
data[2].v = (topHeight + rect.y) / atlasHeight;
data[1].v = (topHeight + centerHeight + rect.y) / atlasHeight;
data[0].v = (rect.y + rect.height) / atlasHeight;
}
renderData.uvDirty = false;
},
updateVerts (sprite) {
@@ -23,8 +23,6 @@
THE SOFTWARE.
****************************************************************************/
const Sprite = require('../../../components/CCSprite');
module.exports = {
createData (sprite) {
return sprite.requestRenderData();
@@ -35,7 +33,6 @@ module.exports = {
if (!renderData.uvDirty && !renderData.vertDirty) return;
let material = sprite.getMaterial();
if (!material || !renderData) return;
let texture = material.effect.getProperty('texture');
let texw = texture._width,
@@ -25,8 +25,6 @@
const js = require('../../platform/js');
const renderers = require('./renderers');
const rendererMap = renderers.map;
const postRendererMap = renderers.postMap;
let RenderComponentWalker = function (device, defaultCamera) {
this._device = device;
@@ -50,18 +48,18 @@ RenderComponentWalker.prototype = {
let comp = node._renderComponent;
let opacity = node.opacity;
let compName = js.getClassName(comp);
if (opacity && compName && rendererMap[compName]) {
this._render(comp, rendererMap[compName]);
let assembler = comp && comp.constructor._assembler;
if (opacity && assembler) {
this._render(comp, assembler);
}
},
_postHandleRender (node) {
let comp = node._renderComponent;
let opacity = node.opacity;
let compName = js.getClassName(comp);
if (opacity && compName && postRendererMap[compName]) {
this._render(comp, postRendererMap[compName]);
let postAssembler = comp && comp.constructor._postAssembler;
if (opacity && postAssembler) {
this._render(comp, postAssembler);
}
},
@@ -0,0 +1,155 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Helper = require('../../../../graphics/helper');
const Types = require('../../../../graphics/types');
const PointFlags = Types.PointFlags;
const LineJoin = Types.LineJoin;
const LineCap = Types.LineCap;
class Impl {
constructor () {
this.cmds = [];
this.style = {
strokeStyle: 'black',
fillStyle: 'white',
lineCap: 'butt',
lineJoin: 'miter',
miterLimit: 10
};
}
set strokeColor (v) {
var strokeStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
this.cmds.push(['strokeStyle', strokeStyle]);
this.style.strokeStyle = strokeStyle;
}
set fillColor (v) {
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
this.cmds.push(['fillStyle', fillStyle]);
this.style.fillStyle = fillStyle;
}
set lineWidth (v) {
this.cmds.push(['lineWidth', v]);
this.style.lineWidth = v;
}
set lineCap (v) {
var lineCap = 'butt';
if (v === LineCap.BUTT) {
lineCap = 'butt';
}
else if (v === LineCap.ROUND) {
lineCap = 'round';
}
else if (v === LineCap.SQUARE) {
lineCap = 'square';
}
this.cmds.push(['lineCap', lineCap]);
this.style.lineCap = lineCap;
}
set lineJoin (v) {
var lineJoin = 'bevel';
if (v === LineJoin.BEVEL) {
lineJoin = 'bevel';
}
else if (v === LineJoin.ROUND) {
lineJoin = 'round';
}
else if (v === LineJoin.MITER) {
lineJoin = 'miter';
}
this.cmds.push(['lineJoin', lineJoin]);
this.style.lineJoin = lineJoin;
}
set miterLimit (v) {
this.cmds.push(['miterLimit', v]);
this.style.miterLimit = v;
}
moveTo (x, y) {
this.cmds.push(['moveTo', [x, y]]);
}
lineTo (x, y) {
this.cmds.push(['lineTo', [x, y]]);
}
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
this.cmds.push(['bezierCurveTo', [c1x, c1y, c2x, c2y, x, y]]);
}
quadraticCurveTo (cx, cy, x, y) {
this.cmds.push(['quadraticCurveTo', [cx, cy, x, y]]);
}
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
}
ellipse (cx, cy, rx, ry) {
Helper.ellipse(this, cx, cy, rx, ry);
}
circle (cx, cy, r) {
Helper.ellipse(this, cx, cy, r, r);
}
rect (x, y, w, h) {
this.moveTo(x, y);
this.lineTo(x, y + h);
this.lineTo(x + w, y + h);
this.lineTo(x + w, y);
this.close();
}
roundRect (x, y, w, h, r) {
Helper.roundRect(this, x, y, w, h, r);
}
clear (comp, clean) {
this.cmds.length = 0;
}
close () {
this.cmds.push(['closePath', []]);
}
stroke () {
this.cmds.push(['stroke', []]);
}
fill () {
this.cmds.push(['fill', []]);
}
}
module.exports = Impl;
@@ -0,0 +1,90 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Impl = require('./impl');
module.exports = {
createImpl () {
return new Impl();
},
draw (ctx, comp) {
let node = comp.node;
// Transform
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
ctx.transform(a, b, c, d, tx, -ty);
ctx.save();
ctx.scale(1, -1);
// TODO: handle blend function
// opacity
ctx.glphaAlpha = node.opacity / 255;
let style = comp._impl.style;
ctx.strokeStyle = style.strokeStyle;
ctx.fillStyle = style.fillStyle;
ctx.lineWidth = style.lineWidth;
ctx.lineJoin = style.lineJoin;
ctx.miterLimit = style.miterLimit;
let endPath = true;
let cmds = comp._impl.cmds;
for (let i = 0, l = cmds.length; i < l; i++) {
let cmd = cmds[i];
let ctxCmd = cmd[0], args = cmd[1];
if (ctxCmd === 'moveTo' && endPath) {
ctx.beginPath();
endPath = false;
}
else if (ctxCmd === 'fill' || ctxCmd === 'stroke' || ctxCmd === 'fillRect') {
endPath = true;
}
if (typeof ctx[ctxCmd] === 'function') {
ctx[ctxCmd].apply(ctx, args);
}
else {
ctx[ctxCmd] = args;
}
}
ctx.restore();
return 1;
},
stroke (comp) {
comp._impl.stroke();
},
fill (comp) {
comp._impl.fill();
}
}
@@ -29,14 +29,18 @@ let Sprite = require('../../../components/CCSprite');
let Label = require('../../../components/CCLabel');
let Mask = require('../../../components/CCMask');
let RichText = require('../../../components/CCRichText');
let Graphics = require('../../../graphics/graphics');
// the following should be placed into their own module folder
// let Graphics = require('../../../graphics/graphics');
// let ParticleSystem = require('../../../../particle/CCParticleSystem');
// let TiledLayer = require('../../../../tilemap/CCTiledLayer');
// let Skeleton = require('../../../../../extensions/spine/Skeleton');
// let Armature = require('../../../../../extensions/dragonbones/ArmatureDisplay');
let spriteRenderer = require('./sprite/');
let spriteRenderer = require('./sprite');
let labelRenderer = require('./label');
let graphicsRenderer = require('./graphics');
let maskRenderer = require('./mask');
let map = {};
let postMap = {};
@@ -48,13 +52,14 @@ function addRenderer (Component, handler, postHandler) {
postMap[name] = postHandler;
}
Component._assembler = handler;
Component._postAssembler = handler;
Component._postAssembler = postHandler;
}
addRenderer(Sprite, spriteRenderer);
addRenderer(Label, null);
addRenderer(Mask, null);
addRenderer(Label, labelRenderer);
addRenderer(Mask, maskRenderer.beforeHandler, maskRenderer.afterHandler);
addRenderer(RichText, null);
addRenderer(Graphics, graphicsRenderer);
module.exports = {
map,
@@ -0,0 +1,113 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const bmfontUtils = require('../../../utils/label/bmfont')
const js = require('../../../../platform/js');
const utils = require('../utils');
module.exports = js.addon({
createData (comp) {
return comp.requestRenderData();
},
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
let dataOffset = renderData.dataLength;
renderData.dataLength += 2;
let data = renderData._data;
let texw = texture.width,
texh = texture.height;
let rectWidth = rect.width,
rectHeight = rect.height;
let l, b, r, t;
if (!rotated) {
l = rect.x;
r = rect.x + rectWidth;
b = rect.y;
t = rect.y + rectHeight;
data[dataOffset].u = l;
data[dataOffset].v = b;
data[dataOffset+1].u = r;
data[dataOffset+1].v = t;
} else {
l = rect.x;
r = rect.x + rectHeight;
b = rect.y;
t = rect.y + rectWidth;
data[dataOffset].u = l;
data[dataOffset].v = t;
data[dataOffset+1].u = l;
data[dataOffset+1].v = b;
}
data[dataOffset].x = x;
data[dataOffset].y = y - rectHeight * scale;
data[dataOffset+1].x = x + rectWidth * scale;
data[dataOffset+1].y = y;
},
draw (ctx, comp) {
let node = comp.node;
// Transform
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
ctx.transform(a, b, c, d, tx, -ty);
// TODO: handle blend function
// opacity
ctx.glphaAlpha = node.opacity / 255;
let tex = comp._texture,
data = comp._renderData._data;
let image = utils.getColorizedImage(tex, node.color);
for (let i = 0, l = data.length; i < l; i+=2) {
let x = data[i].x;
let y = data[i].y;
let w = data[i+1].x - x;
let h = data[i+1].y - y;
y = - y - h;
let sx = data[i].u;
let sy = data[i].v;
let sw = data[i+1].u - sx;
let sh = data[i+1].v - sy;
ctx.drawImage(image,
sx, sy, sw, sh,
x, y, w, h);
}
return 1;
}
}, bmfontUtils);
@@ -2,7 +2,7 @@
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
@@ -13,7 +13,7 @@
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,5 +23,34 @@
THE SOFTWARE.
****************************************************************************/
require('./CCMotionStreak');
require('./motion-streak-assembler');
const ttf = require('./ttf');
const bmfont = require('./bmfont');
module.exports = {
getAssembler (comp) {
let assembler = ttf;
if (comp.font instanceof cc.BitmapFont) {
assembler = bmfont;
}
return assembler;
},
createData (comp) {
return comp._assembler.createData(comp);
},
draw (ctx, comp) {
// Check whether need to render
if (!comp._texture) {
return 0;
}
let assembler = comp._assembler;
if (!assembler) return 0;
assembler.update(comp);
return assembler.draw(ctx, comp);
}
};
@@ -0,0 +1,86 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const ttfUtils = require('../../../utils/label/ttf')
const js = require('../../../../platform/js');
const utils = require('../utils');
module.exports = js.addon({
createData (sprite) {
let renderData = sprite.requestRenderData();
// 0 for bottom left, 1 for top right
renderData.dataLength = 2;
return renderData;
},
_updateVerts (comp) {
let renderData = comp._renderData;
let node = comp.node,
width = node.width,
height = node.height,
appx = node.anchorX * width,
appy = node.anchorY * height;
let data = renderData._data;
data[0].x = -appx;
data[0].y = -appy;
data[1].x = width - appx;
data[1].y = height - appy;
},
_updateTexture (comp) {
ttfUtils._updateTexture(comp);
utils.dropColorizedImage(comp._texture, comp.node.color);
},
draw (ctx, comp) {
let node = comp.node;
// Transform
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
ctx.transform(a, b, c, d, tx, -ty);
// TODO: handle blend function
// opacity
ctx.glphaAlpha = node.opacity / 255;
let tex = comp._texture,
data = comp._renderData._data;
let image = utils.getColorizedImage(tex, node.color);
let x = data[0].x;
let y = data[0].y;
let w = data[1].x - x;
let h = data[1].y - y;
y = - y - h;
ctx.drawImage(image, x, y, w, h);
return 1;
}
}, ttfUtils);
@@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Node = require('../../../CCNode');
const Mask = require('../../../components/CCMask');
const Graphics = require('../../../graphics/graphics');
const graphicsHandler = require('./graphics');
// for nested mask, we might need multiple graphics component to avoid data conflict
let _graphicsPool = [];
function getGraphics () {
let graphics = _graphicsPool.pop();
if (!graphics) {
let graphicsNode = new Node();
graphics = graphicsNode.addComponent(Graphics);
graphics.lineWidth = 0;
}
return graphics;
}
let beforeHandler = {
updateGraphics (mask) {
let node = mask.node;
let graphics = mask._graphics;
// Share render data with graphics content
graphics.clear(false);
let width = node.width;
let height = node.height;
let x = -width * node.anchorX;
let y = -height * node.anchorY;
if (mask._type === Mask.Type.RECT) {
graphics.rect(x, y, width, height);
}
else if (mask._type === Mask.Type.ELLIPSE) {
let cx = x + width / 2,
cy = y + height / 2,
rx = width / 2,
ry = height / 2;
graphics.ellipse(cx, cy, rx, ry);
}
graphics.stroke();
},
draw (ctx, mask) {
let node = mask.node;
// Transform
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
ctx.save();
ctx.transform(a, b, c, d, tx, -ty);
// draw stencil
mask._graphics = getGraphics();
this.updateGraphics(mask);
graphicsHandler.draw(ctx, mask._graphics);
ctx.clip();
}
};
let afterHandler = {
draw (ctx, mask) {
ctx.restore();
}
};
module.exports = {
beforeHandler,
afterHandler
};
@@ -26,6 +26,7 @@
let SpriteType = require('../../../../components/CCSprite').Type;
let simple = require('./simple');
let sliced = require('./sliced');
let tiled = require('./tiled');
module.exports = {
getAssembler: function (sprite) {
@@ -35,7 +36,7 @@ module.exports = {
case SpriteType.SLICED:
return sliced;
case SpriteType.TILED:
return null;
return tiled;
case SpriteType.FILLED:
if (sprite._fillType === FillType.RADIAL) {
return null;
@@ -50,21 +51,6 @@ module.exports = {
return sprite._assembler.createData(sprite);
},
update (sprite) {
let renderData = sprite._renderData;
if (!renderData) {
return;
}
if (renderData.uvDirty) {
sprite._assembler.updateUVs(sprite);
}
if (renderData.vertDirty) {
sprite._assembler.updateVerts(sprite);
}
},
draw (ctx, sprite) {
let node = sprite.node;
// Check whether need to render
@@ -72,7 +58,7 @@ module.exports = {
return 0;
}
// update
this.update(sprite);
sprite._assembler.update(sprite);
return sprite._assembler.draw(ctx, sprite);
}
@@ -34,6 +34,21 @@ let renderer = {
return renderData;
},
update (sprite) {
let renderData = sprite._renderData;
if (!renderData) {
return;
}
if (renderData.uvDirty) {
this.updateUVs(sprite);
}
if (renderData.vertDirty) {
this.updateVerts(sprite);
}
},
updateUVs (sprite) {
let frame = sprite.spriteFrame;
let renderData = sprite._renderData;
@@ -43,9 +58,9 @@ let renderer = {
if (frame._rotated) {
let l = rect.x;
let r = rect.x + rect.height;
let r = rect.height;
let b = rect.y;
let t = rect.y + rect.width;
let t = rect.width;
data[0].u = l;
data[0].v = t;
data[1].u = r;
@@ -53,9 +68,9 @@ let renderer = {
}
else {
let l = rect.x;
let r = rect.x + rect.width;
let r = rect.width;
let b = rect.y;
let t = rect.y + rect.height;
let t = rect.height;
data[0].u = l;
data[0].v = b;
data[1].u = r;
@@ -75,8 +90,8 @@ let renderer = {
if (sprite.trim) {
l = -appx;
b = -appy;
r = cw - appx;
t = ch - appy;
r = cw;
t = ch;
}
else {
let frame = sprite.spriteFrame,
@@ -90,8 +105,8 @@ let renderer = {
let trimTop = offset.y - (oh - rh) / 2;
l = trimLeft * scaleX - appx;
b = trimBottom * scaleY - appy;
r = cw + trimRight * scaleX - appx;
t = ch + trimTop * scaleY - appy;
r = cw;
t = ch;
}
data[0].x = l;
@@ -122,14 +137,14 @@ let renderer = {
let x = data[0].x;
let y = data[0].y;
let w = data[1].x - x;
let h = data[1].y - y;
let w = data[1].x;
let h = data[1].y;
y = - y - h;
let sx = data[0].u;
let sy = data[0].v;
let sw = data[1].u - sx;
let sh = data[1].v - sy;
let sw = data[1].u;
let sh = data[1].v;
ctx.drawImage(image,
sx, sy, sw, sh,
@@ -24,6 +24,7 @@
****************************************************************************/
const utils = require('../utils');
const simple = require('./simple');
let renderer = {
createData (sprite) {
@@ -32,6 +33,8 @@ let renderer = {
renderData.dataLength = 4;
return renderData;
},
update: simple.update,
updateUVs (sprite) {
let frame = sprite.spriteFrame;
@@ -0,0 +1,73 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const utils = require('../utils');
const simple = require('./simple');
let renderer = {
createData (sprite) {
let renderData = sprite.requestRenderData();
return renderData;
},
update (sprite) {},
draw (ctx, sprite) {
let node = sprite.node;
// Transform
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
ctx.transform(a, b, c, d, tx, -ty);
// TODO: handle blend function
// opacity
ctx.glphaAlpha = node.opacity / 255;
let frame = sprite.spriteFrame;
let rect = frame._rect;
let tex = frame._texture;
let sx = rect.x;
let sy = rect.y;
let sw = frame._rotated ? rect.height : rect.width;
let sh = frame._rotated ? rect.width : rect.height;
let image = utils.getFrameCache(tex, node.color, sx, sy, sw, sh);
let w = node.width,
h = node.height,
x = -node.anchorX * w,
y = -node.anchorY * h;
y = - y - h;
ctx.translate(x, y);
ctx.fillStyle = ctx.createPattern(image, 'repeat');
ctx.fillRect(0, 0, w, h);
return 1;
}
}
module.exports = renderer
+103 -54
View File
@@ -24,28 +24,59 @@
****************************************************************************/
const WHITE = (255<<16) + (255<<8) + 255;
const MAX_CANVAS_COUNT = 32;
let textureColorizer = {
colorCanvas: {},
colorUsed: {},
function colorizedFrame (canvas, texture, color, sx, sy, sw, sh) {
let image = texture._image;
let ctx = canvas.getContext("2d");
canvas.width = sw;
canvas.height = sh;
// Draw color
ctx.globalCompositeOperation = 'source-over';
ctx.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')';
ctx.fillRect(0, 0, sw, sh);
// Multiply color with texture
ctx.globalCompositeOperation = 'multiply';
ctx.drawImage(image, sx, sy, sw, sh, 0, 0, sw, sh);
// Clip out transparent pixels
ctx.globalCompositeOperation = "destination-atop";
ctx.drawImage(image, sx, sy, sw, sh, 0, 0, sw, sh);
return canvas;
}
let canvasMgr = {
canvasMap: {},
canvasUsed: {},
canvasPool: [],
checking: false,
check () {
for (let key in this.colorUsed) {
if (!this.colorUsed[key]) {
let canvas = this.colorCanvas[key];
let exist = false;
for (let key in this.canvasUsed) {
exist = true;
if (!this.canvasUsed[key]) {
let canvas = this.canvasMap[key];
canvas.width = 0;
canvas.height = 0;
this.canvasPool.push(canvas);
delete this.colorCanvas[key];
delete this.colorUsed[key];
if (this.canvasPool.length < 32) {
this.canvasPool.push(canvas);
}
delete this.canvasMap[key];
delete this.canvasUsed[key];
}
else {
this.colorUsed[key] = false;
this.canvasUsed[key] = false;
}
}
if (!exist) {
cc.director.off(cc.Director.EVENT_AFTER_DRAW, this.check, this);
this.checking = false;
}
},
startCheck () {
@@ -53,11 +84,32 @@ let textureColorizer = {
this.checking = true;
},
getImage (texture, color) {
getCanvas (key) {
this.canvasUsed[key] = true;
return this.canvasMap[key];
},
cacheCanvas (canvas, key) {
this.canvasMap[key] = canvas;
this.canvasUsed[key] = true;
if (!this.checking) {
this.startCheck();
}
},
dropImage (key) {
if (this.canvasMap[key]) {
delete this.canvasMap[key];
}
}
};
module.exports = {
getColorizedImage (texture, color) {
if (!texture || !texture.url) {
return null;
}
// original image
let cval = color._val & 0x00ffffff;
if (cval === WHITE) {
@@ -66,50 +118,47 @@ let textureColorizer = {
// get from cache
let key = texture.url + cval;
if (this.colorCanvas[key]) {
this.colorUsed[key] = true;
return this.colorCanvas[key];
let cache = canvasMgr.getCanvas(key);
if (!cache) {
cache = canvasMgr.canvasPool.pop() || document.createElement("canvas");
colorizedFrame(cache, texture, color, 0, 0, texture.width, texture.height);
canvasMgr.cacheCanvas(cache, key);
}
let x = 0, y = 0, w = texture.width, h = texture.height;
let image = texture._image;
let canvas = this.canvasPool.pop() || document.createElement("canvas");
let ctx = canvas.getContext("2d");
canvas.width = w;
canvas.height = h;
// Draw color
ctx.globalCompositeOperation = 'source-over';
ctx.fillStyle = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ')';
ctx.fillRect(x, y, w, h);
// Multiply color with texture
ctx.globalCompositeOperation = 'multiply';
ctx.drawImage(image, x, y, w, h);
// Clip out transparent pixels
ctx.globalCompositeOperation = "destination-atop";
ctx.drawImage(image, x, y, w, h);
this.colorCanvas[key] = canvas;
this.colorUsed[key] = true;
if (!this.checking) {
this.startCheck();
}
return canvas;
return cache;
},
dropImage (texture, color) {
let key = texture.url + (color._val & 0x00ffffff);
if (this.colorCanvas[key]) {
delete this.colorCanvas[key];
}
}
};
module.exports = {
getColorizedImage (texture, color) {
return textureColorizer.getImage(texture, color);
getFrameCache (texture, color, sx, sy, sw, sh) {
if (!texture || !texture.url || sx < 0 || sy < 0 || sw <= 0 || sh <= 0) {
return null;
}
let key = texture.url;
let generate = false;
let cval = color._val & 0x00ffffff;
if (cval !== WHITE) {
key += cval;
generate = true;
}
if (sx !== 0 || sy !== 0 && sw !== texture.width && sh !== texture.height) {
key += '_' + sx + '_' + sy + '_' + sw + '_' + sh;
generate = true;
}
if (!generate) {
return texture._image;
}
// get from cache
let cache = canvasMgr.getCanvas(key);
if (!cache) {
cache = canvasMgr.canvasPool.pop() || document.createElement("canvas");
colorizedFrame(cache, texture, color, sx, sy, sw, sh);
canvasMgr.cacheCanvas(cache, key);
}
return cache;
},
dropColorizedImage (texture, color) {
let key = texture.url + (color._val & 0x00ffffff);
canvasMgr.dropImage(key);
}
};
+5 -1
View File
@@ -61,6 +61,8 @@ module.exports = {
_forward: null,
initWebGL (canvas, opts) {
require('./assemblers');
this.Texture2D = renderEngine.Texture2D;
this.canvas = canvas;
@@ -103,7 +105,9 @@ module.exports = {
this._forward = new renderEngine.ForwardRenderer(this.device, builtins);
},
initCanvas (canvas, canvasRenderer) {
initCanvas (canvas) {
let canvasRenderer = require('./canvas');
this.Texture2D = renderEngine.canvas.Texture2D;
this.canvas = canvas;
+7 -7
View File
@@ -13503,9 +13503,6 @@ var _a16_view = new Float32Array(16);
var _a16_proj = new Float32Array(16);
var _a16_viewProj = new Float32Array(16);
// Add stage to renderer
renderer.addStage('transparent');
var ForwardRenderer = (function (superclass) {
function ForwardRenderer (device, builtin) {
superclass.call(this, device, builtin);
@@ -14600,7 +14597,7 @@ var SpriteMaterial = (function (Material$$1) {
};
SpriteMaterial.prototype.clone = function clone () {
var copy = new SpriteMaterial(values);
var copy = new SpriteMaterial();
copy.texture = this.texture;
copy.useTexture = this.useTexture;
copy.useModel = this.useModel;
@@ -14672,7 +14669,7 @@ var GraySpriteMaterial = (function (Material$$1) {
};
GraySpriteMaterial.prototype.clone = function clone () {
var copy = new GraySpriteMaterial(values);
var copy = new GraySpriteMaterial();
copy.texture = this.texture;
copy.updateHash();
return copy;
@@ -14762,7 +14759,7 @@ var StencilMaterial = (function (Material$$1) {
};
StencilMaterial.prototype.clone = function clone () {
var copy = new StencilMaterial(values);
var copy = new StencilMaterial();
copy.useTexture = this.useTexture;
copy.texture = this.texture;
copy.alphaThreshold = this.alphaThreshold;
@@ -14903,7 +14900,7 @@ var ParticleMaterial = (function (Material$$1) {
};
ParticleMaterial.prototype.clone = function clone () {
var copy = new ParticleMaterial(values);
var copy = new ParticleMaterial();
copy.texture = this.texture;
copy.stateMap = this.stateMap;
copy.quadMap = this.quadMap;
@@ -15058,6 +15055,9 @@ var Device$4 = gfx.Device;
var Model$2 = renderer.Model;
var InputAssembler$2 = renderer.InputAssembler;
// Add stage to renderer
renderer.addStage('transparent');
var renderEngine = {
// core classes
Device: Device$4,
File diff suppressed because one or more lines are too long
@@ -31,8 +31,6 @@ const Overflow = Label.Overflow;
const TextUtils = require('../../../utils/text-utils').TextUtils;
const ttf = require('./ttf-assembler');
let FontLetterDefinition = function() {
this._u = 0;
this._v = 0;
@@ -136,10 +134,6 @@ let _labelHeight = 0;
let _maxLineWidth = 0;
module.exports = {
createData (comp) {
return comp.requestRenderData();
},
update (comp) {
if (!comp._renderData.vertDirty) return;
@@ -158,50 +152,6 @@ module.exports = {
this._resetProperties();
},
fillVertexBuffer (comp, off, vbuf, uintbuf) {
let node = comp.node;
let renderData = comp._renderData;
let data = renderData._data;
let z = node._position.z;
let color = node.color._val;
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let a = matrix.m00,
b = matrix.m01,
c = matrix.m04,
d = matrix.m05,
tx = matrix.m12,
ty = matrix.m13;
let vert;
let length = renderData.dataLength;
for (let i = 0; i < length; i++) {
vert = data[i];
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
vbuf[off + 2] = z;
vbuf[off + 4] = vert.u;
vbuf[off + 5] = vert.v;
uintbuf[off + 3] = color;
off += 6;
}
},
fillIndexBuffer (comp, offset, vertexId, ibuf) {
let renderData = comp._renderData;
let length = renderData.indiceCount;
for (let i = 0; i < length; i+=6) {
ibuf[offset++] = vertexId;
ibuf[offset++] = vertexId+1;
ibuf[offset++] = vertexId+2;
ibuf[offset++] = vertexId+1;
ibuf[offset++] = vertexId+3;
ibuf[offset++] = vertexId+2;
vertexId += 4;
}
},
_updateFontScale () {
_bmfontScale = _fontSize / _originFontSize;
},
@@ -724,58 +674,6 @@ module.exports = {
},
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
let dataOffset = renderData.dataLength;
renderData.dataLength += 4;
renderData.vertexCount = renderData.dataLength;
renderData.indiceCount = renderData.dataLength / 2 * 3;
let data = renderData._data;
let texw = texture.width,
texh = texture.height;
let rectWidth = rect.width,
rectHeight = rect.height;
let l, b, r, t;
if (!rotated) {
l = (rect.x) / texw;
r = (rect.x + rectWidth) / texw;
b = (rect.y + rectHeight) / texh;
t = (rect.y) / texh;
data[dataOffset].u = l;
data[dataOffset].v = b;
data[dataOffset+1].u = r;
data[dataOffset+1].v = b;
data[dataOffset+2].u = l;
data[dataOffset+2].v = t;
data[dataOffset+3].u = r;
data[dataOffset+3].v = t;
} else {
l = (rect.x) / texw;
r = (rect.x + rectHeight) / texw;
b = (rect.y + rectWidth) / texh;
t = (rect.y) / texh;
data[dataOffset].u = l;
data[dataOffset].v = t;
data[dataOffset+1].u = l;
data[dataOffset+1].v = b;
data[dataOffset+2].u = r;
data[dataOffset+2].v = t;
data[dataOffset+3].u = r;
data[dataOffset+3].v = b;
}
data[dataOffset].x = x;
data[dataOffset].y = y - rectHeight * scale;
data[dataOffset+1].x = x + rectWidth * scale;
data[dataOffset+1].y = y - rectHeight * scale;
data[dataOffset+2].x = x;
data[dataOffset+2].y = y;
data[dataOffset+3].x = x + rectWidth * scale;
data[dataOffset+3].y = y;
},
_computeAlignmentOffset: function() {
@@ -33,8 +33,6 @@ const Overflow = Label.Overflow;
const TextUtils = utils.TextUtils;
const CustomFontLoader = utils.CustomFontLoader;
const spriteAssembler = require('../sprite/simple');
let _comp = null;
let _context = null;
@@ -72,64 +70,6 @@ let _isItalic = false;
let _isUnderline = false;
module.exports = {
createData (comp) {
let renderData = comp.requestRenderData();
renderData.dataLength = 4;
renderData.vertexCount = 4;
renderData.indiceCount = 6;
let data = renderData._data;
data[0].u = 0;
data[0].v = 1;
data[1].u = 1;
data[1].v = 1;
data[2].u = 0;
data[2].v = 0;
data[3].u = 1;
data[3].v = 0;
return renderData;
},
fillVertexBuffer (comp, off, vbuf, uintbuf) {
let node = comp.node;
let renderData = comp._renderData;
let data = renderData._data;
let z = node._position.z;
let color = cc.Color.WHITE._val;
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let a = matrix.m00,
b = matrix.m01,
c = matrix.m04,
d = matrix.m05,
tx = matrix.m12,
ty = matrix.m13;
let vert;
let length = renderData.dataLength;
for (let i = 0; i < length; i++) {
vert = data[i];
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
vbuf[off + 2] = z;
vbuf[off + 4] = vert.u;
vbuf[off + 5] = vert.v;
uintbuf[off + 3] = color;
off += 6;
}
},
fillIndexBuffer (comp, offset, vertexId, ibuf) {
ibuf[offset + 0] = vertexId;
ibuf[offset + 1] = vertexId + 1;
ibuf[offset + 2] = vertexId + 2;
ibuf[offset + 3] = vertexId + 1;
ibuf[offset + 4] = vertexId + 3;
ibuf[offset + 5] = vertexId + 2;
},
update (comp) {
if (!comp._renderData.vertDirty) return;
@@ -141,13 +81,13 @@ module.exports = {
this._calculateSplitedStrings();
this._updateLabelDimensions();
this._calculateTextBaseline();
this._updateTexture();
this._updateVerts();
this._updateTexture(_comp);
_comp._actualFontSize = _fontSize;
_comp.node.setContentSize(_canvasSize);
this._updateVerts(_comp);
_comp._renderData.vertDirty = _comp._renderData.uvDirty = false;
_context = null;
@@ -159,22 +99,6 @@ module.exports = {
},
_updateVerts () {
let renderData = _comp._renderData;
let width = _canvasSize.width,
height = _canvasSize.height,
appx = renderData._pivotX * width,
appy = renderData._pivotY * height;
let data = renderData._data;
data[0].x = -appx;
data[0].y = -appy;
data[1].x = width - appx;
data[1].y = -appy;
data[2].x = -appx;
data[2].y = height - appy;
data[3].x = width - appx;
data[3].y = height - appy;
},
_updateFontFamly () {
@@ -197,8 +121,9 @@ module.exports = {
},
_updateProperties () {
_context = _comp._context;
_canvas = _comp._canvas;
let assemblerData = _comp._assemblerData;
_context = assemblerData._context;
_canvas = assemblerData._canvas;
_texture = _comp._texture;
_string = _comp.string.toString();
@@ -267,7 +192,7 @@ module.exports = {
return cc.v2(labelX, firstLinelabelY);
},
_updateTexture () {
_updateTexture (comp) {
_context.clearRect(0, 0, _canvas.width, _canvas.height);
_context.font = _fontDesc;
+1 -1
View File
@@ -25,7 +25,7 @@
****************************************************************************/
require('./CCPath');
if (!CC_EDITOR && !CC_JSB && !CC_WECHATGAME && !CC_QQPLAY) {
if (!CC_EDITOR) {
require('./profiler/CCProfiler');
}
require('./find');
+11
View File
@@ -271,6 +271,8 @@ if (CC_DEV) {
// cc.Node
markAsRemoved(cc._BaseNode, [
'tag',
'getTag',
'setTag',
'getChildByTag',
'removeChildByTag'
]);
@@ -291,6 +293,7 @@ if (CC_DEV) {
'isIgnoreAnchorPointForPosition',
'ignoreAnchorPointForPosition',
'isRunning',
'_sgNode',
]);
markFunctionWarning(cc.Node.prototype, {
@@ -317,6 +320,10 @@ if (CC_DEV) {
setSkewX: 'skewX',
getSkewY: 'skewY',
setSkewY: 'skewY',
getScaleX: 'scaleX',
setScaleX: 'scaleX',
getScaleY: 'scaleY',
setScaleY: 'scaleY',
getOpacity: 'opacity',
setOpacity: 'opacity',
getColor: 'color',
@@ -459,6 +466,10 @@ if (CC_DEV) {
rand: 'Math.random() * 0xffffff',
randomMinus1To1: '(Math.random() - 0.5) * 2',
container: 'cc.game.container',
_canvas: 'cc.game.canvas',
_renderType: 'cc.game.renderType',
}, 'cc');
markAsRemovedInObject(cc, [
'BlendFunc',
+16 -13
View File
@@ -428,6 +428,12 @@ let TiledMap = cc.Class({
// refresh layer entities
this._applyFile();
}
this.node.on('anchor-changed', this._syncAnchorPoint, this);
},
onDisable () {
this.node.off('anchor-changed', this._syncAnchorPoint, this);
},
_applyFile () {
@@ -459,6 +465,13 @@ let TiledMap = cc.Class({
this._buildWithMapInfo(mapInfo);
}
},
_syncAnchorPoint () {
let anchor = this.node.getAnchorPoint();
for (let i = 0, l = this._layers.length; i < l; i++) {
this._layers[i].node.setAnchorPoint(anchor);
}
},
_buildWithMapInfo (mapInfo) {
this._mapSize = mapInfo.getMapSize();
@@ -491,7 +504,6 @@ let TiledMap = cc.Class({
if (!child) {
child = new cc.Node();
child.name = name;
child.setAnchorPoint(0.5, 0.5);
node.addChild(child);
}
@@ -509,8 +521,8 @@ let TiledMap = cc.Class({
layerInfo.ownTiles = false;
// update content size with the max size
this.width = Math.max(this.width, child.width);
this.height = Math.max(this.height, child.height);
this.node.width = Math.max(this.node.width, child.width);
this.node.height = Math.max(this.node.height, child.height);
layers.push(layer);
}
@@ -525,17 +537,8 @@ let TiledMap = cc.Class({
}
}
}
},
_parseLayer (layerInfo, mapInfo) {
let node = new cc.Node();
let layer = node.addComponent(cc.TiledLayer);
let tileset = this._tilesetForLayer(layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layer.init(tileset, layerInfo, mapInfo);
layerInfo.ownTiles = false;
return node;
this._syncAnchorPoint();
},
_tilesetForLayer (layerInfo, mapInfo) {
+16 -16
View File
@@ -41,6 +41,7 @@ const mat4 = math.mat4;
const vec3 = math.vec3;
let _mat4_temp = mat4.create();
let _mat4_temp2 = mat4.create();
let _vec3_temp = vec3.create();
let tmxAssembler = js.addon({
@@ -105,15 +106,17 @@ let tmxAssembler = js.addon({
if (!tiles || !comp._tileset) {
return;
}
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
let appx = node._anchorPoint.x * node._contentSize.width,
appy = node._anchorPoint.y * node._contentSize.height;
node.getWorldMatrix(_mat4_temp);
vec3.set(_vec3_temp, -appx, -appy, 0);
mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp);
let a = _mat4_temp.m00, b = _mat4_temp.m01, c = _mat4_temp.m04, d = _mat4_temp.m05,
tx = _mat4_temp.m12, ty = _mat4_temp.m13;
let maptw = comp._mapTileSize.width,
mapth = comp._mapTileSize.height,
tilew = comp._tileset._tileSize.width,
@@ -144,8 +147,8 @@ let tmxAssembler = js.addon({
if (enabledCulling) {
let camera = cc.Camera.findCamera(comp.node);
if (camera) {
camera.getWorldToCameraMatrix(_mat4_temp);
mat4.mul(_mat4_temp, matrix, _mat4_temp);
camera.getWorldToCameraMatrix(_mat4_temp2);
mat4.mul(_mat4_temp, _mat4_temp, _mat4_temp2);
cullingA = _mat4_temp.m00;
cullingD = _mat4_temp.m05;
cullingMapx = ox * cullingA + oy * _mat4_temp.m04 + _mat4_temp.m12;
@@ -155,7 +158,7 @@ let tmxAssembler = js.addon({
}
if (layerOrientation === Orientation.ORTHO) {
cc.vmath.mat4.invert(_mat4_temp, matrix);
mat4.invert(_mat4_temp, _mat4_temp);
let rect = cc.visibleRect;
let a = _mat4_temp.m00, b = _mat4_temp.m01, c = _mat4_temp.m04, d = _mat4_temp.m05,
@@ -249,16 +252,13 @@ let tmxAssembler = js.addon({
// transform
a2 = a; b2 = b; c2 = c; d2 = d; tx2 = tx; ty2 = ty;
tiledNode._updateLocalMatrix();
cc.vmath.mat4.copy(_mat4_temp, tiledNode._mat4_temp);
_vec3_temp.x = -left; _vec3_temp.y = -bottom; _vec3_temp.z = 0;
cc.vmath.mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp);
cc.vmath.mat4.multiply(_mat4_temp, matrix, _mat4_temp);
mat4.copy(_mat4_temp, tiledNode._mat4_temp);
vec3.set(_vec3_temp, -left, -bottom, 0);
mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp);
mat4.multiply(_mat4_temp, node._worldMatrix, _mat4_temp);
a = _mat4_temp.m00; b = _mat4_temp.m01; c = _mat4_temp.m04; d = _mat4_temp.m05;
tx = _mat4_temp.m12; ty = _mat4_temp.m13;
}
left -= appx;
bottom -= appy;
right = left + tilew;
top = bottom + tileh;
-1
View File
@@ -36,7 +36,6 @@ else {
require('./cocos2d/tilemap');
require('./cocos2d/videoplayer/CCVideoPlayer');
require('./cocos2d/webview/CCWebView');
require('./cocos2d/motion-streak');
require('./cocos2d/core/components/CCStudioComponent');
require('./extensions/ccpool/CCNodePool');
require('./cocos2d/actions');
@@ -0,0 +1,79 @@
const Armature = require('./ArmatureDisplay');
const renderEngine = require('../../cocos2d/core/renderer/render-engine');
const math = renderEngine.math;
const utils = require('../../cocos2d/core/renderer/canvas/renderers/utils');
let _color = cc.color();
let _matrix = math.mat4.create();
let _matrix2 = math.mat4.create();
let armatureAssembler = {
draw (ctx, comp) {
let armature = comp._armature;
if (!armature || comp._isChildArmature) return 0;
ctx.save();
let node = comp.node;
node._updateWorldMatrix();
let matrix = node._worldMatrix;
let texture = comp.dragonAtlasAsset.texture;
this.drawArmature(ctx, armature, texture, matrix);
ctx.restore();
return 1;
},
drawArmature (ctx, armature, texture, matrix) {
let slots = armature._slots;
for (let i = 0, l = slots.length; i < l; i++) {
let slot = slots[i];
if (!slot._visible || !slot._displayData) continue;
if (slot.childArmature) {
math.mat4.mul(_matrix, matrix, slot._matrix);
this.drawArmature(ctx, slot.childArmature, texture, _matrix);
continue;
}
let localVertices = slot._localVertices;
if (localVertices.length !== 4) {
continue;
}
ctx.save();
math.mat4.mul(_matrix2, matrix, slot._matrix);
let m = _matrix2;
ctx.transform(m.m00, -m.m01, -m.m04, m.m05, m.m12, -m.m13);
let vertices = slot._vertices;
let sx = vertices[0].u * texture.width;
let sy = vertices[3].v * texture.height;
let sw = vertices[3].u * texture.width - sx;
let sh = vertices[0].v * texture.height - sy;
let x = localVertices[0].x;
let y = localVertices[0].y;
let w = localVertices[3].x - x;
let h = localVertices[3].y - y;
y = -y-h;
_color._val = slot._color;
let image = utils.getFrameCache(texture, _color, sx, sy, sw, sh);
ctx.drawImage(image, x, y, w, h);
ctx.restore();
}
}
};
module.exports = Armature._assembler = armatureAssembler;
+8 -1
View File
@@ -132,7 +132,14 @@ if (!CC_EDITOR || !Editor.isMainProcess) {
require('./DragonBonesAtlasAsset');
require('./ArmatureDisplay')
require('./dragonbones-assembler');
cc.game.once(cc.game.EVENT_RENDERER_INITED, () => {
if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
require('./canvas-assembler');
}
else {
require('./webgl-assembler');
}
})
} else {
require('./DragonBonesAsset');
require('./DragonBonesAtlasAsset');
+2 -1
View File
@@ -41,10 +41,11 @@ const Optimizejs = require('gulp-optimize-js');
var jsbSkipModules = [
'../../cocos2d/audio/CCAudio',
// '../../external/box2d/box2d.js',
// '../../external/chipmunk/chipmunk.js'
];
var aliasifyConfig = {
replacements: {
'(.*)render-engine(.js)?': './cocos2d/core/renderer/render-engine.jsb'
'(.*)render-engine(.js)?': require.resolve('../../cocos2d/core/renderer/render-engine.jsb')
},
verbose: false
};
+4 -1
View File
@@ -26,6 +26,9 @@
// PREDEFINE
// window may be undefined when first load engine from editor
var _global = typeof window === 'undefined' ? global : window;
/**
* !#en
* The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.
@@ -34,7 +37,7 @@
* @module cc
* @main cc
*/
cc = {};
cc = _global.cc || {};
require('./predefine');
require('./CCDebugger');
+1 -1
View File
@@ -1,3 +1,3 @@
{
"presets":["es2015"]
"presets":["env"]
}
+229
View File
@@ -0,0 +1,229 @@
/* Blob.js
* A Blob implementation.
* 2017-11-15
*
* By Eli Grey, http://eligrey.com
* By Devin Samarin, https://github.com/dsamarin
* License: MIT
* See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
*/
/*global self, unescape */
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
plusplus: true */
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
(function(global) {
(function (factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["exports"], factory);
} else if (typeof exports === "object" && typeof exports.nodeName !== "string") {
// CommonJS
factory(exports);
} else {
// Browser globals
factory(global);
}
})(function (exports) {
"use strict";
exports.URL = global.URL || global.webkitURL;
if (global.Blob && global.URL) {
try {
new Blob;
return;
} catch (e) {}
}
// Internally we use a BlobBuilder implementation to base Blob off of
// in order to support older browsers that only have BlobBuilder
var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MozBlobBuilder || (function() {
var
get_class = function(object) {
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
}
, FakeBlobBuilder = function BlobBuilder() {
this.data = [];
}
, FakeBlob = function Blob(data, type, encoding) {
this.data = data;
this.size = data.length;
this.type = type;
this.encoding = encoding;
}
, FBB_proto = FakeBlobBuilder.prototype
, FB_proto = FakeBlob.prototype
, FileReaderSync = global.FileReaderSync
, FileException = function(type) {
this.code = this[this.name = type];
}
, file_ex_codes = (
"NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
+ "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
).split(" ")
, file_ex_code = file_ex_codes.length
, real_URL = global.URL || global.webkitURL || exports
, real_create_object_URL = real_URL.createObjectURL
, real_revoke_object_URL = real_URL.revokeObjectURL
, URL = real_URL
, btoa = global.btoa
, atob = global.atob
, ArrayBuffer = global.ArrayBuffer
, Uint8Array = global.Uint8Array
, origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/
;
FakeBlob.fake = FB_proto.fake = true;
while (file_ex_code--) {
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
}
// Polyfill URL
if (!real_URL.createObjectURL) {
URL = exports.URL = function(uri) {
var
uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
, uri_origin
;
uri_info.href = uri;
if (!("origin" in uri_info)) {
if (uri_info.protocol.toLowerCase() === "data:") {
uri_info.origin = null;
} else {
uri_origin = uri.match(origin);
uri_info.origin = uri_origin && uri_origin[1];
}
}
return uri_info;
};
}
URL.createObjectURL = function(blob) {
var
type = blob.type
, data_URI_header
;
if (type === null) {
type = "application/octet-stream";
}
if (blob instanceof FakeBlob) {
data_URI_header = "data:" + type;
if (blob.encoding === "base64") {
return data_URI_header + ";base64," + blob.data;
} else if (blob.encoding === "URI") {
return data_URI_header + "," + decodeURIComponent(blob.data);
} if (btoa) {
return data_URI_header + ";base64," + btoa(blob.data);
} else {
return data_URI_header + "," + encodeURIComponent(blob.data);
}
} else if (real_create_object_URL) {
return real_create_object_URL.call(real_URL, blob);
}
};
URL.revokeObjectURL = function(object_URL) {
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
real_revoke_object_URL.call(real_URL, object_URL);
}
};
FBB_proto.append = function(data/*, endings*/) {
var bb = this.data;
// decode data to a binary string
if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
var
str = ""
, buf = new Uint8Array(data)
, i = 0
, buf_len = buf.length
;
for (; i < buf_len; i++) {
str += String.fromCharCode(buf[i]);
}
bb.push(str);
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
if (FileReaderSync) {
var fr = new FileReaderSync;
bb.push(fr.readAsBinaryString(data));
} else {
// async FileReader won't work as BlobBuilder is sync
throw new FileException("NOT_READABLE_ERR");
}
} else if (data instanceof FakeBlob) {
if (data.encoding === "base64" && atob) {
bb.push(atob(data.data));
} else if (data.encoding === "URI") {
bb.push(decodeURIComponent(data.data));
} else if (data.encoding === "raw") {
bb.push(data.data);
}
} else {
if (typeof data !== "string") {
data += ""; // convert unsupported types to strings
}
// decode UTF-16 to binary string
bb.push(unescape(encodeURIComponent(data)));
}
};
FBB_proto.getBlob = function(type) {
if (!arguments.length) {
type = null;
}
return new FakeBlob(this.data.join(""), type, "raw");
};
FBB_proto.toString = function() {
return "[object BlobBuilder]";
};
FB_proto.slice = function(start, end, type) {
var args = arguments.length;
if (args < 3) {
type = null;
}
return new FakeBlob(
this.data.slice(start, args > 1 ? end : this.data.length)
, type
, this.encoding
);
};
FB_proto.toString = function() {
return "[object Blob]";
};
FB_proto.close = function() {
this.size = 0;
delete this.data;
};
return FakeBlobBuilder;
}());
exports.Blob = function(blobParts, options) {
var type = options ? (options.type || "") : "";
var builder = new BlobBuilder();
if (blobParts) {
for (var i = 0, len = blobParts.length; i < len; i++) {
if (Uint8Array && blobParts[i] instanceof Uint8Array) {
builder.append(blobParts[i].buffer);
}
else {
builder.append(blobParts[i]);
}
}
}
var blob = builder.getBlob(type);
if (!blob.slice && blob.webkitSlice) {
blob.slice = blob.webkitSlice;
}
return blob;
};
var getPrototypeOf = Object.getPrototypeOf || function(object) {
return object.__proto__;
};
exports.Blob.prototype = getPrototypeOf(new exports.Blob());
});
})(
typeof self !== "undefined" && self ||
typeof window !== "undefined" && window ||
typeof global !== "undefined" && global ||
this.content || this
);
+1
View File
@@ -0,0 +1 @@
!function(){function e(e){this.message=e}var t="undefined"!=typeof exports?exports:"undefined"!=typeof self?self:$.global,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.prototype=new Error,e.prototype.name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var o,n,a=String(t),i=0,f=r,c="";a.charAt(0|i)||(f="=",i%1);c+=f.charAt(63&o>>8-i%1*8)){if(n=a.charCodeAt(i+=.75),n>255)throw new e("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|n}return c}),t.atob||(t.atob=function(t){var o=String(t).replace(/[=]+$/,"");if(o.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,a,i=0,f=0,c="";a=o.charAt(f++);~a&&(n=i%4?64*n+a:a,i++%4)?c+=String.fromCharCode(255&n>>(-2*i&6)):0)a=r.indexOf(a);return c})}();
+7 -3
View File
@@ -22,10 +22,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
// window.CC_JSB = true;
window.CC_JSB = true;
// console.log("CC_JSB:" + CC_JSB);
window.CC_WECHATGAME = true;
// Simulate wechat game API:
@@ -168,6 +166,12 @@ jsb.urlRegExp = new RegExp("^(?:https?|ftp)://\\S*$", "i");
require('./jsb_prepare');
require('./jsb_opengl');
const { btoa, atob } = require('./base64/base64.min');
window.btoa = btoa;
window.atob = atob;
const { Blob, URL } = require('./Blob');
window.Blob = Blob;
window.URL = URL;
window.DOMParser = require('./xmldom/dom-parser').DOMParser;
require('./jsb-adapter');
require('./jsb_audioengine');
+1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let HTMLAudioElement = require('./HTMLAudioElement');
const HAVE_NOTHING = 0
+13 -21
View File
@@ -22,26 +22,18 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const { screenWidth, screenHeight, devicePixelRatio } = {screenWidth: window.innerWidth, screenHeight: window.innerHeight, devicePixelRatio: 1};//cjh wx.getSystemInfoSync()
const innerWidth = screenWidth
const innerHeight = screenHeight
const screen = {
availWidth: innerWidth,
availHeight: innerHeight
class DOMRect {
constructor(x, y, width, height) {
this.x = x ? x : 0;
this.y = y ? y : 0;
this.width = width ? width : 0;
this.height = height ? height : 0;
this.left = this.x;
this.top = this.y;
this.right = this.x + this.width;
this.bottom = this.y + this.height;
}
}
const performance = null//cjh wx.getPerformance()
const ontouchstart = null
const ontouchmove = null
const ontouchend = null
module.exports = {
innerWidth: innerWidth,
innerHeight: innerHeight,
devicePixelRatio: devicePixelRatio,
screen: screen,
performance: performance,
ontouchstart: ontouchstart,
ontouchmove: ontouchmove,
ontouchend: ontouchend
};
module.exports = DOMRect;
+27 -6
View File
@@ -22,14 +22,35 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let Node = require('./Node');
const Node = require('./Node');
const DOMRect = require('./DOMRect');
class Element extends Node {
constructor() {
super()
this.className = ''
this.children = []
}
constructor() {
super()
this.className = ''
this.children = []
this.clientLeft = 0;
this.clientTop = 0;
}
get clientWidth() {
return 0;
}
get clientHeight() {
return 0;
}
getBoundingClientRect() {
return new DOMRect();
}
// attrName is a string that names the attribute to be removed from element.
removeAttribute(attrName) {
}
}
module.exports = Element;
+26 -6
View File
@@ -23,12 +23,32 @@
THE SOFTWARE.
****************************************************************************/
/*
* TODO 使用 wx.readFile 来封装 FileReader
*/
class FileReader {
construct() {
}
const EventTarget = require('./EventTarget')
class FileReader extends EventTarget {
construct() {
this.result = null
}
// Aborts the read operation. Upon return, the readyState will be DONE.
abort() {}
// Starts reading the contents of the specified Blob, once finished, the result attribute contains an ArrayBuffer representing the file's data.
readAsArrayBuffer() {
}
// Starts reading the contents of the specified Blob, once finished, the result attribute contains a data: URL representing the file's data.
readAsDataURL(blob) {
this.result = 'data:image/png;base64,' + window.btoa(blob);
this.onload();
}
// Starts reading the contents of the specified Blob, once finished, the result attribute contains the contents of the file as a text string.
readAsText() {
}
}
module.exports = FileReader;
+1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let EventTarget = require('./EventTarget')
let Event = require('./Event')
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let HTMLMediaElement = require('./HTMLMediaElement');
class HTMLAudioElement extends HTMLMediaElement {
@@ -22,8 +22,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const HTMLElement = require('./HTMLElement');
const ImageData = require('./ImageData');
const DOMRect = require('./DOMRect');
class CanvasGradient {
constructor() {
@@ -276,6 +278,18 @@ class HTMLCanvasElement extends HTMLElement {
return this._height;
}
get clientWidth() {
return this._width;
}
get clientHeight() {
return this._height;
}
getBoundingClientRect() {
return new DOMRect(0, 0, this._width, this._height);
}
addEventListener(eventName, listener, options) {
let ret = super.addEventListener(eventName, listener, options);
if (ret) {
@@ -317,6 +331,10 @@ ctx2DProto.drawImage = function(image, sx, sy, sWidth, sHeight, dx, dy, dWidth,
//TODO:cjh
}
//TODO:cjh
ctx2DProto.bezierCurveTo = function() {}
ctx2DProto.fill = function() {}
function touchEventHandlerFactory(type) {
return (touches) => {
const touchEvent = new TouchEvent(type)
+3 -24
View File
@@ -22,9 +22,9 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Element = require('./Element');
const { noop } = require('./util');
const { innerWidth, innerHeight } = require('./WindowProperties');
class HTMLElement extends Element {
@@ -35,8 +35,8 @@ class HTMLElement extends Element {
this.className = ''
this.children = []
this.style = {
width: `${innerWidth}px`,
height: `${innerHeight}px`
width: `${window.innerWidth}px`,
height: `${window.innerHeight}px`
}
this.insertBefore = noop
@@ -53,27 +53,6 @@ class HTMLElement extends Element {
return this[name]
}
get clientWidth() {
const ret = parseInt(this.style.fontSize, 10) * this.innerHTML.length
return Number.isNaN(ret) ? 0 : ret
}
get clientHeight() {
const ret = parseInt(this.style.fontSize, 10)
return Number.isNaN(ret) ? 0 : ret
}
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: innerWidth,
height: innerHeight
}
}
focus() {
}
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const HTMLElement = require('./HTMLElement');
const Event = require('./Event');
@@ -77,6 +78,18 @@ class HTMLImageElement extends HTMLElement {
get src() {
return this._src;
}
get clientWidth() {
return this.width;
}
get clientHeight() {
return this.height;
}
getBoundingClientRect() {
return new DOMRect(0, 0, this.width, this.height);
}
}
module.exports = HTMLImageElement;
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let HTMLElement = require('./HTMLElement');
class HTMLMediaElement extends HTMLElement {
+1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let HTMLImageElement = require('./HTMLImageElement');
function Image (width, height) {
+1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
class ImageData {
// var imageData = new ImageData(array, width, height);
+1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let EventTarget = require('./EventTarget');
class Node extends EventTarget {
+9 -2
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let HTMLElement = require('./HTMLElement');
let Image = require('./Image');
let Audio = require('./Audio');
@@ -38,12 +39,18 @@ class Document extends Node {
this.documentElement = window
this.hidden = false
this.style = {}
this.location = window.location
this.location = require('./location')
this.head = new HTMLElement('head')
this.body = new HTMLElement('body')
this.fonts = new FontFaceSet()
this.scripts = []
}
createElementNS(namespaceURI, qualifiedName, options) {
return this.createElement(qualifiedName);
}
createElement(tagName) {
@@ -98,7 +105,7 @@ class Document extends Node {
return document.head
} else if (query === 'body') {
return document.body
} else if (query === 'canvas' || query === 'GameCanvas') {
} else if (query === 'canvas') {
return window.canvas
} else if (query === `#${window.canvas.id}`) {
return window.canvas
+2
View File
@@ -22,8 +22,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const location = {
href: 'game.js',
hash: '',
reload() {
}
}
+4 -1
View File
@@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let { noop } = require('./util');
// TODO 需要 wx.getSystemInfo 获取更详细信息
@@ -38,7 +39,9 @@ const navigator = {
getCurrentPosition: noop,
watchPosition: noop,
clearWatch: noop
}
},
maxTouchPoints: 10 //FIXME: getting the number from OS.
}
module.exports = navigator;
+36 -11
View File
@@ -22,10 +22,20 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
function inject () {
window.top = window.parent = window
window.ontouchstart = null;
window.ontouchmove = null;
window.ontouchend = null;
window.ontouchcancel = null;
window.pageXOffset = window.pageYOffset = window.clientTop = window.clientLeft = 0;
window.location = require('./location');
window.document = require('./document');
window.Element = require('./Element');
window.HTMLElement = require('./HTMLElement');
window.HTMLCanvasElement = require('./HTMLCanvasElement');
window.HTMLImageElement = require('./HTMLImageElement');
@@ -38,17 +48,29 @@ function inject () {
window.Image = require('./Image');
window.Audio = require('./Audio');
window.FileReader = require('./FileReader');
window.location = require('./location');
window.FontFace = require('./FontFace');
window.FontFaceSet = require('./FontFaceSet');
window.EventTarget = require('./EventTarget');
window.Event = require('./Event');
window.TouchEvent = require('./TouchEvent');
window.ontouchstart = null;
window.ontouchmove = null;
window.ontouchend = null;
window.ontouchcancel = null;
window.devicePixelRatio = 1.0;
window.screen = {
availTop: 0,
availLeft: 0,
availHeight: window.innerWidth,
availWidth: window.innerHeight,
colorDepth: 8,
pixelDepth: 8,
left: 0,
top: 0,
width: window.innerWidth,
height: window.innerHeight,
orientation: { //FIXME:cjh
type: 'portrait-primary' // portrait-primary, portrait-secondary, landscape-primary, landscape-secondary
},
onorientationchange: function(event) {}
};
window.addEventListener = function(eventName, listener, options) {
window.canvas.addEventListener(eventName, listener, options);
@@ -62,6 +84,15 @@ function inject () {
window.canvas.dispatchEvent(event);
}
window.getComputedStyle = function(element) {
return {
position: 'absolute',
left: '0px',
top: '0px',
height: '0px'
};
}
window._isInjected = true;
}
@@ -69,11 +100,5 @@ if (!window._isInjected) {
inject();
}
window.canvas.getContext = function(name) {
if (name === 'webgl' || name === 'experimental-webgl') {
return window.gl;
}
return null;
};
window.localStorage = sys.localStorage;
+55 -14
View File
@@ -30,10 +30,8 @@
require('./jsb_opengl_constants');
window.gl = window.gl || {};
gl.canvas = {
clientWidth: window.innerWidth,
clientHeight: window.innerHeight
};
gl.drawingBufferWidth = window.innerWidth;
gl.drawingBufferHeight = window.innerHeight;
//
// Create functions
@@ -52,7 +50,7 @@ gl.createBuffer = function() {
gl.createRenderbuffer = function() {
// Returns a "WebGLRenderBuffer" object
var ret = gl._createRenderuffer();
var ret = gl._createRenderbuffer();
return { renderbuffer_id:ret};
};
@@ -164,7 +162,7 @@ gl.bindBuffer = function(target, buffer) {
};
// void bindRenderbuffer(GLenum target, WebGLRenderbuffer? renderbuffer);
gl.bindRenderBuffer = function(target, buffer) {
gl.bindRenderbuffer = function(target, buffer) {
var buffer_id;
// Accept numbers too. eg: gl.bindRenderbuffer(0)
@@ -173,7 +171,7 @@ gl.bindRenderBuffer = function(target, buffer) {
else if (buffer === null)
buffer_id = 0;
else
buffer_id = buffer.buffer_id;
buffer_id = buffer.renderbuffer_id;
gl._bindRenderbuffer(target, buffer_id);
};
@@ -188,14 +186,53 @@ gl.bindFramebuffer = function(target, buffer) {
else if( buffer === null )
buffer_id = null;
else
buffer_id = buffer.buffer_id;
buffer_id = buffer.framebuffer_id;
gl._bindFramebuffer(target, buffer_id);
};
gl.framebufferRenderbuffer = function(target, attachment, renderbuffertarget, renderbuffer) {
gl._framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer.renderbuffer_id);
};
gl.framebufferTexture2D = function(target, attachment, textarget, texture, level) {
gl._framebufferTexture2D(target, attachment, textarget, texture.texture_id, level);
}
};
gl.isFramebuffer = function(buffer) {
if (buffer && buffer.framebuffer_id) {
return gl._isFramebuffer(buffer.framebuffer_id);
}
return false;
};
gl.isProgram = function(program) {
if (program && program.program_id) {
return gl._isProgram(program.program_id);
}
return false;
};
gl.isRenderbuffer = function(buffer) {
if (buffer && buffer.renderbuffer_id) {
return gl._isRenderbuffer(buffer.renderbuffer_id);
}
return false;
};
gl.isShader = function(shader) {
if (shader && shader.shader_id) {
return gl._isShader(shader.shader_id);
}
return false;
};
gl.isTexture = function(texture) {
if (texture && texture.texture_id) {
return gl._isTexture(texture.texture_id);
}
return false;
};
//
// Uniform related
@@ -415,17 +452,19 @@ gl.texImage2D = function(target, level, internalformat, width, height, border, f
format = width;
if (image instanceof HTMLImageElement) {
console.log(`==> texImage2D HTMLImageElement internalformat: ${image._glInternalFormat}, format: ${image._glFormat}, image: w:${image.width}, h:${image.height}, dataLen:${image._data.length}`);
// console.log(`==> texImage2D HTMLImageElement internalformat: ${image._glInternalFormat}, format: ${image._glFormat}, image: w:${image.width}, h:${image.height}, dataLen:${image._data.length}`);
gl.pixelStorei(gl.UNPACK_ALIGNMENT, image._alignment);
_glTexImage2D(target, level, image._glInternalFormat, image.width, image.height, 0, image._glFormat, image._glType, image._data);
}
else if (image instanceof HTMLCanvasElement) {
console.log(`==> texImage2D HTMLCanvasElement internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);//, dataLen:${image._data.length}`);
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data._data);
// console.log(`==> texImage2D HTMLCanvasElement internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);//, dataLen:${image._data.length}`);
if (image._data) {
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data._data);
}
}
else if (image instanceof ImageData) {
console.log(`==> texImage2D ImageData internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);
// console.log(`==> texImage2D ImageData internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data);
}
else {
@@ -463,7 +502,9 @@ gl.texSubImage2D = function(target, level, xoffset, yoffset, width, height, form
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, image._glFormat, image._glType, image._data);
}
else if (image instanceof HTMLCanvasElement) {
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data._data);
if (image._data) {
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data._data);
}
}
else if (image instanceof ImageData) {
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data);
+2
View File
@@ -245,6 +245,7 @@ gl.DECR_WRAP = 0x8508;
gl.DELETE_STATUS = 0x8b80;
gl.DEPTH24_STENCIL8_OES = 0x88f0;
gl.DEPTH_ATTACHMENT = 0x8d00;
gl.DEPTH_STENCIL_ATTACHMENT = 0x821a;
gl.DEPTH_BITS = 0xd56;
gl.DEPTH_BUFFER_BIT = 0x100;
gl.DEPTH_BUFFER_BIT0_QCOM = 0x100;
@@ -856,6 +857,7 @@ gl.WRITE_ONLY_OES = 0x88b9;
gl.Z400_BINARY_AMD = 0x8740;
gl.ZERO = 0x0;
gl.RASTERIZER_DISCARD = 0x8C89;
gl.UNPACK_FLIP_Y_WEBGL = 0x9240;
gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
gl.CONTEXT_LOST_WEBGL = 0x9242;
+8
View File
@@ -0,0 +1,8 @@
{
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0"
}
}
-24
View File
@@ -1,27 +1,3 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
function DOMParser(options){
this.options = options ||{locator:{}};
-25
View File
@@ -1,28 +1,3 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/*
* DOM Level 2
* Object DOMException
-24
View File
@@ -1,27 +1,3 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
exports.entityMap = {
lt: '<',
gt: '>',
-25
View File
@@ -1,28 +1,3 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
//[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
//[5] Name ::= NameStartChar (NameChar)*
-4
View File
@@ -48,10 +48,6 @@ cc.Audio.Type = {
cc.audioEngine = audioEngine;
audioEngine.play = audioEngine.play2d;
audioEngine.setMaxWebAudioSize = function () {};
// deprecated
// var Module = require('../cocos2d/audio/deprecated');
// Module.removed(audioEngine);
// Module.deprecated(audioEngine);
proto.State = audioEngine.AudioState;
+8 -13
View File
@@ -62,8 +62,7 @@
{
"name": "Spine Skeleton",
"entries": [
"./extensions/spine/index.js",
"./jsb/jsb-spine.js"
"./extensions/spine/index.js"
]
},
{
@@ -131,22 +130,19 @@
{
"name": "EditBox",
"entries": [
"./cocos2d/core/components/CCEditBox.js",
"./jsb/jsb-editbox.js"
"./cocos2d/core/components/CCEditBox.js"
]
},
{
"name": "VideoPlayer",
"entries": [
"./cocos2d/videoplayer/CCVideoPlayer.js",
"./jsb/jsb-videoplayer.js"
"./cocos2d/videoplayer/CCVideoPlayer.js"
]
},
{
"name": "WebView",
"entries": [
"./cocos2d/webview/CCWebView.js",
"./jsb/jsb-webview.js"
"./cocos2d/webview/CCWebView.js"
]
},
{
@@ -172,7 +168,8 @@
{
"name": "MotionStreak",
"entries": [
"./cocos2d/motion-streak/index.js"
"./cocos2d/core/components/CCMotionStreak.js",
"./cocos2d/core/renderer/assemblers/motion-streak.js"
]
},
{
@@ -202,15 +199,13 @@
{
"name": "DragonBones",
"entries": [
"./extensions/dragonbones/index.js",
"./jsb/jsb-dragonbones.js"
"./extensions/dragonbones/index.js"
]
},
{
"name": "Physics",
"entries": [
"./cocos2d/core/physics/index.js",
"./jsb/jsb-box2d.js"
"./cocos2d/core/physics/index.js"
],
"dependencies": ["Collider"]
},