From ba2f810f0752bdecf8253b34bd245c7939f23534 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 4 Dec 2025 13:16:21 -0500 Subject: initial chunk rendering --- src/list.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/list.c (limited to 'src/list.c') diff --git a/src/list.c b/src/list.c new file mode 100644 index 0000000..0f00cdd --- /dev/null +++ b/src/list.c @@ -0,0 +1,71 @@ +#include +#include + +#include "list.h" + +static void list_init(List *list, int elmSize) +{ + list->data = NULL; + list->capacity = 0; + list->len = 0; + list->elmSize = elmSize; +} + +void list_initf(List *list) +{ + list_init(list, sizeof(float)); +} + +void list_initi(List *list) +{ + list_init(list, sizeof(int)); +} + +void list_initu(List *list) +{ + list_init(list, sizeof(unsigned int)); +} + +void list_initb(List *list) +{ + list_init(list, sizeof(unsigned char)); +} + +static void list_push(List *list, const void *elm) +{ + if (list->len == list->capacity) { + list->capacity *= 2; + if (!list->capacity) + list->capacity = 8; + list->data = realloc(list->data, list->elmSize * list->capacity); + } + + void *ptr = ((char *)list->data) + list->elmSize * list->len; + memcpy(ptr, elm, list->elmSize); + list->len++; +} + +void list_pushf(List *list, float f) +{ + list_push(list, &f); +} + +void list_pushi(List *list, int i) +{ + list_push(list, &i); +} + +void list_pushu(List *list, unsigned int u) +{ + list_push(list, &u); +} + +void list_pushb(List *list, unsigned char b) +{ + list_push(list, &b); +} + +void list_free(List *list) +{ + free(list->data); +} -- cgit v1.2.3-freya