A fast entity component system (ECS) for C & C++
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:
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:
For more information, check the ECS FAQ!
C99 example:
…Same example in C++:
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()) { }
}If you have a project you'd like to share, let me know on Discord!
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 |
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!
Script: a struct can't use a vector or array type declared earlier in the same script
Re-entering scope of anonymous entity through variable in managed script asserts when script is updated
Multiple up() terms read components from different parents
MSVC C2099 for log2 initializer in script math registry
Adding a component to an instantiated prefab aborts with ECS_ALREADY_IN_USE, which blocks live prefab editing.
Add support for MS-DOS build
up|self traversal failing to combine results correctly in query for relationship
Add context support to query `order_by` callbacks
Allow `ecs_entity_range_set` in stage
Add IWYU pragma comments to internal headers