Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { type IRunnerLibrary } from "../../../library";
import { BaseContext } from "./base.context";

export class ExecutionContext extends BaseContext {
export class ExecutionContext<T extends IRunnerLibrary> extends BaseContext {
protected _isRunning: boolean = true;
protected _currentLibrary: T;

get isRunning() {
return this._isRunning;
}

get lib(): T {
return this._currentLibrary;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export abstract class BaseComponentSystemLibrary
extends Library
implements IComponentSystemLibrary
{
abstract run(context: ExecutionContext): Promise<void>;
abstract run(context: ExecutionContext<this>): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { type IGraphicsLibrary } from "../interfaces";
import { Library } from "../library";

export abstract class BaseGraphicsLibrary extends Library implements IGraphicsLibrary {
abstract run(context: ExecutionContext): Promise<void>;
abstract run(context: ExecutionContext<this>): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { type ExecutionContext } from "../../../../context";
import { type ILibrary } from "../../library.type";

export interface IRunnerLibrary extends ILibrary {
run(context: ExecutionContext): Promise<void>;
run(context: ExecutionContext<IRunnerLibrary>): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ExecutionContext } from "@nanoforge/common";
import { ExecutionContext, type IRunnerLibrary } from "@nanoforge/common";

export class EditableExecutionContext extends ExecutionContext {
export class EditableExecutionContext<T extends IRunnerLibrary> extends ExecutionContext<T> {
setIsRunning(isRunning: boolean) {
this._isRunning = isRunning;
}

setCurrentLibrary(library: T) {
this._currentLibrary = library;
}
}
12 changes: 8 additions & 4 deletions packages/core/src/core/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type ApplicationContext,
ClearContext,
ExecutionContext,
type IRunOptions,
type IRunnerLibrary,
InitContext,
Expand All @@ -11,6 +10,7 @@ import {

import { type ApplicationConfig } from "../application/application-config";
import type { IApplicationOptions } from "../application/application-options.type";
import { EditableExecutionContext } from "../common/context/contexts/executions/execution.editable-context";
import { type EditableLibraryContext } from "../common/context/contexts/library.editable-context";

export class Core {
Expand Down Expand Up @@ -63,8 +63,8 @@ export class Core {
return new InitContext(this.context, this.config.libraryManager, options);
}

private getExecutionContext(): ExecutionContext {
return new ExecutionContext(this.context, this.config.libraryManager);
private getExecutionContext<T extends IRunnerLibrary>(): EditableExecutionContext<T> {
return new EditableExecutionContext(this.context, this.config.libraryManager);
}

private getClearContext(): ClearContext {
Expand All @@ -78,8 +78,12 @@ export class Core {
}
}

private async runExecute(context: ExecutionContext, libraries: LibraryHandle<IRunnerLibrary>[]) {
private async runExecute(
context: EditableExecutionContext<IRunnerLibrary>,
libraries: LibraryHandle<IRunnerLibrary>[],
) {
for (const handle of libraries) {
context.setCurrentLibrary(handle.library);
await handle.library.run(context);
}
}
Expand Down
17 changes: 3 additions & 14 deletions packages/ecs/lib/libecs.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
declare namespace RuntimeExports {
let HEAPF32: any;
let HEAPF64: any;
let HEAP_DATA_VIEW: any;
let HEAP8: any;
let HEAPU8: any;
let HEAP16: any;
let HEAPU16: any;
let HEAP32: any;
let HEAPU32: any;
let HEAP64: any;
let HEAPU64: any;
}
interface WasmModule {
}

Expand All @@ -20,6 +7,8 @@ export interface ClassHandle {
delete(): void;
deleteLater(): this;
isDeleted(): boolean;
// @ts-ignore - If targeting lower than ESNext, this symbol might not exist.
[Symbol.dispose](): void;
clone(): this;
}
export interface container extends ClassHandle {
Expand Down Expand Up @@ -85,5 +74,5 @@ interface EmbindModule {
};
}

export type MainModule = WasmModule & typeof RuntimeExports & EmbindModule;
export type MainModule = WasmModule & EmbindModule;
export default function MainModuleFactory (options?: unknown): Promise<MainModule>;
5 changes: 5 additions & 0 deletions packages/ecs/src/ecs-context.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type ExecutionContext } from "@nanoforge/common";

import { type ECSLibrary } from "./ecs-library";

export type ECSContext = ExecutionContext<ECSLibrary>;
2 changes: 1 addition & 1 deletion packages/ecs/src/ecs-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class ECSLibrary extends BaseComponentSystemLibrary {
this.registry.addSystem(system);
}

getZipper(types: [Component]): [any] {
getZipper(types: [Component, ...Component[]]): [any, ...any[]] {
return this.registry.getZipper(types);
}
}
1 change: 1 addition & 0 deletions packages/ecs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "../lib/libecs.wasm";

export * from "./ecs-library";
export type { ECSContext } from "./ecs-context.type";
3 changes: 1 addition & 2 deletions packages/sound/src/sound.library.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseSoundLibrary } from "@nanoforge/common";
import { NfNotFound } from "@nanoforge/common/src/exceptions";
import { BaseSoundLibrary, NfNotFound } from "@nanoforge/common";

export class SoundLibrary extends BaseSoundLibrary {
private muted: boolean;
Expand Down
Loading