summaryrefslogtreecommitdiff
path: root/src/utils/include
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-10-31 23:55:42 +0000
committeronelin <oscar@nelin.dk>2025-11-02 22:07:17 +0000
commitd38deeef3af2316a666f8fc0173940bd769b748e (patch)
tree6e30d4a9eea18daa5705c894f28cd99ff047e8f9 /src/utils/include
parent6c077751982ea2c7bd2d9262b01b9f8602f80dc8 (diff)
Flatten project structure
This will make it easier to break up the code into smaller chunks again later. One would think doing this seems fun to me at this point.
Diffstat (limited to 'src/utils/include')
-rw-r--r--src/utils/include/engine/utils.h43
-rw-r--r--src/utils/include/engine/utils/btree.h61
-rw-r--r--src/utils/include/engine/utils/fov.h28
-rw-r--r--src/utils/include/engine/utils/hashmap.h61
-rw-r--r--src/utils/include/engine/utils/list.h18
-rw-r--r--src/utils/include/engine/utils/stack.h33
6 files changed, 0 insertions, 244 deletions
diff --git a/src/utils/include/engine/utils.h b/src/utils/include/engine/utils.h
deleted file mode 100644
index 5096aa4..0000000
--- a/src/utils/include/engine/utils.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef ENGINE_UTILS_H
-#define ENGINE_UTILS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <engine/core/types.h>
-#include <cglm/ivec2.h>
-
-#define MIN(a, b) ((a < b) ? (a) : (b))
-#define MAX(a, b) ((a > b) ? (a) : (b))
-
-#define MASK_TL (1 << 0)
-#define MASK_T (1 << 1)
-#define MASK_TR (1 << 2)
-#define MASK_L (1 << 3)
-#define MASK_C (1 << 4)
-#define MASK_R (1 << 5)
-#define MASK_BL (1 << 6)
-#define MASK_B (1 << 7)
-#define MASK_BR (1 << 8)
-
-/* Linear interpolate */
-f32 lerp(f32 dt, f32 a, f32 b);
-i32 int_lerp(f32 dt, i32 a, i32 b);
-
-/* Hashes */
-u32 hash(char* str);
-
-/* Masks surrounding tiles of a kernel size of 3x3 */
-/* In reality we only need 9 bits for this, but I think I had a reason for using
- * i32 */
-i32* kernmap(const void* map, i32* dstmap, const ivec2 mapsize,
- predicate_t* predicate);
-
-/* Returns an index from the given weights. */
-i32 pick_from_sample(const i32* weights, i32 len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/include/engine/utils/btree.h b/src/utils/include/engine/utils/btree.h
deleted file mode 100644
index 1dd2023..0000000
--- a/src/utils/include/engine/utils/btree.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef BTREE_H
-#define BTREE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-
-#define BTREE_DEGREE_DEFAULT 4
-
-#define BTREE_SIZE_MIN 8
-#define BTREE_SIZE_MAX 4096
-
-#define BTREE_CMP_LT (-1)
-#define BTREE_CMP_EQ (0)
-#define BTREE_CMP_GT (1)
-
-struct btree;
-struct btree_iter_t;
-
-/* elem_size: the size of the elements, typically `sizeof(struct <your struct>)`
- * t: degree of the btree, if you're in doubt, use `BTREE_SIZE_DEFAULT`
- * cmp: comparison function, in order to support any operations on the tree.
- *
- * This function just calls `btree_new_with_allocator` with `free` and `malloc`
- * as initializers.
- */
-struct btree* btree_new(size_t elem_size, size_t t,
- int (*cmp)(const void* a, const void* b));
-
-/* Same as `btree_new`, except that it actually initializes a btree, but with
- * the given allocators.
- */
-struct btree* btree_new_with_allocator(size_t elem_size, size_t t,
- int (*cmp)(const void* a, const void* b),
- void* (*alloc)(size_t),
- void (*dealloc)(void*));
-
-void btree_free(struct btree** btree);
-
-void* btree_search(struct btree* btree, void* elem);
-void btree_insert(struct btree* btree, void* elem);
-int btree_delete(struct btree* btree, void* elem);
-
-void btree_print(struct btree* btree, void (*print_elem)(const void*));
-
-void* btree_first(struct btree* btree);
-void* btree_last(struct btree* btree);
-
-size_t btree_size(struct btree* btree);
-
-struct btree_iter_t* btree_iter_t_new(struct btree* tree);
-void btree_iter_t_reset(struct btree* tree, struct btree_iter_t** it);
-
-void* btree_iter(struct btree* tree, struct btree_iter_t* iter);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/include/engine/utils/fov.h b/src/utils/include/engine/utils/fov.h
deleted file mode 100644
index be64a9e..0000000
--- a/src/utils/include/engine/utils/fov.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef ENGINE_FOV_H
-#define ENGINE_FOV_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <engine/core/types.h>
-#include <stdbool.h>
-#include <cglm/ivec2.h>
-
-/* `fov_shadowcast`: */
-/* map: your 2D enum tile grid
- * mapsize: x: width, y: height of the map
- * visblocking: pointer to a function that returns `true` when receiving a
- * pointer to a LOS blocking tile
- * lightmap: [out] 2D lightmap, this is simply overwritten with the
- * distance to the source. range: visibility range/radius. src: 2D
- * point to calculate FOV from
- * */
-void fov_shadowcast(const void* map, const ivec2 mapsize,
- bool (*visblocking)(const void*), i32* lightmap,
- const i32 range, const ivec2 src);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/include/engine/utils/hashmap.h b/src/utils/include/engine/utils/hashmap.h
deleted file mode 100644
index 0113ce5..0000000
--- a/src/utils/include/engine/utils/hashmap.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef ENGINE_HASHMAP_H
-#define ENGINE_HASHMAP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdlib.h>
-
-#include <engine/core/types.h>
-#include <engine/core/memory.h>
-#include <engine/utils/list.h>
-
-usize lolhash(const usize s, usize v);
-
-/* Define a linked list before using this */
-/* Example: DEFINE_LLIST(i32) */
-#define DEFINE_HASHMAP(type, lsize, cmp, type_to_int) \
- typedef DEFINE_LLIST(type); \
- typedef struct hashmap_##type { \
- usize size; \
- List_##type elems[64]; \
- } hashmap_##type; \
- \
- type* hashmap_##type##_lookup(hashmap_##type* hmap, const type* val) { \
- const usize idx = lolhash(64, type_to_int(val)); \
- List_##type* head = &hmap->elems[idx]; \
- while (head != NULL) { \
- if (!cmp(&(head->value), val)) return &(head->value); \
- head = head->next; \
- } \
- return NULL; \
- } \
- \
- void hashmap_##type##_insert(memory* m, hashmap_##type* hmap, \
- const type* val) { \
- const usize idx = lolhash(64, type_to_int(val)); \
- List_##type* head = &(hmap->elems[idx]); \
- \
- /* This is highly dependant on whether the memory is zero-initialized */ \
- if (!type_to_int(&(head->value))) { \
- memcpy(&(head->value), val, sizeof(type)); \
- return; \
- } \
- \
- while (head->next != NULL && cmp(&head->value, val)) { \
- head = head->next; \
- } \
- \
- if (!cmp(&head->value, val)) \
- memcpy(&(head->value), val, sizeof(type)); \
- else { \
- head->next = memory_allocate(m, sizeof(List_##type)); \
- memcpy(&(head->next->value), val, sizeof(type)); \
- } \
- }
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/include/engine/utils/list.h b/src/utils/include/engine/utils/list.h
deleted file mode 100644
index 04dda04..0000000
--- a/src/utils/include/engine/utils/list.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef ENGINE_LIST_H
-#define ENGINE_LIST_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define DEFINE_LLIST(type) \
- struct List_##type { \
- type value; \
- struct List_##type* next; \
- /* Force the user to add `;` for style consistency */ \
- } List_##type
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/include/engine/utils/stack.h b/src/utils/include/engine/utils/stack.h
deleted file mode 100644
index b4caf5f..0000000
--- a/src/utils/include/engine/utils/stack.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef STACK_H
-#define STACK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <engine/core/types.h>
-
-typedef struct {
- usize head; /* current number of elements */
- const usize elem_size; /* size in bytes of each element */
- usize size; /* current memory size used by the stack */
- const usize chunk_size; /* size of which the stack increases when running out
- of mem */
- void* data; /* memory buffer */
-} Stack;
-
-Stack stack_new_ex(const usize element_size, const usize size);
-
-Stack stack_new(const usize element_size);
-
-void stack_free(Stack* s);
-void* stack_pop(Stack* s);
-void stack_push(Stack* s, void* elem);
-void* stack_peek(Stack* s);
-usize stack_size(const Stack* s);
-void stack_swap(Stack* s, Stack* t);
-
-#ifdef __cplusplus
-}
-#endif
-#endif