introduce HandleCollisions system

isolation_bkp/dynres
Dominik Madarász 2021-05-08 11:22:25 +02:00
parent 6a8e5286ea
commit d7975eacb7
3 changed files with 15 additions and 3 deletions

View File

@ -13,6 +13,7 @@ typedef struct {
ECS_DECLARE_COMPONENT(Velocity);
ECS_DECLARE_ENTITY(MoveWalk);
ECS_DECLARE_ENTITY(UpdateTrackerPos);
ECS_DECLARE_ENTITY(HandleCollisions);
} Physics;
#define PhysicsImportHandles(handles)\
@ -22,5 +23,6 @@ typedef struct {
ECS_IMPORT_COMPONENT(handles, Velocity);\
ECS_IMPORT_ENTITY(handles, MoveWalk);\
ECS_IMPORT_ENTITY(handles, UpdateTrackerPos);\
ECS_IMPORT_ENTITY(handles, HandleCollisions);\
void PhysicsImport(ecs_world_t *ecs);

View File

@ -20,8 +20,8 @@ void MovementImpulse(ecs_iter_t *it) {
}
}
#define DEMO_NPC_CHANGEDIR_FACTOR 0.03
#define DEMO_NPC_MOVE_SPEED 100
#define DEMO_NPC_CHANGEDIR_FACTOR 0.01
#define DEMO_NPC_MOVE_SPEED 1000
void DemoNPCMoveAround(ecs_iter_t *it) {
Velocity *v = ecs_column(it, Velocity, 1);

View File

@ -14,7 +14,14 @@ void MoveWalk(ecs_iter_t *it) {
p[i].y += v[i].y * it->delta_time;
v[i].x = zpl_lerp(v[i].x, 0.0f, PHY_WALK_DRAG);
v[i].y = zpl_lerp(v[i].y, 0.0f, PHY_WALK_DRAG);
}
}
void HandleCollisions(ecs_iter_t *it) {
Position *p = ecs_column(it, Position, 1);
Velocity *v = ecs_column(it, Velocity, 2);
for (int i = 0; i < it->count; i++) {
// NOTE(zaklaus): world bounds
{
double w = (double)world_dim()/2.0;
@ -43,6 +50,7 @@ void PhysicsImport(ecs_world_t *ecs) {
ECS_META(ecs, Velocity);
ECS_SYSTEM(ecs, MoveWalk, EcsOnUpdate, general.Position, Velocity);
ECS_SYSTEM(ecs, HandleCollisions, EcsOnValidate, general.Position, Velocity);
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, general.Position);
ECS_SET_TYPE(Movement);
@ -50,4 +58,6 @@ void PhysicsImport(ecs_world_t *ecs) {
ECS_SET_ENTITY(Flying);
ECS_SET_COMPONENT(Velocity);
ECS_SET_ENTITY(MoveWalk);
ECS_SET_ENTITY(UpdateTrackerPos);
ECS_SET_ENTITY(HandleCollisions);
}