-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Implement CallbacksInvoker using a linked list to avoid disorderly calling order caused by array.fastRemoveAt. #17705
Open
dev-jony
wants to merge
3
commits into
cocos:v3.8.5
Choose a base branch
from
dev-jony:v3.8.5
base: v3.8.5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+262
−198
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -23209,8 +23209,77 @@
export function setPropertyEnumType(objectOrConstructor: object, propertyName: string, enumType: __private._cocos_core_value_types_enum__EnumType): void;
export function setPropertyEnumTypeOnAttrs(attrs: Record<string, any>, propertyName: string, enumType: __private._cocos_core_value_types_enum__EnumType): void;
export function isCCObject(object: any): object is CCObject;
export function isValid(value: any, strictMode?: boolean): boolean;
+ /**
+ * @zh CallbacksInvoker 用来根据事件名(Key)管理事件监听器列表并调用回调方法。
+ * @en CallbacksInvoker is used to manager and invoke event listeners with different event keys, each key is mapped to a CallbackList.
+ */
+ export class CallbacksInvoker<EventTypeClass extends __private._cocos_core_event_callbacks_invoker__EventType = __private._cocos_core_event_callbacks_invoker__EventType> {
+ /**
+ * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
+ */
+ _callbackTable: __private._cocos_core_event_callbacks_invoker__ICallbackTable;
+ /**
+ * @zh 向一个事件名注册一个新的事件监听器,包含回调函数和调用者
+ * @en Register an event listener to a given event key with callback and target.
+ *
+ * @param key - Event type
+ * @param callback - Callback function when event triggered
+ * @param target - Callback callee
+ * @param once - Whether invoke the callback only once (and remove it)
+ *
+ * @returns callback
+ */
+ on(key: EventTypeClass, callback: __private.__types_globals__AnyFunction, target?: unknown, once?: boolean): typeof callback;
+ /**
+ * @zh 向一个事件名注册一个新的事件监听器,包含回调函数和调用者,该监听器只执行一次。
+ * @en Register an event listener to a given event key with callback and target.
+ *
+ * @param key - Event type
+ * @param callback - Callback function when event triggered
+ * @param target - Callback callee
+ *
+ * @returns callback
+ */
+ once(key: EventTypeClass, callback: __private.__types_globals__AnyFunction, target?: unknown): Function;
+ /**
+ * @zh 删除以指定事件,回调函数,目标注册的回调。
+ * @en Remove event listeners registered with the given event key, callback and target
+ * @param key - Event type
+ * @param callback - The callback function of the event listener, if absent all event listeners for the given type will be removed
+ * @param target - The callback callee of the event listener
+ */
+ off(key: EventTypeClass, callback: __private.__types_globals__AnyFunction, target?: unknown): void;
+ /**
+ * @zh 移除在特定事件类型中注册的所有回调或在某个目标中注册的所有回调。
+ * @en Removes all callbacks registered in a certain event type or all callbacks registered with a certain target
+ * @param keyOrTarget - The event type or target with which the listeners will be removed
+ */
+ removeAll(keyOrTarget: unknown): void;
+ hasTarget(target: unknown): boolean;
+ /**
+ * @zh 检查指定事件是否已注册回调。
+ * @en Checks whether there is correspond event listener registered on the given event
+ *
+ * @param key - Event type
+ * @param callback - Callback function when event triggered
+ * @param target - Callback callee
+ */
+ hasEventListener(key: EventTypeClass, callback?: __private.__types_globals__AnyFunction, target?: unknown): boolean;
+ /**
+ * @zh 派发一个指定事件,并传递需要的参数
+ * @en Trigger an event directly with the event name and necessary arguments.
+ * @param key - Event type
+ * @param arg0 - The first argument to be passed to the callback
+ * @param arg1 - The second argument to be passed to the callback
+ * @param arg2 - The third argument to be passed to the callback
+ * @param arg3 - The fourth argument to be passed to the callback
+ * @param arg4 - The fifth argument to be passed to the callback
+ */
+ emit(key: EventTypeClass, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void;
+ clear(): void;
+ }
export namespace pipeline {
export enum SetIndex {
GLOBAL = 0,
MATERIAL = 1,
@@ -63608,8 +63677,43 @@
PLUGINS = "plugins",
XR = "xr"
}
export type _cocos_core_value_types_enum__EnumType = Record<string, string | number>;
+ /// <reference types="./@types/globals" />
+ export class _cocos_core_event_callbacks_invoker__CallbackInfo {
+ callback: __types_globals__AnyFunction;
+ target: unknown;
+ once: boolean;
+ valid: boolean;
+ next: _cocos_core_event_callbacks_invoker__CallbackInfo | null;
+ set(callback: __types_globals__AnyFunction, target?: unknown, once?: boolean): this;
+ invalidate(): void;
+ clear(): this;
+ check(): boolean;
+ }
+ /**
+ * @zh 事件监听器列表的简单封装。
+ * @en A simple list of event callbacks
+ */
+ export class _cocos_core_event_callbacks_invoker__CallbackList {
+ isInvoking: boolean;
+ containCanceled: boolean;
+ head: _cocos_core_event_callbacks_invoker__CallbackInfo | null;
+ find(callback: __types_globals__AnyFunction, target?: unknown): _cocos_core_event_callbacks_invoker__CallbackInfo | null;
+ add(callback: __types_globals__AnyFunction, target?: unknown, once?: boolean): Function;
+ remove(callback: __types_globals__AnyFunction, target?: unknown): void;
+ removeByTarget(target: unknown): void;
+ cancel(info: _cocos_core_event_callbacks_invoker__CallbackInfo): void;
+ cancelByCallback(callback: __types_globals__AnyFunction, target?: unknown): void;
+ cancelByTarget(target: unknown): void;
+ cancelAll(): void;
+ purgeCanceled(): void;
+ clear(): this;
+ }
+ export interface _cocos_core_event_callbacks_invoker__ICallbackTable {
+ [x: string]: _cocos_core_event_callbacks_invoker__CallbackList | undefined;
+ }
+ export type _cocos_core_event_callbacks_invoker__EventType = string | number;
export class _cocos_rendering_shadow_csm_layers__ShadowLayerVolume {
protected _shadowObjects: pipeline.IRenderObject[];
protected _shadowCameraFar: number;
protected _level: number;
@@ -63776,123 +63880,8 @@
ADD_POINTER_EVENT_PROCESSOR = 0,
REMOVE_POINTER_EVENT_PROCESSOR = 1,
MARK_LIST_DIRTY = 2
}
- /// <reference types="./@types/globals" />
- export class _cocos_core_event_callbacks_invoker__CallbackInfo {
- callback: __types_globals__AnyFunction;
- target: unknown;
- once: boolean;
- set(callback: __types_globals__AnyFunction, target?: unknown, once?: boolean): void;
- reset(): void;
- check(): boolean;
- }
- /**
- * @zh 事件监听器列表的简单封装。
- * @en A simple list of event callbacks
- */
- export class _cocos_core_event_callbacks_invoker__CallbackList {
- callbackInfos: Array<_cocos_core_event_callbacks_invoker__CallbackInfo | null>;
- isInvoking: boolean;
- containCanceled: boolean;
- /**
- * @zh 从列表中移除与指定目标相同回调函数的事件。
- * @en Remove the event listeners with the given callback from the list
- *
- * @param cb - The callback to be removed
- */
- removeByCallback(cb: __types_globals__AnyFunction): void;
- /**
- * @zh 从列表中移除与指定目标相同调用者的事件。
- * @en Remove the event listeners with the given target from the list
- * @param target
- */
- removeByTarget(target: unknown): void;
- /**
- * @zh 移除指定编号事件。
- * @en Remove the event listener at the given index
- * @param index
- */
- cancel(index: number): void;
- /**
- * @zh 注销所有事件。
- * @en Cancel all event listeners
- */
- cancelAll(): void;
- /**
- * @zh 立即删除所有取消的回调。(在移除过程中会更加紧凑的排列数组)
- * @en Delete all canceled callbacks and compact array
- */
- purgeCanceled(): void;
- /**
- * @zh 清除并重置所有数据。
- * @en Clear all data
- */
- clear(): void;
- }
- export interface _cocos_core_event_callbacks_invoker__ICallbackTable {
- [x: string]: _cocos_core_event_callbacks_invoker__CallbackList | undefined;
- }
- export type _cocos_core_event_callbacks_invoker__EventType = string | number;
- /**
- * @zh CallbacksInvoker 用来根据事件名(Key)管理事件监听器列表并调用回调方法。
- * @en CallbacksInvoker is used to manager and invoke event listeners with different event keys,
- * each key is mapped to a CallbackList.
- * @engineInternal
- */
- export class _cocos_core_event_callbacks_invoker__CallbacksInvoker<EventTypeClass extends _cocos_core_event_callbacks_invoker__EventType = _cocos_core_event_callbacks_invoker__EventType> {
- /**
- * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
- */
- _callbackTable: _cocos_core_event_callbacks_invoker__ICallbackTable;
- /**
- * @zh 向一个事件名注册一个新的事件监听器,包含回调函数和调用者
- * @en Register an event listener to a given event key with callback and target.
- *
- * @param key - Event type
- * @param callback - Callback function when event triggered
- * @param target - Callback callee
- * @param once - Whether invoke the callback only once (and remove it)
- */
- on(key: EventTypeClass, callback: __types_globals__AnyFunction, target?: unknown, once?: boolean): __types_globals__AnyFunction;
- /**
- * @zh 检查指定事件是否已注册回调。
- * @en Checks whether there is correspond event listener registered on the given event
- * @param key - Event type
- * @param callback - Callback function when event triggered
- * @param target - Callback callee
- */
- hasEventListener(key: EventTypeClass, callback?: __types_globals__AnyFunction, target?: unknown): boolean;
- /**
- * @zh 移除在特定事件类型中注册的所有回调或在某个目标中注册的所有回调。
- * @en Removes all callbacks registered in a certain event type or all callbacks registered with a certain target
- * @param keyOrTarget - The event type or target with which the listeners will be removed
- */
- removeAll(keyOrTarget: unknown): void;
- /**
- * @zh 删除以指定事件,回调函数,目标注册的回调。
- * @en Remove event listeners registered with the given event key, callback and target
- * @param key - Event type
- * @param callback - The callback function of the event listener, if absent all event listeners for the given type will be removed
- * @param target - The callback callee of the event listener
- */
- off(key: EventTypeClass, callback?: __types_globals__AnyFunction, target?: unknown): void;
- /**
- * @zh 派发一个指定事件,并传递需要的参数
- * @en Trigger an event directly with the event name and necessary arguments.
- * @param key - event type
- * @param arg0 - The first argument to be passed to the callback
- * @param arg1 - The second argument to be passed to the callback
- * @param arg2 - The third argument to be passed to the callback
- * @param arg3 - The fourth argument to be passed to the callback
- * @param arg4 - The fifth argument to be passed to the callback
- */
- emit(key: EventTypeClass, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void;
- /**
- * 移除所有回调。
- */
- clear(): void;
- }
export interface _cocos_scene_graph_node_event_processor__IMask {
index: number;
comp: Component;
}
@@ -64042,9 +64031,9 @@
static _maskComp: __types_globals__Constructor<Component> | null;
/**
* @internal
*/
- static callbacksInvoker: _cocos_core_event_callbacks_invoker__CallbacksInvoker<_cocos_scene_graph_node_event_processor__DispatcherEventType>;
+ static callbacksInvoker: CallbacksInvoker<_cocos_scene_graph_node_event_processor__DispatcherEventType>;
/**
* Whether the node event is enabled
*/
get isEnabled(): boolean;
@@ -64070,13 +64059,13 @@
get node(): Node;
/**
* Target in bubbling phase.
*/
- bubblingTarget: _cocos_core_event_callbacks_invoker__CallbacksInvoker<_cocos_input_types_event_enum__SystemEventTypeUnion> | null;
+ bubblingTarget: CallbacksInvoker<_cocos_input_types_event_enum__SystemEventTypeUnion> | null;
/**
* Target in capturing phase.
*/
- capturingTarget: _cocos_core_event_callbacks_invoker__CallbacksInvoker<_cocos_input_types_event_enum__SystemEventTypeUnion> | null;
+ capturingTarget: CallbacksInvoker<_cocos_input_types_event_enum__SystemEventTypeUnion> | null;
/**
* Whether the node has registered the mouse event callback
*/
shouldHandleEventMouse: boolean;
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: