Making the most of ECS identifiers

Position position_array[MAX_ENTITY_COUNT];
Velocity velocity_array[MAX_ENTITY_COUNT];
unsigned int ent = world.entity();position_array[ent] = {10, 20};
velocity_array[ent] = {1, 1};

Component ids are Entity ids

entity Platoon_1 = world.entity();
unit_1.add(Platoon_1);
unit_2.add(Platoon_1);
world.each(Platoon_1, [](flecs::entity unit) {
// unit is part of Platoon_1!
});
world.component<Position>()
.set<Struct>({
{"x", world.component<float>() }
{"y", world.component<float>() }
});
auto script_component = world.entity()
.set<flecs::Component>({ component_size, component_alignment });
world.each<flecs::Component>([](flecs::entity component) {
// found a component!
});
world.component<MySingleton>()
.set<MySingleton>({ ... });

Entity Liveliness Tracking

Entity Relations

entity Eats = world.entity();
entity Apples = world.entity();
entity Bob = world.entity();
Bob.add(Eats, Apples); // Bob -(Eats)-> Apples
world.each(world.pair(Eats, flecs::Wildcard), 
[](flecs::entity e) {
// all entities that eat something!
});

Id Partitioning

// Generate entities between 5000 and 6000
world.set_entity_range(5000, 6000);
world.enable_range_check(true);

Type flags

ent.add(world.component<Position>() | flecs::Disabled);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store