Home

Awesome

<p align="center"> <a title="Pub" href="https://pub.dartlang.org/packages/fast_ecs"><img alt="Pub Version" src="https://img.shields.io/pub/v/fast_ecs?color=blue&style=for-the-badge"></a> </p>

Fast ECS

Simple and fast Entity-Component-System (ECS) library written in Dart.

CPU Flame Chart

Demonstration of performance for rotation of 1024 entities

all RotationSystem

void update(double deltaTime, SetEntity entities) {
  for (var i = 0; i < entities.size; i++) {
    Entity entity = entities[i];
    TransformComponent transform = transformComponents[entity];
    VelocityComponent rotation = velocityComponents[entity];
    transform.rotation += rotation.velocity * deltaTime;
    transform.dirty = true;
  }
}

update RotationSystem

SpriteSystem

void updateSprite(TransformComponent transform, SpriteComponent sprite) {
  var textureRegion = sprite.textureRegion;
  if (transform.dirty && textureRegion != null) {
    var scos = cos(transform.rotation) * transform.scale;
    var ssin = sin(transform.rotation) * transform.scale;
    var tx = -scos * textureRegion.anchorX + ssin * textureRegion.anchorY;
    var ty = -ssin * textureRegion.anchorX - scos * textureRegion.anchorY;
    sprite.transformData.set(scos, ssin, tx, ty);
    transform.dirty = false;
  }
}

updateSprite


Demonstration of performance for rotation of 10K entities

update 10K sprites

Support

You can support the development of libraries for creating multiplatform games in Flutter:

Patreon

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Main memory reference ...................... 100 ns             
SSD random read ........................ 150,000 ns  = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns  = 250 µs
Read 1 MB sequentially from SSD* ..... 1,000,000 ns  =   1 ms
Read 1 MB sequentially from disk .... 20,000,000 ns  =  20 ms
Send packet CA->Netherlands->CA .... 150,000,000 ns  = 150 ms

source

History of creation

The source of inspiration was the resource A SIMPLE ENTITY COMPONENT SYSTEM (ECS) [C++]