2024-02-29 11:22:52 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2024-03-04 14:20:50 +08:00
|
|
|
#include "Types.h"
|
2024-02-29 11:22:52 +08:00
|
|
|
#include "util/vector.h"
|
2024-03-04 14:20:50 +08:00
|
|
|
#include "util/tree.h"
|
2024-02-29 16:59:04 +08:00
|
|
|
#include "Physics_Component.h"
|
2024-03-01 17:09:24 +08:00
|
|
|
#include "Player_Component.h"
|
2024-02-29 11:22:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-03-04 14:20:50 +08:00
|
|
|
typedef struct _Entity Entity;
|
|
|
|
typedef void (*entity_Thinker)(Entity *e, Duration deltaTime); // The Thinker function type assigned to Entities
|
|
|
|
|
|
|
|
|
2024-02-29 11:22:52 +08:00
|
|
|
// Entity.
|
2024-02-29 16:17:55 +08:00
|
|
|
typedef struct _Entity {
|
2024-03-01 17:09:24 +08:00
|
|
|
uintptr_t id;
|
2024-03-04 14:20:50 +08:00
|
|
|
char *name; // Allocated on the stack & copied
|
2024-02-29 11:22:52 +08:00
|
|
|
|
2024-02-29 16:17:55 +08:00
|
|
|
Component_Position *position;
|
|
|
|
Component_Hitbox *hitbox;
|
2024-03-01 17:09:24 +08:00
|
|
|
Component_Player *player;
|
2024-03-04 14:20:50 +08:00
|
|
|
|
|
|
|
entity_Thinker thinker; // Called by System_Entity each frame if not NULL.
|
|
|
|
void *thinkerData; // Data managed by the Thinker, if exists.
|
2024-02-29 16:17:55 +08:00
|
|
|
} Entity;
|
2024-02-29 11:22:52 +08:00
|
|
|
|
|
|
|
|
2024-03-04 14:20:50 +08:00
|
|
|
typedef struct _App App;
|
|
|
|
|
|
|
|
// Entity manager.
|
|
|
|
typedef struct {
|
|
|
|
App *super;
|
|
|
|
tree_Tree *entities; // Contains Entity objects on the nodes
|
|
|
|
uintptr_t maxID;
|
|
|
|
|
|
|
|
vector_Vector *flaggedDelete;
|
|
|
|
} System_Entity;
|
|
|
|
|
|
|
|
System_Entity *entity_NewSystem(App *super);
|
|
|
|
void entity_DeleteSystem(System_Entity *sys);
|
|
|
|
|
|
|
|
Entity *entity_Create(System_Entity *sys, const char *name);
|
|
|
|
void entity_Delete(System_Entity *sys, uintptr_t id);
|
|
|
|
|
|
|
|
void entity_Advance(System_Entity *sys, Duration deltaTime);
|
|
|
|
|
|
|
|
|
2024-02-29 11:22:52 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|