Entity creation, empty (n = 1000000):
Framework | Measurement |
---|---|
EnTT | 0.003885 |
EnTT | 0.002851 (batching) |
enum JoinKind { | |
InnerJoin, | |
OuterJoin | |
}; | |
/** Create group. | |
* A group stores a set of entities for a given list of archetypes. | |
* Entities within the group will be ordered according to a component | |
* pivot list, such that the first component is guaranteed to be |
typedef struct Radar { | |
float range; | |
float speed; | |
} Radar; | |
void SetRadar(ecs_rows_t *rows) { | |
ECS_COLUMN(rows, Radar, radar, 1); | |
ECS_COLUMN_COMPONENT(rows, EcsCircle, 2); | |
ECS_COLUMN_COMPONENT(rows, EcsAngularMomentum2D, 3); |
int main(int argc, char *argv[]) { | |
ecs_world_t *world = ecs_init_w_args(argc, argv); | |
ECS_IMPORT(world, FlecsComponentsTransform, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsGeometry, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsGraphics, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsInput, ECS_2D); | |
ECS_IMPORT(world, FlecsSystemsSdl2, ECS_2D); | |
ECS_ENTITY(world, WheelPrefab, EcsPrefab, EcsCircle, EcsColor); |
#include <meta_test.h> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
ECS_STRUCT(Position, { | |
float x; | |
float y; |
/* -- Create single entity -- */ | |
FLECS_EXPORT | |
ecs_entity_t ecs_new_w_entity( | |
ecs_world_t *world, | |
ecs_entity_t component); | |
FLECS_EXPORT | |
ecs_entity_t ecs_new_w_type( | |
ecs_world_t *world, |
struct BulletCount { | |
int32_t count; | |
}; | |
struct Damage { | |
float value; | |
}; | |
int main(int argc, char * argv[]) { | |
flecs::world world(argc, argv); |
Here are some generic design guidelines (emphasis on guidelines, not rules):
When building a new feature, start with the components and spend time thinking about how the components will be used (how often are they written/read, who owns them, how many instances etc)
Design components so that they have a single purpose. It is much easier (and cheap) to combine two components in a query than it is to split up components, which causes a lot of refactoring.
Don't over-generalize. If your code has lots of branches it is possible that you're trying to do too much with a single component. Consider splitting up components. It's ok to have multiple components with the same fields, if this makes your business logic simpler (and faster).
Think twice before adding collections to components. Collections are OK if the contents of the collection are meant to be interpreted as an atomic unit, but if the individual elements must be interpreted in a standalone way, consider creating separate entities instead.
info: bootstrap | |
info: | threading available | |
info: | time management available | |
info: | bootstrap core components | |
info: | | table [EcsComponent,6,CHILDOF|280] created | |
info: | | table [EcsComponent] created | |
info: | | table [Type] created | |
info: | | table [Name] created | |
info: | | table [CHILDOF|280] created | |
info: | | table [Name,CHILDOF|280] created |