feat(engine): 重构游戏引擎核心逻辑
- 重新设计了引擎的初始化和运行流程 - 引入了实体组件系统(ECS)和物理系统 - 优化了渲染系统和输入系统 - 移除了不必要的资源管理系统 - 调整了日志系统的实现
This commit is contained in:
64
game_engine/ecs/ge_entity.h
Normal file
64
game_engine/ecs/ge_entity.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef __GE_ENTIRY_H__
|
||||
#define __GE_ENTIRY_H__
|
||||
|
||||
#include <ge_core.h>
|
||||
#include <utils/ge_vector2i.h>
|
||||
#include "ge_render_component.h"
|
||||
#include "ge_physics_component.h"
|
||||
|
||||
#include <stdint.h>
|
||||
typedef uint16_t ge_ecs_id_t; // 支持65536个实体
|
||||
#define GE_ECS_MAX 128
|
||||
|
||||
typedef enum {
|
||||
GE_COMPONENT_ACVIVE = 1 << 0,
|
||||
GE_COMPONENT_POSITION = 1 << 1,
|
||||
GE_COMPONENT_TRANSFORM = 1 << 2, // TODO not implimented
|
||||
GE_COMPONENT_RENDERABLE = 1 << 3,
|
||||
GE_COMPONENT_PHYSICS_BODY = 1 << 4, // TODO not implimented
|
||||
GE_COMPONENT_COLLIDER = 1 << 5, // TODO not implimented
|
||||
GE_COMPONENT_TIMED_LIFE = 1 << 6, // TODO not implimented
|
||||
} ge_ecs_mask_t;
|
||||
|
||||
#define GE_RENDERABLE_MASK \
|
||||
(GE_COMPONENT_POSITION | GE_COMPONENT_RENDERABLE)
|
||||
#define GE_PHYSICS_MASK \
|
||||
(GE_COMPONENT_POSITION | GE_COMPONENT_PHYSICS_BODY)
|
||||
|
||||
typedef struct ge_entity {
|
||||
ge_ecs_id_t id;
|
||||
ge_ecs_mask_t component_mask;
|
||||
ge_vector2i_t position;
|
||||
ge_render_component_t renderable;
|
||||
ge_physics_component_t physics_body;
|
||||
} ge_entity_t;
|
||||
|
||||
typedef struct {
|
||||
// TODO static storage to dynamic storage
|
||||
ge_entity_t entities[GE_ECS_MAX];
|
||||
ge_ecs_id_t count;
|
||||
} ge_ecs_storage_t;
|
||||
|
||||
typedef struct ge_ecs {
|
||||
ge_ecs_storage_t storage;
|
||||
} ge_ecs_t;
|
||||
|
||||
|
||||
static inline ge_ecs_id_t ge_ecs_add_entity(ge_ecs_t* ecs, ge_entity_t** entity) {
|
||||
ge_ecs_id_t id = ++ecs->storage.count;
|
||||
if (id >= GE_ECS_MAX) {
|
||||
return 0;
|
||||
}
|
||||
// TODO squeze the data
|
||||
if (entity != NULL) *entity = &ecs->storage.entities[id];
|
||||
return id;
|
||||
}
|
||||
|
||||
static inline ge_entity_t* ge_ecs_get_entity(ge_ecs_t* ecs, ge_ecs_id_t id) {
|
||||
if(id >= ecs->storage.count) {
|
||||
return NULL;
|
||||
}
|
||||
return &ecs->storage.entities[id];
|
||||
}
|
||||
|
||||
#endif // __GE_ENTIRY_H__
|
||||
Reference in New Issue
Block a user