From 5be3c38211c6e236fdf39c2885da571d93ad32ae Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Wed, 15 Sep 2021 00:20:47 +0400 Subject: Added systems support --- src/storage.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/storage.c') diff --git a/src/storage.c b/src/storage.c index 3b715ee..1935ae7 100644 --- a/src/storage.c +++ b/src/storage.c @@ -1,4 +1,5 @@ #include "storage.h" +#include "bitset.h" component_pair_t * findPair(storage_t *this, const char *name) @@ -26,12 +27,42 @@ createEntity(storage_t *this) return idx; } +void +registerSystem(storage_t *storage, system_t system, bitset_t components) +{ + int idx = storage->systemsStored++; + storage->systems[idx] = system; + bitarena_copy(&storage->systemSignatures, components, idx); +} + +bitset_t +createSignature(storage_t *storage, char **components) +{ + bitset_t bitset = bitset_create(); + + for (int i = 0; components[i] != NULL; ++i) + { + const char *componentName = components[i]; + component_pair_t *pair = findPair(storage, componentName); + if (pair == NULL) + { + return NULL; + } + else + { + bitset_set(bitset, pair->idx); + } + } + return bitset; +} + // 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) { + .idx = componentIdx, .name = name, .objectSize = size, .objects = malloc(sizeof(char) * size * MAX_OBJECTS) @@ -48,6 +79,8 @@ internal_addComponent(storage_t *this, entity_t idx, const char *name) } // TODO: add bitset implementation + bitset_t bitset = bitarena_at(&this->objectSignatures, idx); + bitset_set(bitset, pair->idx); return &pair->objects[idx]; } -- cgit v1.2.3