#ifndef __MEMPOOL_H #define __MEMPOOL_H #include "EC.h" void init_memory_pools(void); void free_memory_pools(void); typedef struct ULongCircBuffer { unsigned long* buffer; // data buffer unsigned long* buffer_end; // end of data buffer uint32_t capacity; // maximum number of items in the buffer uint32_t count; // number of items in the buffer unsigned long* head; // pointer to head unsigned long* tail; // pointer to tail }ULongCircBuffer_t; typedef struct MemPool { void * const buffer; const unsigned long max_size; const unsigned long elem_size; bool *use_list; ULongCircBuffer_t free_list; } MemPool_t; // Game needs to implement this somewhere extern MemPool_t comp_mempools[N_COMPONENTS]; Entity_t* new_entity_from_mempool(unsigned long* e_idx_ptr); Entity_t* get_entity_wtih_id(unsigned long idx); void free_entity_to_mempool(unsigned long idx); void* new_component_from_mempool(unsigned int comp_type, unsigned long* idx); void* get_component_wtih_id(unsigned int comp_type, unsigned long idx); void free_component_to_mempool(unsigned int comp_type, unsigned long idx); void print_mempool_stats(char* buffer); uint32_t get_num_of_free_entities(void); #define DEFINE_COMP_MEMPOOL_BUF(type, n) \ static type type##_buf[n]; \ const unsigned long type##_CNT = n; \ #define ADD_COMP_MEMPOOL(type) \ {type##_buf, type##_CNT, sizeof(type), NULL, {0}}, \ #define BEGIN_DEFINE_COMP_MEMPOOL \ DEFINE_COMP_MEMPOOL_BUF(CBBox_t, MAX_COMP_POOL_SIZE); \ DEFINE_COMP_MEMPOOL_BUF(CTransform_t, MAX_COMP_POOL_SIZE); \ DEFINE_COMP_MEMPOOL_BUF(CTileCoord_t, MAX_COMP_POOL_SIZE); \ MemPool_t comp_mempools[N_COMPONENTS] = { \ ADD_COMP_MEMPOOL(CBBox_t) \ ADD_COMP_MEMPOOL(CTransform_t) \ ADD_COMP_MEMPOOL(CTileCoord_t) \ #define END_DEFINE_COMP_MEMPOOL }; #endif //__MEMPOOL_H