Skip to content

Commit

Permalink
Merge branch 'dev/1.1' into PR/fix-skin-lazy
Browse files Browse the repository at this point in the history
* dev/1.1: (43 commits)
  fix: skin mesh error (galacean#1675)
  fix: test error (galacean#1674)
  test: fix github test (galacean#1669)
  test: fix ci not work (galacean#1670)
  glTF support basisu (galacean#1662)
  fix: `EventDispatcher` static pool bug
  fix: eventdispatcher bug (galacean#1671)
  fix: animation event bug (galacean#1666)
  Fix parse glTF texture wrap & filterMode bug (galacean#1659)
  Fix text wrap bug (galacean#1644)
  chore: use strict error msg and type (galacean#1647)
  Fix text error for set text to "" and set enableWrapping to true (galacean#1634)
  "v1.0.0-beta.17"
  Process GLTFBufferParser and GLTFTextureParser pipelines in parallel (galacean#1638)
  Fix animation clip loader, clip change promise to assetPromise, controller json parse (galacean#1506)
  fix: the layer is not cloned when the node is cloned (galacean#1636)
  Fix glTF texture mipmap bug (galacean#1637)
  "v1.0.0-beta.16"
  Adjust main light to directional lights first (galacean#1635)
  Fix  `AmbientLight` can't destroy bug (galacean#1633)
  ...
  • Loading branch information
GuoLei1990 committed Aug 3, 2023
2 parents 785088a + d64b320 commit 22328a9
Show file tree
Hide file tree
Showing 90 changed files with 1,741 additions and 769 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand All @@ -63,6 +63,12 @@ jobs:
node-version: 16.x
cache: pnpm

- name: Install
run: pnpm install
- name: Build
run: npm run build
- name: Test
run: npm run test-cov
- run: pnpm install codecov -w
- name: Upload coverage to Codecov
run: ./node_modules/.bin/codecov
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@galacean/engine-root",
"version": "1.0.0",
"packageManager": "pnpm@8.3.1",
"packageManager": "pnpm@8.6.2",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/2d/atlas/SpriteAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ export class SpriteAtlas extends ReferResource {
*/
_addSprite(sprite: Sprite): void {
this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
sprite._atlas = this;
sprite.isGCIgnored = true;
}

/**
* @internal
*/
protected override _onDestroy(): void {
super._onDestroy();
const { _sprites: sprites } = this;
for (let i = 0, n = sprites.length; i < n; i++) {
sprites[i].destroy();
}
sprites.length = 0;
this._sprites = null;
this._spriteNamesToIndex = null;
}
Expand Down
89 changes: 66 additions & 23 deletions packages/core/src/2d/sprite/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UpdateFlagManager } from "../../UpdateFlagManager";
import { ReferResource } from "../../asset/ReferResource";
import { Texture2D } from "../../texture/Texture2D";
import { SpriteModifyFlags } from "../enums/SpriteModifyFlags";
import { SpriteAtlas } from "../atlas/SpriteAtlas";

/**
* 2D sprite.
Expand Down Expand Up @@ -32,6 +33,8 @@ export class Sprite extends ReferResource {

private _dirtyUpdateFlag: SpriteUpdateFlags = SpriteUpdateFlags.all;

/** @internal */
_atlas: SpriteAtlas;
/** @internal */
_updateFlagManager: UpdateFlagManager = new UpdateFlagManager();

Expand Down Expand Up @@ -153,14 +156,7 @@ export class Sprite extends ReferResource {
}

set region(value: Rect) {
const region = this._region;
const x = MathUtil.clamp(value.x, 0, 1);
const y = MathUtil.clamp(value.y, 0, 1);
region.set(x, y, MathUtil.clamp(value.width, 0, 1 - x), MathUtil.clamp(value.height, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.region);
if (this._customWidth === undefined || this._customHeight === undefined) {
this._dispatchSpriteChange(SpriteModifyFlags.size);
}
this._region !== value && this._region.copyFrom(value);
}

/**
Expand All @@ -172,16 +168,7 @@ export class Sprite extends ReferResource {
}

set pivot(value: Vector2) {
const pivot = this._pivot;
if (pivot === value) {
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
} else {
const { x, y } = value;
if (pivot.x !== x || pivot.y !== y) {
pivot.set(x, y);
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
}
}
this._pivot !== value && this._pivot.copyFrom(value);
}

/**
Expand All @@ -196,11 +183,7 @@ export class Sprite extends ReferResource {
}

set border(value: Vector4) {
const border = this._border;
const x = MathUtil.clamp(value.x, 0, 1);
const y = MathUtil.clamp(value.y, 0, 1);
border.set(x, y, MathUtil.clamp(value.z, 0, 1 - x), MathUtil.clamp(value.w, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.border);
this._border !== value && this._border.copyFrom(value);
}

/**
Expand All @@ -222,6 +205,15 @@ export class Sprite extends ReferResource {
) {
super(engine);
this._texture = texture;
this._onRegionChange = this._onRegionChange.bind(this);
this._onPivotChange = this._onPivotChange.bind(this);
this._onBorderChange = this._onBorderChange.bind(this);
// @ts-ignore
this._region._onValueChanged = this._onRegionChange;
// @ts-ignore
this._pivot._onValueChanged = this._onPivotChange;
// @ts-ignore
this._border._onValueChanged = this._onBorderChange;
region && this._region.copyFrom(region);
pivot && this._pivot.copyFrom(pivot);
border && this._border.copyFrom(border);
Expand Down Expand Up @@ -264,12 +256,32 @@ export class Sprite extends ReferResource {
return this._bounds;
}

/**
* @internal
*/
override _addReferCount(value: number): void {
super._addReferCount(value);
this._atlas?._addReferCount(value);
}

/**
* @internal
*/
protected override _onDestroy(): void {
super._onDestroy();
this._positions.length = 0;
this._positions = null;
this._uvs.length = 0;
this._uvs = null;
this._atlasRegion = null;
this._atlasRegionOffset = null;
this._region = null;
this._pivot = null;
this._border = null;
this._bounds = null;
this._atlas = null;
this._texture = null;
this._updateFlagManager = null;
}

private _calDefaultSize(): void {
Expand Down Expand Up @@ -368,6 +380,37 @@ export class Sprite extends ReferResource {
}
this._updateFlagManager.dispatch(type);
}

private _onRegionChange(): void {
const { _region: region } = this;
// @ts-ignore
region._onValueChanged = null;
const x = MathUtil.clamp(region.x, 0, 1);
const y = MathUtil.clamp(region.y, 0, 1);
region.set(x, y, MathUtil.clamp(region.width, 0, 1 - x), MathUtil.clamp(region.height, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.region);
if (this._customWidth === undefined || this._customHeight === undefined) {
this._dispatchSpriteChange(SpriteModifyFlags.size);
}
// @ts-ignore
region._onValueChanged = this._onRegionChange;
}

private _onPivotChange(): void {
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
}

private _onBorderChange(): void {
const { _border: border } = this;
// @ts-ignore
border._onValueChanged = null;
const x = MathUtil.clamp(border.x, 0, 1);
const y = MathUtil.clamp(border.y, 0, 1);
border.set(x, y, MathUtil.clamp(border.z, 0, 1 - x), MathUtil.clamp(border.w, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.border);
// @ts-ignore
border._onValueChanged = this._onBorderChange;
}
}

enum SpriteUpdateFlags {
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/2d/sprite/SpriteMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ export class SpriteMask extends Renderer {
set sprite(value: Sprite | null) {
const lastSprite = this._sprite;
if (lastSprite !== value) {
lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
if (lastSprite) {
lastSprite._addReferCount(-1);
lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
}
this._dirtyUpdateFlag |= SpriteMaskUpdateFlags.All;
if (value) {
value._addReferCount(1);
value._updateFlagManager.addListener(this._onSpriteChange);
this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
} else {
Expand Down Expand Up @@ -229,7 +233,12 @@ export class SpriteMask extends Renderer {
*/
protected override _onDestroy(): void {
super._onDestroy();
this._sprite?._updateFlagManager.removeListener(this._onSpriteChange);
const sprite = this._sprite;
if (sprite) {
sprite._addReferCount(-1);
sprite._updateFlagManager.removeListener(this._onSpriteChange);
}
this._entity = null;
this._sprite = null;
this._verticesData = null;
}
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/2d/sprite/SpriteRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ export class SpriteRenderer extends Renderer {
set sprite(value: Sprite | null) {
const lastSprite = this._sprite;
if (lastSprite !== value) {
lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
if (lastSprite) {
lastSprite._addReferCount(-1);
lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
}
this._dirtyUpdateFlag |= SpriteRendererUpdateFlags.All;
if (value) {
value._addReferCount(1);
value._updateFlagManager.addListener(this._onSpriteChange);
this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
} else {
Expand Down Expand Up @@ -329,7 +333,12 @@ export class SpriteRenderer extends Renderer {
*/
protected override _onDestroy(): void {
super._onDestroy();
this._sprite?._updateFlagManager.removeListener(this._onSpriteChange);
const sprite = this._sprite;
if (sprite) {
sprite._addReferCount(-1);
sprite._updateFlagManager.removeListener(this._onSpriteChange);
}
this._entity = null;
this._color = null;
this._sprite = null;
this._assembler = null;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/2d/text/SubFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class SubFont {
const fontAtlas = new FontAtlas(engine);
const texture = new Texture2D(engine, 256, 256);
fontAtlas.texture = texture;
fontAtlas.isGCIgnored = texture.isGCIgnored = true;
this._fontAtlases.push(fontAtlas);

const nativeFontString = this.nativeFontString;
Expand Down
Loading

0 comments on commit 22328a9

Please sign in to comment.