Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize spine performance & fix memory leaks. #16485

Merged
merged 22 commits into from
Nov 9, 2023
Merged

Conversation

bofeng-song
Copy link
Contributor

Re: # #16384

Changelog

Fix memory leaks.
Improve the performance of wasm interaction with TS.
Optimize the code of attach node synchronization.
Optimize spine rendering data processing logic.
*


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Copy link

github-actions bot commented Nov 8, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -50631,8 +50631,21 @@
          THE SOFTWARE.
          */
         /* eslint @typescript-eslint/no-explicit-any: "off" */
         export namespace spine {
+            export class String {
+                length: number;
+                isEmpty: boolean;
+                strPtr: number;
+                str: string;
+            }
+            export class SPVectorFloat {
+                size(): number;
+                resize(newSize: number, defaultValue: number);
+                set(index: number, value: number);
+                get(index: number): number;
+                delete();
+            }
             export class Animation {
                 constructor(name: string, timelines: Array<Timeline>, duration: number);
                 duration: number;
                 name: string;
@@ -51146,9 +51159,8 @@
                 ikConstraints: Array<IkConstraint>;
                 transformConstraints: Array<TransformConstraint>;
                 pathConstraints: Array<PathConstraint>;
                 _updateCache: Updatable[];
-                updateCacheReset: Updatable[];
                 skin: Skin;
                 color: Color;
                 time: number;
                 scaleX: number;
@@ -51261,9 +51273,9 @@
             export class SkeletonJson {
                 attachmentLoader: AttachmentLoader;
                 scale: number;
                 constructor(attachmentLoader: AttachmentLoader);
-                readSkeletonData(json: string | any): SkeletonData;
+                readSkeletonData(json: any): SkeletonData;
                 readAttachment(map: any, skin: Skin, slotIndex: number, name: string, skeletonData: SkeletonData): Attachment;
                 readVertices(map: any, attachment: VertexAttachment, verticesLength: number): void;
                 readAnimation(map: any, name: string, skeletonData: SkeletonData): void;
                 readCurve(map: any, timeline: CurveTimeline, frameIndex: number): void;
@@ -51719,9 +51731,18 @@
                 begin(skeleton: Skeleton): void;
                 transform(x: number, y: number): void;
                 end(): void;
             }
+            export class SkeletonSystem {
+                public static updateAnimation(deltaTime: number): void;
+                public static updateRenderData(): void;
+                public static getCount(): number;
+            }
             export class SkeletonInstance {
+                dtRate: number;
+                isCache: boolean;
+                isDelete: boolean;
+                enable: boolean;
                 initSkeleton(data: SkeletonData);
                 getAnimationState();
                 setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null;
                 setSkin(name: string);
@@ -51854,8 +51875,14 @@
              * @zh 私有缓存模式。
              */
             PRIVATE_CACHE = 2
         }
+        export interface TempColor {
+            r: number;
+            g: number;
+            b: number;
+            a: number;
+        }
         /**
          * @en
          * The Sockets attached to bones, synchronous transform with spine animation.
          * @zh
@@ -51909,9 +51936,8 @@
             protected _premultipliedAlpha: boolean;
             protected _timeScale: number;
             protected _preCacheMode: AnimationCacheMode;
             protected _cacheMode: AnimationCacheMode;
-            protected _defaultCacheMode: AnimationCacheMode;
             protected _sockets: SpineSocket[];
             protected _useTint: boolean;
             protected _debugMesh: boolean;
             protected _debugBones: boolean;
@@ -51944,8 +51970,14 @@
             protected _isAniComplete: boolean;
             protected _playTimes: number;
             protected _needUpdateSkeltonData: boolean;
             protected _listener: __private._cocos_spine_track_entry_listeners__TrackEntryListeners | null;
+            _vLength: number;
+            _vBuffer: Uint8Array | null;
+            _iLength: number;
+            _iBuffer: Uint8Array | null;
+            _model: any;
+            _tempColor: TempColor;
             constructor();
             /**
              * @en
              * The skeleton data contains the skeleton information (bind pose bones, slots, draw order,
@@ -52021,9 +52053,9 @@
              * @zh 是否显示 mesh 的 debug 信息。
              */
             get debugMesh(): boolean;
             set debugMesh(value: boolean);
-            get socketNodes(): Map<number, Node>;
+            get socketNodes(): Map<number, Node> | null;
             /**
              * @en The name of current playing animation.
              * @zh 当前播放的动画名称。
              * @property {String} animation
@@ -67074,22 +67106,30 @@
             texture: Texture2D | null;
             indexOffset: number;
             indexCount: number;
         }
+        export class _cocos_spine_skeleton_cache__FrameBoneInfo {
+            a: number;
+            b: number;
+            c: number;
+            d: number;
+            worldX: number;
+            worldY: number;
+        }
         /**
          * @en Attach node tool
          * @zh 挂点工具类
          * @class sp.AttachUtil
          */
         export class _cocos_spine_attach_util__AttachUtil {
-            protected _inited: boolean;
-            protected _skeleton: sp.spine.Skeleton | null;
-            protected _skeletonNode: Node | null;
-            protected _skeletonComp: sp.Skeleton | null;
+            protected _isInitialized: boolean;
+            protected _skeletonBones: sp.spine.Bone[] | _cocos_spine_skeleton_cache__FrameBoneInfo[] | null;
+            protected _socketNodes: Map<number, Node> | null;
             constructor();
             init(skeletonComp: sp.Skeleton): void;
             reset(): void;
             _syncAttachedNode(): void;
+            matrixHandle(node: Node, bone: any): void;
         }
         export type _cocos_spine_track_entry_listeners__TrackListener = (x: sp.spine.TrackEntry) => void;
         export type _cocos_spine_track_entry_listeners__TrackListener2 = (x: sp.spine.TrackEntry, ev: sp.spine.Event) => void;
         export type _cocos_spine_track_entry_listeners__CommonTrackEntryListener = _cocos_spine_track_entry_listeners__TrackListener | _cocos_spine_track_entry_listeners__TrackListener2;
@@ -67115,16 +67155,8 @@
             vData: Uint8Array;
             iData: Uint16Array;
             meshes: _cocos_spine_skeleton_cache__SpineDrawItem[];
         }
-        export class _cocos_spine_skeleton_cache__FrameBoneInfo {
-            a: number;
-            b: number;
-            c: number;
-            d: number;
-            worldX: number;
-            worldY: number;
-        }
         export interface _cocos_spine_skeleton_cache__AnimationFrame {
             model: _cocos_spine_skeleton_cache__SpineModel;
             boneInfos: _cocos_spine_skeleton_cache__FrameBoneInfo[];
         }
@@ -67163,14 +67195,14 @@
             isInvalid(): boolean;
             invalidAllFrame(): void;
             enableCacheAttachedInfo(): void;
             clear(): void;
-            destory(): void;
+            destroy(): void;
         }
         export interface _cocos_spine_skeleton_cache__SkeletonCacheItemInfo {
-            skeleton: sp.spine.Skeleton;
-            clipper: sp.spine.SkeletonClipping;
-            state: sp.spine.AnimationState;
+            skeleton: sp.spine.Skeleton | null;
+            clipper: sp.spine.SkeletonClipping | null;
+            state: sp.spine.AnimationState | null;
             listener: _cocos_spine_track_entry_listeners__TrackEntryListeners;
             curAnimationCache: _cocos_spine_skeleton_cache__AnimationCache | null;
             animationsCache: {
                 [key: string]: _cocos_spine_skeleton_cache__AnimationCache;

@minggo minggo merged commit 6d31bbd into cocos:v3.8.2 Nov 9, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants