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_SYSTEM(ecs, Move, EcsOnUpdate, Position, Velocity);
ecs_set(ecs, e, Position, {10, 20});
ecs_set(ecs, e, Velocity, {1, 2});
}
FLECS_API bool ecs_progress(ecs_world_t *world, ecs_ftime_t delta_time)
Progress a world.
#define ECS_SYSTEM(world, id, phase,...)
Declare & define a system.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
ecs_entity_t ecs_new_id(ecs_world_t *world)
Create new entity id.
#define ECS_COMPONENT(world, id)
Declare & define a component.
ecs_world_t * ecs_init(void)
Create a new world.
Same example in C++11:
struct Position {
float x, y;
};
struct Velocity {
float x, y;
};
int main(int argc, char *argv[]) {
ecs.system<Position, const Velocity>()
.each([](Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
});
.set([](Position& p, Velocity& v) {
p = {10, 20};
v = {1, 2};
});
while (ecs.progress()) { }
}
void each(Func &&func) const
Iterate over all entities with components in argument list of function.
flecs::entity entity(Args &&... args) const
Create an entity.
flecs::system system(flecs::entity e) const
Upcast entity to a system.
Projects using Flecs
If you have a project you'd like to share, let me know on Discord!
Territory Control
https://store.steampowered.com/app/690290/Territory_Control_2/
Sol Survivor
https://nicok.itch.io/sol-survivor-demo
The Forge
https://github.com/ConfettiFX/The-Forge
Equilibrium Engine
https://github.com/clibequilibrium/EquilibriumEngine
Gravitas
https://thepunkcollective.itch.io/gravitas
After Sun
https://github.com/foxnne/aftersun
Tower defense (open source demo)
https://www.flecs.dev/tower_defense/etc (repository)
Procedural City (open source demo)
https://www.flecs.dev/city (repository)
Resources
Resources provided by the community :heart:
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.
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!
from Hacker News https://ift.tt/TdEfuHn
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.