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

Improve the @pixi/runner developer experience #10243

Open
wants to merge 3 commits into
base: v7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/framebuffer/Framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Framebuffer
depthTexture: BaseTexture;
colorTextures: Array<BaseTexture>;
glFramebuffers: {[key: string]: GLFramebuffer};
disposeRunner: Runner;
disposeRunner: Runner<'disposeFramebuffer', [framebuffer: Framebuffer, contextLost?: boolean]>;

/**
* @param width - Width of the frame buffer
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/geometry/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Buffer

public static: boolean;
public id: number;
disposeRunner: Runner;
disposeRunner: Runner<'disposeBuffer', [buffer: Buffer, contextLost?: boolean]>;

/**
* A map of renderer IDs to webgl buffer
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/geometry/BufferSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class BufferSystem implements ISystem
* @param {PIXI.Buffer} buffer - buffer with data
* @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
dispose(buffer: Buffer, contextLost?: boolean): void
disposeBuffer(buffer: Buffer, contextLost?: boolean): void
{
if (!this.managedBuffers[buffer.id])
{
Expand Down Expand Up @@ -207,7 +207,7 @@ export class BufferSystem implements ISystem

for (let i = 0; i < all.length; i++)
{
this.dispose(this.managedBuffers[all[i]], contextLost);
this.disposeBuffer(this.managedBuffers[all[i]], contextLost);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/geometry/Geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Geometry
* @type {object}
*/
glVertexArrayObjects: {[key: number]: {[key: string]: WebGLVertexArrayObject}};
disposeRunner: Runner;
disposeRunner: Runner<'disposeGeometry', [geometry: Geometry, contextLost?: boolean]>;

/** Count of existing (not destroyed) meshes that reference this geometry. */
refCount: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/geometry/GeometrySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class GeometrySystem implements ISystem
buf.refCount--;
if (buf.refCount === 0 && !contextLost)
{
bufferSystem.dispose(buffers[i], contextLost);
bufferSystem.disposeBuffer(buffers[i], contextLost);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shader/Shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Shader
*/
uniformBindCount = 0;

disposeRunner: Runner;
disposeRunner: Runner<'disposeShader', [shader: Shader]>;

/**
* @param program - The program the shader will use.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/system/SystemManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ISystemConfig<R>
export class SystemManager<R=IRenderer> extends EventEmitter
{
/** a collection of runners defined by the user */
readonly runners: {[key: string]: Runner} = {};
readonly runners: {[key: string]: Runner<string, any[]>} = {};

private _systemsHash: Record<string, ISystem> = {};

Expand Down Expand Up @@ -123,7 +123,7 @@ export class SystemManager<R=IRenderer> extends EventEmitter
* @param runner - the runner to target
* @param options - key value options for each system
*/
emitWithCustomOptions(runner: Runner, options: Record<string, unknown>): void
emitWithCustomOptions(runner: Runner<string, any[]>, options: Record<string, unknown>): void
{
const systemHashKeys = Object.keys(this._systemsHash);

Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/textures/resources/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@ export abstract class Resource
* @member {Runner}
* @private
*/
protected onResize: Runner; // TODO: Should this be private? It doesn't seem to be used anywhere else.
// TODO: Should this be private? It doesn't seem to be used anywhere else.
protected onResize: Runner<'setRealSize', [width: number, height: number]>;

/**
* Mini-runner for handling update events
* @member {Runner}
* @private
*/
protected onUpdate: Runner;
protected onUpdate: Runner<'update', []>;

/**
* Handle internal errors, such as loading errors
* accepts 1 param: error
* @member {Runner}
* @private
*/
protected onError: Runner;
protected onError: Runner<'onError', [error: any]>;

/**
* @param width - Width of the resource
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transformFeedback/TransformFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TransformFeedback

buffers: Buffer[];

disposeRunner: Runner;
disposeRunner: Runner<'disposeTransformFeedback', [tf: TransformFeedback, contextLost?: boolean]>;

constructor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class TransformFeedbackSystem implements ISystem
buf.refCount--;
if (buf.refCount === 0 && !contextLost)
{
bufferSystem.dispose(buffer, contextLost);
bufferSystem.disposeBuffer(buffer, contextLost);
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions packages/runner/src/Runner.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
export type RunnerListenerCallback<ARG extends unknown[] = any[]> = (...args: ARG) => unknown;
export type RunnerListenerCallback<ARG extends any[]> = (...args: ARG) => any;

type RunnerItemValid<T extends string, ARG extends unknown[] = any[]> =
{ [K in T]: RunnerListenerCallback<ARG> | unknown };
type RunnerItemValid<T extends string, ARG extends any[]> = {
[K in T]: RunnerListenerCallback<ARG>;
};

type RunnerItemAny = Record<string, unknown>;
type RunnerItemAny = Record<string, any>;

type RunnerItemEmpty = Record<string, never>;

export type RunnerItem<T = string, ARG extends unknown[] = any[]> =
T extends string ?
RunnerItemValid<T, ARG> & RunnerItemAny | RunnerItemEmpty :
unknown;
export type RunnerItem<T extends string, ARG extends any[]> =
| RunnerItemValid<T, ARG>
| RunnerItemAny;

/**
* A Runner is a highly performant and simple alternative to signals. Best used in situations
Expand Down Expand Up @@ -98,7 +96,7 @@ export type RunnerItem<T = string, ARG extends unknown[] = any[]> =
* @template ARG - The argument types for the event handler functions.
* @memberof PIXI
*/
export class Runner<T = any, ARG extends unknown[] = any[]>
export class Runner<T extends string, ARG extends any[]>
{
public items: any[];
private _name: T;
Expand Down