Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
21 changes: 15 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ 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 { Process } from "./lib/processes/process";
import { IProcessImplementation } from "./lib/processes/process/types";
import { Scheduler } from "./lib/processes/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 @@ -92,14 +93,18 @@ namespace Tina {
* Used to add new processes to the processor.
*
* @param name process name to add.
* @param executionGroup your own executionGroup to run the process on.
* @returns a Process object.
*/
export function process(name: string): Process {
if (Process.processes.has(name)) {
return Process.processes.get(name)!;
export function process(
name: string,
executionGroup?: RBXScriptSignal,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can execution group be the same as in the ECS? It seems weird to have the same name in two places but supporting different functionality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking on this as well, I was going to discuss this with Luna, if processes can be the same as Systems as in the ECS.

): IProcessImplementation {
if (Scheduler.has(name)) {
return Scheduler.get(name)!;
}

return new Process(name, Scheduler);
return new Process(name, executionGroup);
}

export const log: Scope = Logger.scope("TINA");
Expand Down Expand Up @@ -246,6 +251,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.

3 changes: 3 additions & 0 deletions src/lib/processes/process.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="@rbxts/testez/globals" />

export = (): void => {};
36 changes: 36 additions & 0 deletions src/lib/processes/process/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { EventEmitter } from "../../events";
import { Scheduler } from "../scheduler";
import { TProcessStatus } from "../scheduler/types";
import { IProcessImplementation } from "./types";

interface IProcessEvent {
_default: [dt: number];
}

export class Process extends EventEmitter<IProcessEvent> implements IProcessImplementation {
public lastTick: number = os.clock();

public ticksPerSecond?: number;

constructor(public readonly name: string, public readonly executionGroup?: RBXScriptSignal) {
super();

Scheduler.add(name, this);
}

public resume(): void {
return Scheduler.unsuspend(this.name);
}

public suspend(ticks: number): void {
return Scheduler.suspend(this.name, ticks);
}

public status(): TProcessStatus {
return Scheduler.status(this.name);
}

public _update(dt: number): void {
return this.emit("_default", dt);
}
}
27 changes: 27 additions & 0 deletions src/lib/processes/process/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TProcessStatus } from "../scheduler/types";

export interface IProcessImplementation {
/**
* Initializes current process.
*/
resume(): void;

/**
* Suspends the current process by the given ticks, defaults to 1.
*
* @param ticks the amount of ticks to suspend the process.
*/
suspend(ticks: number): void;

/**
* Returns the current status of the process.
*
* @returns A string for it's status.
*/
status(): TProcessStatus;

/**
* @hidden (internal usage, DO NOT USE)
*/
_update(dt: number): void;
}
Loading