summaryrefslogtreecommitdiff
path: root/src/storage.c
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-09-12 20:21:28 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-09-12 20:21:28 +0400
commit5438fe938f6a15f4eadcc0bb2fd09a02130aafb4 (patch)
treef05d70112e40c255c225cb29d0d08853df633ae2 /src/storage.c
parent259c4e23a136d2077c4083c4bbbad55a2a31bcef (diff)
Renamed most of structs and changed allocation strategy for storage
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/storage.c b/src/storage.c
index 2fd2601..3b715ee 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1,11 +1,11 @@
#include "storage.h"
-component_pair *
-findPair(storage *this, const char *name)
+component_pair_t *
+findPair(storage_t *this, const char *name)
{
for (int i = 0; i < this->componentsStored; ++i)
{
- component_pair *pair = &this->objects[i];
+ component_pair_t *pair = &this->objects[i];
if (strcmp(name, pair->name) == 0)
{
return pair;
@@ -14,55 +14,54 @@ findPair(storage *this, const char *name)
return NULL;
}
-Entity
-createEntity(storage *this)
+entity_t
+createEntity(storage_t *this)
{
- Entity idx = this->objectsStored++;
+ entity_t idx = this->objectsStored++;
for (int i = 0; i < this->componentsStored; ++i)
{
- this->objects[i].objects[idx] = NULL;
+ 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 *storage, char *name, size_t size)
+internal_registerComponent(storage_t *storage, const char *name, size_t size)
{
unsigned int componentIdx = storage->componentsStored++;
- storage->objects[componentIdx] = (component_pair) {
+ storage->objects[componentIdx] = (component_pair_t) {
.name = name,
.objectSize = size,
- .objects = malloc(sizeof(void*) * MAX_OBJECTS)
+ .objects = malloc(sizeof(char) * size * MAX_OBJECTS)
};
}
void * // NULL if component with such name is not found
-internal_addComponent(storage *this, Entity idx, const char *name)
+internal_addComponent(storage_t *this, entity_t idx, const char *name)
{
- component_pair *pair = findPair(this, name);
+ component_pair_t *pair = findPair(this, name);
if (pair == NULL)
{
return NULL;
}
- pair->objects[idx] = (void *) malloc(pair->objectSize);
- void *component = pair->objects[idx];
- // component = (void *) malloc(pair->objectSize);
+ // TODO: add bitset implementation
- return component;
+ return &pair->objects[idx];
}
// Not intended for use outside of macros
void * // NULL if component is not found
-internal_getComponent(storage *this, Entity idx, const char *name)
+internal_getComponent(storage_t *this, entity_t idx, const char *name)
{
for (int i = 0; i < this->componentsStored; ++i)
{
- component_pair *pair = &this->objects[i];
+ component_pair_t *pair = &this->objects[i];
if (strcmp(name, pair->name) == 0)
{
- return pair->objects[idx];
+ return &pair->objects[idx];
}
}
return NULL;