archeus/include/arc/std/entity.h
2025-06-21 18:39:16 -06:00

133 lines
4.4 KiB
C

#ifndef ARC_STD_ENTITY_H_
#define ARC_STD_ENTITY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/array.h"
#include "arc/std/bool.h"
#include <stdint.h>
/**
* @brief an entity component system type
*/
typedef struct ARC_EntitySystem ARC_EntitySystem;
/**
* @brief an entity type (just an id)
*/
typedef uint32_t ARC_Entity;
/**
* @brief flags to define an entities current state
*/
typedef enum ARC_EntityFlags {
ARC_ENTITY_DEAD = 0,
ARC_ENTITY_ALIVE = 1
} ARC_EntityFlags;
/**
* @brief an entity component system type
*/
typedef uint32_t ARC_EntityComponent;
/**
* @brief a callback function for components attached to an entity to create an empty type when a new entity is created
*
* @param[out] type, the place to create an empty type
*/
typedef void (* ARC_EntityCoponent_CreateEmptyFn)(void **type);
/**
* @brief creates an empty entity system, use ARC_EntitySystem_RegisterComponent to add compenents to the entity system
*
* @parm[out] entitySystem an empty entity system
*/
void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem);
/**
* @brief destroys an ARC_EntitySystem
*
* @param[in] entitySystem ARC_EntitySystem to free
*/
void ARC_EntitySystem_Destroy(ARC_EntitySystem *entitySystem);
/**
* @brief registers space for a component and an id for the compenent within the entity system
*
* @note this function will set arc_errno if the components run out of space
*
* @param[in] entitySystem the entity system to register the component to
* @param[in] componentSize the size of the component to register
*
* @return a uint32_t id for for the component
*/
uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint32_t componentSize);
/**
* @brief inits an empty entity, usually use ARC_EntitySystem_AddComponent to add compenets to the entity this function creates
*
* @param[in] entitySystem the entitySystem to init a new entity in
*
* @return an ARC_Entity that holds the id of the newly inited slot
*/
ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem);
/**
* @brief releases an entity from a given entity system
*
* @param[in] entitySystem the entity system to remove the entity from
* @param[in] entity the entity to remove
*/
void ARC_EntitySystem_ReleaseEntity(ARC_EntitySystem *entitySystem, ARC_Entity entity);
/**
* @brief adds a component to a given entity within an entity system
*
* @note data will be copied, so if data was created elsewere it needs to be freed elsewhere
*
* @param[in] entitySystem the entity system that holds the entity which is being modified
* @param[in] entity the entity as an id which a component is being added to
* @param[in] component the id of the compenent for the entity system
* @param[in] data the components data as a void *
*/
void ARC_EntitySystem_AddComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component, void *data);
/**
* @brief checks if an entity has a component within an entity system
*
* @param[in] entitySystem the entity system that holds the entity which is being checked
* @param[in] entity the entity as an id
* @param[in] component the id of the compenent for the entity system
*
* @return ARC_True if the entity has the given component, otherwise ARC_False
*/
ARC_Bool ARC_EntitySystem_HasComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
/**
* @brief retrieves a components data for a specific entity
*
* @param[in] entitySystem the entity system that holds the entity which is being retrieved
*
* @param[in] entity the entity as an id
* @param[in] component the id of the compenent for the entity system
* @return the components data as a void * on success, otherwise NULL
*/
void *ARC_EntitySystem_GetComponentData(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
/**
* @brief retrieves all entities which have the given components
*
* @note this function will not check for exact matches, it just returns the entitys which have all the components (the entity might have more components than what is given)
*
* @param[in] entitySystem the entity system to query entities from
* @param[in] components the components a entity has to have to match
*/
ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components);
#ifdef __cplusplus
}
#endif
#endif // !ARC_STD_ENTITY_H_