Files
school_stm32/game_engine/ecs/ge_physics_system.h
ZZY 89bede93a9 feat(engine): 重构游戏引擎核心逻辑
- 重新设计了引擎的初始化和运行流程
- 引入了实体组件系统(ECS)和物理系统
- 优化了渲染系统和输入系统
- 移除了不必要的资源管理系统
- 调整了日志系统的实现
2025-06-29 18:46:36 +08:00

40 lines
1.3 KiB
C

#ifndef __GE_PHYSICS_SYSTEM_H__
#define __GE_PHYSICS_SYSTEM_H__
#include "ge_entity.h"
#include "ge_physics_component.h"
#include <pynic_log/pynic_log.h>
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_COMPONENT_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_COMPONENT_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__