Merge v2.0-release

# Conflicts:
#	cocos2d/core/renderer/render-engine.js
This commit is contained in:
Jare Guo
2018-09-12 14:23:38 +08:00
19 changed files with 116 additions and 111 deletions
+3 -3
View File
@@ -863,7 +863,7 @@ var Node = cc.Class({
/**
* !#en Skew x
* !#zh 该节点 Y 轴倾斜角度。
* !#zh 该节点 X 轴倾斜角度。
* @property skewX
* @type {Number}
* @example
@@ -883,7 +883,7 @@ var Node = cc.Class({
/**
* !#en Skew y
* !#zh 该节点 X 轴倾斜角度。
* !#zh 该节点 Y 轴倾斜角度。
* @property skewY
* @type {Number}
* @example
@@ -2327,7 +2327,7 @@ var Node = cc.Class({
* Set world position.
* This is not a public API yet, its usage could be updated
* @method setWorldPos
* @param {vec3} pos
* @param {Vec3} pos
*/
setWorldPos (pos) {
// NOTE: this is faster than invert world matrix and transform the point
+1 -1
View File
@@ -112,7 +112,7 @@ let Camera = cc.Class({
properties: {
_cullingMask: 0xffffffff,
_clearFlags: 0,
_clearFlags: ClearFlags.DEPTH | ClearFlags.STENCIL,
_backgroundColor: cc.color(0, 0, 0, 255),
_depth: 0,
_zoomRatio: 1,
+1 -2
View File
@@ -487,14 +487,12 @@ var Sprite = cc.Class({
if (this._state === State.GRAY) {
if (!this._graySpriteMaterial) {
this._graySpriteMaterial = new GraySpriteMaterial();
this.node._renderFlag |= RenderFlow.FLAG_COLOR;
}
material = this._graySpriteMaterial;
}
else {
if (!this._spriteMaterial) {
this._spriteMaterial = new SpriteMaterial();
this.node._renderFlag |= RenderFlow.FLAG_COLOR;
}
material = this._spriteMaterial;
}
@@ -512,6 +510,7 @@ var Sprite = cc.Class({
this._renderData.material = material;
}
this.node._renderFlag |= RenderFlow.FLAG_COLOR;
this.markForUpdateRenderData(true);
this.markForRender(true);
}
+2 -3
View File
@@ -639,9 +639,8 @@ let EditBox = cc.Class({
},
/**
* !#en Let the EditBox get focus, only valid when stayOnTop is true.
* !#zh 让当前 EditBox 获得焦点,只有在 stayOnTop 为 true 的时候设置有效
* Note: only available on Web at the moment.
* !#en Let the EditBox get focus
* !#zh 让当前 EditBox 获得焦点
* @method setFocus
*/
setFocus () {
@@ -45,6 +45,8 @@ let _matrix = math.mat4.create();
let _matrix_temp = math.mat4.create();
let _vec3 = cc.v3();
let _currentEditBoxImpl = null;
// polyfill
let polyfill = {
zoomInvalid: false
@@ -120,9 +122,7 @@ let EditBoxImpl = cc.Class({
},
setFocus () {
if (this._edTxt) {
this._edTxt.focus();
}
this._beginEditing();
},
isFocused() {
@@ -134,7 +134,7 @@ let EditBoxImpl = cc.Class({
},
stayOnTop (flag) {
if(this._alwaysOnTop === flag) return;
if(this._alwaysOnTop === flag || !this._edTxt) return;
this._alwaysOnTop = flag;
@@ -153,13 +153,13 @@ let EditBoxImpl = cc.Class({
maxLength = 65535;
}
this._maxLength = maxLength;
this._edTxt.maxLength = maxLength;
this._edTxt && (this._edTxt.maxLength = maxLength);
}
},
setString (text) {
this._text = text;
this._edTxt.value = text;
this._edTxt && (this._edTxt.value = text);
},
getString () {
@@ -216,12 +216,12 @@ let EditBoxImpl = cc.Class({
setFontSize (fontSize) {
this._edFontSize = fontSize || this._edFontSize;
this._edTxt.style.fontSize = this._edFontSize + 'px';
this._edTxt && (this._edTxt.style.fontSize = this._edFontSize + 'px');
},
setFontColor (color) {
this._textColor = color;
this._edTxt.style.color = color.toCSS('rgba');
this._edTxt && (this._edTxt.style.color = color.toCSS('rgba'));
},
setSize (width, height) {
@@ -256,31 +256,30 @@ let EditBoxImpl = cc.Class({
},
_beginEditing () {
if (!this._alwaysOnTop) {
if (this._edTxt.style.display === 'none') {
this._edTxt.style.display = '';
let self = this;
function startFocus () {
self._edTxt.focus();
}
if (cc.sys.browserType === cc.sys.BROWSER_TYPE_UC) {
setTimeout(startFocus, FOCUS_DELAY_UC);
}
else if (cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX) {
setTimeout(startFocus, FOCUS_DELAY_FIREFOX);
}
else {
startFocus();
}
if (cc.sys.isMobile && !this._editing) {
// Pre adaptation
this._beginEditingOnMobile();
}
if (this._edTxt) {
this._edTxt.style.display = '';
let self = this;
function startFocus () {
self._edTxt.focus();
}
if (cc.sys.browserType === cc.sys.BROWSER_TYPE_UC) {
setTimeout(startFocus, FOCUS_DELAY_UC);
}
else if (cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX) {
setTimeout(startFocus, FOCUS_DELAY_FIREFOX);
}
else {
startFocus();
}
}
if (cc.sys.isMobile && !this._editing) {
// Pre adaptation and
this._beginEditingOnMobile();
}
this._editing = true;
},
@@ -312,6 +311,7 @@ let EditBoxImpl = cc.Class({
_updateDomInputType () {
let inputMode = this._inputMode;
let edTxt = this._edTxt;
if (!edTxt) return;
if (this._inputFlag === InputFlag.PASSWORD) {
edTxt.type = 'password';
@@ -447,6 +447,7 @@ _p._beginEditingOnMobile = function () {
}
this.__autoResize = cc.view._resizeWithBrowserSize;
cc.view.resizeWithBrowserSize(false);
_currentEditBoxImpl = this;
};
// Called after keyboard disappeared to readapte the game view
@@ -466,11 +467,15 @@ _p._endEditingOnMobile = function () {
window.removeEventListener('orientationchange', this.__orientationChanged);
window.scrollTo && window.scrollTo(0, 0);
if(this.__fullscreen) {
cc.view.enableAutoFullScreen(true);
}
if (this.__autoResize) {
// In case focus on editBox A from editBox B
// A disable resizeWithBrowserSize
// whilte B enable resizeWithBrowserSize
// Only _currentEditBoxImpl can enable resizeWithBrowserSize
if (this.__autoResize && _currentEditBoxImpl === this) {
cc.view.resizeWithBrowserSize(true);
}
};
@@ -518,7 +523,7 @@ function registerInputEventListener (tmpEdTxt, editBoxImpl, isTextarea) {
}
if (cc.sys.isMobile) {
editBoxImpl._onFocusOnMobile();
editBoxImpl._beginEditingOnMobile();
}
if (editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingDidBegan) {
@@ -553,24 +558,6 @@ function registerInputEventListener (tmpEdTxt, editBoxImpl, isTextarea) {
editBoxImpl._addDomToGameContainer();
}
// Called after editbox focus to readapte the game view
_p._onFocusOnMobile = function (editBox) {
if (cc.view._isRotated) {
cc.game.container.style['-webkit-transform'] = 'rotate(0deg)';
cc.game.container.style.transform = 'rotate(0deg)';
cc.view._isRotated = false;
let policy = cc.view.getResolutionPolicy();
policy.apply(cc.view, cc.view.getDesignResolutionSize());
cc.view._isRotated = true;
//use window scrollTo to adjust the input area
window.scrollTo(35, 35);
this.__rotateScreen = true;
} else {
this.__rotateScreen = false;
}
this._adjustEditBoxPosition();
};
_p._createDomInput = function () {
this.removeDom();
+9
View File
@@ -348,6 +348,15 @@ cc.js.mixin(View.prototype, {
cc.game.container.style['-webkit-transform-origin'] = '0px 0px 0px';
cc.game.container.style.transformOrigin = '0px 0px 0px';
this._isRotated = true;
// Fix for issue: https://github.com/cocos-creator/fireball/issues/8365
// Reference: https://www.douban.com/note/343402554/
// For Chrome, z-index not working after container transform rotate 90deg.
// Because 'transform' style adds canvas (the top-element of container) to a new stack context.
// That causes the DOM Input was hidden under canvas.
// This should be done after container rotated, instead of in style-mobile.css.
cc.game.canvas.style['-webkit-transform'] = 'translateZ(0px)';
cc.game.canvas.style.transform = 'translateZ(0px)';
}
if (this._orientationChanging) {
setTimeout(function () {
@@ -50,6 +50,7 @@ RenderComponentWalker.prototype = {
let ctx = this._device._ctx;
let cam = this._camera;
ctx.setTransform(cam.a, cam.b, cam.c, cam.d, cam.tx, cam.ty);
ctx.scale(1, -1);
assembler.draw(ctx, comp);
},
@@ -36,10 +36,8 @@ module.exports = {
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.transform(a, b, c, d, tx, ty);
ctx.save();
ctx.scale(1, -1);
// TODO: handle blend function
@@ -79,7 +79,8 @@ module.exports = js.addon({
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.transform(a, b, c, d, tx, ty);
ctx.scale(1, -1);
// TODO: handle blend function
@@ -62,7 +62,8 @@ module.exports = js.addon({
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.transform(a, b, c, d, tx, ty);
ctx.scale(1, -1);
// TODO: handle blend function
@@ -30,12 +30,6 @@ let beforeHandler = {
updateRenderData (comp) {},
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();
// draw stencil
@@ -123,7 +123,8 @@ let renderer = {
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.transform(a, b, c, d, tx, ty);
ctx.scale(1, -1);
// TODO: handle blend function
@@ -116,7 +116,8 @@ let renderer = {
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.transform(a, b, c, d, tx, ty);
ctx.scale(1, -1);
// TODO: handle blend function
@@ -44,7 +44,8 @@ let renderer = {
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.transform(a, b, c, d, tx, ty);
ctx.scale(1, -1);
// TODO: handle blend function
+5 -5
View File
@@ -14148,7 +14148,7 @@ var SpriteMaterial = (function (Material$$1) {
prototypeAccessors.useTexture.set = function (val) {
this._effect.define('useTexture', val);
};
prototypeAccessors.useModel.get = function () {
return this._effect.getDefine('useModel');
};
@@ -14460,7 +14460,7 @@ var MeshMaterial = (function (Material$$1) {
{ name: 'useJointsTexture', valu: true},
{ name: 'useAttributeColor', valu: false} ]
);
this._mainTech = mainTech;
this._texture = null;
this._jointsTexture = null;
@@ -14478,7 +14478,7 @@ var MeshMaterial = (function (Material$$1) {
prototypeAccessors.effect.get = function () {
return this._effect;
};
prototypeAccessors.useModel.get = function () {
return this._effect.getDefine('useModel');
};
@@ -14596,8 +14596,8 @@ var MeshMaterial = (function (Material$$1) {
return MeshMaterial;
}(Material));
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
var Device$2 = function Device(canvasEL) {
var ctx;
+14 -7
View File
@@ -338,18 +338,25 @@ var BaseNode = cc.Class({
},
/**
* !#en The parent of the node.
* !#zh 该节点的父节点。
* @property parent
* @type {Node}
* @default null
* !#en Get parent of the node.
* !#zh 获取该节点的父节点。
* @method getParent
* @return {Node}
* @example
* node.parent = newNode;
* var parent = this.node.getParent();
*/
getParent () {
return this._parent;
},
/**
* !#en Set parent of the node.
* !#zh 设置该节点的父节点。
* @method setParent
* @param {Node} value
* @example
* node.setParent(newNode);
*/
setParent (value) {
if (this._parent === value) {
return;
@@ -501,7 +508,7 @@ var BaseNode = cc.Class({
* !#en Get the sibling index.
* !#zh 获取同级索引。
* @method getSiblingIndex
* @return {number}
* @return {Number}
* @example
* var index = node.getSiblingIndex();
*/
+3 -16
View File
@@ -708,7 +708,6 @@ var ParticleSystem = cc.Class({
ctor: function () {
this._previewTimer = null;
this._focused = false;
this._willStart = false;
this._texture = null;
this._simulator = new ParticleSimulator(this);
@@ -768,20 +767,6 @@ var ParticleSystem = cc.Class({
this._focused = true;
if (this.preview) {
this.resetSystem();
var self = this;
this._previewTimer = setInterval(function () {
// attemptToReplay
if (!self._willStart && self.particleCount === 0) {
self._willStart = true;
setTimeout(function () {
self._willStart = false;
if (self.preview && self._focused && !self.active && !cc.engine.isPlaying) {
self.resetSystem();
}
}, 600);
}
}, 100);
}
},
@@ -1164,7 +1149,9 @@ var ParticleSystem = cc.Class({
_finishedSimulation: function () {
if (CC_EDITOR) {
this.stopSystem();
if (this.preview && this._focused && !this.active && !cc.engine.isPlaying) {
this.resetSystem();
}
return;
}
this.disableRender();
+2 -3
View File
@@ -317,10 +317,9 @@ Simulator.prototype.step = function (dt) {
let particle = particles[particleIdx];
// life
particle.timeToLive -= dt;
if (particle.timeToLive > 0) {
// life
particle.timeToLive -= dt;
// Mode A: gravity, direction, tangential accel & radial accel
if (psys.emitterMode === cc.ParticleSystem.EmitterMode.GRAVITY) {
let tmp = _tpc, radial = _tpa, tangential = _tpb;
+26 -6
View File
@@ -23,6 +23,7 @@
THE SOFTWARE.
****************************************************************************/
const StencilManager = require('../../cocos2d/core/renderer/webgl/stencil-manager').sharedManager;
const Skeleton = require('./Skeleton');
const spine = require('./lib/spine');
const renderer = require('../../cocos2d/core/renderer');
@@ -32,6 +33,8 @@ const renderEngine = renderer.renderEngine;
const gfx = renderEngine.gfx;
const SpriteMaterial = renderEngine.SpriteMaterial;
const STENCIL_SEP = '@';
let _sharedMaterials = {};
let _slotColor = cc.color(0, 0, 255, 255);
@@ -43,6 +46,10 @@ _debugMaterial.useColor = false;
_debugMaterial.useTexture = false;
_debugMaterial.updateHash();
function _updateKeyWithStencilRef (key, stencilRef) {
return key.replace(/@\d+$/, STENCIL_SEP + stencilRef);
}
function _getSlotMaterial (slot, tex, premultiAlpha) {
let src, dst;
switch (slot.data.blendMode) {
@@ -64,7 +71,8 @@ function _getSlotMaterial (slot, tex, premultiAlpha) {
dst = cc.macro.ONE_MINUS_SRC_ALPHA;
break;
}
let key = tex.url + src + dst;
let key = tex.url + src + dst + STENCIL_SEP + '0';
let material = _sharedMaterials[key];
if (!material) {
material = new SpriteMaterial();
@@ -72,7 +80,7 @@ function _getSlotMaterial (slot, tex, premultiAlpha) {
// update texture
material.texture = tex;
material.useColor = false;
// update blend function
let pass = material._mainTech.passes[0];
pass.setBlend(
@@ -82,11 +90,11 @@ function _getSlotMaterial (slot, tex, premultiAlpha) {
src, dst
);
_sharedMaterials[key] = material;
material.updateHash();
material.updateHash(key);
}
else if (material.texture !== tex) {
material.texture = tex;
material.updateHash();
material.updateHash(key);
}
return material;
}
@@ -126,7 +134,7 @@ var spineAssembler = {
if (comp.debugSlots && vertexCount === 4) {
let graphics = comp._debugRenderer;
// Debug Slot
let VERTEX = spine.RegionAttachment;
graphics.strokeColor = _slotColor;
@@ -269,7 +277,7 @@ var spineAssembler = {
graphics.moveTo(bone.worldX, bone.worldY);
graphics.lineTo(x, y);
graphics.stroke();
// Bone origins.
graphics.circle(bone.worldX, bone.worldY, Math.PI * 2);
graphics.fill();
@@ -296,6 +304,18 @@ var spineAssembler = {
for (let index = 0, length = renderDatas.length; index < length; index++) {
let data = renderDatas[index];
// For generate new material for skeleton render data nested in mask,
// otherwise skeleton inside/outside mask with same material will interfere each other
let key = data.material._hash;
let newKey = _updateKeyWithStencilRef(key, StencilManager.getStencilRef());
if (key !== newKey) {
data.material = _sharedMaterials[newKey] || data.material.clone();
data.material.updateHash(newKey);
if (!_sharedMaterials[newKey]) {
_sharedMaterials[newKey] = data.material;
}
}
if (data.material !== renderer.material) {
renderer._flush();
renderer.node = comp.node;