• Stars
    star
    6,345
  • Rank 6,286 (Top 0.2 %)
  • Language
    C
  • License
    Other
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast entity component system (ECS) for C & C++

flecs

Version MIT Documentation actions Discord Chat

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:

Flecs Explorer

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!

Try it out!

The Flecs playground lets you try Flecs without writing any C/C++ code!

Flecs playground

To learn how to use the playground, check the Flecs Script Tutorial.

Documentation

Performance

For a list of regularly tracked benchmarks, see the ECS Benchmark project.

Show me the code!

C99 example:

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

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

  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_new_id(ecs);
  ecs_set(ecs, e, Position, {10, 20});
  ecs_set(ecs, e, Velocity, {1, 2});

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

Same example in C++11:

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()
    .set([](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!

Hytale

We knew that we wanted to build Hytale around an Entity-Component-System (ECS). When we analyzed the options, FLECS rose to the top. FLECS provides the backbone of the Hytale Game Engine. Its flexibility has allowed us to build highly varied gameplay while supporting our vision for empowering Creators.

-- Dann Webster, Hypixel studios

Tempest Rising

image

image

image

image

image

image

image

Flecs Demo's

https://www.flecs.dev/tower_defense/etc (repository) image

https://www.flecs.dev/city (repository) image

Resources

Resources provided by the community ❤️

Flecs around the web

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.

Module Description
flecs.components.cglm Component registration for cglm (math) types
flecs.components.input Components that describe keyboard and mouse input
flecs.components.transform Components that describe position, rotation and scale
flecs.components.physics Components that describe physics and movement
flecs.components.geometry Components that describe geometry
flecs.components.graphics Components used for computer graphics
flecs.components.gui Components used to describe GUI components
flecs.systems.transform Hierarchical transforms for scene graphs
flecs.systems.physics Systems for moving objects and collision detection
flecs.systems.sokol Sokol-based renderer
flecs.game Generic 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!

More Repositories

1

ecs-faq

Frequently asked questions about Entity Component Systems
1,984
star
2

bake

Bake, A build system for building, testing and running C & C++ projects
C
678
star
3

y

Simple, introspective language for creating the best software. Inspired by vlang.io
88
star
4

tower_defense

Tower defense game written in Flecs
C++
65
star
5

ecs_nbody

Implementation of n-body in the flecs ECS framework
C
42
star
6

colorize

Make your C/C++ console apps prettier!
C
39
star
7

ecs_pong

A no-frills implementation of pong in the flecs ECS framework
C
36
star
8

ecs_benchmark

Flecs benchmarks
C
33
star
9

ecs_collisions

ECS example that demonstrates collision detection in the flecs ECS framework
C
26
star
10

flecs_not_for_dummies

An in-depth introduction to using Flecs
23
star
11

ecs_squares

Sokol rendering example
C
10
star
12

vectorize_test

Test the performance difference between vectorized and non-vectorized code
C
8
star
13

ecs_graphics

Basic ECS application demonstrating input and rendering simple graphics
C
7
star
14

ecs_solar

Demo of rendering hierarchically organized entities
C
5
star
15

flecs-cpp_tools

C++ tools for Flecs
C++
4
star
16

flecs-components-dds

Components describing a DDS application
C
4
star
17

rti-systems-connext

Implementation of flecs-components-dds
C
3
star
18

ecs_backup

Shows how inheritance can be used to build a backup system
C
3
star
19

ecs_rock_paper_scissors

A tiny rock, paper, scissors implementation in ECS
C
3
star
20

sqlite

SQLite binding for corto
C
2
star
21

flecs-gx

ECS based renderer
C
2
star
22

cities

Replicator to dataset that contains all cities in the world
C
2
star
23

dds-helloworld

A minimalistic OMG DDS example
C++
2
star
24

ecs_colliding_shapes

A demo with a large number of colliding shapes
C
2
star
25

trees

Example code for Flecs Prefab blog
C++
2
star
26

ecs_presentation

2
star
27

ecs_inheritance

ECS demo that showcases inheritance
C
2
star
28

amalgamate

Simple amalgamation tool for bake projects
C
1
star
29

python-binding

Python for Corto
C
1
star
30

dds-mq

A type safe, brokerless queue built with DDS
C++
1
star
31

icecx

DDS to Cortex bridge for the MDPnP ICE demo
C
1
star
32

example

Example bake application (used for testing)
C
1
star
33

SanderMertens.github.io

CSS
1
star
34

dds-bench

Simple benchmarking tool for OMG-DDS
C
1
star
35

dDDS

Dynamic DDS API prototype
C
1
star
36

dds-requestreply

A request-reply example using vanilla OMG DDS
C++
1
star
37

rti-connext

RTI connext build instructions & bake driver
C
1
star
38

kitchen-explorer

Flecs explorer example
C++
1
star