#ifndef VOXULA_UTILITY_H #define VOXULA_UTILITY_H #include #include typedef struct vx_uuid_table vx_uuid_table_s; typedef struct vx_uuid_block vx_uuid_block_s; typedef struct vx_uuid_entry vx_uuid_entry_s; typedef uint64_t vx_uuid_d; typedef struct vx_vec2f vx_vec2f_s; typedef struct vx_vec3f vx_vec3f_s; typedef struct vx_vec4f vx_vec4f_s; typedef struct vx_mat2f vx_mat2f_s; typedef struct vx_mat3f vx_mat3f_s; typedef struct vx_mat4f vx_mat4f_s; typedef struct vx_pool vx_pool_s; typedef struct vx_pool_slot_header vx_pool_slot_header_s; typedef struct vx_arena vx_arena_s; struct vx_uuid_entry { vx_uuid_d uuid; }; struct vx_uuid_block { /// @brief Start of the block's UUIDs; /// this must be multiplied with 4096 /// to get the first ID's number. uint32_t offset; uint8_t num_ids; vx_uuid_entry_s entries[256]; }; struct vx_uuid_table { uint32_t block_capacity; uint32_t num_blocks; vx_uuid_block_s **blocks; }; struct vx_vec2f { float x; float y; }; struct vx_vec3f { float x; float y; float z; }; struct vx_vec4f { float x; float y; float z; float w; }; struct vx_mat2f { float val[4]; }; struct vx_mat3f { float val[9]; }; struct vx_mat4f { float val[16]; }; struct vx_pool_slot_header { vx_pool_slot_header_s *next; vx_pool_s *pool; }; struct vx_pool { uint32_t capacity; uint32_t unit_size; void *allocation; vx_pool_slot_header_s *first_free; vx_pool_s *continuation; }; struct vx_arena { uint32_t capacity; uint32_t usage; void *allocation; vx_arena_s *continuation; }; vx_uuid_table_s * vx_new_uuid_table(); vx_uuid_d vx_new_uuid(vx_uuid_table_s *table); uint32_t vx_measure_string_up_to(const char *string, uint32_t maximum); vx_vec3f_s vx_vec3f_negative(vx_vec3f_s vector); vx_mat2f_s vx_mat2f_identity(); vx_mat3f_s vx_mat3f_identity(); vx_mat4f_s vx_mat4f_identity(); void vx_mat4f_stringify(FILE *file, vx_mat4f_s matrix); vx_mat4f_s vx_mat4f_translate( vx_mat4f_s matrix, vx_vec3f_s translation ); vx_mat4f_s vx_mat4f_rotate_x( vx_mat4f_s matrix, float rotation ); vx_mat4f_s vx_mat4f_rotate_y( vx_mat4f_s matrix, float rotation ); vx_mat4f_s vx_mat4f_rotate_z( vx_mat4f_s matrix, float rotation ); vx_mat4f_s vx_mat4f_scale( vx_mat4f_s matrix, vx_vec3f_s scaling ); vx_mat4f_s vx_mat4f_perspective( float aspect_ratio, float fov, float near_plane, float far_plane ); uint64_t vx_ceil_to(uint64_t base, uint64_t anchor); uint64_t vx_ceil_pow2(uint64_t base); uint64_t vx_min_u64(uint64_t first, uint64_t second); uint64_t vx_max_u64(uint64_t first, uint64_t second); // Pool Functions vx_pool_s * vx_new_pool(uint32_t unit_size, uint32_t capacity); void vx_free_pool(vx_pool_s *pool); void * vx_pool(vx_pool_s *pool); void vx_unpool(void *allocation); // Arena Functions vx_arena_s * vx_new_arena(uint32_t capacity); void vx_free_arena(vx_arena_s *arena); void * vx_arena_alloc(vx_arena_s *arena, uint32_t length); char * vx_arena_dupe_string(vx_arena_s *arena, const char *string); char * vx_arena_dupe_string_up_to(vx_arena_s *arena, const char *string, uint32_t maximum); #endif // VOXULA_UTILITY_H