summaryrefslogtreecommitdiff
path: root/src/storage.c
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-09-15 00:20:47 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-09-15 00:20:47 +0400
commit5be3c38211c6e236fdf39c2885da571d93ad32ae (patch)
treee1199b932626c1830ad41eb60269825dcf9b477e /src/storage.c
parent11048808cbe3dc77bb2bee6d2643a33a45574509 (diff)
Added systems support
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c33
1 files changed, 33 insertions, 0 deletions
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];
}