#ifndef __GE_PHYSICS_SYSTEM_H__ #define __GE_PHYSICS_SYSTEM_H__ #include "ge_entity.h" #include "ge_physics_component.h" #include typedef struct ge_physics_system { ge_ecs_storage_t* ecs; } ge_physics_system_t; #define _GE_PHYSICS_MASK (GE_PHYSICS_MASK | GE_COMPONENT_ACVIVE) static inline void ge_physics_system_run_all(ge_physics_system_t* ctx) { Assert(ctx != NULL); ge_ecs_storage_t* ecs = ctx->ecs; Assert(ecs != NULL); for (int i = 1; i <= ecs->count && i < GE_ECS_MAX; ++i) { ge_entity_t* entity = &ecs->entities[i]; ge_ecs_mask_t mask = entity->component_mask; if ((mask & _GE_PHYSICS_MASK) != _GE_PHYSICS_MASK) continue; ge_physics_component_t* comp = &entity->physics_body; Assert(comp != NULL); ge_physics_component_type_t type= comp->type; if (type & GE_PHYSICS_COMP_TYPE_ACCELERATION) { comp->velocity.x += comp->acceleration.x >> GE_PHYSICS_ACCELERATION_BIT; comp->velocity.y += comp->acceleration.y >> GE_PHYSICS_ACCELERATION_BIT; } if (type & GE_PHYSICS_COMP_TYPE_VELOCITY) { entity->position.x += comp->velocity.x >> GE_PHYSICS_VELOCITY_BIT; entity->position.y += comp->velocity.y >> GE_PHYSICS_VELOCITY_BIT; } } } #endif // __GE_PHYSICS_SYSTEM_H__