From aa0fe8457cfff9c47c0c9fa4a1c86a79c7cbf9c5 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:01:16 +1000 Subject: add a pool insert function. move RenderEnt to use handles --- src/std/mem.c | 7 +++++++ src/std/mem.h | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/std') diff --git a/src/std/mem.c b/src/std/mem.c index 4a4454a..a537330 100644 --- a/src/std/mem.c +++ b/src/std/mem.c @@ -126,3 +126,10 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle) { pool->count--; } + +u32 void_pool_insert(void_pool* pool, void* item) { + u32 raw_handle; + void* item_dest = void_pool_alloc(pool, &raw_handle); + memcpy(item_dest, item, pool->entry_size); + return raw_handle; +} \ No newline at end of file diff --git a/src/std/mem.h b/src/std/mem.h index c9346cc..56c1230 100644 --- a/src/std/mem.h +++ b/src/std/mem.h @@ -66,6 +66,7 @@ bool void_pool_is_full(void_pool* pool); void* void_pool_get(void_pool* pool, u32 raw_handle); void* void_pool_alloc(void_pool* pool, u32* out_raw_handle); void void_pool_dealloc(void_pool* pool, u32 raw_handle); +u32 void_pool_insert(void_pool* pool, void* item); // TODO: fn to dealloc from the pointer that was handed out // TODO: macro that lets us specialise @@ -88,4 +89,8 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle); } \ static inline void Name##_pool_dealloc(Name##_pool* pool, Name##Handle handle) { \ void_pool_dealloc(&pool->inner, handle.raw); \ - }\ + } \ + static Name##Handle Name##_pool_insert(Name##_pool* pool, T* item) { \ + u32 raw_handle = void_pool_insert(pool, item); \ + return (Name##Handle){ .raw = raw_handle }; \ + } -- cgit v1.2.3-70-g09d2