2021-05-04 17:41:30 +00:00
|
|
|
#include "modules/controllers.h"
|
|
|
|
|
|
|
|
#include "modules/general.h"
|
|
|
|
#include "modules/physics.h"
|
2021-05-07 14:43:54 +00:00
|
|
|
#include "zpl.h"
|
|
|
|
|
|
|
|
void MovementImpulse(ecs_iter_t *it) {
|
|
|
|
Input *in = ecs_column(it, Input, 1);
|
|
|
|
Velocity *v = ecs_column(it, Velocity, 2);
|
|
|
|
|
|
|
|
for (int i = 0; i < it->count; i++) {
|
2021-05-07 15:24:22 +00:00
|
|
|
if (zpl_abs(v[i].x) < 1000.0f)
|
|
|
|
v[i].x = in[i].x*1000.0;
|
|
|
|
if (zpl_abs(v[i].x) < 1000.0f)
|
|
|
|
v[i].y = in[i].y*1000.0;
|
2021-05-07 14:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-04 17:41:30 +00:00
|
|
|
|
|
|
|
void ControllersImport(ecs_world_t *ecs) {
|
|
|
|
ECS_MODULE(ecs, Controllers);
|
|
|
|
ecs_set_name_prefix(ecs, "Controllers");
|
|
|
|
|
|
|
|
ECS_IMPORT(ecs, General);
|
|
|
|
ECS_IMPORT(ecs, Physics);
|
|
|
|
ECS_IMPORT(ecs, FlecsMeta);
|
2021-05-07 14:43:54 +00:00
|
|
|
|
2021-05-04 17:41:30 +00:00
|
|
|
ECS_META(ecs, Input);
|
|
|
|
|
|
|
|
ECS_TAG(ecs, EcsActor);
|
|
|
|
ECS_TAG(ecs, EcsPlayer);
|
|
|
|
ECS_TAG(ecs, EcsBuilder);
|
2021-05-07 14:43:54 +00:00
|
|
|
|
|
|
|
ECS_SYSTEM(ecs, MovementImpulse, EcsOnUpdate, Input, physics.Velocity);
|
2021-05-04 17:41:30 +00:00
|
|
|
|
|
|
|
ECS_PREFAB(ecs, Base, general.Position, physics.Velocity, Input, EcsActor);
|
|
|
|
ECS_TYPE(ecs, Player, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Walking, EcsActor, EcsPlayer);
|
|
|
|
ECS_TYPE(ecs, Builder, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Flying, EcsActor, EcsBuilder);
|
|
|
|
|
|
|
|
ECS_SET_COMPONENT(Input);
|
|
|
|
ECS_SET_ENTITY(EcsActor);
|
|
|
|
ECS_SET_ENTITY(EcsPlayer);
|
|
|
|
ECS_SET_ENTITY(EcsBuilder);
|
|
|
|
ECS_SET_TYPE(Builder);
|
|
|
|
ECS_SET_TYPE(Player);
|
2021-05-07 14:43:54 +00:00
|
|
|
ECS_SET_ENTITY(MovementImpulse);
|
2021-05-04 17:41:30 +00:00
|
|
|
}
|