Last active
April 26, 2019 23:51
-
-
Save SanderMertens/6e36e7f6d85c6ab14afb64c3c7071152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
ECS_COLUMN_COMPONENT(rows, EcsLine, 4); | |
for (int i = 0; i < rows->count; i ++) { | |
ecs_entity_t radar = rows->entities[i]; | |
ecs_entity_t range = ecs_lookup_child(world, radar, "RadarRange"); | |
ecs_entity_t sweep = ecs_lookup_child(word, radar, "RadarSweep"); | |
ecs_set(rows->world, range, EcsCircle, {radar[i].range}); | |
ecs_set(rows->world, sweep, EcsAngularMomentum2D, {radar[i].speed}); | |
ecs_set(rows->world, sweep, EcsLine, {0, 0}, {0, radar[i].range}); | |
} | |
} | |
int main(int argc, char *argv) { | |
ecs_world_t *world = ecs_init(); | |
/* Radar prefab */ | |
ECS_ENTITY(world, RadarPrefab, | |
EcsPrefab, | |
Radar: {range: 0}, | |
EcsPosition2D: {0, 0}); | |
ECS_ENTITY(world, RadarRange, | |
EcsPrefab: {parent: RadarPrefab}, | |
EcsPosition2D: {0, 0}, | |
EcsCircle: {0}); | |
ECS_ENTITY(world, RadarSweep, | |
EcsPrefab: {parent: RadarPrefab}, | |
EcsPosition2D: {0, 0}, | |
EcsRotation2D: {0}, | |
EcsAngularMomentum2D: {0}, | |
EcsLine: {{0, 0}, {0, 0}}); | |
ECS_SYSTEM(world, SetRadar, EcsOnSet, Radar, | |
ID.EcsCircle, | |
ID.EcsAngularMomentum2D, | |
ID.EcsLine); | |
ECS_SYSTEM(world, UpdateRadar, EcsOnUpdate, Radar); | |
/* Ship prefab */ | |
ECS_ENTITY(world, ShipPrefab, | |
EcsPrefab, | |
EcsPosition2D: {0, 0}, | |
EcsRotatino2D: {0, 0}, | |
EcsCircle: {0, 0}); | |
ECS_ENTITY(world, ShipRadar, RadarPrefab | |
EcsPrefab: {.parent = ShipPrefab}, | |
Radar: {range: 100}); | |
/* Plane prefab */ | |
ECS_ENTITY(world, PlanePrefab, | |
EcsPrefab, | |
EcsPosition2D: {0, 0}, | |
EcsRotatino2D: {0, 0}, | |
EcsCircle: {0, 0}); | |
ECS_ENTITY(world, PlaneRadar, RadarPrefab | |
EcsPrefab: {parent: PlanePrefab}, | |
Radar: {range: 50}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment