feat(engine): 重构游戏引擎核心逻辑
- 重新设计了引擎的初始化和运行流程 - 引入了实体组件系统(ECS)和物理系统 - 优化了渲染系统和输入系统 - 移除了不必要的资源管理系统 - 调整了日志系统的实现
This commit is contained in:
69
game_engine/ecs/ge_render_system.h
Normal file
69
game_engine/ecs/ge_render_system.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef __GE_RENDER_SYSTEM_H__
|
||||
#define __GE_RENDER_SYSTEM_H__
|
||||
|
||||
#include "ge_entity.h"
|
||||
#include "ge_render_component.h"
|
||||
#include <pynic_log/pynic_log.h>
|
||||
|
||||
typedef struct ge_render_system {
|
||||
ge_render_t* render;
|
||||
ge_ecs_storage_t* ecs;
|
||||
} ge_render_system_t;
|
||||
|
||||
static inline void
|
||||
ge_render_system_init(ge_render_system_t* ctx, ge_render_t* render) {
|
||||
Assert(ctx != NULL && render != NULL);
|
||||
ctx->render = render;
|
||||
}
|
||||
|
||||
#define _GE_RENDERABLE_MASK (GE_RENDERABLE_MASK | GE_COMPONENT_ACVIVE)
|
||||
|
||||
static inline void
|
||||
ge_render_system_draw_all(ge_render_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_RENDERABLE_MASK) != _GE_RENDERABLE_MASK) continue;
|
||||
|
||||
ge_render_pos2_t pos = {
|
||||
entity->position.x,
|
||||
entity->position.y,
|
||||
};
|
||||
ge_render_component_t* comp = &entity->renderable;
|
||||
Assert(comp != NULL);
|
||||
|
||||
switch (comp->type) {
|
||||
case GE_RENDER_COMPONENT_TYPE_POINT:
|
||||
ctx->render->func_draw_point(
|
||||
ctx->render,
|
||||
&pos,
|
||||
comp->data.point.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_RECT:
|
||||
ctx->render->func_draw_rect(
|
||||
ctx->render,
|
||||
&(ge_render_rect_t) {
|
||||
pos,
|
||||
comp->data.rect.size,
|
||||
},
|
||||
comp->data.rect.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_TEXT:
|
||||
TODO();
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_RECOURCE:
|
||||
TODO();
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("render component not set Avaliable type %d, id %d", comp->type, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __GE_RENDER_SYSTEM_H__
|
||||
Reference in New Issue
Block a user