brzeszczot

brzeszczot.git
git clone git://git.lenczewski.org/brzeszczot.git
Log | Files | Refs

wad.c (718B)


      1 #include "libriot/wad.h"
      2 
      3 b32
      4 riot_wad_ctx_init(struct riot_wad_ctx *self) {
      5 	assert(self);
      6 
      7 	if (!MEM_POOL_INIT(&self->chunk_pool, struct riot_wad_chunk, RIOT_WAD_CTX_CHUNK_POOL_SZ))
      8 		goto chunk_pool_alloc_failure;
      9 
     10 	return true;
     11 
     12 chunk_pool_alloc_failure:
     13 	return false;
     14 }
     15 
     16 void
     17 riot_wad_ctx_free(struct riot_wad_ctx *self) {
     18 	assert(self);
     19 
     20 	mem_pool_free(&self->chunk_pool);
     21 }
     22 
     23 b32
     24 riot_wad_ctx_pushn_chunk(struct riot_wad_ctx *self, u32 count, riot_offptr_t *out) {
     25 	assert(self);
     26 	assert(out);
     27 
     28 	void *absptr = MEM_POOL_ALLOC(&self->chunk_pool, struct riot_wad_chunk, count);
     29 	if (!absptr) return false;
     30 
     31 	*out = (struct riot_wad_chunk *)absptr - (struct riot_wad_chunk *)self->chunk_pool.ptr;
     32 
     33 	return true;
     34 }