All Projects → Trixt0r → ecsts

Trixt0r / ecsts

Licence: MIT License
A simple entity component system library written in TypeScript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ecsts

ecs
A dependency free, lightweight, fast Entity-Component System (ECS) implementation in Swift
Stars: ✭ 79 (+132.35%)
Mutual labels:  ecs
ecsgo
Provides an interactive prompt to connect to ECS Containers using the ECS ExecuteCommand API.
Stars: ✭ 30 (-11.76%)
Mutual labels:  ecs
ecs-rust
Tiny ECS library in Rust
Stars: ✭ 32 (-5.88%)
Mutual labels:  ecs
ECSEntityBuilder
Unity ECS Entity Builder/Wrapper
Stars: ✭ 39 (+14.71%)
Mutual labels:  ecs
terraform-ecs-fargate-nlb
A Terraform template used for provisioning network application stacks on AWS ECS Fargate
Stars: ✭ 50 (+47.06%)
Mutual labels:  ecs
URSA
[DEPRECATED] integrated ECS framework for Unity
Stars: ✭ 30 (-11.76%)
Mutual labels:  ecs
Entitas-Redux
An entity-component framework for Unity with code generation and visual debugging
Stars: ✭ 84 (+147.06%)
Mutual labels:  ecs
provose
Provose is a new way to manage your Amazon Web Services infrastructure.
Stars: ✭ 27 (-20.59%)
Mutual labels:  ecs
ActionFlow
基于Unity ECS的节点执行图。可支持状态机执行流程和行为树的执行流程
Stars: ✭ 61 (+79.41%)
Mutual labels:  ecs
terraform-aws-ecs-fargate-scheduled-task
AWS ECS Fargate Schedule Task Terraform Module
Stars: ✭ 25 (-26.47%)
Mutual labels:  ecs
cog
Macro powered ECS Framework written in Haxe
Stars: ✭ 29 (-14.71%)
Mutual labels:  ecs
ecs-drain-lambda
Automation of Draining ECS instances with Lambda, based on Autoscaling Group Lifecycle hooks or Spot Instance Interruption Notices
Stars: ✭ 56 (+64.71%)
Mutual labels:  ecs
ECS-Game
A roguelike written in Python adhering to ECS
Stars: ✭ 23 (-32.35%)
Mutual labels:  ecs
ECS-CommunityEdition
ECS Community Edition "Free & Frictionless"
Stars: ✭ 125 (+267.65%)
Mutual labels:  ecs
terraform-aws-alb-ingress
Terraform module to provision an HTTP style ingress rule based on hostname and path for an ALB using target groups
Stars: ✭ 20 (-41.18%)
Mutual labels:  ecs
ecs-benchmark
ECS benchmark comparison
Stars: ✭ 68 (+100%)
Mutual labels:  ecs
ecs-logging-java
Centralized logging for Java applications with the Elastic stack made easy
Stars: ✭ 128 (+276.47%)
Mutual labels:  ecs
terraform-aws-ecs-web-app
Terraform module that implements a web app on ECS and supports autoscaling, CI/CD, monitoring, ALB integration, and much more.
Stars: ✭ 175 (+414.71%)
Mutual labels:  ecs
neo4j-aws-ha-cluster
Neo4j Enterprise HA Cluster on AWS ECS
Stars: ✭ 13 (-61.76%)
Mutual labels:  ecs
polymorph
A fast and frugal entity-component-system library with a focus on code generation and compile time optimisation.
Stars: ✭ 74 (+117.65%)
Mutual labels:  ecs

ECS-TS

A simple to use entity component system library written in TypeScript.

It is meant to be used for any use case. So you will not find any game specific logic in this library.

Install

npm install @trixt0r/ecs

Examples

Checkout the examples.

Check the rectangles example out, if you do not want to checkout the code.

Usage

The main parts of this library are

Component

A Component is defined as an interface with no specific methods or properties.
I highly suggest you to implement your components as classes, since the systems will rely on those.

For example, you could define a position like this:

import { Component } from '@trixt0r/ecs';

class Position implements Component {
  constructor(public x = 0, public y = 0) {}
}

Entity

Entities are the elements, your systems will work with and have an unique identifier.

Since this library doesn't want you to tell, how to generate your ids, the base class AbstractEntity is abstract.
This means your entity implementation should extend AbstractEntity.

For example, you could do something like this:

import { AbstractEntity } from '@trixt0r/ecs';

class MyEntity extends AbstractEntity {
  constructor() {
    super(makeId());
  }
}

Adding components is just as simple as:

myComponent.components.add(new Position(10, 20));

An entity, is a Dispatcher, which means, you can register an EntityListener on it, to check whether a component has been added, removed, the components have been sorted or cleared.

System

Systems implement the actual behavior of your entities, based on which components they own.

For programming your own systems, you should implement the abstract class System.
This base class provides basic functionalities, such as

  • an updating flag, which indicates whether a system is still updating.
  • an active flag, which tells the engine to either run the system in the next update call or not.
  • an engine property, which will be set/unset, as soon as the system gets added/removed to/from an engine.

A system is also a Dispatcher, which means, you can react to any actions happening to a system, by registering a SystemListener.

Here is a minimal example of a system, which obtains a list of entities with the component type Position.

import { System, Aspect } from '@trixt0r/ecs';

class MySystem extends System {
  private aspect: Aspect;

  constructor() {
    super(/* optional priority here */);
  }

  onAddedToEngine(engine: Engine): void {
    // get entities by component 'Position'
    this.aspect = Aspect.for(engine).all(Position);
  }

  async process(): void {
    const entities = this.aspect.entities;
    entities.forEach(entity => {
      const position = entity.components.get(Position);
      //... do your logic here
    });
  }
}

Note that process can be async.
If your systems need to do asynchronous tasks, you can implement them as those. Your engine can then run them as such.
This might be useful, if you do not have data which needs to be processed every frame.

In order to keep your focus on the actual system and not the boilerplate code around, you can use the AbstractEntitySystem.

The class will help you by providing component types for directly defining an aspect for your system. The above code would become:

import { System, Aspect } from '@trixt0r/ecs';

class MySystem extends AbstractEntitySystem<MyEntity> {

  constructor() {
    super(/* optional priority here */, [Position]);
  }

  processEntity(entity: MyEntity): void {
    const position = entity.components.get(Position);
    //... do your logic here
  }
}

Engine

An Engine ties systems and entities together.
It holds collections of both types, to which you can register listeners. But you could also register an EngineListener, to listen for actions happening inside an engine.

Here is a minimal example on how to initialize an engine and add systems and/or entities to it:

import { Engine, EngineMode } from '@trixt0r/ecs';

// Init the engine
const engine = new Engine();

engine.systems.add(new MySystem());
engine.entities.add(new MyEntity());

// anywhere in your business logic or main loop
engine.run(delta);

// if you want to perform your tasks asynchronously
engine.run(delta, EngineMode.SUCCESSIVE); // Wait for a task to finish
// or...
engine.run(delta, EngineMode.PARALLEL); // Run all systems asynchronously in parallel

Support

If you find any odd behavior or other improvements, feel free to create issues. Pull requests are also welcome!

Otherwise you can help me out by buying me a coffee.

paypal

Buy Me A Coffee

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].