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

fix(process): rework #108

Open
wants to merge 5 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { Internals } from "./lib/net/internal";
import { Client } from "./lib/net/util/client";
import { Identifiers } from "./lib/net/util/identifiers";
import { Server } from "./lib/net/util/server";
import { Process } from "./lib/process/process";
import Scheduler from "./lib/process/scheduler";
import { Component, ComponentData, Flyweight, FlyweightData, TagComponent } from "./lib/types/ecs";
import { Users } from "./lib/user";
import { DefaultUserDeclaration } from "./lib/user/default/types";
Expand Down Expand Up @@ -88,20 +86,6 @@ namespace Tina {
return new TinaCore();
}

/**
* Used to add new processes to the processor.
*
* @param name process name to add.
* @returns a Process object.
*/
export function process(name: string): Process {
if (Process.processes.has(name)) {
return Process.processes.get(name)!;
}

return new Process(name, Scheduler);
}

export const log: Scope = Logger.scope("TINA");

/**
Expand Down Expand Up @@ -246,6 +230,10 @@ export { User, Users } from "./lib/user";
/** State namespace */
export { State } from "./lib/state";

/** Process class and scheduler namespace */
export { Process } from "./lib/processes/process";
export { Scheduler } from "./lib/processes/scheduler";

/** Container export */
export { Container } from "./lib/container";

Expand Down
38 changes: 0 additions & 38 deletions src/lib/process/process.spec.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/lib/process/process.ts

This file was deleted.

77 changes: 0 additions & 77 deletions src/lib/process/scheduler.spec.ts

This file was deleted.

112 changes: 0 additions & 112 deletions src/lib/process/scheduler.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/lib/processes/process.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@rbxts/testez/globals" />
52 changes: 52 additions & 0 deletions src/lib/processes/process/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Scheduler, TinaScheduler } from "../scheduler";
import { ProcessStatus } from "./types";

export abstract class Process {
public scheduler: Scheduler = TinaScheduler;

constructor() {
this.scheduler.schedule(this);
}

/**
* Suspends current process by the given ticks (defaults to 1).
*
* @param ticks amount of ticks.
*/
public suspend(ticks = 1): void {
return this.scheduler.suspend(this, ticks);
}

/**
* Resumes current process.
*/
public resume(): void {
return this.scheduler.unsuspend(this);
}

/**
* Returns current process Status.
*
* @returns a string indicating it's current status.
*/
public status(): ProcessStatus {
const isActive = this.scheduler.has(this);
const isSuspended = this.scheduler.isSuspended(this);

return isSuspended ? "suspended" : isActive ? "active" : !isActive ? "dead" : "unknown";
}

/**
* Deletes current process, not anymore needed.
*/
public delete(): void {
return this.scheduler.unschedule(this);
}

/**
* Method invoked every tick (specified on the scheduler)
*
* @param dt delta time between ticks.
*/
public abstract update(dt: number): void;
}
1 change: 1 addition & 0 deletions src/lib/processes/process/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ProcessStatus = "active" | "dead" | "suspended" | "unknown";
Loading