Kaltenberg/modules/utility/inc-c/voxula/internals/utility.h

285 lines
5.8 KiB
C
Raw Normal View History

#ifndef VOXULA_UTILITY_H
#define VOXULA_UTILITY_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
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_vec2u vx_vec2u_s;
typedef struct vx_vec3u vx_vec3u_s;
typedef struct vx_vec4u vx_vec4u_s;
typedef struct vx_vec2i vx_vec2i_s;
typedef struct vx_vec3i vx_vec3i_s;
typedef struct vx_vec4i vx_vec4i_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;
typedef enum
{
VX_ASCII_EXCLAMATION_MARK = '!',
VX_ASCII_DOUBLE_QUOTATION_MARK = '"',
VX_ASCII_NUMBER_SIGN = '#',
VX_ASCII_DOLLAR_SIGN = '$',
VX_ASCII_PERCENT_SIGN = '%',
VX_ASCII_AMPERSAND = '&',
VX_ASCII_SINGLE_QUOTATION_MARK = '\'',
VX_ASCII_OPENING_PARENTHESIS = '(',
VX_ASCII_CLOSING_PARENTHESIS = ')',
VX_ASCII_ASTERISK = '*',
VX_ASCII_ADDITION_SIGN = '+',
VX_ASCII_COMMA = ',',
VX_ASCII_HYPHEN = '-',
VX_ASCII_DOT = '.',
VX_ASCII_FORWARD_SLASH = '/',
VX_ASCII_COLON = ':',
VX_ASCII_SEMICOLON = ';',
VX_ASCII_LESS_THAN_SIGN = '<',
VX_ASCII_EQUALS_SIGN = '=',
VX_ASCII_GREATER_THAN_SIGN = '>',
VX_ASCII_QUESTION_MARK = '?',
VX_ASCII_AT_SIGN = '@',
VX_ASCII_OPENING_BRACKET = '[',
VX_ASCII_BACKSLASH = '\\',
VX_ASCII_CLOSING_BRACKET = ']',
VX_ASCII_CARET = '^',
VX_ASCII_UNDERSCORE = '_',
VX_ASCII_BACKTICK = '`',
VX_ASCII_OPENING_BRACE = '{',
VX_ASCII_VERTICAL_BAR = '|',
VX_ASCII_CLOSING_BRACE = '}',
VX_ACII_TILDE = '~'
} vx_ascii_sign_e;
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_vec2u
{
uint64_t x;
uint64_t y;
};
struct vx_vec3u
{
uint64_t x;
uint64_t y;
uint64_t z;
};
struct vx_vec4u
{
uint64_t x;
uint64_t y;
uint64_t z;
uint64_t w;
};
struct vx_vec2i
{
int64_t x;
int64_t y;
};
struct vx_vec3i
{
int64_t x;
int64_t y;
int64_t z;
};
struct vx_vec4i
{
int64_t x;
int64_t y;
int64_t z;
int64_t 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);
// Character Functions
bool vx_is_ascii_sign(char character);
bool vx_is_ascii_sign_of_block_1(char character);
bool vx_is_ascii_sign_of_block_2(char character);
bool vx_is_ascii_sign_of_block_3(char character);
bool vx_is_ascii_sign_of_block_4(char character);
bool vx_is_ascii_letter(char character);
bool vx_is_ascii_lower(char character);
bool vx_is_ascii_upper(char character);
bool vx_is_ascii_digit(char character);
bool vx_is_ascii_blank(char character);
bool vx_is_ascii_control(char character);
uint8_t vx_digits_for_decimal(uint32_t decimal);
void vx_write_spaces(FILE *output, uint32_t count);
#endif // VOXULA_UTILITY_H