From be8ab99b38c25e899008582d68e891150b328a4d Mon Sep 17 00:00:00 2001 From: Omni Date: Sun, 18 Aug 2024 14:03:25 +1000 Subject: start on stack array --- src/animation.h | 1 - src/std/containers/stack_array.h | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/std/containers/stack_array.h (limited to 'src') diff --git a/src/animation.h b/src/animation.h index 2a489b8..5883f13 100644 --- a/src/animation.h +++ b/src/animation.h @@ -4,7 +4,6 @@ #include "darray.h" #include "defines.h" #include "maths_types.h" -#include "mem.h" #include "ral_types.h" typedef enum Interpolation { diff --git a/src/std/containers/stack_array.h b/src/std/containers/stack_array.h new file mode 100644 index 0000000..d2b6bdd --- /dev/null +++ b/src/std/containers/stack_array.h @@ -0,0 +1,19 @@ +#pragma once +#include + +// Defines "_sarray" types + +#define TYPED_STACK_ARRAY(T, Name, Len) \ + typedef struct Name##_sarray { \ + T items[ Len ]; \ + size_t len; \ + } Name##_sarray; \ + Name##_sarray Name##_sarray_create() { \ + Name##_sarray arr = { .len = 0 }; \ + return arr; \ + } \ + bool Name##_sarray_push(Name##_sarray* arr, T item) { \ + if (arr->len == Len) { return false; }\ + arr->items[arr->len++] = item;\ + return true;\ + } -- cgit v1.2.3-70-g09d2