refactor(input): inject emitter pool via field instead of constructor

The pool is infrastructure that doesn't belong in PointerEventEmitter's
construction contract -- it had leaked into the emitter constructor, the
registry type, and the registerPointerEventEmitter decorator. Emitters now
have a no-arg constructor and PointerManager injects the pool into the
_pool field right after creating each emitter, so the registry and
decorator signatures simplify to `new () => Emitter`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
cptbtptpbcptdtptp
2026-06-16 22:24:10 +08:00
parent 19bfe6c67c
commit 82b6f8b50c
2 changed files with 17 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ import { PointerEventData } from "./PointerEventData";
import { PhysicsPointerEventEmitter } from "./emitter/PhysicsPointerEventEmitter";
import { PointerEventEmitter } from "./emitter/PointerEventEmitter";
type PointerEventEmitterConstructor = new (pool: ClearableObjectPool<PointerEventData>) => PointerEventEmitter;
type PointerEventEmitterConstructor = new () => PointerEventEmitter;
/**
* Pointer Manager.
@@ -206,15 +206,24 @@ export class PointerManager implements IInput {
}
private _addEmitters(pointer: Pointer): void {
const { _eventPool: eventPool, _engine: engine } = this;
const { _eventPool: pool, _engine: engine } = this;
const emitters = pointer._emitters;
engine._physicsInitialized && emitters.push(new PhysicsPointerEventEmitter(eventPool));
engine._physicsInitialized && emitters.push(this._createEmitter(PhysicsPointerEventEmitter, pool));
const emitterTypes = PointerManager._pointerEventEmitters;
for (let i = 0, n = emitterTypes.length; i < n; i++) {
emitters.push(new emitterTypes[i](eventPool));
emitters.push(this._createEmitter(emitterTypes[i], pool));
}
}
private _createEmitter(
type: PointerEventEmitterConstructor,
pool: ClearableObjectPool<PointerEventData>
): PointerEventEmitter {
const emitter = new type();
emitter._pool = pool;
return emitter;
}
private _onPointerEvent(evt: PointerEvent) {
this._nativeEvents.push(evt);
}
@@ -329,7 +338,7 @@ export class PointerManager implements IInput {
* Declare pointer event emitter decorator.
*/
export function registerPointerEventEmitter() {
return <T extends PointerEventEmitter>(Target: { new (pool: ClearableObjectPool<PointerEventData>): T }) => {
return <T extends PointerEventEmitter>(Target: { new (): T }) => {
PointerManager._pointerEventEmitters.push(Target);
};
}

View File

@@ -11,10 +11,10 @@ export abstract class PointerEventEmitter {
protected static _tempRay: Ray = new Ray();
protected _hitResult: IHitResult;
protected _pool: ClearableObjectPool<PointerEventData>;
/** @internal injected by PointerManager (the pool owner). */
_pool: ClearableObjectPool<PointerEventData>;
constructor(pool: ClearableObjectPool<PointerEventData>) {
this._pool = pool;
constructor() {
this._init();
}