- 重构了游戏引擎的核心逻辑和架构 - 添加了新的实体组件系统(ECS) - 实现了简单的碰撞检测和响应 - 新增了地图和子弹功能 - 优化了输入处理和渲染逻辑 - 调整了游戏控制方式
40 lines
1.3 KiB
C
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_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__
|