Skip to content

Commit

Permalink
Merge branch 'v3.3' of https://gitlab.cocos.net/publics/engine into f…
Browse files Browse the repository at this point in the history
…inalization
  • Loading branch information
SantyWang committed Jun 11, 2021
2 parents 5bb075f + 518c760 commit 40986f8
Show file tree
Hide file tree
Showing 208 changed files with 7,395 additions and 7,245 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ rules:
import/extensions: off # typescript doesn't support this
import/no-unresolved: off # TODO: fix internal modules
import/prefer-default-export: off # prefer named exports
indent: [warn, 4] # we use 4-space convention
indent: off # use @typescript-eslint/indent instead for better compatibility

lines-between-class-members: off # be more lenient on member declarations
max-classes-per-file: off # helper classes are common
max-len: [warn, 150] # more lenient on max length per line
Expand All @@ -96,6 +97,9 @@ rules:

##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####

'@typescript-eslint/indent': [warn, 4, {
SwitchCase: 0
}]
'@typescript-eslint/no-unused-expressions': warn

# TODO: this is just too much work
Expand Down
1 change: 1 addition & 0 deletions @types/jsb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ declare namespace jsb {
export let onOrientationChanged: (event: {orientation: number}) => void | undefined; // TODO: enum orientation type
export let onResume: () => void | undefined;
export let onPause: () => void | undefined;
export let onClose: () => void | undefined;
export function openURL(url: string): void;
export function garbageCollect(): void;

Expand Down
10 changes: 8 additions & 2 deletions @types/pal/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module 'pal/input' {
/**
* Type of the input event used to quickly distinguish between event types.
*/
readonly type: string;
readonly type: import('../../cocos/core/platform/event-manager/event-enum').SystemEventTypeUnion;
/**
* Timestamp when the input event is triggered.
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ declare module 'pal/input' {
/**
* Numerical code identifying the unique value of the pressed key.
*/
readonly code: number;
readonly code: import('../../cocos/core/platform/event-manager/key-code').KeyCode;
}
type KeyboardCallback = (res: KeyboardInputEvent) => void;
/**
Expand All @@ -144,6 +144,12 @@ declare module 'pal/input' {
* @param cb
*/
public onDown (cb: KeyboardCallback);
/**
* Register the key pressing event callback.
* NOTE: Compability for the deprecated KEY_DOWN event type. It should be removed in the future.
* @param cb
*/
public onPressing (cb: KeyboardCallback);
/**
* Register the key up event callback.
* @param cb
Expand Down
4 changes: 4 additions & 0 deletions @types/pal/system.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ declare module 'pal/system' {
public now (): number;
public restartJSVM (): void;

public close ();

public onHide (cb: () => void);
public onShow (cb: () => void);
public onClose (cb: () => void);
public onViewResize (cb: () => void);
public onOrientationChange (cb: () => void);

public offHide (cb?: () => void);
public offShow (cb?: () => void);
public offClose (cb?: () => void);
public offViewResize (cb?: () => void);
public offOrientationChange (cb?: () => void);

Expand Down
16 changes: 16 additions & 0 deletions EngineErrorMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,14 @@ cc.ParticleSystem: unknown image format with Data

cc.ParticleSystem.initWithDictionary() : error loading the texture

### 6033

cc.ParticleSystem: not allowing create to be invoked twice with different particle system

### 6034

cc.ParticleSystem: shouldn't be initialized repetitively, otherwise there will be potential leak

### 6100

<!-- DEPRECATED -->
Expand Down Expand Up @@ -3022,6 +3030,14 @@ The PrivateNode is deprecated, please use Node directly with CCObject.Flags.Dont

SubModel can only support %d passes.

### 12005

Material already initialized, request aborted.

### 12006

Pass already destroyed.

### 12100

The font size is too big to be fitted into texture atlas. Please switch to other label cache modes or choose a smaller font size.
3 changes: 2 additions & 1 deletion cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"cocos/core/gfx/index.ts": "cocos/core/gfx/index.jsb.ts",
"cocos/core/gfx/pipeline-state.ts": "cocos/core/gfx/pipeline-state.jsb.ts",
"cocos/spine/index.ts": "cocos/spine/index.jsb.ts",
"cocos/dragon-bones/index.ts": "cocos/dragon-bones/index.jsb.ts"
"cocos/dragon-bones/index.ts": "cocos/dragon-bones/index.jsb.ts",
"cocos/core/renderer/scene/native-scene.ts": "cocos/core/renderer/scene/native-scene.jsb.ts"
}
},
{
Expand Down
85 changes: 61 additions & 24 deletions cocos/2d/assembler/sprite/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ export const simple: IAssembler = {
// sprite.renderData!.indicesCount,
// );
// const commitBuffer: IUIRenderData = renderer.createUIRenderData();
const dataList: IRenderData[] = sprite.renderData!.data;
const renderData = sprite.renderData;

const dataList: IRenderData[] = renderData!.data;
const node = sprite.node;

let buffer = renderer.acquireBufferBatch()!;

let vertexOffset = buffer.byteOffset >> 2;
let indicesOffset = buffer.indicesOffset;
let vertexId = buffer.vertexOffset;
Expand All @@ -111,41 +114,75 @@ export const simple: IAssembler = {
// buffer data may be reallocated, need get reference after request.
const vBuf = buffer.vData!;
const iBuf = buffer.iData!;
const vData = sprite.renderData!.vData!;
const vData = renderData!.vData!;

const data0 = dataList[0];
const data3 = dataList[3];
const matrix = node.worldMatrix;
const a = matrix.m00; const b = matrix.m01;
const c = matrix.m04; const d = matrix.m05;

const justTranslate = a === 1 && b === 0 && c === 0 && d === 1;

const tx = matrix.m12; const ty = matrix.m13;
const vl = data0.x; const vr = data3.x;
const vb = data0.y; const vt = data3.y;
const al = a * vl; const ar = a * vr;
const bl = b * vl; const br = b * vr;
const cb = c * vb; const ct = c * vt;
const db = d * vb; const dt = d * vt;
// left bottom
vData[0] = al + cb + tx;
vData[1] = bl + db + ty;
// right bottom
vData[9] = ar + cb + tx;
vData[10] = br + db + ty;
// left top
vData[18] = al + ct + tx;
vData[19] = bl + dt + ty;
// right top
vData[27] = ar + ct + tx;
vData[28] = br + dt + ty;

if (justTranslate) {
const vltx = vl + tx;
const vrtx = vr + tx;
const vbty = vb + ty;
const vtty = vt + ty;

// left bottom
vData[0] = vltx;
vData[1] = vbty;
// right bottom
vData[9] = vrtx;
vData[10] = vbty;
// left top
vData[18] = vltx;
vData[19] = vtty;
// right top
vData[27] = vrtx;
vData[28] = vtty;
} else {
const al = a * vl; const ar = a * vr;
const bl = b * vl; const br = b * vr;
const cb = c * vb; const ct = c * vt;
const db = d * vb; const dt = d * vt;

const cbtx = cb + tx;
const cttx = ct + tx;
const dbty = db + ty;
const dtty = dt + ty;

// left bottom
vData[0] = al + cbtx;
vData[1] = bl + dbty;
// right bottom
vData[9] = ar + cbtx;
vData[10] = br + dbty;
// left top
vData[18] = al + cttx;
vData[19] = bl + dtty;
// right top
vData[27] = ar + cttx;
vData[28] = br + dtty;
}

vBuf.set(vData, vertexOffset);

const index0 = vertexId; const index1 = vertexId + 1;
const index2 = vertexId + 2; const index3 = vertexId + 3;

// fill index data
iBuf[indicesOffset++] = vertexId;
iBuf[indicesOffset++] = vertexId + 1;
iBuf[indicesOffset++] = vertexId + 2;
iBuf[indicesOffset++] = vertexId + 2;
iBuf[indicesOffset++] = vertexId + 1;
iBuf[indicesOffset++] = vertexId + 3;
iBuf[indicesOffset++] = index0;
iBuf[indicesOffset++] = index1;
iBuf[indicesOffset++] = index2;
iBuf[indicesOffset++] = index2;
iBuf[indicesOffset++] = index1;
iBuf[indicesOffset++] = index3;
},

updateVertexData (sprite: Sprite) {
Expand Down
11 changes: 11 additions & 0 deletions cocos/2d/components/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export class Graphics extends Renderable2D {
protected _isDrawing = false;
protected _isNeedUploadData = true;

private _graphicsUseSubMeshes: RenderingSubMesh[] = [];

constructor () {
super();
this._instanceMaterialType = InstanceMaterialType.ADD_COLOR;
Expand Down Expand Up @@ -280,6 +282,14 @@ export class Graphics extends Renderable2D {
this.model = null;
}

const subMeshLength = this._graphicsUseSubMeshes.length;
if (subMeshLength > 0) {
for (let i = 0; i < subMeshLength; ++i) {
this._graphicsUseSubMeshes[i].destroy();
}
this._graphicsUseSubMeshes.length = 0;
}

if (!this.impl) {
return;
}
Expand Down Expand Up @@ -599,6 +609,7 @@ export class Graphics extends Renderable2D {
renderMesh.subMeshIdx = 0;

this.model.initSubModel(idx, renderMesh, this.getMaterialInstance(0)!);
this._graphicsUseSubMeshes.push(renderMesh);
}
}

Expand Down
5 changes: 3 additions & 2 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,9 @@ export class Label extends Renderable2D {
this._ttfSpriteFrame = new SpriteFrame();
this._assemblerData = this._assembler!.getAssemblerData();
const image = new ImageAsset(this._assemblerData!.canvas);
const tex = image._texture;
this._ttfSpriteFrame.texture = tex;
const texture = new Texture2D();
texture.image = image;
this._ttfSpriteFrame.texture = texture;
}

if (this.cacheMode !== CacheMode.CHAR) {
Expand Down
13 changes: 8 additions & 5 deletions cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, visible, override, serializable, range, slide } from 'cc.decorator';
import { InstanceMaterialType, Renderable2D } from '../framework/renderable-2d';
import { clamp, Color, Mat4, Vec2, Vec3 } from '../../core/math';
import { SystemEventType, warnID } from '../../core/platform';
import { warnID } from '../../core/platform';
import { Batcher2D } from '../renderer/batcher-2d';
import { ccenum } from '../../core/value-types/enum';
import { Graphics } from './graphics';
Expand Down Expand Up @@ -352,6 +352,8 @@ export class Mask extends Renderable2D {

protected _graphics: Graphics | null = null;

private _clearModelMesh: RenderingSubMesh| null = null;

constructor () {
super();
this._instanceMaterialType = InstanceMaterialType.ADD_COLOR;
Expand Down Expand Up @@ -389,8 +391,9 @@ export class Mask extends Renderable2D {

public onDestroy () {
super.onDestroy();
if (this._clearModel) {
if (this._clearModel && this._clearModelMesh) {
director.root!.destroyModel(this._clearModel);
this._clearModelMesh.destroy();
}

if (this._clearStencilMtl) {
Expand Down Expand Up @@ -561,10 +564,10 @@ export class Mask extends Renderable2D {

const ib = new Uint16Array([0, 1, 2, 2, 1, 3]);
indexBuffer.update(ib);
const renderMesh = new RenderingSubMesh([vertexBuffer], vfmt, PrimitiveMode.TRIANGLE_LIST, indexBuffer);
renderMesh.subMeshIdx = 0;
this._clearModelMesh = new RenderingSubMesh([vertexBuffer], vfmt, PrimitiveMode.TRIANGLE_LIST, indexBuffer);
this._clearModelMesh.subMeshIdx = 0;

this._clearModel.initSubModel(0, renderMesh, this._clearStencilMtl);
this._clearModel.initSubModel(0, this._clearModelMesh, this._clearStencilMtl);
}
}

Expand Down
15 changes: 8 additions & 7 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, multiline, type, serializable } from 'cc.decorator';
import { DEV, EDITOR } from 'internal:constants';
import { Font, SpriteAtlas, TTFFont, SpriteFrame } from '../assets';
import { assert, EventTouch, SystemEventType, warnID } from '../../core/platform';
import { assert, EventTouch, warnID } from '../../core/platform';
import { BASELINE_RATIO, fragmentText, isUnicodeCJK, isUnicodeSpace } from '../utils/text-utils';
import { HtmlTextParser, IHtmlTextParserResultObj, IHtmlTextParserStack } from '../utils/html-text-parser';
import Pool from '../../core/utils/pool';
Expand All @@ -46,6 +46,7 @@ import { legacyCC } from '../../core/global-exports';
import { Component } from '../../core/components';
import assetManager from '../../core/asset-manager/asset-manager';
import { CCObject } from '../../core';
import { NodeEventType } from '../../core/scene-graph/node-event';

const _htmlTextParser = new HtmlTextParser();
const RichTextChildName = 'RICHTEXT_CHILD';
Expand Down Expand Up @@ -458,7 +459,7 @@ export class RichText extends UIComponent {
}

public onLoad () {
this.node.on(SystemEventType.LAYER_CHANGED, this._applyLayer, this);
this.node.on(NodeEventType.LAYER_CHANGED, this._applyLayer, this);
}

public onEnable () {
Expand All @@ -480,7 +481,7 @@ export class RichText extends UIComponent {

public start () {
this._onTTFLoaded();
this.node.on(Node.EventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
this.node.on(NodeEventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
}

public onRestore () {
Expand Down Expand Up @@ -508,16 +509,16 @@ export class RichText extends UIComponent {
}
}

this.node.off(Node.EventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
this.node.off(SystemEventType.LAYER_CHANGED, this._applyLayer, this);
this.node.off(NodeEventType.ANCHOR_CHANGED, this._updateRichTextPosition, this);
this.node.off(NodeEventType.LAYER_CHANGED, this._applyLayer, this);
}

protected _addEventListeners () {
this.node.on(Node.EventType.TOUCH_END, this._onTouchEnded, this);
this.node.on(NodeEventType.TOUCH_END, this._onTouchEnded, this);
}

protected _removeEventListeners () {
this.node.off(Node.EventType.TOUCH_END, this._onTouchEnded, this);
this.node.off(NodeEventType.TOUCH_END, this._onTouchEnded, this);
}

protected _updateLabelSegmentTextAttributes () {
Expand Down
Loading

0 comments on commit 40986f8

Please sign in to comment.