From 259c4e23a136d2077c4083c4bbbad55a2a31bcef Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Sat, 11 Sep 2021 13:48:08 +0400 Subject: initial commit --- src/storage.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/storage.h (limited to 'src/storage.h') diff --git a/src/storage.h b/src/storage.h new file mode 100644 index 0000000..44fe5fb --- /dev/null +++ b/src/storage.h @@ -0,0 +1,53 @@ +#ifndef storage_h_INCLUDED +#define storage_h_INCLUDED + +#include +#include + +#ifndef MAX_OBJECTS +#define MAX_OBJECTS 4096 +#endif + +#ifndef MAX_COMPONENTS +#define MAX_COMPONENTS 32 +#endif + +#define GET_COMPONENT(storage, componentType, idx) (componentType *) internal_getComponent(storage, idx, #componentType) +#define REGISTER_COMPONENT(storage, componentType) internal_registerComponent(storage, #componentType, sizeof(componentType)) +#define ADD_COMPONENT(storage, idx, componentType) internal_addComponent(storage, idx, #componentType) + +typedef unsigned int Entity; + +typedef struct +{ + char *name; + size_t objectSize; + void **objects; +} component_pair; + +typedef struct +{ + unsigned int componentsStored; + unsigned int objectsStored; + component_pair *objects; +} storage; + +component_pair * // NULL if pair is not found +findPair(storage *this, const char *name); + +Entity +createEntity(storage *this); + +// Not intended for use outside of macros +void +internal_registerComponent(storage *storage, char *name, size_t size); + +void * // NULL if component with such name is not found +internal_addComponent(storage *this, Entity idx, const char *name); + +// Not intended for use outside of macros +void * // NULL if component is not found +internal_getComponent(storage *this, Entity idx, const char *name); + +#endif // storage_h_INCLUDED + -- cgit v1.2.3