Coder Social home page Coder Social logo

jaimegensler / thyseus Goto Github PK

View Code? Open in Web Editor NEW
74.0 4.0 3.0 1.38 MB

An archetypal Entity Component System, built entirely in Typescript

License: MIT License

TypeScript 95.75% JavaScript 4.25%
archetype ecs entity-component-system javascript typescript js ts multithreaded

thyseus's Introduction

npm version license: mit pull requests: welcome code style: prettier

Thyseus is a DX & performance oriented archetypal Entity Component System (ECS) for Typescript. It provides an expressive, type-driven API so you can focus on how data moves through your app instead of worrying about how to manage it. Many features are included out of the box, including:

  • Effortless integration with third-party libraries like three.js.
  • Archetypal storage for lean memory use and cache-friendly iteration.
  • Complex queries with filters like Maybe, And, Or, With, and Without.
  • First class support for Resources (singletons) and Events.
  • Boilerplate-free and safety-first worker thread support - no eval()!
  • Deeply customizable execution logic for easy handling of patterns like fixed updates.

Get started with the docs, or join us on the Web-ECS Discord!

Installation

# pnpm
pnpm add thyseus

# yarn
yarn add thyseus

# npm
npm i thyseus

Contributing

If you're interested in contributing, please have a look at the code of conduct and the contributing guide first.

API

Components

class Vec2 {
  x: number;
  y: number;
  constructor(x = 0, y = 0) {
    this.x = x;
    this.y = y;
  }

  add(other: Vec2) {
    this.x += other.x;
    this.y += other.y;
  }
}
export class Position extends Vec2 {}
export class Velocity extends Vec2 {}

Systems

import { Query } from 'thyseus'
import { Position, Velocity } from './components';

export function spawnEntities(commands: Commands) {
  commands.spawn().add(new Position()).add(new Velocity(1, 2));
}

export function move(query: Query<[Position, Velocity]>) {
  for (const [pos, vel] of query) {
    pos.add(vel);
  }
}

Worlds

import { World, Schedule } from 'thyseus';
import { moveSystem, spawnEntitiesSystem } from './systems';

class SetupSchedule extends Schedule {}

export const myWorld = await new World()
  .addEventListener('start', async world => {
	await world.runSchedule(SetupSchedule);
	function loop() {
		await world.runSchedule(Schedule);
		requestAnimationFrame(loop);
	}
	loop();
  })
  .addSystems(SetupSchedule, spawnEntities)
  .addSystems(Schedule, move)
  .prepare();

myWorld.start();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.