diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 480e5646949..55e14a954ae 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1202,7 +1202,7 @@ declare namespace spine { setJitterEffect(jitter: spine.VertexEffect); setSwirlEffect(swirl: spine.VertexEffect); updateRenderData(); - setListener(id: number, type: number); + setListener(id: number); setDebugMode(debug: boolean); getDebugShapes(); resizeSlotRegion(slotName: string, width: number, height: number, createNew: boolean); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 46944e393eb..cc10f81cf11 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1689,6 +1689,8 @@ export class Skeleton extends UIRenderer { protected _ensureListener (): void { if (!this._listener) { this._listener = new TrackEntryListeners(); + const listenerID = TrackEntryListeners.addListener(this._listener); + this._instance!.setListener(listenerID); } } @@ -1699,8 +1701,6 @@ export class Skeleton extends UIRenderer { */ public setStartListener (listener: TrackListener): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.start); this._listener!.start = listener; } @@ -1711,8 +1711,6 @@ export class Skeleton extends UIRenderer { */ public setInterruptListener (listener: TrackListener): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.interrupt); this._listener!.interrupt = listener; } @@ -1723,8 +1721,6 @@ export class Skeleton extends UIRenderer { */ public setEndListener (listener: TrackListener): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.end); this._listener!.end = listener; } @@ -1735,8 +1731,6 @@ export class Skeleton extends UIRenderer { */ public setDisposeListener (listener: TrackListener): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.dispose); this._listener!.dispose = listener; } @@ -1747,8 +1741,6 @@ export class Skeleton extends UIRenderer { */ public setCompleteListener (listener: TrackListener): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.complete); this._listener!.complete = listener; } @@ -1759,8 +1751,6 @@ export class Skeleton extends UIRenderer { */ public setEventListener (listener: TrackListener2): void { this._ensureListener(); - const listenerID = TrackEntryListeners.addListener(listener); - this._instance!.setListener(listenerID, spine.EventType.event); this._listener!.event = listener; } @@ -1813,7 +1803,6 @@ export class Skeleton extends UIRenderer { public setTrackCompleteListener (entry: spine.TrackEntry, listener: TrackListener2): void { const onComplete = (trackEntry: spine.TrackEntry): void => { const loopCount = Math.floor(trackEntry.trackTime / trackEntry.animationEnd); - const listenerID = TrackEntryListeners.addListener(listener); listener(trackEntry, loopCount); // this._instance.setListener(listenerID, spine.EventType.event); // this._listener!.event = listener; diff --git a/cocos/spine/track-entry-listeners.ts b/cocos/spine/track-entry-listeners.ts index c51b0b38844..eaaf4d580cd 100644 --- a/cocos/spine/track-entry-listeners.ts +++ b/cocos/spine/track-entry-listeners.ts @@ -50,12 +50,44 @@ export class TrackEntryListeners { return entry.listener; } - static emitListener (id: number, entry: spine.TrackEntry, event: spine.Event): void { + static emitListener (id: number, entry: spine.TrackEntry, event: spine.Event, eventType: spine.EventType): void { const listener = TrackEntryListeners._listenerSet.get(id); if (!listener) return; - const listener2 = listener as TrackListener2; - if (listener2) { - listener2(entry, event); + switch (eventType) { + case spine.EventType.event: + if (listener.event) { + listener.event(entry, event); + } + break; + case spine.EventType.start: + if (listener.start) { + listener.start(entry); + } + break; + case spine.EventType.interrupt: + if (listener.interrupt) { + listener.interrupt(entry); + } + break; + case spine.EventType.end: + if (listener.end) { + listener.end(entry); + } + break; + case spine.EventType.dispose: + if (listener.dispose) { + listener.dispose(entry); + } + this._listenerSet.delete(id); + break; + case spine.EventType.complete: + if (listener.complete) { + listener.complete(entry); + } + break; + default: + warn('emitListener doesn\'t handled', eventType); + break; } } @@ -101,13 +133,13 @@ export class TrackEntryListeners { } } - static addListener (listener: CommonTrackEntryListener): number { + static addListener (listener: TrackEntryListeners): number { const id = ++_listener_ID; TrackEntryListeners._listenerSet.set(id, listener); return id; } - private static _listenerSet = new Map(); + private static _listenerSet = new Map(); private static _trackSet = new Map(); } diff --git a/native/cocos/editor-support/spine-wasm/library_spine.js b/native/cocos/editor-support/spine-wasm/library_spine.js index ee6dc3b98f7..6c47c49341c 100644 --- a/native/cocos/editor-support/spine-wasm/library_spine.js +++ b/native/cocos/editor-support/spine-wasm/library_spine.js @@ -4,7 +4,8 @@ mergeInto(LibraryManager.library, { var listenerID = wasmUtil.getCurrentListenerID(); var trackEntry = wasmUtil.getCurrentTrackEntry(); var event = wasmUtil.getCurrentEvent(); - globalThis.TrackEntryListeners.emitListener(listenerID, trackEntry, event); + var eventType = wasmUtil.getCurrentEventType(); + globalThis.TrackEntryListeners.emitListener(listenerID, trackEntry, event, eventType.value); }, spineTrackListenerCallback: function() { diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 8b171a4c750..4fe0b12b068 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -84,8 +84,6 @@ void SpineSkeletonInstance::setSkin(const std::string &name) { if (!_skeleton) return; _skeleton->setSkin(name.c_str()); _skeleton->setSlotsToSetupPose(); - _animState->apply(*_skeleton); - _skeleton->updateWorldTransform(); } void SpineSkeletonInstance::updateAnimation(float dltTime) { @@ -412,29 +410,6 @@ void SpineSkeletonInstance::setMix(const std::string &from, const std::string &t _animStateData->setMix(from.c_str(), to.c_str(), duration); } -void SpineSkeletonInstance::setListener(uint32_t listenerID, uint32_t type) { - switch (type) { - case EventType_Start: - _startListenerID = listenerID; - break; - case EventType_Interrupt: - _interruptListenerID = listenerID; - break; - case EventType_End: - _endListenerID = listenerID; - break; - case EventType_Dispose: - _disposeListenerID = listenerID; - break; - case EventType_Complete: - _completeListenerID = listenerID; - break; - case EventType_Event: - _eventListenerID = listenerID; - break; - } -} - void SpineSkeletonInstance::setTrackEntryListener(uint32_t trackId, TrackEntry *entry) { if (!entry->getRendererObject()) { _trackEntryListenerID = trackId; @@ -464,43 +439,9 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t SpineWasmUtil::s_currentType = type; SpineWasmUtil::s_currentEntry = entry; SpineWasmUtil::s_currentEvent = event; - switch (type) { - case EventType_Start: - if (_startListenerID != 0) { - SpineWasmUtil::s_listenerID = _startListenerID; - spineListenerCallBackFromJS(); - } - break; - case EventType_Interrupt: - if (_interruptListenerID != 0) { - SpineWasmUtil::s_listenerID = _interruptListenerID; - spineListenerCallBackFromJS(); - } - break; - case EventType_End: - if (_endListenerID != 0) { - SpineWasmUtil::s_listenerID = _endListenerID; - spineListenerCallBackFromJS(); - } - break; - case EventType_Dispose: - if (_disposeListenerID != 0) { - SpineWasmUtil::s_listenerID = _disposeListenerID; - spineListenerCallBackFromJS(); - } - break; - case EventType_Complete: - if (_completeListenerID != 0) { - SpineWasmUtil::s_listenerID = _completeListenerID; - spineListenerCallBackFromJS(); - } - break; - case EventType_Event: - if (_eventListenerID != 0) { - SpineWasmUtil::s_listenerID = _eventListenerID; - spineListenerCallBackFromJS(); - } - break; + if (_eventListenerID != 0) { + SpineWasmUtil::s_listenerID = _eventListenerID; + spineListenerCallBackFromJS(); } } diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index c1b53149ebf..a1a15bf1e92 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -51,7 +51,7 @@ class SpineSkeletonInstance { void clearEffect(); AnimationState *getAnimationState(); void setMix(const std::string &from, const std::string &to, float duration); - void setListener(uint32_t listenerID, uint32_t type); + inline void setListener(uint32_t listenerID) { _eventListenerID = listenerID;} void setTrackEntryListener(uint32_t trackId, TrackEntry *entry); void onAnimationStateEvent(TrackEntry *entry, EventType type, Event *event); void onTrackEntryEvent(TrackEntry *entry, EventType type, Event *event); @@ -73,11 +73,6 @@ class SpineSkeletonInstance { SkeletonClipping *_clipper = nullptr; VertexEffect *_effect = nullptr; SpineModel *_model = nullptr; - uint32_t _startListenerID = 0; - uint32_t _interruptListenerID = 0; - uint32_t _endListenerID = 0; - uint32_t _disposeListenerID = 0; - uint32_t _completeListenerID = 0; uint32_t _eventListenerID = 0; uint32_t _trackEntryListenerID = 0; UserData _userData; diff --git a/native/external-config.json b/native/external-config.json index 78ca7978643..c2416bbfd75 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-23" + "checkout": "v3.8.4-1" } } \ No newline at end of file