Combine Component, Entity + Manager headers
It has reached a point where it is much easier to combine these three than to separate them.scene_man
parent
e1a7774bfb
commit
4478a512a3
|
@ -1,5 +1,4 @@
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "entManager.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
1
main.c
1
main.c
|
@ -1,5 +1,6 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "scene_impl.h"
|
#include "scene_impl.h"
|
||||||
|
#include "mempool.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define N_SCENES 3
|
#define N_SCENES 3
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
#ifndef __COMPONENTS_H
|
#ifndef __ENTITY_H
|
||||||
#define __COMPONENTS_H
|
#define __ENTITY_H
|
||||||
#include "raylib.h"
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "entity.h"
|
#include <stdbool.h>
|
||||||
// TODO: Look at sc to use macros to auto generate functions
|
#include "raylib.h"
|
||||||
|
#include "sc/map/sc_map.h"
|
||||||
|
#include "sc/queue/sc_queue.h"
|
||||||
|
|
||||||
|
#define N_TAGS 4
|
||||||
|
#define N_COMPONENTS 10
|
||||||
|
#define MAX_COMP_POOL_SIZE 1024
|
||||||
|
typedef struct EntityManager EntityManager_t;
|
||||||
|
typedef struct Entity Entity_t;
|
||||||
|
|
||||||
typedef enum ComponentEnum {
|
typedef enum ComponentEnum {
|
||||||
CBBOX_COMP_T,
|
CBBOX_COMP_T,
|
||||||
|
@ -134,4 +141,41 @@ static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
||||||
p_bbox->half_size.x = (unsigned int)(x / 2);
|
p_bbox->half_size.x = (unsigned int)(x / 2);
|
||||||
p_bbox->half_size.y = (unsigned int)(y / 2);
|
p_bbox->half_size.y = (unsigned int)(y / 2);
|
||||||
}
|
}
|
||||||
#endif // __COMPONENTS_H
|
|
||||||
|
typedef enum EntityTag {
|
||||||
|
NO_ENT_TAG,
|
||||||
|
PLAYER_ENT_TAG,
|
||||||
|
ENEMY_ENT_TAG,
|
||||||
|
CRATES_ENT_TAG,
|
||||||
|
} EntityTag_t;
|
||||||
|
|
||||||
|
struct Entity {
|
||||||
|
unsigned long m_id;
|
||||||
|
EntityTag_t m_tag;
|
||||||
|
bool m_alive;
|
||||||
|
unsigned long components[N_COMPONENTS];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EntityManager {
|
||||||
|
// All fields are Read-Only
|
||||||
|
struct sc_map_64v entities; // ent id : entity
|
||||||
|
struct sc_map_64v entities_map[N_TAGS]; // [{ent id: ent}]
|
||||||
|
struct sc_map_64v component_map[N_COMPONENTS]; // [{ent id: comp}, ...]
|
||||||
|
struct sc_queue_uint to_add;
|
||||||
|
struct sc_queue_uint to_remove;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_entity_manager(EntityManager_t* p_manager);
|
||||||
|
void update_entity_manager(EntityManager_t* p_manager);
|
||||||
|
void clear_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);
|
||||||
|
void remove_entity(EntityManager_t* p_manager, unsigned long id);
|
||||||
|
Entity_t *get_entity(EntityManager_t* p_manager, unsigned long id);
|
||||||
|
|
||||||
|
void* add_component(EntityManager_t* p_manager, Entity_t *entity, ComponentEnum_t comp_type);
|
||||||
|
void* get_component(EntityManager_t* p_manager, Entity_t *entity, ComponentEnum_t comp_type);
|
||||||
|
void remove_component(EntityManager_t* p_manager, Entity_t* entity, ComponentEnum_t comp_type);
|
||||||
|
|
||||||
|
#endif // __ENTITY_H
|
|
@ -1,4 +1,4 @@
|
||||||
#include "entManager.h"
|
#include "mempool.h"
|
||||||
|
|
||||||
void init_entity_manager(EntityManager_t* p_manager)
|
void init_entity_manager(EntityManager_t* p_manager)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
#ifndef __ENTITY_MANAGER_H
|
|
||||||
#define __ENTITY_MANAGER_H
|
|
||||||
#include "sc/queue/sc_queue.h"
|
|
||||||
#include "sc/map/sc_map.h"
|
|
||||||
#include "mempool.h" // includes entity and components
|
|
||||||
|
|
||||||
typedef struct EntityManager {
|
|
||||||
// All fields are Read-Only
|
|
||||||
struct sc_map_64v entities; // ent id : entity
|
|
||||||
struct sc_map_64v entities_map[N_TAGS]; // [{ent id: ent}]
|
|
||||||
struct sc_map_64v component_map[N_COMPONENTS]; // [{ent id: comp}, ...]
|
|
||||||
struct sc_queue_uint to_add;
|
|
||||||
struct sc_queue_uint to_remove;
|
|
||||||
} EntityManager_t;
|
|
||||||
|
|
||||||
void init_entity_manager(EntityManager_t* p_manager);
|
|
||||||
void update_entity_manager(EntityManager_t* p_manager);
|
|
||||||
void clear_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);
|
|
||||||
void remove_entity(EntityManager_t* p_manager, unsigned long id);
|
|
||||||
Entity_t *get_entity(EntityManager_t* p_manager, unsigned long id);
|
|
||||||
|
|
||||||
void* add_component(EntityManager_t* p_manager, Entity_t *entity, ComponentEnum_t comp_type);
|
|
||||||
void* get_component(EntityManager_t* p_manager, Entity_t *entity, ComponentEnum_t comp_type);
|
|
||||||
void remove_component(EntityManager_t* p_manager, Entity_t* entity, ComponentEnum_t comp_type);
|
|
||||||
|
|
||||||
#endif // __ENTITY_MANAGER_H
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef __ENTITY_H
|
|
||||||
#define __ENTITY_H
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#define N_TAGS 4
|
|
||||||
#define N_COMPONENTS 10
|
|
||||||
typedef enum EntityTag {
|
|
||||||
NO_ENT_TAG,
|
|
||||||
PLAYER_ENT_TAG,
|
|
||||||
ENEMY_ENT_TAG,
|
|
||||||
CRATES_ENT_TAG,
|
|
||||||
} EntityTag_t;
|
|
||||||
|
|
||||||
typedef struct Entity {
|
|
||||||
unsigned long m_id;
|
|
||||||
EntityTag_t m_tag;
|
|
||||||
bool m_alive;
|
|
||||||
unsigned long components[N_COMPONENTS];
|
|
||||||
|
|
||||||
} Entity_t;
|
|
||||||
#endif // __ENTITY_H
|
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef __MEMPOOL_H
|
#ifndef __MEMPOOL_H
|
||||||
#define __MEMPOOL_H
|
#define __MEMPOOL_H
|
||||||
#include "entity.h"
|
#include "EC.h"
|
||||||
#include "components.h"
|
|
||||||
#define MAX_COMP_POOL_SIZE 1024
|
|
||||||
void init_memory_pools(void);
|
void init_memory_pools(void);
|
||||||
void free_memory_pools(void);
|
void free_memory_pools(void);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __ASSETS_H
|
#ifndef __ASSETS_H
|
||||||
#define __ASSETS_H
|
#define __ASSETS_H
|
||||||
#include "sc/map/sc_map.h"
|
#include "sc/map/sc_map.h"
|
||||||
#include "components.h"
|
#include "EC.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
typedef struct Assets
|
typedef struct Assets
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef __ENGINE_H
|
#ifndef __ENGINE_H
|
||||||
#define __ENGINE_H
|
#define __ENGINE_H
|
||||||
#include "entManager.h"
|
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
#include "sc/array/sc_array.h"
|
#include "sc/array/sc_array.h"
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef __ENT_IMPL_H
|
#ifndef __ENT_IMPL_H
|
||||||
#define __ENT_IMPL_H
|
#define __ENT_IMPL_H
|
||||||
#include "entManager.h"
|
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
|
|
||||||
bool init_player_creation(const char* info_file, Assets_t* assets);
|
bool init_player_creation(const char* info_file, Assets_t* assets);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "AABB.h"
|
#include "AABB.h"
|
||||||
|
#include "EC.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue