Back to Flecs

README

README.md

4.1.59.1 KB
Original Source

Flecs is a fast and lightweight Entity Component System that lets you build games and simulations with millions of entities (join the Discord!). Here are some of the framework's highlights:

To support the project, give it a star 🌟 !

What is an Entity Component System?

ECS is a way of organizing code and data that lets you build games that are larger, more complex and are easier to extend. Something is called an ECS when it:

  • Has entities that uniquely identify objects in a game
  • Has components which are datatypes that can be added to entities
  • Has systems which are functions that run for all entities matching a component query

For more information, check the ECS FAQ!

Show me the code!

C99 example:

c
typedef struct {
  float x, y;
} Position, Velocity;

void Move(ecs_iter_t *it) {
  Position *p = ecs_field(it, Position, 0);
  Velocity *v = ecs_field(it, Velocity, 1);

  for (int i = 0; i < it->count; i++) {
    p[i].x += v[i].x;
    p[i].y += v[i].y;
  }
}

int main(int argc, char *argv[]) {
  ecs_world_t *ecs = ecs_init();

  ECS_COMPONENT(ecs, Position);
  ECS_COMPONENT(ecs, Velocity);

  ECS_SYSTEM(ecs, Move, EcsOnUpdate, Position, Velocity);

  ecs_entity_t e = ecs_insert(ecs,
    ecs_value(Position, {10, 20}),
    ecs_value(Velocity, {1, 2}));

  while (ecs_progress(ecs, 0)) { }
}

Same example in C++:

cpp
struct Position {
  float x, y;
};

struct Velocity {
  float x, y;
};

int main(int argc, char *argv[]) {
  flecs::world ecs;

  ecs.system<Position, const Velocity>()
    .each([](Position& p, const Velocity& v) {
      p.x += v.x;
      p.y += v.y;
    });

  auto e = ecs.entity()
    .insert([](Position& p, Velocity& v) {
      p = {10, 20};
      v = {1, 2};
    });

  while (ecs.progress()) { }
}

Projects using Flecs

If you have a project you'd like to share, let me know on Discord!

Tempest Rising

Territory Control 2

Resistance is Brutal

Rescue Ops: Wildfire

Age of Respair

FEAST

Gloam Vault

Antimatcher

Writ of Battle

Extermination Shock

The Forge

ECS survivors

Tome Tumble Tournament

Sol Survivor

After Sun

Flecs Hub

Flecs Hub is a collection of repositories that show how Flecs can be used to build game systems like input handling, hierarchical transforms and rendering.

ModuleDescription
flecs.components.cglmComponent registration for cglm (math) types
flecs.components.inputComponents that describe keyboard and mouse input
flecs.components.transformComponents that describe position, rotation and scale
flecs.components.physicsComponents that describe physics and movement
flecs.components.geometryComponents that describe geometry
flecs.components.graphicsComponents used for computer graphics
flecs.components.guiComponents used to describe GUI components
flecs.systems.transformHierarchical transforms for scene graphs
flecs.systems.physicsSystems for moving objects and collision detection
flecs.systems.sokolSokol-based renderer
flecs.gameGeneric game systems, like a camera controller

Language bindings

The following language bindings have been developed with Flecs! Note that these are projects built and maintained by helpful community members, and may not always be up to date with the latest commit from master!