You've already forked flecs_tests
Add a makefile, change imgui with nuklear and add file dropping and loading
This commit is contained in:
31
src/util.h
31
src/util.h
@@ -84,10 +84,10 @@ typedef struct vector_t {
|
||||
} vector_t;
|
||||
|
||||
#define MAX_BUCKET_SIZE (0xffffffffu)
|
||||
#define MAX_STRIPE_SIZE (0xffffu)
|
||||
#define MAX_STRIPE_SIZE (0xffffffu)
|
||||
#define FIXED_START (0xfffu)
|
||||
|
||||
static vector_t vector_create(uint16_t stripe); //Create a new vector with a default size
|
||||
static vector_t vector_create(uint32_t stripe); //Create a new vector with a default size
|
||||
static void vector_clear(vector_t *vector);
|
||||
static void vector_free(vector_t *vector);
|
||||
|
||||
@@ -97,7 +97,7 @@ static void vector_set(vector_t *vector, uint32_t index, void *data);
|
||||
static uint32_t vector_push(vector_t *vector, void *data);
|
||||
static sg_range vector_range(vector_t *vector);
|
||||
|
||||
static vector_t vector_create(uint16_t stripe)
|
||||
static vector_t vector_create(uint32_t stripe)
|
||||
{
|
||||
assert(stripe >= sizeof(uint32_t));
|
||||
assert(stripe <= MAX_STRIPE_SIZE);
|
||||
@@ -158,32 +158,37 @@ static sg_range vector_range(vector_t *vector)
|
||||
|
||||
typedef struct mem_pool_t {
|
||||
void **data; //Memory pool
|
||||
uint16_t stripe; //Bit per item
|
||||
uint32_t stripe; //Bit per item
|
||||
uint32_t size; //Current amount of items
|
||||
uint32_t capacity; //Max capacity
|
||||
uint32_t free; //Linked list of available indices
|
||||
} mem_pool_t;
|
||||
|
||||
static mem_pool_t pool_create(uint16_t stripe); //Create a new memory pool with a default size
|
||||
static mem_pool_t pool_create_default(uint32_t stripe); //Create a new memory pool with a default size
|
||||
static mem_pool_t pool_create(uint32_t stripe, uint32_t size); //Create a new memory pool with a default size
|
||||
static void pool_clear(mem_pool_t *pool);
|
||||
static void pool_free(mem_pool_t *pool);
|
||||
|
||||
static uint32_t pool_add(mem_pool_t *pool); //Request a new free index
|
||||
static void* pool_get(mem_pool_t *pool, uint32_t index); //Get the pointer
|
||||
static const uint32_t pool_add(mem_pool_t *pool); //Request a new free index
|
||||
static const void* pool_get(mem_pool_t *pool, uint32_t index); //Get the pointer
|
||||
static void pool_remove(mem_pool_t *pool, uint32_t index); //Flag the given index as free
|
||||
|
||||
static mem_pool_t pool_create(uint16_t stripe)
|
||||
static mem_pool_t pool_create_default(uint32_t stripe)
|
||||
{
|
||||
return pool_create(stripe, FIXED_START);
|
||||
}
|
||||
static mem_pool_t pool_create(uint32_t stripe, uint32_t size)
|
||||
{
|
||||
assert(stripe >= sizeof(uint32_t));
|
||||
assert(stripe <= MAX_STRIPE_SIZE);
|
||||
assert(FIXED_START * stripe <= MAX_BUCKET_SIZE);
|
||||
assert(size * stripe <= MAX_BUCKET_SIZE);
|
||||
|
||||
return (mem_pool_t) {
|
||||
.capacity = FIXED_START,
|
||||
.capacity = size,
|
||||
.size = 0,
|
||||
.stripe = stripe,
|
||||
.free = UINT32_MAX,
|
||||
.data = (void**) malloc(FIXED_START * stripe),
|
||||
.data = (void**) malloc(size * stripe),
|
||||
};
|
||||
}
|
||||
static void pool_clear(mem_pool_t *pool)
|
||||
@@ -196,7 +201,7 @@ static void pool_free(mem_pool_t *pool)
|
||||
free(pool->data);
|
||||
}
|
||||
|
||||
static uint32_t pool_add(mem_pool_t *pool)
|
||||
static const uint32_t pool_add(mem_pool_t *pool)
|
||||
{
|
||||
if(pool->free != UINT32_MAX)
|
||||
{
|
||||
@@ -218,7 +223,7 @@ static uint32_t pool_add(mem_pool_t *pool)
|
||||
return pool->size++;
|
||||
}
|
||||
}
|
||||
static void* pool_get(mem_pool_t *pool, uint32_t index)
|
||||
static const void* pool_get(mem_pool_t *pool, uint32_t index)
|
||||
{
|
||||
assert(index > 0);
|
||||
assert(index < pool->capacity);
|
||||
|
||||
Reference in New Issue
Block a user