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
3 changes: 3 additions & 0 deletions packages/core/src/application/nanoforge-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export abstract class NanoforgeApplication {
private _core?: Core;
private readonly _options: IApplicationOptions;

protected abstract get type(): "client" | "server";

constructor(options?: Partial<IApplicationOptions>) {
this.applicationConfig = new ApplicationConfig();

Expand Down Expand Up @@ -47,6 +49,7 @@ export abstract class NanoforgeApplication {
this._core = new Core(
this.applicationConfig,
new EditableApplicationContext(this.applicationConfig.libraryManager),
this.type === "server",
);
return this._core.init(options, this._options);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/application/nanoforge-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
import { NanoforgeApplication } from "./nanoforge-application";

export class NanoforgeClient extends NanoforgeApplication {
protected get type(): "client" {
return "client";
}

public useGraphics(library: IGraphicsLibrary) {
this.applicationConfig.useGraphicsLibrary(library);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/application/nanoforge-server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { NanoforgeApplication } from "./nanoforge-application";

export class NanoforgeServer extends NanoforgeApplication {}
export class NanoforgeServer extends NanoforgeApplication {
protected get type(): "server" {
return "server";
}
}
17 changes: 15 additions & 2 deletions packages/core/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export class Core {
private readonly context: ApplicationContext;
private options?: IApplicationOptions;
private _configRegistry?: ConfigRegistry;
private _isServer;

constructor(config: ApplicationConfig, context: ApplicationContext) {
constructor(config: ApplicationConfig, context: ApplicationContext, isServer: boolean) {
this.config = config;
this.context = context;
this._isServer = isServer;
}

public async init(options: IRunOptions, appOptions: IApplicationOptions): Promise<void> {
Expand All @@ -52,12 +54,23 @@ export class Core {
this.runClear(this.getClearContext());
return;
}
};

const renderClient = () => {
render();
cancelAnimationFrame(requestAnimationFrameHandle);
requestAnimationFrameHandle = requestAnimationFrame(runner);
};

const renderServer = () => {
render();
};

context.application.setIsRunning(true);
const intervalHandle = setInterval(render, 1000 / this.options.tickRate);
const intervalHandle = setInterval(
this._isServer ? renderServer : renderClient,
1000 / this.options.tickRate,
);
}

private getInitContext(options: IRunOptions): InitContext {
Expand Down
Loading