Skip to content

SanderMertens/flecs

Repository files navigation

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:

  • Hasentitiesthat uniquely identify objects in a game
  • Hascomponentswhich are datatypes that can be added to entities
  • Hassystemswhich are functions that run for all entities matching a componentquery

For more information, check theECS FAQ!

Show me the code!

C99 example:

typedefstruct{
floatx,y;
}Position,Velocity;

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

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

intmain(intargc,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_te=ecs_insert(ecs,
ecs_value(Position,{10,20}),
ecs_value(Velocity,{1,2}));

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

Same example in C++11:

structPosition{
floatx, y;
};

structVelocity{
floatx, y;
};

intmain(intargc,char*argv[]) {
flecs::world ecs;

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

autoe = 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 onDiscord!

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

Tempest Rising

Territory Control 2

image

The Forge

image

Extermination Shock

image

Tome Tumble Tournament

image

Hyperion Minecraft Server

image

Sol Survivor

image

Equilibrium Engine

image

After Sun

image

Flecs Demo's

https://github /SanderMertens/tower_defense Tower Defense

https://github /flecs-hub/city City

Flecs Hub

Flecs Hubis 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 ponents.cglm Component registration for cglm (math) types
flecs ponents.input Components that describe keyboard and mouse input
flecs ponents.transform Components that describe position, rotation and scale
flecs ponents.physics Components that describe physics and movement
flecs ponents.geometry Components that describe geometry
flecs ponents.graphics Components used for computer graphics
flecs ponents.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!