Refactor Entity Tag out of EC

Tags are game-specific things. So, move out of EC
scene_man
En Yi 2023-05-29 21:41:17 +08:00
parent 29c9b4eec7
commit b5f026c96b
6 changed files with 15 additions and 12 deletions

View File

@ -1,4 +1,5 @@
#include "mempool.h" #include "mempool.h"
#include "ent_impl.h"
#include <stdio.h> #include <stdio.h>
int main(void) int main(void)

View File

@ -151,17 +151,9 @@ static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
p_bbox->half_size.y = (unsigned int)(y / 2); p_bbox->half_size.y = (unsigned int)(y / 2);
} }
typedef enum EntityTag {
NO_ENT_TAG,
PLAYER_ENT_TAG,
ENEMY_ENT_TAG,
CRATES_ENT_TAG,
BOULDER_ENT_TAG,
} EntityTag_t;
struct Entity { struct Entity {
unsigned long m_id; unsigned long m_id;
EntityTag_t m_tag; unsigned int m_tag;
bool m_alive; bool m_alive;
unsigned long components[N_COMPONENTS]; unsigned long components[N_COMPONENTS];
EntityManager_t* manager; EntityManager_t* manager;
@ -181,7 +173,7 @@ void update_entity_manager(EntityManager_t* p_manager);
void clear_entity_manager(EntityManager_t* p_manager); void clear_entity_manager(EntityManager_t* p_manager);
void free_entity_manager(EntityManager_t* p_manager); void free_entity_manager(EntityManager_t* p_manager);
Entity_t* add_entity(EntityManager_t* p_manager, EntityTag_t tag); Entity_t* add_entity(EntityManager_t* p_manager, unsigned int tag);
void remove_entity(EntityManager_t* p_manager, unsigned long id); void remove_entity(EntityManager_t* p_manager, unsigned long id);
Entity_t *get_entity(EntityManager_t* p_manager, unsigned long id); Entity_t *get_entity(EntityManager_t* p_manager, unsigned long id);

View File

@ -74,7 +74,7 @@ void free_entity_manager(EntityManager_t* p_manager)
sc_queue_term(&p_manager->to_remove); sc_queue_term(&p_manager->to_remove);
} }
Entity_t *add_entity(EntityManager_t* p_manager, EntityTag_t tag) Entity_t *add_entity(EntityManager_t* p_manager, unsigned int tag)
{ {
unsigned long e_idx = 0; unsigned long e_idx = 0;
Entity_t* p_ent = new_entity_from_mempool(&e_idx); Entity_t* p_ent = new_entity_from_mempool(&e_idx);

View File

@ -157,7 +157,7 @@ Entity_t* new_entity_from_mempool(unsigned long* e_idx_ptr)
ent->components[j] = MAX_COMP_POOL_SIZE; ent->components[j] = MAX_COMP_POOL_SIZE;
} }
ent->m_alive = true; ent->m_alive = true;
ent->m_tag = NO_ENT_TAG; ent->m_tag = 0;
return ent; return ent;
} }

View File

@ -2,6 +2,15 @@
#define __ENT_IMPL_H #define __ENT_IMPL_H
#include "assets.h" #include "assets.h"
typedef enum EntityTag {
NO_ENT_TAG = 0,
PLAYER_ENT_TAG,
ENEMY_ENT_TAG,
CRATES_ENT_TAG,
BOULDER_ENT_TAG,
} EntityTag_t;
bool init_player_creation(const char* info_file, Assets_t* assets); bool init_player_creation(const char* info_file, Assets_t* assets);
Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets); Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets);
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal); Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal);

View File

@ -1,4 +1,5 @@
#include "game_systems.h" #include "game_systems.h"
#include "ent_impl.h"
#include "AABB.h" #include "AABB.h"
#include "EC.h" #include "EC.h"
#include "constants.h" #include "constants.h"