Skip to content

QiXi/fast_ecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pub Version

Fast ECS

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

CPU Flame Chart

Demonstration of performance for rotation of 1024 entities

  • device Nexus 5 (2014) android 6.0.1
  • fast_ecs version 0.0.1
  • all time 10500(ms)
  • 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

  • device Nexus 5 (2014) android 6.0.1
  • fast_ecs version 0.1.0
  • all time 10.5 sec.
  • 10000 entities
  • update rotation - 0.85 sec.
  • update sprite - 3.6 sec.

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++]