Added CAPI files
I forgot to add CAPI files to .gitignore with previous commits :/
This commit is contained in:
parent
6e45e7b053
commit
0002852303
4 changed files with 1569 additions and 1 deletions
207
c-api/becs.h
Normal file
207
c-api/becs.h
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#ifndef __BECS__
|
||||
#define __BECS__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdalign.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct BECSSystem
|
||||
{
|
||||
|
||||
}BECSSystem;
|
||||
|
||||
typedef struct BECSArray
|
||||
{
|
||||
size_t size;
|
||||
void* ptr;
|
||||
}BECSArray;
|
||||
|
||||
typedef struct EntityID
|
||||
{
|
||||
///Index to entity in IDManager.
|
||||
uint32_t id;
|
||||
///Counter required for reusing ID.
|
||||
uint32_t counter;
|
||||
}EntityID;
|
||||
|
||||
typedef struct Entity
|
||||
{
|
||||
///Entity ID.
|
||||
EntityID id;
|
||||
}Entity;
|
||||
|
||||
typedef struct ComponentRef
|
||||
{
|
||||
///pointer to component
|
||||
void* ptr;
|
||||
///component index
|
||||
uint16_t id;
|
||||
}ComponentRef;
|
||||
|
||||
typedef ComponentRef EventRef;
|
||||
|
||||
typedef struct BECSComponentInfo
|
||||
{
|
||||
///Component size
|
||||
uint16_t size;
|
||||
///Component data alignment
|
||||
uint16_t alignment;
|
||||
///Initialization data
|
||||
BECSArray init_data;
|
||||
///Pointer to component destroy callback
|
||||
void* destroy_callback;
|
||||
///Pointer to component create callback
|
||||
void* create_callback;
|
||||
//void* create_callback;
|
||||
}BECSComponentInfo;
|
||||
|
||||
typedef struct BECSEventRegisterInfo
|
||||
{
|
||||
///Component size
|
||||
uint16_t size;
|
||||
///Component data alignment
|
||||
uint16_t alignment;
|
||||
}BECSEventRegisterInfo;
|
||||
|
||||
typedef struct EntityTemplate
|
||||
{
|
||||
/*///Entity components data
|
||||
BECSArray entity_data;
|
||||
///Pointer to entity type info.
|
||||
void* info;*/
|
||||
}EntityTemplate;
|
||||
|
||||
enum BECSSystemComponentAttribute
|
||||
{
|
||||
required = 0,
|
||||
optional = 1,
|
||||
excluded = 2
|
||||
};
|
||||
|
||||
enum BECSSystemComponentAccess
|
||||
{
|
||||
writable = 0,
|
||||
readonly = 1
|
||||
};
|
||||
|
||||
typedef struct BECSSystemComponentInfo
|
||||
{
|
||||
uint16_t id;
|
||||
enum BECSSystemComponentAttribute attribute;
|
||||
enum BECSSystemComponentAccess access;
|
||||
}BECSSystemComponentInfo;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSListenerCallData
|
||||
{
|
||||
uint32_t count;
|
||||
void* context;
|
||||
}BECSListenerCallData;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSSystemCallData
|
||||
{
|
||||
uint32_t count;
|
||||
uint32_t thread_id;
|
||||
uint32_t job_id;
|
||||
void* context;
|
||||
}BECSSystemCallData;
|
||||
|
||||
///C-API structure conatin only subset of real data which can be accessed directly. Component arrays can be retrived using function calls.
|
||||
typedef struct BECSEventCallData
|
||||
{
|
||||
Entity* entity;
|
||||
void* event;
|
||||
void* context;
|
||||
}BECSEventCallData;
|
||||
|
||||
typedef struct BECSEventCallback
|
||||
{
|
||||
uint16_t id;
|
||||
void (*callback)(BECSEventCallData* data);
|
||||
}BECSEventCallback;
|
||||
|
||||
typedef struct BECSSystemRegisterInfo
|
||||
{
|
||||
uint32_t pass_id;
|
||||
int32_t priority;
|
||||
uint32_t max_jobs;
|
||||
|
||||
size_t components_count;
|
||||
BECSSystemComponentInfo* components;
|
||||
|
||||
size_t event_handlers_count;
|
||||
BECSEventCallback* event_handlers;
|
||||
|
||||
size_t system_size;
|
||||
void* init_data;
|
||||
|
||||
void (*on_update)(BECSSystemCallData* call_data);
|
||||
void (*on_create)(void* system_pointer);
|
||||
void (*on_destroy)(void* system_pointer);
|
||||
void (*on_enable)(void* system_pointer);
|
||||
void (*on_disable)(void* system_pointer);
|
||||
char (*on_begin)(void* system_pointer);
|
||||
void (*on_end)(void* system_pointer);
|
||||
void (*on_add_entity)(BECSListenerCallData*);
|
||||
void (*on_remove_entity)(BECSListenerCallData*);
|
||||
void (*on_change_entity)(BECSListenerCallData*);
|
||||
void (*filter_entity)(void* system_pointer, void* info);
|
||||
}BECSSystemRegisterInfo;
|
||||
|
||||
void becsInitialize();
|
||||
void becsDestroy();
|
||||
|
||||
void becsBeginRegister();
|
||||
void becsEndRegister();
|
||||
|
||||
void becsBegin();
|
||||
void becsEnd();
|
||||
void becsCommit();
|
||||
|
||||
void becsUpdate(uint16_t pass_id);
|
||||
void becsUpdateMT(uint16_t pass_id);
|
||||
|
||||
uint16_t becsRegisterComponent(const char* name, BECSComponentInfo info);
|
||||
uint16_t becsRegisterEvent(const char* name, BECSEventRegisterInfo info);
|
||||
uint16_t becsRegisterSystem(const char* name, BECSSystemRegisterInfo info);
|
||||
uint16_t becsRegisterPass(const char* name);
|
||||
|
||||
Entity* becsAddEntity(EntityTemplate* template);
|
||||
Entity* becsAddEntityCopy(EntityID id);
|
||||
void becsRemoveEntity(EntityID id);
|
||||
|
||||
Entity* becsGetEntity(EntityID id);
|
||||
|
||||
void becsAddComponents(const EntityID entity_id, size_t length, ComponentRef* comps);
|
||||
void becsRemoveComponents(const EntityID entity_id, size_t length, uint16_t* comps);
|
||||
|
||||
EntityTemplate* becsAllocateTemplate(uint32_t count, uint16_t* components);
|
||||
EntityTemplate* becsAllocateTemplateFromEntity(EntityID id, uint8_t fill_default);
|
||||
EntityTemplate* becsAllocateTemplateCopy(EntityTemplate* tmpl);
|
||||
EntityTemplate* becsAllocateTemplateFromTemplate(EntityTemplate* tmpl, size_t new_count, uint16_t* components, size_t remove_count, uint16_t* remove_components);
|
||||
void becsFreeTemplate(EntityTemplate* tmpl);
|
||||
|
||||
void* becsEntityGetComponent(Entity* entity, uint16_t component_id);
|
||||
|
||||
void* becsSystemCallDataGetComponentArray(BECSSystemCallData* data, uint16_t component_id);
|
||||
Entity* becsSystemCallDataGetEntitiesArray(BECSSystemCallData* data);
|
||||
|
||||
void* becsListenerCallDataGetComponentArray(BECSListenerCallData* data, uint16_t component_id);
|
||||
Entity* becsListenerCallDataGetEntitiesArray(BECSListenerCallData* data);
|
||||
|
||||
void becsCallEntitiesFunction(uint16_t system_id, void (*on_update)(BECSSystemCallData* call_data), void* context);
|
||||
|
||||
void becsSendEvent(EntityID id, EventRef event);
|
||||
|
||||
#define BECS_REGISTER_COMPONENT(comp) \
|
||||
({ \
|
||||
void* mem_ptr = malloc(sizeof(comp)); \
|
||||
memcpy(mem_ptr, &comp, sizeof(comp)); \
|
||||
becsRegisterComponent(#comp, (BECSComponentInfo){sizeof(comp), alignof(comp), (BECSArray){sizeof(comp), mem_ptr}, 0, 0}); \
|
||||
})
|
||||
|
||||
//BECSComponentInfo(sizeof(comp), 4, 0, 0, 0));
|
||||
|
||||
#endif //__BECS__
|
||||
Loading…
Add table
Add a link
Reference in a new issue