#include "storage.h" component_pair_t * findPair(storage_t *this, const char *name) { for (int i = 0; i < this->componentsStored; ++i) { component_pair_t *pair = &this->objects[i]; if (strcmp(name, pair->name) == 0) { return pair; } } return NULL; } entity_t createEntity(storage_t *this) { entity_t idx = this->objectsStored++; for (int i = 0; i < this->componentsStored; ++i) { component_pair_t pair = this->objects[i]; memset(&pair.objects[idx], 0, pair.objectSize); } return idx; } // Not intended for use outside of macros void internal_registerComponent(storage_t *storage, const char *name, size_t size) { unsigned int componentIdx = storage->componentsStored++; storage->objects[componentIdx] = (component_pair_t) { .name = name, .objectSize = size, .objects = malloc(sizeof(char) * size * MAX_OBJECTS) }; } void * // NULL if component with such name is not found internal_addComponent(storage_t *this, entity_t idx, const char *name) { component_pair_t *pair = findPair(this, name); if (pair == NULL) { return NULL; } // TODO: add bitset implementation return &pair->objects[idx]; } // Not intended for use outside of macros void * // NULL if component is not found internal_getComponent(storage_t *this, entity_t idx, const char *name) { for (int i = 0; i < this->componentsStored; ++i) { component_pair_t *pair = &this->objects[i]; if (strcmp(name, pair->name) == 0) { return &pair->objects[idx]; } } return NULL; }