2025-03-11 00:41:24 -06:00
|
|
|
#ifndef ARC_STD_ENTITY_H_
|
|
|
|
|
#define ARC_STD_ENTITY_H_
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-03-14 01:02:00 -06:00
|
|
|
#include "arc/std/array.h"
|
|
|
|
|
#include "arc/std/bool.h"
|
2025-03-11 00:41:24 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief an entity component system type
|
|
|
|
|
*/
|
|
|
|
|
typedef struct ARC_EntitySystem ARC_EntitySystem;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:39:16 -06:00
|
|
|
* @brief an entity type (just an id)
|
2025-03-11 00:41:24 -06:00
|
|
|
*/
|
|
|
|
|
typedef uint32_t ARC_Entity;
|
|
|
|
|
|
2025-03-14 01:02:00 -06:00
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @brief flags to define an entities current state
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
typedef enum ARC_EntityFlags {
|
|
|
|
|
ARC_ENTITY_DEAD = 0,
|
|
|
|
|
ARC_ENTITY_ALIVE = 1
|
|
|
|
|
} ARC_EntityFlags;
|
|
|
|
|
|
2025-03-13 19:22:27 -06:00
|
|
|
/**
|
|
|
|
|
* @brief an entity component system type
|
|
|
|
|
*/
|
|
|
|
|
typedef uint32_t ARC_EntityComponent;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-13 19:22:27 -06:00
|
|
|
*/
|
|
|
|
|
typedef void (* ARC_EntityCoponent_CreateEmptyFn)(void **type);
|
|
|
|
|
|
2025-03-11 00:41:24 -06:00
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @brief creates an empty entity system, use ARC_EntitySystem_RegisterComponent to add compenents to the entity system
|
|
|
|
|
*
|
|
|
|
|
* @parm[out] entitySystem an empty entity system
|
2025-03-11 00:41:24 -06:00
|
|
|
*/
|
|
|
|
|
void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief destroys an ARC_EntitySystem
|
|
|
|
|
*
|
2025-03-14 01:02:00 -06:00
|
|
|
* @param[in] entitySystem ARC_EntitySystem to free
|
2025-03-11 00:41:24 -06:00
|
|
|
*/
|
|
|
|
|
void ARC_EntitySystem_Destroy(ARC_EntitySystem *entitySystem);
|
|
|
|
|
|
2025-03-14 01:02:00 -06:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*
|
2025-06-21 18:24:55 -06:00
|
|
|
* @return a uint32_t id for for the component
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint32_t componentSize);
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem);
|
2025-03-13 19:22:27 -06:00
|
|
|
|
2025-03-14 01:02:00 -06:00
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
void ARC_EntitySystem_ReleaseEntity(ARC_EntitySystem *entitySystem, ARC_Entity entity);
|
2025-03-13 19:22:27 -06:00
|
|
|
|
2025-03-14 01:02:00 -06:00
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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 *
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
void ARC_EntitySystem_AddComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component, void *data);
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
ARC_Bool ARC_EntitySystem_HasComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
|
|
|
|
void *ARC_EntitySystem_GetComponentData(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-21 18:24:55 -06:00
|
|
|
* @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
|
2025-03-14 01:02:00 -06:00
|
|
|
*/
|
2025-03-16 01:35:09 -06:00
|
|
|
ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components);
|
2025-03-13 19:22:27 -06:00
|
|
|
|
2025-03-11 00:41:24 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // !ARC_STD_ENTITY_H_
|