From 4bea4f6505a76a9806fa6ff75195c18bf726be28 Mon Sep 17 00:00:00 2001 From: Doyle Thai Date: Mon, 1 May 2017 14:01:05 +1000 Subject: [PATCH] Change naming scheme to be more compact --- dqn.h | 935 ++++++++++++++++++++++++---------------------- dqn_unit_test.cpp | 654 ++++++++++++++++---------------- 2 files changed, 808 insertions(+), 781 deletions(-) diff --git a/dqn.h b/dqn.h index 7563edc..a4de59f 100644 --- a/dqn.h +++ b/dqn.h @@ -66,6 +66,7 @@ typedef float f32; // DArray - Dynamic Array //////////////////////////////////////////////////////////////////////////////// // REMINDER: Dynamic Array can be used as a stack. Don't need to create one. +#if 1 template struct DqnArray { @@ -76,32 +77,32 @@ struct DqnArray #if 0 template -bool dqn_array_init (DqnArray *array, size_t capacity); -bool dqn_array_grow (DqnArray *array); -T *dqn_array_push (DqnArray *array, T item); -T *dqn_array_pop (DqnArray *array) -T *dqn_array_get (DqnArray *array, u64 index); -bool dqn_array_clear (DqnArray *array); -bool dqn_array_free (DqnArray *array); -bool dqn_array_remove (DqnArray *array, u64 index); -bool dqn_array_remove_stable(DqnArray *array, u64 index); +bool DqnArray_init (DqnArray *array, size_t capacity); +bool DqnArray_grow (DqnArray *array); +T *DqnArray_push (DqnArray *array, T item); +T *DqnArray_pop (DqnArray *array) +T *DqnArray_get (DqnArray *array, u64 index); +bool DqnArray_clear (DqnArray *array); +bool DqnArray_free (DqnArray *array); +bool DqnArray_remove (DqnArray *array, u64 index); +bool DqnArray_remove_stable(DqnArray *array, u64 index); #endif // Implementation taken from Milton, developed by Serge at // https://github.com/serge-rgb/milton#license template -bool dqn_array_init(DqnArray *array, size_t capacity) +bool DqnArray_Init(DqnArray *array, size_t capacity) { if (!array) return false; if (array->data) { // TODO(doyle): Logging? The array already exists - if (!dqn_array_free(array)) return false; + if (!DqnArray_Free(array)) return false; } array->data = - (T *)dqn_mem_alloc_internal((size_t)capacity * sizeof(T), true); + (T *)Dqn_MemAllocInternal((size_t)capacity * sizeof(T), true); if (!array->data) return false; array->count = 0; @@ -110,7 +111,7 @@ bool dqn_array_init(DqnArray *array, size_t capacity) } template -bool dqn_array_grow(DqnArray *array) +bool DqnArray_Grow(DqnArray *array) { if (!array || !array->data) return false; @@ -118,7 +119,7 @@ bool dqn_array_grow(DqnArray *array) size_t newCapacity = (size_t)(array->capacity * GROWTH_FACTOR); if (newCapacity == array->capacity) newCapacity++; - T *newMem = (T *)dqn_mem_realloc_internal( + T *newMem = (T *)Dqn_MemReallocInternal( array->data, (size_t)(newCapacity * sizeof(T))); if (newMem) { @@ -133,13 +134,13 @@ bool dqn_array_grow(DqnArray *array) } template -T *dqn_array_push(DqnArray *array, T item) +T *DqnArray_Push(DqnArray *array, T item) { if (!array) return NULL; if (array->count >= array->capacity) { - if (!dqn_array_grow(array)) return NULL; + if (!DqnArray_Grow(array)) return NULL; } DQN_ASSERT(array->count < array->capacity); @@ -149,7 +150,7 @@ T *dqn_array_push(DqnArray *array, T item) } template -T *dqn_array_pop(DqnArray *array) +T *DqnArray_Pop(DqnArray *array) { if (!array) return NULL; if (array->count == 0) return NULL; @@ -159,7 +160,7 @@ T *dqn_array_pop(DqnArray *array) } template -T *dqn_array_get(DqnArray *array, u64 index) +T *DqnArray_Get(DqnArray *array, u64 index) { T *result = NULL; if (index >= 0 && index <= array->count) result = &array->data[index]; @@ -167,7 +168,7 @@ T *dqn_array_get(DqnArray *array, u64 index) } template -bool dqn_array_clear(DqnArray *array) +bool DqnArray_Clear(DqnArray *array) { if (array) { @@ -179,7 +180,7 @@ bool dqn_array_clear(DqnArray *array) } template -bool dqn_array_free(DqnArray *array) +bool DqnArray_Free(DqnArray *array) { if (array && array->data) { @@ -193,7 +194,7 @@ bool dqn_array_free(DqnArray *array) } template -bool dqn_array_remove(DqnArray *array, u64 index) +bool DqnArray_Remove(DqnArray *array, u64 index) { if (!array) return false; if (index >= array->count) return false; @@ -212,7 +213,7 @@ bool dqn_array_remove(DqnArray *array, u64 index) } template -bool dqn_array_remove_stable(DqnArray *array, u64 index) +bool DqnArray_RemoveStable(DqnArray *array, u64 index) { if (!array) return false; if (index >= array->count) return false; @@ -238,12 +239,13 @@ bool dqn_array_remove_stable(DqnArray *array, u64 index) array->count--; return true; } +#endif //////////////////////////////////////////////////////////////////////////////// // Math //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE f32 dqn_math_lerp(f32 a, f32 t, f32 b); -DQN_FILE_SCOPE f32 dqn_math_sqrtf(f32 a); +DQN_FILE_SCOPE f32 DqnMath_Lerp(f32 a, f32 t, f32 b); +DQN_FILE_SCOPE f32 DqnMath_Sqrtf(f32 a); //////////////////////////////////////////////////////////////////////////////// // Vec2 @@ -256,24 +258,24 @@ typedef union DqnV2 { } DqnV2; // Create a vector using ints and typecast to floats -DQN_FILE_SCOPE DqnV2 dqn_v2i(i32 x, i32 y); -DQN_FILE_SCOPE DqnV2 dqn_v2 (f32 x, f32 y); +DQN_FILE_SCOPE DqnV2 DqnV2_2i(i32 x, i32 y); +DQN_FILE_SCOPE DqnV2 DqnV2_2f(f32 x, f32 y); -DQN_FILE_SCOPE DqnV2 dqn_v2_add (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE DqnV2 dqn_v2_sub (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE DqnV2 dqn_v2_scale (DqnV2 a, f32 b); -DQN_FILE_SCOPE DqnV2 dqn_v2_hadamard(DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE f32 dqn_v2_dot (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE bool dqn_v2_equals (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Add (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Sub (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Scale (DqnV2 a, f32 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Hadamard(DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE f32 DqnV2_Dot (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE bool DqnV2_Equals (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE f32 dqn_v2_length_squared(DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE f32 dqn_v2_length (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE DqnV2 dqn_v2_normalise (DqnV2 a); -DQN_FILE_SCOPE bool dqn_v2_overlaps (DqnV2 a, DqnV2 b); -DQN_FILE_SCOPE DqnV2 dqn_v2_perpendicular (DqnV2 a); +DQN_FILE_SCOPE f32 DqnV2_LengthSquared(DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE f32 DqnV2_Length (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Normalise (DqnV2 a); +DQN_FILE_SCOPE bool DqnV2_Overlaps (DqnV2 a, DqnV2 b); +DQN_FILE_SCOPE DqnV2 DqnV2_Perpendicular(DqnV2 a); // Resize the dimension to fit the aspect ratio provided. Downscale only. -DQN_FILE_SCOPE DqnV2 dqn_v2_constrain_to_ratio(DqnV2 dim, DqnV2 ratio); +DQN_FILE_SCOPE DqnV2 DqnV2_ConstrainToRatio(DqnV2 dim, DqnV2 ratio); //////////////////////////////////////////////////////////////////////////////// // Vec3 @@ -286,17 +288,16 @@ typedef union DqnV3 } DqnV3; // Create a vector using ints and typecast to floats -DQN_FILE_SCOPE DqnV3 dqn_v3i(i32 x, i32 y, i32 z); -DQN_FILE_SCOPE DqnV3 dqn_v3 (f32 x, f32 y, f32 z); +DQN_FILE_SCOPE DqnV3 DqnV3_3i(i32 x, i32 y, i32 z); +DQN_FILE_SCOPE DqnV3 DqnV3_3f(f32 x, f32 y, f32 z); -DQN_FILE_SCOPE DqnV3 dqn_v3_add (DqnV3 a, DqnV3 b); -DQN_FILE_SCOPE DqnV3 dqn_v3_sub (DqnV3 a, DqnV3 b); -DQN_FILE_SCOPE DqnV3 dqn_v3_scale (DqnV3 a, f32 b); -DQN_FILE_SCOPE DqnV3 dqn_v3_hadamard(DqnV3 a, DqnV3 b); -DQN_FILE_SCOPE f32 dqn_v3_dot (DqnV3 a, DqnV3 b); -DQN_FILE_SCOPE bool dqn_v3_equals (DqnV3 a, DqnV3 b); - -DQN_FILE_SCOPE DqnV3 dqn_v3_cross(DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE DqnV3 DqnV3_Add (DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE DqnV3 DqnV3_Sub (DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE DqnV3 DqnV3_Scale (DqnV3 a, f32 b); +DQN_FILE_SCOPE DqnV3 DqnV3_Hadamard(DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE f32 DqnV3_Dot (DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE bool DqnV3_Equals (DqnV3 a, DqnV3 b); +DQN_FILE_SCOPE DqnV3 DqnV3_Cross (DqnV3 a, DqnV3 b); //////////////////////////////////////////////////////////////////////////////// // Vec4 @@ -310,15 +311,15 @@ typedef union DqnV4 } DqnV4; // Create a vector using ints and typecast to floats -DQN_FILE_SCOPE DqnV4 dqn_v4i(i32 x, i32 y, i32 z, f32 w); -DQN_FILE_SCOPE DqnV4 dqn_v4 (f32 x, f32 y, f32 z, f32 w); +DQN_FILE_SCOPE DqnV4 DqnV4_4i(i32 x, i32 y, i32 z, f32 w); +DQN_FILE_SCOPE DqnV4 DqnV4_4f(f32 x, f32 y, f32 z, f32 w); -DQN_FILE_SCOPE DqnV4 dqn_v4_add (DqnV4 a, DqnV4 b); -DQN_FILE_SCOPE DqnV4 dqn_v4_sub (DqnV4 a, DqnV4 b); -DQN_FILE_SCOPE DqnV4 dqn_v4_scale (DqnV4 a, f32 b); -DQN_FILE_SCOPE DqnV4 dqn_v4_hadamard(DqnV4 a, DqnV4 b); -DQN_FILE_SCOPE f32 dqn_v4_dot (DqnV4 a, DqnV4 b); -DQN_FILE_SCOPE bool dqn_v4_equals (DqnV4 a, DqnV4 b); +DQN_FILE_SCOPE DqnV4 DqnV4_Add (DqnV4 a, DqnV4 b); +DQN_FILE_SCOPE DqnV4 DqnV4_Sub (DqnV4 a, DqnV4 b); +DQN_FILE_SCOPE DqnV4 DqnV4_Scale (DqnV4 a, f32 b); +DQN_FILE_SCOPE DqnV4 DqnV4_Hadamard(DqnV4 a, DqnV4 b); +DQN_FILE_SCOPE f32 DqnV4_Dot (DqnV4 a, DqnV4 b); +DQN_FILE_SCOPE bool DqnV4_Equals (DqnV4 a, DqnV4 b); //////////////////////////////////////////////////////////////////////////////// // 4D Matrix Mat4 @@ -330,13 +331,13 @@ typedef union DqnMat4 f32 e[4][4]; } DqnMat4; -DQN_FILE_SCOPE DqnMat4 dqn_mat4_identity (); -DQN_FILE_SCOPE DqnMat4 dqn_mat4_ortho (f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar); -DQN_FILE_SCOPE DqnMat4 dqn_mat4_translate(f32 x, f32 y, f32 z); -DQN_FILE_SCOPE DqnMat4 dqn_mat4_rotate (f32 radians, f32 x, f32 y, f32 z); -DQN_FILE_SCOPE DqnMat4 dqn_mat4_scale (f32 x, f32 y, f32 z); -DQN_FILE_SCOPE DqnMat4 dqn_mat4_mul (DqnMat4 a, DqnMat4 b); -DQN_FILE_SCOPE DqnV4 dqn_mat4_mul_vec4 (DqnMat4 a, DqnV4 b); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Identity (); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Ortho (f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Translate(f32 x, f32 y, f32 z); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Rotate (f32 radians, f32 x, f32 y, f32 z); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Scale (f32 x, f32 y, f32 z); +DQN_FILE_SCOPE DqnMat4 DqnMat4_Mul (DqnMat4 a, DqnMat4 b); +DQN_FILE_SCOPE DqnV4 DqnMat4_MulV4 (DqnMat4 a, DqnV4 b); //////////////////////////////////////////////////////////////////////////////// // Other Math @@ -347,54 +348,53 @@ typedef struct DqnRect DqnV2 max; } DqnRect; -DQN_FILE_SCOPE DqnRect dqn_rect (DqnV2 origin, DqnV2 size); -DQN_FILE_SCOPE void dqn_rect_get_size_2f(DqnRect rect, f32 *width, f32 *height); -DQN_FILE_SCOPE DqnV2 dqn_rect_get_size_v2(DqnRect rect); -DQN_FILE_SCOPE DqnV2 dqn_rect_get_centre (DqnRect rect); -DQN_FILE_SCOPE DqnRect dqn_rect_move (DqnRect rect, DqnV2 shift); -DQN_FILE_SCOPE bool dqn_rect_contains_p (DqnRect rect, DqnV2 p); +DQN_FILE_SCOPE DqnRect DqnRect_Init (DqnV2 origin, DqnV2 size); +DQN_FILE_SCOPE void DqnRect_GetSize2f(DqnRect rect, f32 *width, f32 *height); +DQN_FILE_SCOPE DqnV2 DqnRect_GetSizev2(DqnRect rect); +DQN_FILE_SCOPE DqnV2 DqnRect_GetCenter(DqnRect rect); +DQN_FILE_SCOPE DqnRect DqnRect_Move (DqnRect rect, DqnV2 shift); +DQN_FILE_SCOPE bool DqnRect_ContainsP(DqnRect rect, DqnV2 p); //////////////////////////////////////////////////////////////////////////////// // char String Operations //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE char dqn_char_to_lower (char c); -DQN_FILE_SCOPE char dqn_char_to_upper (char c); -DQN_FILE_SCOPE bool dqn_char_is_digit (char c); -DQN_FILE_SCOPE bool dqn_char_is_alpha (char c); -DQN_FILE_SCOPE bool dqn_char_is_alphanum(char c); +DQN_FILE_SCOPE char DqnChar_ToLower (char c); +DQN_FILE_SCOPE char DqnChar_ToUpper (char c); +DQN_FILE_SCOPE bool DqnChar_IsDigit (char c); +DQN_FILE_SCOPE bool DqnChar_IsAlpha (char c); +DQN_FILE_SCOPE bool DqnChar_IsAlphanum(char c); -DQN_FILE_SCOPE i32 dqn_strcmp (const char *a, const char *b); +DQN_FILE_SCOPE i32 Dqn_strcmp(const char *a, const char *b); // Returns the length without the null terminator -DQN_FILE_SCOPE i32 dqn_strlen (const char *a); -DQN_FILE_SCOPE i32 dqn_strlen_delimit_with(const char *a, const char delimiter); -DQN_FILE_SCOPE char *dqn_strncpy (char *dest, const char *src, i32 numChars); +DQN_FILE_SCOPE i32 Dqn_strlen (const char *a); +DQN_FILE_SCOPE i32 Dqn_strlenDelimitWith(const char *a, const char delimiter); +DQN_FILE_SCOPE char *Dqn_strncpy (char *dest, const char *src, i32 numChars); #define DQN_I32_TO_STR_MAX_BUF_SIZE 11 -DQN_FILE_SCOPE bool dqn_str_reverse (char *buf, const i32 bufSize); -DQN_FILE_SCOPE bool dqn_str_has_substring(const char *const a, const i32 lenA, +DQN_FILE_SCOPE bool Dqn_StrReverse (char *buf, const i32 bufSize); +DQN_FILE_SCOPE bool Dqn_StrHasSubstring(const char *const a, const i32 lenA, const char *const b, const i32 lenB); -DQN_FILE_SCOPE i32 dqn_str_to_i32(const char *const buf, const i32 bufSize); +DQN_FILE_SCOPE i32 Dqn_StrToI32(const char *const buf, const i32 bufSize); // Return the len of the derived string -DQN_FILE_SCOPE i32 dqn_i32_to_str(i32 value, char *buf, i32 bufSize); +DQN_FILE_SCOPE i32 Dqn_I32ToStr(i32 value, char *buf, i32 bufSize); // Both return the number of bytes read, return 0 if invalid codepoint or UTF8 -DQN_FILE_SCOPE u32 dqn_ucs_to_utf8(u32 *dest, u32 character); -DQN_FILE_SCOPE u32 dqn_utf8_to_ucs(u32 *dest, u32 character); +DQN_FILE_SCOPE u32 Dqn_UCSToUTF8(u32 *dest, u32 character); +DQN_FILE_SCOPE u32 Dqn_UTF8ToUCS(u32 *dest, u32 character); //////////////////////////////////////////////////////////////////////////////// // wchar String Operations //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE bool dqn_wchar_is_digit(const wchar_t c); -DQN_FILE_SCOPE wchar_t dqn_wchar_to_lower(const wchar_t c); +DQN_FILE_SCOPE bool DqnWChar_IsDigit(const wchar_t c); +DQN_FILE_SCOPE wchar_t DqnWChar_ToLower(const wchar_t c); -DQN_FILE_SCOPE i32 dqn_wstrlen (const wchar_t *a); -DQN_FILE_SCOPE i32 dqn_wstrcmp (const wchar_t *a, const wchar_t *b); +DQN_FILE_SCOPE i32 Dqn_wstrlen(const wchar_t *a); +DQN_FILE_SCOPE i32 Dqn_wstrcmp(const wchar_t *a, const wchar_t *b); -DQN_FILE_SCOPE bool dqn_wstr_reverse (wchar_t *buf, const i32 bufSize); - -DQN_FILE_SCOPE i32 dqn_wstr_to_i32 (const wchar_t *const buf, const i32 bufSize); -DQN_FILE_SCOPE i32 dqn_i32_to_wstr (i32 value, wchar_t *buf, i32 bufSize); +DQN_FILE_SCOPE bool Dqn_WStrReverse(wchar_t *buf, const i32 bufSize); +DQN_FILE_SCOPE i32 Dqn_WStrToI32(const wchar_t *const buf, const i32 bufSize); +DQN_FILE_SCOPE i32 Dqn_I32ToWStr(i32 value, wchar_t *buf, i32 bufSize); //////////////////////////////////////////////////////////////////////////////// // Win32 Specific @@ -402,13 +402,13 @@ DQN_FILE_SCOPE i32 dqn_i32_to_wstr (i32 value, wchar_t *buf, i32 bufSize); #ifdef DQN_WIN32 // Out is a pointer to the buffer to receive the characters. // outLen is the length/capacity of the out buffer -DQN_FILE_SCOPE bool dqn_win32_utf8_to_wchar (const char *const in, wchar_t *const out, const i32 outLen); -DQN_FILE_SCOPE bool dqn_win32_wchar_to_utf8 (const wchar_t *const in, char *const out, const i32 outLen); +DQN_FILE_SCOPE bool DqnWin32_UTF8ToWChar (const char *const in, wchar_t *const out, const i32 outLen); +DQN_FILE_SCOPE bool DqnWin32_WCharToUTF8 (const wchar_t *const in, char *const out, const i32 outLen); -DQN_FILE_SCOPE void dqn_win32_get_client_dim (const HWND window, LONG *width, LONG *height); -DQN_FILE_SCOPE void dqn_win32_get_rect_dim (RECT rect, LONG *width, LONG *height); -DQN_FILE_SCOPE void dqn_win32_display_last_error(const char *const errorPrefix); -DQN_FILE_SCOPE void dqn_win32_display_error_code(const DWORD error, const char *const errorPrefix); +DQN_FILE_SCOPE void DqnWin32_GetClientDim (const HWND window, LONG *width, LONG *height); +DQN_FILE_SCOPE void DqnWin32_GetRectDim (RECT rect, LONG *width, LONG *height); +DQN_FILE_SCOPE void DqnWin32_DisplayLastError(const char *const errorPrefix); +DQN_FILE_SCOPE void DqnWin32_DisplayErrorCode(const DWORD error, const char *const errorPrefix); #endif /* DQN_WIN32 */ //////////////////////////////////////////////////////////////////////////////// @@ -445,36 +445,36 @@ typedef struct DqnFile } DqnFile; // Open a handle to the file -DQN_FILE_SCOPE bool dqn_file_open(const char *const path, DqnFile *const file, +DQN_FILE_SCOPE bool DqnFile_Open(const char *const path, DqnFile *const file, const u32 permissionFlags, const enum DqnFileAction action); -DQN_FILE_SCOPE bool dqn_file_openw(const wchar_t *const path, DqnFile *const file, +DQN_FILE_SCOPE bool DqnFile_OpenW(const wchar_t *const path, DqnFile *const file, const u32 permissionFlags, const enum DqnFileAction action); // File offset is the byte offset to starting writing from -DQN_FILE_SCOPE size_t dqn_file_write(const DqnFile *const file, +DQN_FILE_SCOPE size_t DqnFile_Write(const DqnFile *const file, const u8 *const buffer, const size_t numBytesToWrite, const size_t fileOffset); // Return the number of bytes read -DQN_FILE_SCOPE size_t dqn_file_read(const DqnFile file, const u8 *const buffer, +DQN_FILE_SCOPE size_t DqnFile_Read(const DqnFile file, const u8 *const buffer, const size_t numBytesToRead); -DQN_FILE_SCOPE void dqn_file_close(DqnFile *const file); +DQN_FILE_SCOPE void DqnFile_Close(DqnFile *const file); // Return an array of strings of the files in the directory in UTF-8. numFiles // returns the number of strings read. // This is allocated using malloc and MUST BE FREED! Can be done manually or // using the helper function. -DQN_FILE_SCOPE char **dqn_dir_read (char *dir, u32 *numFiles); -DQN_FILE_SCOPE void dqn_dir_read_free(char **fileList, u32 numFiles); +DQN_FILE_SCOPE char **DqnDir_Read (char *dir, u32 *numFiles); +DQN_FILE_SCOPE void DqnDir_ReadFree(char **fileList, u32 numFiles); //////////////////////////////////////////////////////////////////////////////// // Timer //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE f64 dqn_time_now_in_s(); -DQN_FILE_SCOPE f64 dqn_time_now_in_ms(); +DQN_FILE_SCOPE f64 DqnTime_NowInS(); +DQN_FILE_SCOPE f64 DqnTime_NowInMs(); //////////////////////////////////////////////////////////////////////////////// // PCG (Permuted Congruential Generator) Random Number Generator @@ -487,15 +487,15 @@ typedef struct DqnRandPCGState // Initialise the random number generator using a seed. If not given it is // automatically created by using rdtsc. The generator is not valid until it's // been seeded. -DQN_FILE_SCOPE void dqn_rnd_pcg_init_with_seed(DqnRandPCGState *pcg, u32 seed); -DQN_FILE_SCOPE void dqn_rnd_pcg_init(DqnRandPCGState *pcg); +DQN_FILE_SCOPE void DqnRnd_PCGInitWithSeed(DqnRandPCGState *pcg, u32 seed); +DQN_FILE_SCOPE void DqnRnd_PCGInit(DqnRandPCGState *pcg); // Returns a random number N between [0, 0xFFFFFFFF] -DQN_FILE_SCOPE u32 dqn_rnd_pcg_next (DqnRandPCGState *pcg); +DQN_FILE_SCOPE u32 DqnRnd_PCGNext (DqnRandPCGState *pcg); // Returns a random float N between [0.0, 1.0f] -DQN_FILE_SCOPE f32 dqn_rnd_pcg_nextf(DqnRandPCGState *pcg); +DQN_FILE_SCOPE f32 DqnRnd_PCGNextf(DqnRandPCGState *pcg); // Returns a random integer N between [min, max] -DQN_FILE_SCOPE i32 dqn_rnd_pcg_range(DqnRandPCGState *pcg, i32 min, i32 max); +DQN_FILE_SCOPE i32 DqnRnd_PCGRange(DqnRandPCGState *pcg, i32 min, i32 max); //////////////////////////////////////////////////////////////////////////////// // PushBuffer Header @@ -513,8 +513,8 @@ typedef struct DqnPushBuffer { DqnPushBufferBlock *block; - i32 tempBufferCount; - u32 alignment; + i32 tempBufferCount; + size_t alignment; } DqnPushBuffer; typedef struct DqnTempBuffer @@ -525,13 +525,14 @@ typedef struct DqnTempBuffer } DqnTempBuffer; -DQN_FILE_SCOPE bool dqn_push_buffer_init (DqnPushBuffer *buffer, size_t size, u32 alignment); -DQN_FILE_SCOPE void *dqn_push_buffer_allocate (DqnPushBuffer *buffer, size_t size); -DQN_FILE_SCOPE void dqn_push_buffer_free_last_buffer(DqnPushBuffer *buffer); -DQN_FILE_SCOPE void dqn_push_buffer_free (DqnPushBuffer *buffer); +DQN_FILE_SCOPE bool DqnPushBuffer_Init (DqnPushBuffer *const buffer, size_t size, const size_t alignment); +DQN_FILE_SCOPE void *DqnPushBuffer_Allocate (DqnPushBuffer *const buffer, size_t size); +DQN_FILE_SCOPE void DqnPushBuffer_FreeLastBuffer(DqnPushBuffer *const buffer); +DQN_FILE_SCOPE void DqnPushBuffer_Free (DqnPushBuffer *const buffer); +DQN_FILE_SCOPE void DqnPushBuffer_ClearCurrBlock(DqnPushBuffer *const buffer, const bool clearToZero); -DQN_FILE_SCOPE DqnTempBuffer dqn_push_buffer_begin_temp_region(DqnPushBuffer *buffer); -DQN_FILE_SCOPE void dqn_push_buffer_end_temp_region (DqnTempBuffer tempBuffer); +DQN_FILE_SCOPE DqnTempBuffer DqnPushBuffer_BeginTempRegion(DqnPushBuffer *const buffer); +DQN_FILE_SCOPE void DqnPushBuffer_EndTempRegion(DqnTempBuffer tempBuffer); #endif /* DQN_H */ @@ -572,14 +573,14 @@ int main() data[size] = '\0'; fclose(fp); - DqnIni *ini = dqn_ini_load(data); + DqnIni *ini = DqnIni_Load(data); free(data); - int second_index = dqn_ini_find_property(ini, DQN_INI_GLOBAL_SECTION, "SecondSetting"); - char const *second = dqn_ini_property_value(ini, DQN_INI_GLOBAL_SECTION, second_index); - int section = dqn_ini_find_section(ini, "MySection"); - int third_index = dqn_ini_find_property(ini, section, "ThirdSetting"); - char const *third = dqn_ini_property_value(ini, section, third_index); - dqn_ini_destroy(ini); + int second_index = DqnIni_FindProperty(ini, DQN_INI_GLOBAL_SECTION, "SecondSetting"); + char const *second = DqnIni_PropertyValue(ini, DQN_INI_GLOBAL_SECTION, second_index); + int section = DqnIni_FindSection(ini, "MySection"); + int third_index = DqnIni_FindProperty(ini, section, "ThirdSetting"); + char const *third = DqnIni_PropertyValue(ini, section, third_index); + DqnIni_Destroy(ini); return 0; } @@ -593,16 +594,16 @@ Creating a new ini file int main() { - DqnIni *ini = dqn_ini_create(); - dqn_ini_property_add(ini, DQN_INI_GLOBAL_SECTION, "FirstSetting", "Test"); - dqn_ini_property_add(ini, DQN_INI_GLOBAL_SECTION, "SecondSetting", "2"); - int section = dqn_ini_section_add(ini, "MySection"); - dqn_ini_property_add(ini, section, "ThirdSetting", "Three"); + DqnIni *ini = DqnInit_Create(); + DqnIni_PropertyAdd(ini, DQN_INI_GLOBAL_SECTION, "FirstSetting", "Test"); + DqnIni_PropertyAdd(ini, DQN_INI_GLOBAL_SECTION, "SecondSetting", "2"); + int section = DqnIni_SectionAdd(ini, "MySection"); + DqnIni_PropertyAdd(ini, section, "ThirdSetting", "Three"); - int size = dqn_ini_save(ini, NULL, 0); // Find the size needed + int size = DqnIni_Save(ini, NULL, 0); // Find the size needed char *data = (char *)malloc(size); - size = dqn_ini_save(ini, data, size); // Actually save the file - dqn_ini_destroy(ini); + size = DqnIni_Save(ini, data, size); // Actually save the file + DqnIni_Destroy(ini); FILE *fp = fopen("test.ini", "w"); fwrite(data, 1, size, fp); @@ -618,30 +619,30 @@ int main() typedef struct DqnIni DqnIni; -DqnIni *dqn_ini_create(void *memctx); -DqnIni *dqn_ini_load (char const *data, void *memctx); +DqnIni *DqnInit_Create(void *memctx); +DqnIni *DqnIni_Load (char const *data, void *memctx); -int dqn_ini_save (DqnIni const *ini, char *data, int size); -void dqn_ini_destroy(DqnIni *ini); +int DqnIni_Save (DqnIni const *ini, char *data, int size); +void DqnIni_Destroy(DqnIni *ini); -int dqn_ini_section_count(DqnIni const *ini); -char const *dqn_ini_section_name (DqnIni const *ini, int section); +int DqnIni_SectionCount(DqnIni const *ini); +char const *DqnIni_SectionName (DqnIni const *ini, int section); -int dqn_ini_property_count(DqnIni const *ini, int section); -char const *dqn_ini_property_name (DqnIni const *ini, int section, int property); -char const *dqn_ini_property_value(DqnIni const *ini, int section, int property); +int DqnIni_PropertyCount(DqnIni const *ini, int section); +char const *DqnIni_PropertyName (DqnIni const *ini, int section, int property); +char const *DqnIni_PropertyValue(DqnIni const *ini, int section, int property); -int dqn_ini_find_section (DqnIni const *ini, char const *name, int name_length); -int dqn_ini_find_property(DqnIni const *ini, int section, char const *name, int name_length); +int DqnIni_FindSection (DqnIni const *ini, char const *name, int name_length); +int DqnIni_FindProperty(DqnIni const *ini, int section, char const *name, int name_length); -int dqn_ini_section_add (DqnIni *ini, char const *name, int length); -void dqn_ini_property_add (DqnIni *ini, int section, char const *name, int name_length, char const *value, int value_length); -void dqn_ini_section_remove (DqnIni *ini, int section); -void dqn_ini_property_remove(DqnIni *ini, int section, int property); +int DqnIni_SectionAdd (DqnIni *ini, char const *name, int length); +void DqnIni_PropertyAdd (DqnIni *ini, int section, char const *name, int name_length, char const *value, int value_length); +void DqnIni_SectionRemove (DqnIni *ini, int section); +void DqnIni_PropertyRemove(DqnIni *ini, int section, int property); -void dqn_ini_section_name_set (DqnIni *ini, int section, char const *name, int length); -void dqn_ini_property_name_set (DqnIni *ini, int section, int property, char const *name, int length); -void dqn_ini_property_value_set(DqnIni *ini, int section, int property, char const *value, int length); +void DqnIni_SectionNameSet (DqnIni *ini, int section, char const *name, int length); +void DqnIni_PropertyNameSet (DqnIni *ini, int section, int property, char const *name, int length); +void DqnIni_PropertyValueSet(DqnIni *ini, int section, int property, char const *value, int length); /** Customization @@ -669,7 +670,7 @@ following code: where `my_custom_malloc` and `my_custom_free` are your own memory allocation/deallocation functions. The `ctx` parameter is an optional parameter -of type `void*`. When `dqn_ini_create` or `dqn_ini_load` is called, you can pass +of type `void*`. When `DqnInit_Create` or `DqnIni_Load` is called, you can pass in a `memctx` parameter, which can be a pointer to anything you like, and which will be passed through as the `ctx` parameter to every `DQN_INI_MALLOC`/`DQN_INI_FREE` call. For example, if you are doing memory @@ -694,119 +695,119 @@ an example: If no custom function is defined, ini.h will default to the C runtime library equivalent. -dqn_ini_create +DqnInit_Create ---------- - DqnIni* dqn_ini_create( void* memctx ) + DqnIni* DqnInit_Create( void* memctx ) Instantiates a new, empty ini structure, which can be manipulated with other API calls, to fill it with data. To save it out to an ini-file string, use -`dqn_ini_save`. When no longer needed, it can be destroyed by calling -`dqn_ini_destroy`. `memctx` is a pointer to user defined data which will be +`DqnIni_Save`. When no longer needed, it can be destroyed by calling +`DqnIni_Destroy`. `memctx` is a pointer to user defined data which will be passed through to the custom DQN_INI_MALLOC/DQN_INI_FREE calls. It can be NULL if no user defined data is needed. -dqn_ini_load +DqnIni_Load -------- - DqnIni* dqn_ini_load( char const* data, void* memctx ) + DqnIni* DqnIni_Load( char const* data, void* memctx ) Parse the zero-terminated string `data` containing an ini-file, and create a new DqnIni instance containing the data. The instance can be manipulated with other API calls to enumerate sections/properties and retrieve values. When no -longer needed, it can be destroyed by calling `dqn_ini_destroy`. `memctx` is +longer needed, it can be destroyed by calling `DqnIni_Destroy`. `memctx` is a pointer to user defined data which will be passed through to the custom DQN_INI_MALLOC/DQN_INI_FREE calls. It can be NULL if no user defined data is needed. -dqn_ini_save +DqnIni_Save -------- - int dqn_ini_save( DqnIni const* ini, char* data, int size ) + int DqnIni_Save( DqnIni const* ini, char* data, int size ) Saves an ini structure as a zero-terminated ini-file string, into the specified buffer. Returns the number of bytes written, including the zero terminator. If -`data` is NULL, nothing is written, but `dqn_ini_save` still returns the number +`data` is NULL, nothing is written, but `DqnIni_Save` still returns the number of bytes it would have written. If the size of `data`, as specified in the `size` parameter, is smaller than that required, only part of the ini-file -string will be written. `dqn_ini_save` still returns the number of bytes it +string will be written. `DqnIni_Save` still returns the number of bytes it would have written had the buffer been large enough. -dqn_ini_destroy +DqnIni_Destroy ----------- - void dqn_ini_destroy( DqnIni* ini ) + void DqnIni_Destroy( DqnIni* ini ) -Destroy an `DqnIni` instance created by calling `dqn_ini_load` or -`dqn_ini_create`, releasing the memory allocated by it. No further API calls are -valid on an `DqnIni` instance after calling `dqn_ini_destroy` on it. +Destroy an `DqnIni` instance created by calling `DqnIni_Load` or +`DqnInit_Create`, releasing the memory allocated by it. No further API calls are +valid on an `DqnIni` instance after calling `DqnIni_Destroy` on it. -dqn_ini_section_count +DqnIni_SectionCount ----------------- - int dqn_ini_section_count( DqnIni const* ini ) + int DqnIni_SectionCount( DqnIni const* ini ) Returns the number of sections in an ini file. There's at least one section in an ini file (the global section), but there can be many more, each specified in the file by the section name wrapped in square brackets [ ]. -dqn_ini_section_name +DqnIni_SectionName ---------------- - char const* dqn_ini_section_name( DqnIni const* ini, int section ) + char const* DqnIni_SectionName( DqnIni const* ini, int section ) Returns the name of the section with the specified index. `section` must be -non-negative and less than the value returned by `dqn_ini_section_count`, or -`dqn_ini_section_name` will return NULL. The defined constant +non-negative and less than the value returned by `DqnIni_SectionCount`, or +`DqnIni_SectionName` will return NULL. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. -dqn_ini_property_count +DqnIni_PropertyCount ------------------ - int dqn_ini_property_count( DqnIni const* ini, int section ) + int DqnIni_PropertyCount( DqnIni const* ini, int section ) Returns the number of properties belonging to the section with the specified index. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`, or `dqn_ini_section_name` will return 0. The defined +`DqnIni_SectionCount`, or `DqnIni_SectionName` will return 0. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. Properties are declared in the ini-file on he format `name=value`. -dqn_ini_property_name +DqnIni_PropertyName ----------------- - char const* dqn_ini_property_name( DqnIni const* ini, int section, int property ) + char const* DqnIni_PropertyName( DqnIni const* ini, int section, int property ) Returns the name of the property with the specified index `property` in the section with the specified index `section`. `section` must be non-negative and -less than the value returned by `dqn_ini_section_count`, and `property` must be -non-negative and less than the value returned by `dqn_ini_property_count`, or -`dqn_ini_property_name` will return NULL. The defined constant +less than the value returned by `DqnIni_SectionCount`, and `property` must be +non-negative and less than the value returned by `DqnIni_PropertyCount`, or +`DqnIni_PropertyName` will return NULL. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. -dqn_ini_property_value +DqnIni_PropertyValue ------------------ - char const* dqn_ini_property_value( DqnIni const* ini, int section, int property ) + char const* DqnIni_PropertyValue( DqnIni const* ini, int section, int property ) Returns the value of the property with the specified index `property` in the section with the specified index `section`. `section` must be non-negative and -less than the value returned by `dqn_ini_section_count`, and `property` must be -non-negative and less than the value returned by `dqn_ini_property_count`, or -`dqn_ini_property_value` will return NULL. The defined constant +less than the value returned by `DqnIni_SectionCount`, and `property` must be +non-negative and less than the value returned by `DqnIni_PropertyCount`, or +`DqnIni_PropertyValue` will return NULL. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. -dqn_ini_find_section +DqnIni_FindSection ---------------- - int dqn_ini_find_section( DqnIni const* ini, char const* name, int name_length ) + int DqnIni_FindSection( DqnIni const* ini, char const* name, int name_length ) Finds the section with the specified name, and returns its index. `name_length` specifies the number of characters in `name`, which does not have to be @@ -816,10 +817,10 @@ with the specified name could be found, the value `DQN_INI_NOT_FOUND` is returned. -dqn_ini_find_property +DqnIni_FindProperty ----------------- - int dqn_ini_find_property( DqnIni const* ini, int section, char const* name, int name_length ) + int DqnIni_FindProperty( DqnIni const* ini, int section, char const* name, int name_length ) Finds the property with the specified name, within the section with the specified index, and returns the index of the property. `name_length` specifies @@ -828,15 +829,15 @@ If `name_length` is zero, the length is determined automatically, but in this case `name` has to be zero-terminated. If no property with the specified name could be found within the specified section, the value `DQN_INI_NOT_FOUND` is returned. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`, or `dqn_ini_find_property` will return +`DqnIni_SectionCount`, or `DqnIni_FindProperty` will return `DQN_INI_NOT_FOUND`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. -dqn_ini_section_add +DqnIni_SectionAdd --------------- - int dqn_ini_section_add( DqnIni* ini, char const* name, int length ) + int DqnIni_SectionAdd( DqnIni* ini, char const* name, int length ) Adds a section with the specified name, and returns the index it was added at. There is no check done to see if a section with the specified name already @@ -846,10 +847,10 @@ number of characters in `name`, which does not have to be zero-terminated. If `name` has to be zero-terminated. -dqn_ini_property_add +DqnIni_PropertyAdd ---------------- - void dqn_ini_property_add( DqnIni* ini, int section, char const* name, int name_length, char const* value, int value_length ) + void DqnIni_PropertyAdd( DqnIni* ini, int section, char const* name, int name_length, char const* value, int value_length ) Adds a property with the specified name and value to the specified section, and returns the index it was added at. There is no check done to see if a property with the specified name already exists - multiple properties of the same name @@ -857,34 +858,34 @@ are allowed. `name_length` and `value_length` specifies the number of characters in `name` and `value`, which does not have to be zero-terminated. If `name_length` or `value_length` is zero, the length is determined automatically, but in this case `name`/`value` has to be zero-terminated. `section` must be -non-negative and less than the value returned by `dqn_ini_section_count`, or the +non-negative and less than the value returned by `DqnIni_SectionCount`, or the property will not be added. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. -dqn_ini_section_remove +DqnIni_SectionRemove ------------------ - void dqn_ini_section_remove( DqnIni* ini, int section ) + void DqnIni_SectionRemove( DqnIni* ini, int section ) Removes the section with the specified index, and all properties within it. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`. The defined constant `DQN_INI_GLOBAL_SECTION` can be +`DqnIni_SectionCount`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. Note that removing a section will shuffle section indices, so that section indices you may have stored will no longer indicate the same section as it did before the remove. Use the find functions to update your indices. -dqn_ini_property_remove +DqnIni_PropertyRemove ------------------- - void dqn_ini_property_remove( DqnIni* ini, int section, int property ) + void DqnIni_PropertyRemove( DqnIni* ini, int section, int property ) Removes the property with the specified index from the specified section. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`, and `property` must be non-negative and less than the -value returned by `dqn_ini_property_count`. The defined constant +`DqnIni_SectionCount`, and `property` must be non-negative and less than the +value returned by `DqnIni_PropertyCount`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. Note that removing a property will shuffle property indices within the specified section, so that property indices you may have stored will no longer indicate the same @@ -892,43 +893,43 @@ property as it did before the remove. Use the find functions to update your indices. -dqn_ini_section_name_set +DqnIni_SectionNameSet -------------------- - void dqn_ini_section_name_set( DqnIni* ini, int section, char const* name, int length ) + void DqnIni_SectionNameSet( DqnIni* ini, int section, char const* name, int length ) Change the name of the section with the specified index. `section` must be -non-negative and less than the value returned by `dqn_ini_section_count`. The +non-negative and less than the value returned by `DqnIni_SectionCount`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. `length` specifies the number of characters in `name`, which does not have to be zero-terminated. If `length` is zero, the length is determined automatically, but in this case `name` has to be zero-terminated. -dqn_ini_property_name_set +DqnIni_PropertyNameSet --------------------- - void dqn_ini_property_name_set( DqnIni* ini, int section, int property, char const* name, int length ) + void DqnIni_PropertyNameSet( DqnIni* ini, int section, int property, char const* name, int length ) Change the name of the property with the specified index in the specified section. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`, and `property` must be non-negative and less than the -value returned by `dqn_ini_property_count`. The defined constant +`DqnIni_SectionCount`, and `property` must be non-negative and less than the +value returned by `DqnIni_PropertyCount`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. `length` specifies the number of characters in `name`, which does not have to be zero-terminated. If `length` is zero, the length is determined automatically, but in this case `name` has to be zero-terminated. -dqn_ini_property_value_set +DqnIni_PropertyValueSet ---------------------- - void dqn_ini_property_value_set( DqnIni* ini, int section, int property, char const* value, int length ) + void DqnIni_PropertyValueSet( DqnIni* ini, int section, int property, char const* value, int length ) Change the value of the property with the specified index in the specified section. `section` must be non-negative and less than the value returned by -`dqn_ini_section_count`, and `property` must be non-negative and less than the -value returned by `dqn_ini_property_count`. The defined constant +`DqnIni_SectionCount`, and `property` must be non-negative and less than the +value returned by `DqnIni_PropertyCount`. The defined constant `DQN_INI_GLOBAL_SECTION` can be used to indicate the global section. `length` specifies the number of characters in `value`, which does not have to be zero-terminated. If `length` is zero, the length is determined automatically, @@ -943,7 +944,7 @@ zero-terminated. If `length` is zero, the length is determined automatically, #define STB_SPRINTF_DECORATE(name) dqn_##name //////////////////////////////////////////////////////////////////////////////// -// STB_Sprintf renamed to dqn_sprintf +// STB_Sprintf renamed to Dqn_Sprintf //////////////////////////////////////////////////////////////////////////////// /* Public Domain library originally written by Jeff Roberts at RAD Game Tools @@ -951,13 +952,13 @@ Public Domain library originally written by Jeff Roberts at RAD Game Tools API: ==== -int dqn_sprintf (char *buf, char const * fmt, ...) -int dqn_snprintf(char *buf, int count, char const *fmt, ...) +int Dqn_sprintf (char *buf, char const * fmt, ...) +int Dqn_snprintf(char *buf, int count, char const *fmt, ...) - Convert an arg list into a buffer. - dqn_snprintf always returns a zero-terminated string (unlike regular snprintf). -int dqn_vsprintf (char *buf, char const *fmt, va_list va) -int dqn_vsnprintf(char *buf, int count, char const *fmt, va_list va) +int Dqn_vsprintf (char *buf, char const *fmt, va_list va) +int Dqn_vsnprintf(char *buf, int count, char const *fmt, va_list va) - Convert a va_list arg list into a buffer. - dqn_vsnprintf always returns a zero-terminated string (unlike regular snprintf). @@ -1067,13 +1068,13 @@ STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char comma, char peri // NOTE: DQN_INI_IMPLEMENTATION modified to be included when DQN_IMPLEMENTATION defined // #define DQN_INI_IMPLEMENTATION -#define DQN_INI_STRLEN(s) dqn_strlen(s) +#define DQN_INI_STRLEN(s) Dqn_strlen(s) //////////////////////////////////////////////////////////////////////////////// // Memory //////////////////////////////////////////////////////////////////////////////// // NOTE: All memory allocations in dqn.h go through these functions. So they can // be rerouted fairly easily especially for platform specific mallocs. -FILE_SCOPE void *dqn_mem_alloc_internal(size_t size, bool zeroClear) +FILE_SCOPE void *Dqn_MemAllocInternal(size_t size, bool zeroClear) { void *result = NULL; @@ -1088,13 +1089,19 @@ FILE_SCOPE void *dqn_mem_alloc_internal(size_t size, bool zeroClear) return result; } -FILE_SCOPE void *dqn_mem_realloc_internal(void *memory, size_t newSize) +FILE_SCOPE void Dqn_MemClearInternal(void *memory, u8 clearValue, + size_t size) +{ + if (memory) memset(memory, clearValue, size); +} + +FILE_SCOPE void *Dqn_MemReallocInternal(void *memory, size_t newSize) { void *result = realloc(memory, newSize); return result; } -FILE_SCOPE void dqn_mem_free_internal(void *memory) +FILE_SCOPE void Dqn_MemFreeInternal(void *memory) { if (memory) { @@ -1106,7 +1113,7 @@ FILE_SCOPE void dqn_mem_free_internal(void *memory) //////////////////////////////////////////////////////////////////////////////// // Math //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE f32 dqn_math_lerp(f32 a, f32 t, f32 b) +DQN_FILE_SCOPE f32 DqnMath_Lerp(f32 a, f32 t, f32 b) { /* Linear blend between two values. We having a starting point "a", and @@ -1124,7 +1131,7 @@ DQN_FILE_SCOPE f32 dqn_math_lerp(f32 a, f32 t, f32 b) return result; } -DQN_FILE_SCOPE f32 dqn_math_sqrtf(f32 a) +DQN_FILE_SCOPE f32 DqnMath_Sqrtf(f32 a) { f32 result = sqrtf(a); return result; @@ -1133,7 +1140,7 @@ DQN_FILE_SCOPE f32 dqn_math_sqrtf(f32 a) //////////////////////////////////////////////////////////////////////////////// // Vec2 //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE DqnV2 dqn_v2(f32 x, f32 y) +DQN_FILE_SCOPE DqnV2 DqnV2_2f(f32 x, f32 y) { DqnV2 result = {}; result.x = x; @@ -1142,49 +1149,49 @@ DQN_FILE_SCOPE DqnV2 dqn_v2(f32 x, f32 y) return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2i(i32 x, i32 y) +DQN_FILE_SCOPE DqnV2 DqnV2_2i(i32 x, i32 y) { - DqnV2 result = dqn_v2((f32)x, (f32)y); + DqnV2 result = DqnV2_2f((f32)x, (f32)y); return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_add(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE DqnV2 DqnV2_Add(DqnV2 a, DqnV2 b) { - DqnV2 result; + DqnV2 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] + b.e[i]; return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_sub(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE DqnV2 DqnV2_Sub(DqnV2 a, DqnV2 b) { - DqnV2 result; + DqnV2 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] - b.e[i]; return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_scale(DqnV2 a, f32 b) +DQN_FILE_SCOPE DqnV2 DqnV2_Scale(DqnV2 a, f32 b) { - DqnV2 result; + DqnV2 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b; return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_hadamard(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE DqnV2 DqnV2_Hadamard(DqnV2 a, DqnV2 b) { - DqnV2 result; + DqnV2 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b.e[i]; return result; } -DQN_FILE_SCOPE f32 dqn_v2_dot(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE f32 DqnV2_Dot(DqnV2 a, DqnV2 b) { /* DOT PRODUCT @@ -1200,15 +1207,15 @@ DQN_FILE_SCOPE f32 dqn_v2_dot(DqnV2 a, DqnV2 b) return result; } -DQN_FILE_SCOPE bool dqn_v2_equals(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE bool DqnV2_Equals(DqnV2 a, DqnV2 b) { - bool result = TRUE; + bool result = true; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) - if (a.e[i] != b.e[i]) result = FALSE; + if (a.e[i] != b.e[i]) result = false; return result; } -DQN_FILE_SCOPE f32 dqn_v2_length_squared(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE f32 DqnV2_LengthSquared(DqnV2 a, DqnV2 b) { f32 x = b.x - a.x; f32 y = b.y - a.y; @@ -1216,22 +1223,22 @@ DQN_FILE_SCOPE f32 dqn_v2_length_squared(DqnV2 a, DqnV2 b) return result; } -DQN_FILE_SCOPE f32 dqn_v2_length(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE f32 DqnV2_Length(DqnV2 a, DqnV2 b) { - f32 lengthSq = dqn_v2_length_squared(a, b); - f32 result = dqn_math_sqrtf(lengthSq); + f32 lengthSq = DqnV2_LengthSquared(a, b); + f32 result = DqnMath_Sqrtf(lengthSq); return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_normalise(DqnV2 a) +DQN_FILE_SCOPE DqnV2 DqnV2_Normalise(DqnV2 a) { - f32 magnitude = dqn_v2_length(dqn_v2(0, 0), a); - DqnV2 result = dqn_v2(a.x, a.y); - result = dqn_v2_scale(a, 1 / magnitude); + f32 magnitude = DqnV2_Length(DqnV2_2f(0, 0), a); + DqnV2 result = DqnV2_2f(a.x, a.y); + result = DqnV2_Scale(a, 1 / magnitude); return result; } -DQN_FILE_SCOPE bool dqn_v2_overlaps(DqnV2 a, DqnV2 b) +DQN_FILE_SCOPE bool DqnV2_Overlaps(DqnV2 a, DqnV2 b) { bool result = false; @@ -1254,14 +1261,14 @@ DQN_FILE_SCOPE bool dqn_v2_overlaps(DqnV2 a, DqnV2 b) return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_perpendicular(DqnV2 a) +DQN_FILE_SCOPE DqnV2 DqnV2_Perpendicular(DqnV2 a) { DqnV2 result = {a.y, -a.x}; return result; } -DQN_FILE_SCOPE DqnV2 dqn_v2_constrain_to_ratio(DqnV2 dim, DqnV2 ratio) +DQN_FILE_SCOPE DqnV2 DqnV2_ConstrainToRatio(DqnV2 dim, DqnV2 ratio) { DqnV2 result = {}; f32 numRatioIncrementsToWidth = (f32)(dim.w / ratio.w); @@ -1278,7 +1285,7 @@ DQN_FILE_SCOPE DqnV2 dqn_v2_constrain_to_ratio(DqnV2 dim, DqnV2 ratio) //////////////////////////////////////////////////////////////////////////////// // Vec3 //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE DqnV3 dqn_v3(f32 x, f32 y, f32 z) +DQN_FILE_SCOPE DqnV3 DqnV3_3f(f32 x, f32 y, f32 z) { DqnV3 result = {}; result.x = x; @@ -1287,49 +1294,49 @@ DQN_FILE_SCOPE DqnV3 dqn_v3(f32 x, f32 y, f32 z) return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3i(i32 x, i32 y, i32 z) +DQN_FILE_SCOPE DqnV3 DqnV3_3i(i32 x, i32 y, i32 z) { - DqnV3 result = dqn_v3((f32)x, (f32)y, (f32)z); + DqnV3 result = DqnV3_3f((f32)x, (f32)y, (f32)z); return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3_add(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE DqnV3 DqnV3_Add(DqnV3 a, DqnV3 b) { - DqnV3 result; + DqnV3 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] + b.e[i]; return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3_sub(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE DqnV3 DqnV3_Sub(DqnV3 a, DqnV3 b) { - DqnV3 result; + DqnV3 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] - b.e[i]; return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3_scale(DqnV3 a, f32 b) +DQN_FILE_SCOPE DqnV3 DqnV3_Scale(DqnV3 a, f32 b) { - DqnV3 result; + DqnV3 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b; return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3_hadamard(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE DqnV3 DqnV3_Hadamard(DqnV3 a, DqnV3 b) { - DqnV3 result; + DqnV3 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b.e[i]; return result; } -DQN_FILE_SCOPE f32 dqn_v3_dot(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE f32 DqnV3_Dot(DqnV3 a, DqnV3 b) { /* DOT PRODUCT @@ -1345,15 +1352,15 @@ DQN_FILE_SCOPE f32 dqn_v3_dot(DqnV3 a, DqnV3 b) return result; } -DQN_FILE_SCOPE bool dqn_v3_equals(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE bool DqnV3_Equals(DqnV3 a, DqnV3 b) { - bool result = TRUE; + bool result = true; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) - if (a.e[i] != b.e[i]) result = FALSE; + if (a.e[i] != b.e[i]) result = false; return result; } -DQN_FILE_SCOPE DqnV3 dqn_v3_cross(DqnV3 a, DqnV3 b) +DQN_FILE_SCOPE DqnV3 DqnV3_Cross(DqnV3 a, DqnV3 b) { /* CROSS PRODUCT @@ -1372,54 +1379,55 @@ DQN_FILE_SCOPE DqnV3 dqn_v3_cross(DqnV3 a, DqnV3 b) //////////////////////////////////////////////////////////////////////////////// // Vec4 //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE DqnV4 dqn_v4(f32 x, f32 y, f32 z, f32 w) +DQN_FILE_SCOPE DqnV4 DqnV4_4f(f32 x, f32 y, f32 z, f32 w) { DqnV4 result = {x, y, z, w}; return result; } -DQN_FILE_SCOPE DqnV4 dqn_v4i(i32 x, i32 y, i32 z, i32 w) { - DqnV4 result = dqn_v4((f32)x, (f32)y, (f32)z, (f32)w); +DQN_FILE_SCOPE DqnV4 DqnV4_4i(i32 x, i32 y, i32 z, i32 w) +{ + DqnV4 result = DqnV4_4f((f32)x, (f32)y, (f32)z, (f32)w); return result; } -DQN_FILE_SCOPE DqnV4 dqn_v4_add(DqnV4 a, DqnV4 b) +DQN_FILE_SCOPE DqnV4 DqnV4_Add(DqnV4 a, DqnV4 b) { - DqnV4 result; + DqnV4 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] + b.e[i]; return result; } -DQN_FILE_SCOPE DqnV4 dqn_v4_sub(DqnV4 a, DqnV4 b) +DQN_FILE_SCOPE DqnV4 DqnV4_Sub(DqnV4 a, DqnV4 b) { - DqnV4 result; + DqnV4 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] - b.e[i]; return result; } -DQN_FILE_SCOPE DqnV4 dqn_v4_scale(DqnV4 a, f32 b) +DQN_FILE_SCOPE DqnV4 DqnV4_Scale(DqnV4 a, f32 b) { - DqnV4 result; + DqnV4 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b; return result; } -DQN_FILE_SCOPE DqnV4 dqn_v4_hadamard(DqnV4 a, DqnV4 b) +DQN_FILE_SCOPE DqnV4 DqnV4_Hadamard(DqnV4 a, DqnV4 b) { - DqnV4 result; + DqnV4 result = {}; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) result.e[i] = a.e[i] * b.e[i]; return result; } -DQN_FILE_SCOPE f32 dqn_v4_dot(DqnV4 a, DqnV4 b) +DQN_FILE_SCOPE f32 DqnV4_Dot(DqnV4 a, DqnV4 b) { /* DOT PRODUCT @@ -1435,18 +1443,18 @@ DQN_FILE_SCOPE f32 dqn_v4_dot(DqnV4 a, DqnV4 b) return result; } -DQN_FILE_SCOPE bool dqn_v4_equals(DqnV4 a, DqnV4 b) +DQN_FILE_SCOPE bool DqnV4_Equals(DqnV4 a, DqnV4 b) { - bool result = TRUE; + bool result = true; for (i32 i = 0; i < DQN_ARRAY_COUNT(a.e); i++) - if (a.e[i] != b.e[i]) result = FALSE; + if (a.e[i] != b.e[i]) result = false; return result; } //////////////////////////////////////////////////////////////////////////////// // 4D Matrix Mat4 //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE DqnMat4 dqn_mat4_identity() +DQN_FILE_SCOPE DqnMat4 DqnMat4_Identity() { DqnMat4 result = {0}; result.e[0][0] = 1; @@ -1457,9 +1465,9 @@ DQN_FILE_SCOPE DqnMat4 dqn_mat4_identity() } DQN_FILE_SCOPE DqnMat4 -dqn_mat4_ortho(f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar) +DqnMat4_Ortho(f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar) { - DqnMat4 result = dqn_mat4_identity(); + DqnMat4 result = DqnMat4_Identity(); result.e[0][0] = +2.0f / (right - left); result.e[1][1] = +2.0f / (top - bottom); result.e[2][2] = -2.0f / (zFar - zNear); @@ -1471,18 +1479,18 @@ dqn_mat4_ortho(f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar) return result; } -DQN_FILE_SCOPE DqnMat4 dqn_mat4_translate(f32 x, f32 y, f32 z) +DQN_FILE_SCOPE DqnMat4 DqnMat4_Translate(f32 x, f32 y, f32 z) { - DqnMat4 result = dqn_mat4_identity(); + DqnMat4 result = DqnMat4_Identity(); result.e[3][0] = x; result.e[3][1] = y; result.e[3][2] = z; return result; } -DQN_FILE_SCOPE DqnMat4 dqn_mat4_rotate(f32 radians, f32 x, f32 y, f32 z) +DQN_FILE_SCOPE DqnMat4 DqnMat4_Rotate(f32 radians, f32 x, f32 y, f32 z) { - DqnMat4 result = dqn_mat4_identity(); + DqnMat4 result = DqnMat4_Identity(); f32 sinVal = sinf(radians); f32 cosVal = cosf(radians); @@ -1503,7 +1511,7 @@ DQN_FILE_SCOPE DqnMat4 dqn_mat4_rotate(f32 radians, f32 x, f32 y, f32 z) return result; } -DQN_FILE_SCOPE DqnMat4 dqn_mat4_scale(f32 x, f32 y, f32 z) +DQN_FILE_SCOPE DqnMat4 DqnMat4_Scale(f32 x, f32 y, f32 z) { DqnMat4 result = {0}; result.e[0][0] = x; @@ -1513,7 +1521,7 @@ DQN_FILE_SCOPE DqnMat4 dqn_mat4_scale(f32 x, f32 y, f32 z) return result; } -DQN_FILE_SCOPE DqnMat4 dqn_mat4_mul(DqnMat4 a, DqnMat4 b) +DQN_FILE_SCOPE DqnMat4 DqnMat4_Mul(DqnMat4 a, DqnMat4 b) { DqnMat4 result = {0}; for (i32 j = 0; j < 4; j++) { @@ -1528,7 +1536,7 @@ DQN_FILE_SCOPE DqnMat4 dqn_mat4_mul(DqnMat4 a, DqnMat4 b) return result; } -DQN_FILE_SCOPE DqnV4 dqn_mat4_mul_vec4(DqnMat4 a, DqnV4 b) +DQN_FILE_SCOPE DqnV4 DqnMat4_MulV4(DqnMat4 a, DqnV4 b) { DqnV4 result = {0}; @@ -1547,48 +1555,48 @@ DQN_FILE_SCOPE DqnV4 dqn_mat4_mul_vec4(DqnMat4 a, DqnV4 b) //////////////////////////////////////////////////////////////////////////////// // Rect //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE DqnRect dqn_rect(DqnV2 origin, DqnV2 size) +DQN_FILE_SCOPE DqnRect DqnRect_Init(DqnV2 origin, DqnV2 size) { DqnRect result = {}; result.min = origin; - result.max = dqn_v2_add(origin, size); + result.max = DqnV2_Add(origin, size); return result; } -DQN_FILE_SCOPE void dqn_rect_get_size_2f(DqnRect rect, f32 *width, f32 *height) +DQN_FILE_SCOPE void DqnRect_GetSize2f(DqnRect rect, f32 *width, f32 *height) { *width = DQN_ABS(rect.max.x - rect.min.x); *height = DQN_ABS(rect.max.y - rect.min.y); } -DQN_FILE_SCOPE DqnV2 dqn_rect_get_size_v2(DqnRect rect) +DQN_FILE_SCOPE DqnV2 DqnRect_GetSizeV2(DqnRect rect) { f32 width = DQN_ABS(rect.max.x - rect.min.x); f32 height = DQN_ABS(rect.max.y - rect.min.y); - DqnV2 result = dqn_v2(width, height); + DqnV2 result = DqnV2_2f(width, height); return result; } -DQN_FILE_SCOPE DqnV2 dqn_rect_get_centre(DqnRect rect) +DQN_FILE_SCOPE DqnV2 DqnRect_GetCentre(DqnRect rect) { f32 sumX = rect.min.x + rect.max.x; f32 sumY = rect.min.y + rect.max.y; - DqnV2 result = dqn_v2_scale(dqn_v2(sumX, sumY), 0.5f); + DqnV2 result = DqnV2_Scale(DqnV2_2f(sumX, sumY), 0.5f); return result; } -DQN_FILE_SCOPE DqnRect dqn_rect_move(DqnRect rect, DqnV2 shift) +DQN_FILE_SCOPE DqnRect DqnRect_Move(DqnRect rect, DqnV2 shift) { DqnRect result = {0}; - result.min = dqn_v2_add(rect.min, shift); - result.max = dqn_v2_add(rect.max, shift); + result.min = DqnV2_Add(rect.min, shift); + result.max = DqnV2_Add(rect.max, shift); return result; } -DQN_FILE_SCOPE bool dqn_rect_contains_p(DqnRect rect, DqnV2 p) +DQN_FILE_SCOPE bool DqnRect_ContainsP(DqnRect rect, DqnV2 p) { bool outsideOfRectX = false; if (p.x < rect.min.x || p.x > rect.max.w) @@ -1606,7 +1614,7 @@ DQN_FILE_SCOPE bool dqn_rect_contains_p(DqnRect rect, DqnV2 p) //////////////////////////////////////////////////////////////////////////////// // char String Operations //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE char dqn_char_to_lower(char c) +DQN_FILE_SCOPE char DqnChar_ToLower(char c) { if (c >= 'A' && c <= 'Z') { @@ -1617,7 +1625,7 @@ DQN_FILE_SCOPE char dqn_char_to_lower(char c) return c; } -DQN_FILE_SCOPE char dqn_char_to_upper(char c) +DQN_FILE_SCOPE char DqnChar_ToUpper(char c) { if (c >= 'a' && c <= 'z') { @@ -1629,25 +1637,25 @@ DQN_FILE_SCOPE char dqn_char_to_upper(char c) } -DQN_FILE_SCOPE bool dqn_char_is_digit(char c) +DQN_FILE_SCOPE bool DqnChar_IsDigit(char c) { if (c >= '0' && c <= '9') return true; return false; } -DQN_FILE_SCOPE bool dqn_char_is_alpha(char c) +DQN_FILE_SCOPE bool DqnChar_IsAlpha(char c) { if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return true; return false; } -DQN_FILE_SCOPE bool dqn_char_is_alphanum(char c) +DQN_FILE_SCOPE bool DqnChar_IsAlphaNum(char c) { - if (dqn_char_is_alpha(c) || dqn_char_is_digit(c)) return true; + if (DqnChar_IsAlpha(c) || DqnChar_IsDigit(c)) return true; return false; } -DQN_FILE_SCOPE i32 dqn_strcmp(const char *a, const char *b) +DQN_FILE_SCOPE i32 Dqn_strcmp(const char *a, const char *b) { if (!a && !b) return -1; if (!a) return -1; @@ -1663,7 +1671,7 @@ DQN_FILE_SCOPE i32 dqn_strcmp(const char *a, const char *b) return (((*a) < (*b)) ? -1 : 1); } -DQN_FILE_SCOPE i32 dqn_strlen(const char *a) +DQN_FILE_SCOPE i32 Dqn_strlen(const char *a) { i32 result = 0; while (a && a[result]) result++; @@ -1671,14 +1679,14 @@ DQN_FILE_SCOPE i32 dqn_strlen(const char *a) return result; } -DQN_FILE_SCOPE i32 dqn_strlen_delimit_with(const char *a, const char delimiter) +DQN_FILE_SCOPE i32 Dqn_strlenDelimitWith(const char *a, const char delimiter) { i32 result = 0; while (a && a[result] && a[result] != delimiter) result++; return result; } -DQN_FILE_SCOPE char *dqn_strncpy(char *dest, const char *src, i32 numChars) +DQN_FILE_SCOPE char *Dqn_strncpy(char *dest, const char *src, i32 numChars) { if (!dest) return NULL; if (!src) return dest; @@ -1689,7 +1697,7 @@ DQN_FILE_SCOPE char *dqn_strncpy(char *dest, const char *src, i32 numChars) return dest; } -DQN_FILE_SCOPE bool dqn_str_reverse(char *buf, const i32 bufSize) +DQN_FILE_SCOPE bool Dqn_StrReverse(char *buf, const i32 bufSize) { if (!buf) return false; i32 mid = bufSize / 2; @@ -1704,7 +1712,7 @@ DQN_FILE_SCOPE bool dqn_str_reverse(char *buf, const i32 bufSize) return true; } -DQN_FILE_SCOPE bool dqn_str_has_substring(const char *const a, const i32 lenA, +DQN_FILE_SCOPE bool Dqn_StrHasSubstring(const char *const a, const i32 lenA, const char *const b, const i32 lenB) { if (!a || !b) return false; @@ -1743,8 +1751,8 @@ DQN_FILE_SCOPE bool dqn_str_has_substring(const char *const a, const i32 lenA, i32 index = 0; for (;;) { - if (dqn_char_to_lower(longSubstr[index]) == - dqn_char_to_lower(shortStr[index])) + if (DqnChar_ToLower(longSubstr[index]) == + DqnChar_ToLower(shortStr[index])) { index++; if (index >= shortLen || !shortStr[index]) @@ -1763,7 +1771,7 @@ DQN_FILE_SCOPE bool dqn_str_has_substring(const char *const a, const i32 lenA, return matchedSubstr; } -DQN_FILE_SCOPE i32 dqn_str_to_i32(const char *const buf, const i32 bufSize) +DQN_FILE_SCOPE i32 Dqn_StrToI32(const char *const buf, const i32 bufSize) { if (!buf || bufSize == 0) return 0; @@ -1774,7 +1782,7 @@ DQN_FILE_SCOPE i32 dqn_str_to_i32(const char *const buf, const i32 bufSize) if (buf[index] == '-') isNegative = true; index++; } - else if (!dqn_char_is_digit(buf[index])) + else if (!DqnChar_IsDigit(buf[index])) { return 0; } @@ -1782,7 +1790,7 @@ DQN_FILE_SCOPE i32 dqn_str_to_i32(const char *const buf, const i32 bufSize) i32 result = 0; for (i32 i = index; i < bufSize; i++) { - if (dqn_char_is_digit(buf[i])) + if (DqnChar_IsDigit(buf[i])) { result *= 10; result += (buf[i] - '0'); @@ -1798,7 +1806,7 @@ DQN_FILE_SCOPE i32 dqn_str_to_i32(const char *const buf, const i32 bufSize) return result; } -DQN_FILE_SCOPE i32 dqn_i32_to_str(i32 value, char *buf, i32 bufSize) +DQN_FILE_SCOPE i32 Dqn_I32ToStr(i32 value, char *buf, i32 bufSize) { if (!buf || bufSize == 0) return 0; @@ -1827,11 +1835,11 @@ DQN_FILE_SCOPE i32 dqn_i32_to_str(i32 value, char *buf, i32 bufSize) // from the second character, so we don't put the negative sign at the end if (negative) { - dqn_str_reverse(buf + 1, charIndex - 1); + Dqn_StrReverse(buf + 1, charIndex - 1); } else { - dqn_str_reverse(buf, charIndex); + Dqn_StrReverse(buf, charIndex); } return charIndex; @@ -1857,7 +1865,7 @@ DQN_FILE_SCOPE i32 dqn_i32_to_str(i32 value, char *buf, i32 bufSize) The UCS code values 0xd800–0xdfff (UTF-16 surrogates) as well as 0xfffe and 0xffff (UCS noncharacters) should not appear in conforming UTF-8 streams. */ -DQN_FILE_SCOPE u32 dqn_ucs_to_utf8(u32 *dest, u32 character) +DQN_FILE_SCOPE u32 Dqn_UCSToUTF8(u32 *dest, u32 character) { if (!dest) return 0; @@ -1926,7 +1934,7 @@ DQN_FILE_SCOPE u32 dqn_ucs_to_utf8(u32 *dest, u32 character) return 0; } -DQN_FILE_SCOPE u32 dqn_utf8_to_ucs(u32 *dest, u32 character) +DQN_FILE_SCOPE u32 Dqn_UTF8ToUCS(u32 *dest, u32 character) { if (!dest) return 0; @@ -2002,13 +2010,13 @@ DQN_FILE_SCOPE u32 dqn_utf8_to_ucs(u32 *dest, u32 character) //////////////////////////////////////////////////////////////////////////////// // wchar String Operations //////////////////////////////////////////////////////////////////////////////// -DQN_FILE_SCOPE bool dqn_wchar_is_digit(const wchar_t c) +DQN_FILE_SCOPE bool DqnWChar_IsDigit(const wchar_t c) { if (c >= L'0' && c <= L'9') return true; return false; } -DQN_FILE_SCOPE wchar_t dqn_wchar_to_lower(const wchar_t c) +DQN_FILE_SCOPE wchar_t DqnWChar_ToLower(const wchar_t c) { if (c >= L'A' && c <= L'Z') { @@ -2019,14 +2027,14 @@ DQN_FILE_SCOPE wchar_t dqn_wchar_to_lower(const wchar_t c) return c; } -DQN_FILE_SCOPE i32 dqn_wstrlen(const wchar_t *a) +DQN_FILE_SCOPE i32 Dqn_wstrlen(const wchar_t *a) { i32 result = 0; while (a && a[result]) result++; return result; } -DQN_FILE_SCOPE i32 dqn_wstrcmp(const wchar_t *a, const wchar_t *b) +DQN_FILE_SCOPE i32 Dqn_wstrcmp(const wchar_t *a, const wchar_t *b) { if (!a && !b) return -1; if (!a) return -1; @@ -2042,7 +2050,7 @@ DQN_FILE_SCOPE i32 dqn_wstrcmp(const wchar_t *a, const wchar_t *b) return (((*a) < (*b)) ? -1 : 1); } -DQN_FILE_SCOPE bool dqn_wstr_reverse(wchar_t *buf, const i32 bufSize) +DQN_FILE_SCOPE bool Dqn_WStrReverse(wchar_t *buf, const i32 bufSize) { if (!buf) return false; i32 mid = bufSize / 2; @@ -2057,7 +2065,7 @@ DQN_FILE_SCOPE bool dqn_wstr_reverse(wchar_t *buf, const i32 bufSize) return true; } -DQN_FILE_SCOPE i32 dqn_wstr_to_i32(const wchar_t *const buf, const i32 bufSize) +DQN_FILE_SCOPE i32 Dqn_WStrToI32(const wchar_t *const buf, const i32 bufSize) { if (!buf || bufSize == 0) return 0; @@ -2068,7 +2076,7 @@ DQN_FILE_SCOPE i32 dqn_wstr_to_i32(const wchar_t *const buf, const i32 bufSize) if (buf[index] == L'-') isNegative = true; index++; } - else if (!dqn_wchar_is_digit(buf[index])) + else if (!DqnWChar_IsDigit(buf[index])) { return 0; } @@ -2076,7 +2084,7 @@ DQN_FILE_SCOPE i32 dqn_wstr_to_i32(const wchar_t *const buf, const i32 bufSize) i32 result = 0; for (i32 i = index; i < bufSize; i++) { - if (dqn_wchar_is_digit(buf[i])) + if (DqnWChar_IsDigit(buf[i])) { result *= 10; result += (buf[i] - L'0'); @@ -2092,7 +2100,7 @@ DQN_FILE_SCOPE i32 dqn_wstr_to_i32(const wchar_t *const buf, const i32 bufSize) return result; } -DQN_FILE_SCOPE i32 dqn_i32_to_wstr(i32 value, wchar_t *buf, i32 bufSize) +DQN_FILE_SCOPE i32 Dqn_I32ToWstr(i32 value, wchar_t *buf, i32 bufSize) { if (!buf || bufSize == 0) return 0; @@ -2121,11 +2129,11 @@ DQN_FILE_SCOPE i32 dqn_i32_to_wstr(i32 value, wchar_t *buf, i32 bufSize) // from the second character, so we don't put the negative sign at the end if (negative) { - dqn_wstr_reverse(buf + 1, charIndex - 1); + Dqn_WStrReverse(buf + 1, charIndex - 1); } else { - dqn_wstr_reverse(buf, charIndex); + Dqn_WStrReverse(buf, charIndex); } return charIndex; @@ -2135,9 +2143,8 @@ DQN_FILE_SCOPE i32 dqn_i32_to_wstr(i32 value, wchar_t *buf, i32 bufSize) //////////////////////////////////////////////////////////////////////////////// #ifdef DQN_WIN32 -DQN_FILE_SCOPE bool dqn_win32_utf8_to_wchar(const char *const in, - wchar_t *const out, - const i32 outLen) +DQN_FILE_SCOPE bool DqnWin32_UTF8ToWChar(const char *const in, + wchar_t *const out, const i32 outLen) { u32 result = MultiByteToWideChar(CP_UTF8, 0, in, -1, out, outLen-1); @@ -2150,8 +2157,8 @@ DQN_FILE_SCOPE bool dqn_win32_utf8_to_wchar(const char *const in, return true; } -DQN_FILE_SCOPE bool dqn_win32_wchar_to_utf8(const wchar_t *const in, - char *const out, const i32 outLen) +DQN_FILE_SCOPE bool DqnWin32_WCharToUTF8(const wchar_t *const in, + char *const out, const i32 outLen) { u32 result = WideCharToMultiByte(CP_UTF8, 0, in, -1, out, outLen, NULL, NULL); @@ -2165,8 +2172,8 @@ DQN_FILE_SCOPE bool dqn_win32_wchar_to_utf8(const wchar_t *const in, return true; } -DQN_FILE_SCOPE void dqn_win32_get_client_dim(const HWND window, LONG *width, - LONG *height) +DQN_FILE_SCOPE void DqnWin32_GetClientDim(const HWND window, LONG *width, + LONG *height) { RECT rect; GetClientRect(window, &rect); @@ -2174,13 +2181,13 @@ DQN_FILE_SCOPE void dqn_win32_get_client_dim(const HWND window, LONG *width, if (height) *height = rect.bottom - rect.top; } -DQN_FILE_SCOPE void dqn_win32_get_rect_dim(RECT rect, LONG *width, LONG *height) +DQN_FILE_SCOPE void DqnWin32_GetRectDim(RECT rect, LONG *width, LONG *height) { if (width) *width = rect.right - rect.left; if (height) *height = rect.bottom - rect.top; } -DQN_FILE_SCOPE void dqn_win32_display_last_error(const char *const errorPrefix) +DQN_FILE_SCOPE void DqnWin32_DisplayLastError(const char *const errorPrefix) { DWORD error = GetLastError(); char errorMsg[1024] = {}; @@ -2192,7 +2199,7 @@ DQN_FILE_SCOPE void dqn_win32_display_last_error(const char *const errorPrefix) DQN_WIN32_ERROR_BOX(formattedError, NULL); } -DQN_FILE_SCOPE void dqn_win32_display_error_code(const DWORD error, const char *const errorPrefix) +DQN_FILE_SCOPE void DqnWin32_DisplayErrorCode(const DWORD error, const char *const errorPrefix) { char errorMsg[1024] = {}; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -2204,10 +2211,10 @@ DQN_FILE_SCOPE void dqn_win32_display_error_code(const DWORD error, const char * } #endif -FILE_SCOPE bool dqn_file_open_internal(const wchar_t *const path, - DqnFile *const file, - const u32 permissionFlags, - const enum DqnFileAction action) +FILE_SCOPE bool DqnFile_OpenInternal(const wchar_t *const path, + DqnFile *const file, + const u32 permissionFlags, + const enum DqnFileAction action) { if (!file || !path) return false; @@ -2245,7 +2252,7 @@ FILE_SCOPE bool dqn_file_open_internal(const wchar_t *const path, LARGE_INTEGER size; if (GetFileSizeEx(handle, &size) == 0) { - dqn_win32_display_last_error("GetFileSizeEx() failed"); + DqnWin32_DisplayLastError("GetFileSizeEx() failed"); return false; } @@ -2261,45 +2268,44 @@ FILE_SCOPE bool dqn_file_open_internal(const wchar_t *const path, } DQN_FILE_SCOPE -bool dqn_file_openw(const wchar_t *const path, DqnFile *const file, - const u32 permissionFlags, const enum DqnFileAction action) +bool DqnFile_OpenW(const wchar_t *const path, DqnFile *const file, + const u32 permissionFlags, const enum DqnFileAction action) { if (!file || !path) return false; #ifdef DQN_WIN32 - return dqn_file_open_internal(path, file, permissionFlags, action); + return DqnFile_OpenInternal(path, file, permissionFlags, action); #else return false; #endif } DQN_FILE_SCOPE -bool dqn_file_open(const char *const path, DqnFile *const file, - const u32 permissionFlags, const enum DqnFileAction action) +bool DqnFile_Open(const char *const path, DqnFile *const file, + const u32 permissionFlags, const enum DqnFileAction action) { if (!file || !path) return false; #ifdef DQN_WIN32 wchar_t widePath[MAX_PATH] = {}; - dqn_win32_utf8_to_wchar(path, widePath, DQN_ARRAY_COUNT(widePath)); - dqn_file_open_internal(widePath, file, permissionFlags, action); + DqnWin32_UTF8ToWChar(path, widePath, DQN_ARRAY_COUNT(widePath)); + return DqnFile_OpenInternal(widePath, file, permissionFlags, action); #else return false; #endif - - return true; } -DQN_FILE_SCOPE size_t dqn_file_read(const DqnFile file, const u8 *const buffer, - const size_t numBytesToRead) +DQN_FILE_SCOPE size_t DqnFile_Read(const DqnFile file, const u8 *const buffer, + const size_t numBytesToRead) { size_t numBytesRead = 0; #ifdef DQN_WIN32 if (file.handle && buffer) { + DWORD bytesToRead = (DWORD)numBytesToRead; DWORD bytesRead = 0; HANDLE win32Handle = file.handle; - BOOL result = ReadFile(win32Handle, (void *)buffer, numBytesToRead, + BOOL result = ReadFile(win32Handle, (void *)buffer, bytesToRead, &bytesRead, NULL); numBytesRead = (size_t)bytesRead; @@ -2314,10 +2320,10 @@ DQN_FILE_SCOPE size_t dqn_file_read(const DqnFile file, const u8 *const buffer, return numBytesRead; } -DQN_FILE_SCOPE size_t dqn_file_write(const DqnFile *const file, - const u8 *const buffer, - const size_t numBytesToWrite, - const size_t fileOffset) +DQN_FILE_SCOPE size_t DqnFile_Write(const DqnFile *const file, + const u8 *const buffer, + const size_t numBytesToWrite, + const size_t fileOffset) { size_t numBytesWritten = 0; @@ -2328,9 +2334,10 @@ DQN_FILE_SCOPE size_t dqn_file_write(const DqnFile *const file, #ifdef DQN_WIN32 + DWORD bytesToWrite = (DWORD)numBytesToWrite; DWORD bytesWritten; BOOL result = - WriteFile(file->handle, buffer, numBytesToWrite, &bytesWritten, NULL); + WriteFile(file->handle, buffer, bytesToWrite, &bytesWritten, NULL); numBytesWritten = (size_t)bytesWritten; // TODO(doyle): Better logging system @@ -2345,7 +2352,7 @@ DQN_FILE_SCOPE size_t dqn_file_write(const DqnFile *const file, } -DQN_FILE_SCOPE void dqn_file_close(DqnFile *const file) +DQN_FILE_SCOPE void DqnFile_Close(DqnFile *const file) { #ifdef DQN_WIN32 if (file && file->handle) @@ -2358,14 +2365,14 @@ DQN_FILE_SCOPE void dqn_file_close(DqnFile *const file) #endif } -DQN_FILE_SCOPE char **dqn_dir_read(char *dir, u32 *numFiles) +DQN_FILE_SCOPE char **DqnDir_Read(char *dir, u32 *numFiles) { if (!dir) return NULL; #ifdef DQN_WIN32 u32 currNumFiles = 0; wchar_t wideDir[MAX_PATH] = {}; - dqn_win32_utf8_to_wchar(dir, wideDir, DQN_ARRAY_COUNT(wideDir)); + DqnWin32_UTF8ToWChar(dir, wideDir, DQN_ARRAY_COUNT(wideDir)); // Enumerate number of files first { @@ -2386,7 +2393,7 @@ DQN_FILE_SCOPE char **dqn_dir_read(char *dir, u32 *numFiles) DWORD error = GetLastError(); if (error != ERROR_NO_MORE_FILES) { - dqn_win32_display_error_code(error, + DqnWin32_DisplayErrorCode(error, "FindNextFileW() failed"); } @@ -2415,26 +2422,26 @@ DQN_FILE_SCOPE char **dqn_dir_read(char *dir, u32 *numFiles) return NULL; } - char **list = (char **)dqn_mem_alloc_internal( + char **list = (char **)Dqn_MemAllocInternal( sizeof(*list) * (currNumFiles), true); if (!list) { - DQN_WIN32_ERROR_BOX("dqn_mem_alloc_internal() failed.", NULL); + DQN_WIN32_ERROR_BOX("Dqn_MemAllocInternal() failed.", NULL); return NULL; } for (u32 i = 0; i < currNumFiles; i++) { list[i] = - (char *)dqn_mem_alloc_internal(sizeof(**list) * MAX_PATH, true); + (char *)Dqn_MemAllocInternal(sizeof(**list) * MAX_PATH, true); if (!list[i]) { for (u32 j = 0; j < i; j++) { - dqn_mem_free_internal(list[j]); + Dqn_MemFreeInternal(list[j]); } - DQN_WIN32_ERROR_BOX("dqn_mem_alloc_internal() failed.", NULL); + DQN_WIN32_ERROR_BOX("Dqn_MemAllocInternal() failed.", NULL); return NULL; } } @@ -2443,7 +2450,7 @@ DQN_FILE_SCOPE char **dqn_dir_read(char *dir, u32 *numFiles) WIN32_FIND_DATAW findData = {}; while (FindNextFileW(findHandle, &findData) != 0) { - dqn_win32_wchar_to_utf8(findData.cFileName, list[listIndex++], + DqnWin32_WCharToUTF8(findData.cFileName, list[listIndex++], MAX_PATH); } @@ -2452,20 +2459,22 @@ DQN_FILE_SCOPE char **dqn_dir_read(char *dir, u32 *numFiles) return list; } +#else + return NULL; #endif } -DQN_FILE_SCOPE void dqn_dir_read_free(char **fileList, u32 numFiles) +DQN_FILE_SCOPE void DqnDir_ReadFree(char **fileList, u32 numFiles) { if (fileList) { for (u32 i = 0; i < numFiles; i++) { - if (fileList[i]) dqn_mem_free_internal(fileList[i]); + if (fileList[i]) Dqn_MemFreeInternal(fileList[i]); fileList[i] = NULL; } - dqn_mem_free_internal(fileList); + Dqn_MemFreeInternal(fileList); } } @@ -2473,7 +2482,7 @@ DQN_FILE_SCOPE void dqn_dir_read_free(char **fileList, u32 numFiles) // Timer //////////////////////////////////////////////////////////////////////////////// #ifdef DQN_WIN32 -FILE_SCOPE f64 dqn_win32_query_perf_counter_time_in_s_internal() +FILE_SCOPE f64 DqnWin32_QueryPerfCounterTimeInSInternal() { LOCAL_PERSIST LARGE_INTEGER queryPerformanceFrequency = {}; if (queryPerformanceFrequency.QuadPart == 0) @@ -2492,20 +2501,17 @@ FILE_SCOPE f64 dqn_win32_query_perf_counter_time_in_s_internal() } #endif -f64 dqn_time_now_in_s() +f64 DqnTime_NowInS() { -#ifdef _WIN32 - return dqn_win32_query_perf_counter_time_in_s_internal(); +#ifdef DQN_WIN32 + return DqnWin32_QueryPerfCounterTimeInSInternal(); #else DQN_ASSERT(DQN_INVALID_CODE_PATH); return 0; #endif }; -f64 dqn_time_now_in_ms() -{ - return dqn_time_now_in_s() * 1000.0f; -} +f64 DqnTime_NowInMs() { return DqnTime_NowInS() * 1000.0f; } //////////////////////////////////////////////////////////////////////////////// // PCG (Permuted Congruential Generator) Random Number Generator @@ -2515,7 +2521,7 @@ f64 dqn_time_now_in_ms() // Convert a randomized u32 value to a float value x in the range 0.0f <= x // < 1.0f. Contributed by Jonatan Hedborg -FILE_SCOPE f32 dqn_rnd_f32_normalized_from_u32_internal(u32 value) +FILE_SCOPE f32 DqnRnd_F32NormalizedFromU32Internal(u32 value) { u32 exponent = 127; u32 mantissa = value >> 9; @@ -2524,7 +2530,7 @@ FILE_SCOPE f32 dqn_rnd_f32_normalized_from_u32_internal(u32 value) return fresult - 1.0f; } -FILE_SCOPE u64 dqn_rnd_murmur3_avalanche64_internal(u64 h) +FILE_SCOPE u64 DqnRnd_Murmur3Avalanche64Internal(u64 h) { h ^= h >> 33; h *= 0xff51afd7ed558ccd; @@ -2534,35 +2540,37 @@ FILE_SCOPE u64 dqn_rnd_murmur3_avalanche64_internal(u64 h) return h; } -FILE_SCOPE u32 dqn_rnd_make_seed_internal() +FILE_SCOPE u32 DqnRnd_MakeSeedInternal() { #ifdef _WIN32 __int64 numClockCycles = __rdtsc(); return (u32)numClockCycles; -#else +#elif __ANDROID__ + DQN_ASSERT(DQN_INVALID_CODE_PATH); +#elif __linux__ unsigned long long numClockCycles = rdtsc(); return (u32)numClockCycles; #endif } -DQN_FILE_SCOPE void dqn_rnd_pcg_init_with_seed(DqnRandPCGState *pcg, u32 seed) +DQN_FILE_SCOPE void DqnRnd_PCGInitWithSeed(DqnRandPCGState *pcg, u32 seed) { u64 value = (((u64)seed) << 1ULL) | 1ULL; - value = dqn_rnd_murmur3_avalanche64_internal(value); + value = DqnRnd_Murmur3Avalanche64Internal(value); pcg->state[0] = 0U; pcg->state[1] = (value << 1ULL) | 1ULL; - dqn_rnd_pcg_next(pcg); - pcg->state[0] += dqn_rnd_murmur3_avalanche64_internal(value); - dqn_rnd_pcg_next(pcg); + DqnRnd_PCGNext(pcg); + pcg->state[0] += DqnRnd_Murmur3Avalanche64Internal(value); + DqnRnd_PCGNext(pcg); } -DQN_FILE_SCOPE void dqn_rnd_pcg_init(DqnRandPCGState *pcg) +DQN_FILE_SCOPE void DqnRnd_PCGInit(DqnRandPCGState *pcg) { - u32 seed = dqn_rnd_make_seed_internal(); - dqn_rnd_pcg_init_with_seed(pcg, seed); + u32 seed = DqnRnd_MakeSeedInternal(); + DqnRnd_PCGInitWithSeed(pcg, seed); } -DQN_FILE_SCOPE u32 dqn_rnd_pcg_next(DqnRandPCGState *pcg) +DQN_FILE_SCOPE u32 DqnRnd_PCGNext(DqnRandPCGState *pcg) { u64 oldstate = pcg->state[0]; pcg->state[0] = oldstate * 0x5851f42d4c957f2dULL + pcg->state[1]; @@ -2571,35 +2579,35 @@ DQN_FILE_SCOPE u32 dqn_rnd_pcg_next(DqnRandPCGState *pcg) return (xorshifted >> rot) | (xorshifted << ((-(i32)rot) & 31)); } -DQN_FILE_SCOPE f32 dqn_rnd_pcg_nextf(DqnRandPCGState *pcg) +DQN_FILE_SCOPE f32 DqnRnd_PCGNextf(DqnRandPCGState *pcg) { - return dqn_rnd_f32_normalized_from_u32_internal(dqn_rnd_pcg_next(pcg)); + return DqnRnd_F32NormalizedFromU32Internal(DqnRnd_PCGNext(pcg)); } -DQN_FILE_SCOPE i32 dqn_rnd_pcg_range(DqnRandPCGState *pcg, i32 min, i32 max) +DQN_FILE_SCOPE i32 DqnRnd_PCGRange(DqnRandPCGState *pcg, i32 min, i32 max) { i32 const range = (max - min) + 1; if (range <= 0) return min; - i32 const value = (i32)(dqn_rnd_pcg_nextf(pcg) * range); + i32 const value = (i32)(DqnRnd_PCGNextf(pcg) * range); return min + value; } //////////////////////////////////////////////////////////////////////////////// // DqnPushBuffer Header //////////////////////////////////////////////////////////////////////////////// -FILE_SCOPE size_t dqn_size_alignment_internal(u32 alignment, size_t size) +FILE_SCOPE size_t Dqn_SizeAlignmentInternal(size_t alignment, size_t size) { - size_t result = ((size + (alignment-1)) & ~(alignment-1)); + size_t result = ((size + (alignment-1)) & (size_t)(~(alignment-1))); return result; } FILE_SCOPE DqnPushBufferBlock * -dqn_push_buffer_alloc_block_internal(u32 alignment, size_t size) +DqnPushBuffer_AllocBlockInternal(size_t alignment, size_t size) { - size_t alignedSize = dqn_size_alignment_internal(alignment, size); + size_t alignedSize = Dqn_SizeAlignmentInternal(alignment, size); size_t totalSize = alignedSize + sizeof(DqnPushBufferBlock); - DqnPushBufferBlock *result = (DqnPushBufferBlock *)dqn_mem_alloc_internal(totalSize, true); + DqnPushBufferBlock *result = (DqnPushBufferBlock *)Dqn_MemAllocInternal(totalSize, true); if (!result) return NULL; result->memory = (u8 *)result + sizeof(*result); @@ -2608,12 +2616,13 @@ dqn_push_buffer_alloc_block_internal(u32 alignment, size_t size) return result; } -DQN_FILE_SCOPE bool dqn_push_buffer_init(DqnPushBuffer *buffer, size_t size, u32 alignment) +DQN_FILE_SCOPE bool DqnPushBuffer_Init(DqnPushBuffer *const buffer, + size_t size, const size_t alignment) { if (!buffer || size <= 0) return false; DQN_ASSERT(!buffer->block); - buffer->block = dqn_push_buffer_alloc_block_internal(alignment, size); + buffer->block = DqnPushBuffer_AllocBlockInternal(alignment, size); if (!buffer->block) return false; buffer->tempBufferCount = 0; @@ -2621,16 +2630,16 @@ DQN_FILE_SCOPE bool dqn_push_buffer_init(DqnPushBuffer *buffer, size_t size, u32 return true; } -DQN_FILE_SCOPE void *dqn_push_buffer_allocate(DqnPushBuffer *buffer, size_t size) +DQN_FILE_SCOPE void *DqnPushBuffer_Allocate(DqnPushBuffer *const buffer, size_t size) { if (!buffer || size == 0) return NULL; - size_t alignedSize = dqn_size_alignment_internal(buffer->alignment, size); + size_t alignedSize = Dqn_SizeAlignmentInternal(buffer->alignment, size); if (!buffer->block || (buffer->block->used + alignedSize) > buffer->block->size) { size_t newBlockSize = DQN_MAX(alignedSize, buffer->block->size); - DqnPushBufferBlock *newBlock = dqn_push_buffer_alloc_block_internal( + DqnPushBufferBlock *newBlock = DqnPushBuffer_AllocBlockInternal( buffer->alignment, newBlockSize); if (!newBlock) return NULL; @@ -2639,7 +2648,7 @@ DQN_FILE_SCOPE void *dqn_push_buffer_allocate(DqnPushBuffer *buffer, size_t size } u8 *currPointer = buffer->block->memory + buffer->block->used; - u8 *alignedResult = (u8 *)dqn_size_alignment_internal(buffer->alignment, (size_t)currPointer); + u8 *alignedResult = (u8 *)Dqn_SizeAlignmentInternal(buffer->alignment, (size_t)currPointer); size_t alignmentOffset = (size_t)(alignedResult - currPointer); void *result = alignedResult; @@ -2648,26 +2657,44 @@ DQN_FILE_SCOPE void *dqn_push_buffer_allocate(DqnPushBuffer *buffer, size_t size return result; } -DQN_FILE_SCOPE void dqn_push_buffer_free_last_buffer(DqnPushBuffer *buffer) +DQN_FILE_SCOPE void +DqnPushBuffer_FreeLastBuffer(DqnPushBuffer *const buffer) { DqnPushBufferBlock *prevBlock = buffer->block->prevBlock; - dqn_mem_free_internal(buffer->block); + Dqn_MemFreeInternal(buffer->block); buffer->block = prevBlock; // No more blocks, then last block has been freed if (!buffer->block) DQN_ASSERT(buffer->tempBufferCount == 0); } -DQN_FILE_SCOPE void dqn_push_buffer_free(DqnPushBuffer *buffer) +DQN_FILE_SCOPE void DqnPushBuffer_Free(DqnPushBuffer *buffer) { if (!buffer) return; while (buffer->block) { - dqn_push_buffer_free_last_buffer(buffer); + DqnPushBuffer_FreeLastBuffer(buffer); } } -DQN_FILE_SCOPE DqnTempBuffer dqn_push_buffer_begin_temp_region(DqnPushBuffer *buffer) +DQN_FILE_SCOPE void +DqnPushBuffer_ClearCurrBlock(DqnPushBuffer *const buffer, + const bool clearToZero) +{ + if (!buffer) return; + if (buffer->block) + { + buffer->block->used = 0; + if (clearToZero) + { + Dqn_MemClearInternal(buffer->block->memory, 0, + buffer->block->size); + } + } +} + +DQN_FILE_SCOPE DqnTempBuffer +DqnPushBuffer_BeginTempRegion(DqnPushBuffer *const buffer) { DqnTempBuffer result = {}; result.buffer = buffer; @@ -2678,11 +2705,11 @@ DQN_FILE_SCOPE DqnTempBuffer dqn_push_buffer_begin_temp_region(DqnPushBuffer *bu return result; } -DQN_FILE_SCOPE void dqn_push_buffer_end_temp_region(DqnTempBuffer tempBuffer) +DQN_FILE_SCOPE void DqnPushBuffer_EndTempRegion(DqnTempBuffer tempBuffer) { DqnPushBuffer *buffer = tempBuffer.buffer; while (buffer->block != tempBuffer.startingBlock) - dqn_push_buffer_free_last_buffer(buffer); + DqnPushBuffer_FreeLastBuffer(buffer); if (buffer->block) { @@ -3799,7 +3826,7 @@ struct DqnIni void *memctx; }; -static int dqn_ini_internal_property_index(DqnIni const *ini, int section, +static int DqnIni_InternalPropertyIndex(DqnIni const *ini, int section, int property) { int i; @@ -3821,7 +3848,7 @@ static int dqn_ini_internal_property_index(DqnIni const *ini, int section, return DQN_INI_NOT_FOUND; } -DqnIni *dqn_ini_create(void *memctx) +DqnIni *DqnInit_Create(void *memctx) { DqnIni *ini; @@ -3840,7 +3867,7 @@ DqnIni *dqn_ini_create(void *memctx) return ini; } -DqnIni *dqn_ini_load(char const *data, void *memctx) +DqnIni *DqnIni_Load(char const *data, void *memctx) { DqnIni *ini; char const *ptr; @@ -3849,7 +3876,7 @@ DqnIni *dqn_ini_load(char const *data, void *memctx) char const *start2; int l; - ini = dqn_ini_create(memctx); + ini = DqnInit_Create(memctx); ptr = data; if (ptr) @@ -3880,7 +3907,7 @@ DqnIni *dqn_ini_load(char const *data, void *memctx) if (*ptr == ']') { - s = dqn_ini_section_add(ini, start, (int)(ptr - start)); + s = DqnIni_SectionAdd(ini, start, (int)(ptr - start)); ++ptr; } } @@ -3903,7 +3930,7 @@ DqnIni *dqn_ini_load(char const *data, void *memctx) while (*(--ptr) <= ' ') (void)ptr; ptr++; - dqn_ini_property_add(ini, s, start, l, start2, + DqnIni_PropertyAdd(ini, s, start, l, start2, (int)(ptr - start2)); } } @@ -3913,7 +3940,7 @@ DqnIni *dqn_ini_load(char const *data, void *memctx) return ini; } -int dqn_ini_save(DqnIni const *ini, char *data, int size) +int DqnIni_Save(DqnIni const *ini, char *data, int size) { int s; int p; @@ -3990,7 +4017,7 @@ int dqn_ini_save(DqnIni const *ini, char *data, int size) return 0; } -void dqn_ini_destroy(DqnIni *ini) +void DqnIni_Destroy(DqnIni *ini) { int i; @@ -4012,13 +4039,13 @@ void dqn_ini_destroy(DqnIni *ini) } } -int dqn_ini_section_count(DqnIni const *ini) +int DqnIni_SectionCount(DqnIni const *ini) { if (ini) return ini->section_count; return 0; } -char const *dqn_ini_section_name(DqnIni const *ini, int section) +char const *DqnIni_SectionName(DqnIni const *ini, int section) { if (ini && section >= 0 && section < ini->section_count) return ini->sections[section].name_large @@ -4028,7 +4055,7 @@ char const *dqn_ini_section_name(DqnIni const *ini, int section) return NULL; } -int dqn_ini_property_count(DqnIni const *ini, int section) +int DqnIni_PropertyCount(DqnIni const *ini, int section) { int i; int count; @@ -4046,13 +4073,13 @@ int dqn_ini_property_count(DqnIni const *ini, int section) return 0; } -char const *dqn_ini_property_name(DqnIni const *ini, int section, int property) +char const *DqnIni_PropertyName(DqnIni const *ini, int section, int property) { int p; if (ini && section >= 0 && section < ini->section_count) { - p = dqn_ini_internal_property_index(ini, section, property); + p = DqnIni_InternalPropertyIndex(ini, section, property); if (p != DQN_INI_NOT_FOUND) return ini->properties[p].name_large ? ini->properties[p].name_large : ini->properties[p].name; @@ -4061,13 +4088,13 @@ char const *dqn_ini_property_name(DqnIni const *ini, int section, int property) return NULL; } -char const *dqn_ini_property_value(DqnIni const *ini, int section, int property) +char const *DqnIni_PropertyValue(DqnIni const *ini, int section, int property) { int p; if (ini && section >= 0 && section < ini->section_count) { - p = dqn_ini_internal_property_index(ini, section, property); + p = DqnIni_InternalPropertyIndex(ini, section, property); if (p != DQN_INI_NOT_FOUND) return ini->properties[p].value_large ? ini->properties[p].value_large @@ -4077,7 +4104,7 @@ char const *dqn_ini_property_value(DqnIni const *ini, int section, int property) return NULL; } -int dqn_ini_find_section(DqnIni const *ini, char const *name, int name_length) +int DqnIni_FindSection(DqnIni const *ini, char const *name, int name_length) { int i; @@ -4098,7 +4125,7 @@ int dqn_ini_find_section(DqnIni const *ini, char const *name, int name_length) return DQN_INI_NOT_FOUND; } -int dqn_ini_find_property(DqnIni const *ini, int section, char const *name, +int DqnIni_FindProperty(DqnIni const *ini, int section, char const *name, int name_length) { int i; @@ -4126,7 +4153,7 @@ int dqn_ini_find_property(DqnIni const *ini, int section, char const *name, return DQN_INI_NOT_FOUND; } -int dqn_ini_section_add(DqnIni *ini, char const *name, int length) +int DqnIni_SectionAdd(DqnIni *ini, char const *name, int length) { struct dqn_ini_internal_section_t *new_sections; @@ -4165,7 +4192,7 @@ int dqn_ini_section_add(DqnIni *ini, char const *name, int length) return DQN_INI_NOT_FOUND; } -void dqn_ini_property_add(DqnIni *ini, int section, char const *name, +void DqnIni_PropertyAdd(DqnIni *ini, int section, char const *name, int name_length, char const *value, int value_length) { struct dqn_ini_internal_property_t *new_properties; @@ -4228,7 +4255,7 @@ void dqn_ini_property_add(DqnIni *ini, int section, char const *name, } } -void dqn_ini_section_remove(DqnIni *ini, int section) +void DqnIni_SectionRemove(DqnIni *ini, int section) { int p; @@ -4258,13 +4285,13 @@ void dqn_ini_section_remove(DqnIni *ini, int section) } } -void dqn_ini_property_remove(DqnIni *ini, int section, int property) +void DqnIni_PropertyRemove(DqnIni *ini, int section, int property) { int p; if (ini && section >= 0 && section < ini->section_count) { - p = dqn_ini_internal_property_index(ini, section, property); + p = DqnIni_InternalPropertyIndex(ini, section, property); if (p != DQN_INI_NOT_FOUND) { if (ini->properties[p].value_large) @@ -4277,7 +4304,7 @@ void dqn_ini_property_remove(DqnIni *ini, int section, int property) } } -void dqn_ini_section_name_set(DqnIni *ini, int section, char const *name, +void DqnIni_SectionNameSet(DqnIni *ini, int section, char const *name, int length) { if (ini && name && section >= 0 && section < ini->section_count) @@ -4303,7 +4330,7 @@ void dqn_ini_section_name_set(DqnIni *ini, int section, char const *name, } } -void dqn_ini_property_name_set(DqnIni *ini, int section, int property, +void DqnIni_PropertyNameSet(DqnIni *ini, int section, int property, char const *name, int length) { int p; @@ -4311,7 +4338,7 @@ void dqn_ini_property_name_set(DqnIni *ini, int section, int property, if (ini && name && section >= 0 && section < ini->section_count) { if (length <= 0) length = (int)DQN_INI_STRLEN(name); - p = dqn_ini_internal_property_index(ini, section, property); + p = DqnIni_InternalPropertyIndex(ini, section, property); if (p != DQN_INI_NOT_FOUND) { if (ini->properties[p].name_large) @@ -4335,7 +4362,7 @@ void dqn_ini_property_name_set(DqnIni *ini, int section, int property, } } -void dqn_ini_property_value_set(DqnIni *ini, int section, int property, +void DqnIni_PropertyValueSet(DqnIni *ini, int section, int property, char const *value, int length) { int p; @@ -4343,7 +4370,7 @@ void dqn_ini_property_value_set(DqnIni *ini, int section, int property, if (ini && value && section >= 0 && section < ini->section_count) { if (length <= 0) length = (int)DQN_INI_STRLEN(value); - p = dqn_ini_internal_property_index(ini, section, property); + p = DqnIni_InternalPropertyIndex(ini, section, property); if (p != DQN_INI_NOT_FOUND) { if (ini->properties[p].value_large) diff --git a/dqn_unit_test.cpp b/dqn_unit_test.cpp index 05653f9..67bdedf 100644 --- a/dqn_unit_test.cpp +++ b/dqn_unit_test.cpp @@ -3,39 +3,39 @@ #include "stdio.h" -void dqn_strings_test() +void StringsTest() { { // Char Checks - DQN_ASSERT(dqn_char_is_alpha('a') == true); - DQN_ASSERT(dqn_char_is_alpha('A') == true); - DQN_ASSERT(dqn_char_is_alpha('0') == false); - DQN_ASSERT(dqn_char_is_alpha('@') == false); - DQN_ASSERT(dqn_char_is_alpha(' ') == false); - DQN_ASSERT(dqn_char_is_alpha('\n') == false); + DQN_ASSERT(DqnChar_IsAlpha('a') == true); + DQN_ASSERT(DqnChar_IsAlpha('A') == true); + DQN_ASSERT(DqnChar_IsAlpha('0') == false); + DQN_ASSERT(DqnChar_IsAlpha('@') == false); + DQN_ASSERT(DqnChar_IsAlpha(' ') == false); + DQN_ASSERT(DqnChar_IsAlpha('\n') == false); - DQN_ASSERT(dqn_char_is_digit('1') == true); - DQN_ASSERT(dqn_char_is_digit('n') == false); - DQN_ASSERT(dqn_char_is_digit('N') == false); - DQN_ASSERT(dqn_char_is_digit('*') == false); - DQN_ASSERT(dqn_char_is_digit(' ') == false); - DQN_ASSERT(dqn_char_is_digit('\n') == false); + DQN_ASSERT(DqnChar_IsDigit('1') == true); + DQN_ASSERT(DqnChar_IsDigit('n') == false); + DQN_ASSERT(DqnChar_IsDigit('N') == false); + DQN_ASSERT(DqnChar_IsDigit('*') == false); + DQN_ASSERT(DqnChar_IsDigit(' ') == false); + DQN_ASSERT(DqnChar_IsDigit('\n') == false); - DQN_ASSERT(dqn_char_is_alphanum('1') == true); - DQN_ASSERT(dqn_char_is_alphanum('a') == true); - DQN_ASSERT(dqn_char_is_alphanum('A') == true); - DQN_ASSERT(dqn_char_is_alphanum('*') == false); - DQN_ASSERT(dqn_char_is_alphanum(' ') == false); - DQN_ASSERT(dqn_char_is_alphanum('\n') == false); + DQN_ASSERT(DqnChar_IsAlphaNum('1') == true); + DQN_ASSERT(DqnChar_IsAlphaNum('a') == true); + DQN_ASSERT(DqnChar_IsAlphaNum('A') == true); + DQN_ASSERT(DqnChar_IsAlphaNum('*') == false); + DQN_ASSERT(DqnChar_IsAlphaNum(' ') == false); + DQN_ASSERT(DqnChar_IsAlphaNum('\n') == false); - DQN_ASSERT(dqn_char_to_lower(L'A') == L'a'); - DQN_ASSERT(dqn_char_to_lower(L'a') == L'a'); - DQN_ASSERT(dqn_char_to_lower(L' ') == L' '); + DQN_ASSERT(DqnChar_ToLower(L'A') == L'a'); + DQN_ASSERT(DqnChar_ToLower(L'a') == L'a'); + DQN_ASSERT(DqnChar_ToLower(L' ') == L' '); - DQN_ASSERT(dqn_char_to_upper(L'A') == L'A'); - DQN_ASSERT(dqn_char_to_upper(L'a') == L'A'); - DQN_ASSERT(dqn_char_to_upper(L' ') == L' '); + DQN_ASSERT(DqnChar_ToUpper(L'A') == L'A'); + DQN_ASSERT(DqnChar_ToUpper(L'a') == L'A'); + DQN_ASSERT(DqnChar_ToUpper(L' ') == L' '); - printf("dqn_strings_test(): char_checks: Completed successfully\n"); + printf("StringsTest(): CharChecks: Completed successfully\n"); } // String Checks @@ -46,40 +46,40 @@ void dqn_strings_test() // Check simple compares { - DQN_ASSERT(dqn_strcmp(a, "str_a") == +0); - DQN_ASSERT(dqn_strcmp(a, "str_b") == -1); - DQN_ASSERT(dqn_strcmp("str_b", a) == +1); - DQN_ASSERT(dqn_strcmp(a, "") == +1); - DQN_ASSERT(dqn_strcmp("", "") == 0); + DQN_ASSERT(Dqn_strcmp(a, "str_a") == +0); + DQN_ASSERT(Dqn_strcmp(a, "str_b") == -1); + DQN_ASSERT(Dqn_strcmp("str_b", a) == +1); + DQN_ASSERT(Dqn_strcmp(a, "") == +1); + DQN_ASSERT(Dqn_strcmp("", "") == 0); // NOTE: Check that the string has not been trashed. - DQN_ASSERT(dqn_strcmp(a, "str_a") == +0); + DQN_ASSERT(Dqn_strcmp(a, "str_a") == +0); } // Check ops against null { - DQN_ASSERT(dqn_strcmp(NULL, NULL) != +0); - DQN_ASSERT(dqn_strcmp(a, NULL) != +0); - DQN_ASSERT(dqn_strcmp(NULL, a) != +0); + DQN_ASSERT(Dqn_strcmp(NULL, NULL) != +0); + DQN_ASSERT(Dqn_strcmp(a, NULL) != +0); + DQN_ASSERT(Dqn_strcmp(NULL, a) != +0); } - printf("dqn_strings_test(): strcmp: Completed successfully\n"); + printf("StringsTest(): strcmp: Completed successfully\n"); } // strlen { char *a = "str_a"; - DQN_ASSERT(dqn_strlen(a) == 5); - DQN_ASSERT(dqn_strlen("") == 0); - DQN_ASSERT(dqn_strlen(" a ") == 6); - DQN_ASSERT(dqn_strlen("a\n") == 2); + DQN_ASSERT(Dqn_strlen(a) == 5); + DQN_ASSERT(Dqn_strlen("") == 0); + DQN_ASSERT(Dqn_strlen(" a ") == 6); + DQN_ASSERT(Dqn_strlen("a\n") == 2); // NOTE: Check that the string has not been trashed. - DQN_ASSERT(dqn_strcmp(a, "str_a") == 0); + DQN_ASSERT(Dqn_strcmp(a, "str_a") == 0); - DQN_ASSERT(dqn_strlen(NULL) == 0); + DQN_ASSERT(Dqn_strlen(NULL) == 0); - printf("dqn_strings_test(): strlen: Completed successfully\n"); + printf("StringsTest(): strlen: Completed successfully\n"); } // strncpy @@ -89,37 +89,37 @@ void dqn_strings_test() char b[10] = {}; // Check copy into empty array { - char *result = dqn_strncpy(b, a, dqn_strlen(a)); - DQN_ASSERT(dqn_strcmp(b, "str_a") == 0); - DQN_ASSERT(dqn_strcmp(a, "str_a") == 0); - DQN_ASSERT(dqn_strcmp(result, "str_a") == 0); - DQN_ASSERT(dqn_strlen(result) == 5); + char *result = Dqn_strncpy(b, a, Dqn_strlen(a)); + DQN_ASSERT(Dqn_strcmp(b, "str_a") == 0); + DQN_ASSERT(Dqn_strcmp(a, "str_a") == 0); + DQN_ASSERT(Dqn_strcmp(result, "str_a") == 0); + DQN_ASSERT(Dqn_strlen(result) == 5); } // Check copy into array offset, overlap with old results { - char *newResult = dqn_strncpy(&b[1], a, dqn_strlen(a)); - DQN_ASSERT(dqn_strcmp(newResult, "str_a") == 0); - DQN_ASSERT(dqn_strlen(newResult) == 5); + char *newResult = Dqn_strncpy(&b[1], a, Dqn_strlen(a)); + DQN_ASSERT(Dqn_strcmp(newResult, "str_a") == 0); + DQN_ASSERT(Dqn_strlen(newResult) == 5); - DQN_ASSERT(dqn_strcmp(a, "str_a") == 0); - DQN_ASSERT(dqn_strlen(a) == 5); + DQN_ASSERT(Dqn_strcmp(a, "str_a") == 0); + DQN_ASSERT(Dqn_strlen(a) == 5); - DQN_ASSERT(dqn_strcmp(b, "sstr_a") == 0); - DQN_ASSERT(dqn_strlen(b) == 6); + DQN_ASSERT(Dqn_strcmp(b, "sstr_a") == 0); + DQN_ASSERT(Dqn_strlen(b) == 6); } } // Check strncpy with NULL pointers { - DQN_ASSERT(dqn_strncpy(NULL, NULL, 5) == NULL); + DQN_ASSERT(Dqn_strncpy(NULL, NULL, 5) == NULL); char *a = "str"; - char *result = dqn_strncpy(a, NULL, 5); + char *result = Dqn_strncpy(a, NULL, 5); - DQN_ASSERT(dqn_strcmp(a, "str") == 0); - DQN_ASSERT(dqn_strcmp(result, "str") == 0); - DQN_ASSERT(dqn_strcmp(result, a) == 0); + DQN_ASSERT(Dqn_strcmp(a, "str") == 0); + DQN_ASSERT(Dqn_strcmp(result, "str") == 0); + DQN_ASSERT(Dqn_strcmp(result, a) == 0); } // Check strncpy with 0 chars to copy @@ -127,92 +127,92 @@ void dqn_strings_test() char *a = "str"; char *b = "ing"; - char *result = dqn_strncpy(a, b, 0); - DQN_ASSERT(dqn_strcmp(a, "str") == 0); - DQN_ASSERT(dqn_strcmp(b, "ing") == 0); - DQN_ASSERT(dqn_strcmp(result, "str") == 0); + char *result = Dqn_strncpy(a, b, 0); + DQN_ASSERT(Dqn_strcmp(a, "str") == 0); + DQN_ASSERT(Dqn_strcmp(b, "ing") == 0); + DQN_ASSERT(Dqn_strcmp(result, "str") == 0); } - printf("dqn_strings_test(): strncpy: Completed successfully\n"); + printf("StringsTest(): strncpy: Completed successfully\n"); } - // str_reverse + // StrReverse { // Basic reverse operations { char a[] = "aba"; - DQN_ASSERT(dqn_str_reverse(a, dqn_strlen(a)) == true); - DQN_ASSERT(dqn_strcmp(a, "aba") == 0); + DQN_ASSERT(Dqn_StrReverse(a, Dqn_strlen(a)) == true); + DQN_ASSERT(Dqn_strcmp(a, "aba") == 0); - DQN_ASSERT(dqn_str_reverse(a, 2) == true); - DQN_ASSERT(dqn_strcmp(a, "baa") == 0); + DQN_ASSERT(Dqn_StrReverse(a, 2) == true); + DQN_ASSERT(Dqn_strcmp(a, "baa") == 0); - DQN_ASSERT(dqn_str_reverse(a, dqn_strlen(a)) == true); - DQN_ASSERT(dqn_strcmp(a, "aab") == 0); + DQN_ASSERT(Dqn_StrReverse(a, Dqn_strlen(a)) == true); + DQN_ASSERT(Dqn_strcmp(a, "aab") == 0); - DQN_ASSERT(dqn_str_reverse(&a[1], 2) == true); - DQN_ASSERT(dqn_strcmp(a, "aba") == 0); + DQN_ASSERT(Dqn_StrReverse(&a[1], 2) == true); + DQN_ASSERT(Dqn_strcmp(a, "aba") == 0); - DQN_ASSERT(dqn_str_reverse(a, 0) == true); - DQN_ASSERT(dqn_strcmp(a, "aba") == 0); + DQN_ASSERT(Dqn_StrReverse(a, 0) == true); + DQN_ASSERT(Dqn_strcmp(a, "aba") == 0); } // Try reverse empty string { char a[] = ""; - DQN_ASSERT(dqn_str_reverse(a, dqn_strlen(a)) == true); - DQN_ASSERT(dqn_strcmp(a, "") == 0); + DQN_ASSERT(Dqn_StrReverse(a, Dqn_strlen(a)) == true); + DQN_ASSERT(Dqn_strcmp(a, "") == 0); } // Try reverse single char string { char a[] = "a"; - DQN_ASSERT(dqn_str_reverse(a, dqn_strlen(a)) == true); - DQN_ASSERT(dqn_strcmp(a, "a") == 0); + DQN_ASSERT(Dqn_StrReverse(a, Dqn_strlen(a)) == true); + DQN_ASSERT(Dqn_strcmp(a, "a") == 0); - DQN_ASSERT(dqn_str_reverse(a, 0) == true); - DQN_ASSERT(dqn_strcmp(a, "a") == 0); + DQN_ASSERT(Dqn_StrReverse(a, 0) == true); + DQN_ASSERT(Dqn_strcmp(a, "a") == 0); } printf( - "dqn_strings_test(): str_reverse: Completed successfully\n"); + "StringsTest(): StrReverse: Completed successfully\n"); } - // str_to_i32 + // StrToI32 { char *a = "123"; - DQN_ASSERT(dqn_str_to_i32(a, dqn_strlen(a)) == 123); + DQN_ASSERT(Dqn_StrToI32(a, Dqn_strlen(a)) == 123); char *b = "-123"; - DQN_ASSERT(dqn_str_to_i32(b, dqn_strlen(b)) == -123); - DQN_ASSERT(dqn_str_to_i32(b, 1) == 0); - DQN_ASSERT(dqn_str_to_i32(&b[1], dqn_strlen(&b[1])) == 123); + DQN_ASSERT(Dqn_StrToI32(b, Dqn_strlen(b)) == -123); + DQN_ASSERT(Dqn_StrToI32(b, 1) == 0); + DQN_ASSERT(Dqn_StrToI32(&b[1], Dqn_strlen(&b[1])) == 123); char *c = "-0"; - DQN_ASSERT(dqn_str_to_i32(c, dqn_strlen(c)) == 0); + DQN_ASSERT(Dqn_StrToI32(c, Dqn_strlen(c)) == 0); char *d = "+123"; - DQN_ASSERT(dqn_str_to_i32(d, dqn_strlen(d)) == 123); - DQN_ASSERT(dqn_str_to_i32(&d[1], dqn_strlen(&d[1])) == 123); + DQN_ASSERT(Dqn_StrToI32(d, Dqn_strlen(d)) == 123); + DQN_ASSERT(Dqn_StrToI32(&d[1], Dqn_strlen(&d[1])) == 123); - printf("dqn_strings_test(): str_to_i32: Completed successfully\n"); + printf("StringsTest(): StrToI32: Completed successfully\n"); } // i32_to_str { char a[DQN_I32_TO_STR_MAX_BUF_SIZE] = {}; - dqn_i32_to_str(+100, a, DQN_ARRAY_COUNT(a)); - DQN_ASSERT(dqn_strcmp(a, "100") == 0); + Dqn_I32ToStr(+100, a, DQN_ARRAY_COUNT(a)); + DQN_ASSERT(Dqn_strcmp(a, "100") == 0); char b[DQN_I32_TO_STR_MAX_BUF_SIZE] = {}; - dqn_i32_to_str(-100, b, DQN_ARRAY_COUNT(b)); - DQN_ASSERT(dqn_strcmp(b, "-100") == 0); + Dqn_I32ToStr(-100, b, DQN_ARRAY_COUNT(b)); + DQN_ASSERT(Dqn_strcmp(b, "-100") == 0); char c[DQN_I32_TO_STR_MAX_BUF_SIZE] = {}; - dqn_i32_to_str(0, c, DQN_ARRAY_COUNT(c)); - DQN_ASSERT(dqn_strcmp(c, "0") == 0); + Dqn_I32ToStr(0, c, DQN_ARRAY_COUNT(c)); + DQN_ASSERT(Dqn_strcmp(c, "0") == 0); - printf("dqn_strings_test(): str_to_i32: Completed successfully\n"); + printf("StringsTest(): StrToI32: Completed successfully\n"); } } @@ -221,29 +221,29 @@ void dqn_strings_test() { char *a = "Microsoft"; char *b = "icro"; - i32 lenA = dqn_strlen(a); - i32 lenB = dqn_strlen(b); - DQN_ASSERT(dqn_str_has_substring(a, lenA, b, lenB) == true); - DQN_ASSERT(dqn_str_has_substring(a, lenA, "iro", - dqn_strlen("iro")) == false); - DQN_ASSERT(dqn_str_has_substring(b, lenB, a, lenA) == true); - DQN_ASSERT(dqn_str_has_substring("iro", dqn_strlen("iro"), a, + i32 lenA = Dqn_strlen(a); + i32 lenB = Dqn_strlen(b); + DQN_ASSERT(Dqn_StrHasSubstring(a, lenA, b, lenB) == true); + DQN_ASSERT(Dqn_StrHasSubstring(a, lenA, "iro", + Dqn_strlen("iro")) == false); + DQN_ASSERT(Dqn_StrHasSubstring(b, lenB, a, lenA) == true); + DQN_ASSERT(Dqn_StrHasSubstring("iro", Dqn_strlen("iro"), a, lenA) == false); - DQN_ASSERT(dqn_str_has_substring("", 0, "iro", 4) == false); - DQN_ASSERT(dqn_str_has_substring("", 0, "", 0) == false); - DQN_ASSERT(dqn_str_has_substring(NULL, 0, NULL, 0) == false); + DQN_ASSERT(Dqn_StrHasSubstring("", 0, "iro", 4) == false); + DQN_ASSERT(Dqn_StrHasSubstring("", 0, "", 0) == false); + DQN_ASSERT(Dqn_StrHasSubstring(NULL, 0, NULL, 0) == false); } { char *a = "Micro"; char *b = "irob"; - i32 lenA = dqn_strlen(a); - i32 lenB = dqn_strlen(b); - DQN_ASSERT(dqn_str_has_substring(a, lenA, b, lenB) == false); - DQN_ASSERT(dqn_str_has_substring(b, lenB, a, lenA) == false); + i32 lenA = Dqn_strlen(a); + i32 lenB = Dqn_strlen(b); + DQN_ASSERT(Dqn_StrHasSubstring(a, lenA, b, lenB) == false); + DQN_ASSERT(Dqn_StrHasSubstring(b, lenB, a, lenA) == false); } - printf("dqn_strings_test(): str_has_substring: Completed successfully\n"); + printf("StringsTest(): StrHasSubstring: Completed successfully\n"); } // UCS <-> UTF8 Checks @@ -253,11 +253,11 @@ void dqn_strings_test() u32 codepoint = '@'; u32 string[1] = {}; - u32 bytesUsed = dqn_ucs_to_utf8(&string[0], codepoint); + u32 bytesUsed = Dqn_UCSToUTF8(&string[0], codepoint); DQN_ASSERT(bytesUsed == 1); DQN_ASSERT(string[0] == '@'); - bytesUsed = dqn_utf8_to_ucs(&string[0], codepoint); + bytesUsed = Dqn_UTF8ToUCS(&string[0], codepoint); DQN_ASSERT(string[0] >= 0 && string[0] < 0x80); DQN_ASSERT(bytesUsed == 1); } @@ -267,11 +267,11 @@ void dqn_strings_test() u32 codepoint = 0x278; u32 string[1] = {}; - u32 bytesUsed = dqn_ucs_to_utf8(&string[0], codepoint); + u32 bytesUsed = Dqn_UCSToUTF8(&string[0], codepoint); DQN_ASSERT(bytesUsed == 2); DQN_ASSERT(string[0] == 0xC9B8); - bytesUsed = dqn_utf8_to_ucs(&string[0], string[0]); + bytesUsed = Dqn_UTF8ToUCS(&string[0], string[0]); DQN_ASSERT(string[0] == codepoint); DQN_ASSERT(bytesUsed == 2); } @@ -281,11 +281,11 @@ void dqn_strings_test() u32 codepoint = 0x0A0A; u32 string[1] = {}; - u32 bytesUsed = dqn_ucs_to_utf8(&string[0], codepoint); + u32 bytesUsed = Dqn_UCSToUTF8(&string[0], codepoint); DQN_ASSERT(bytesUsed == 3); DQN_ASSERT(string[0] == 0xE0A88A); - bytesUsed = dqn_utf8_to_ucs(&string[0], string[0]); + bytesUsed = Dqn_UTF8ToUCS(&string[0], string[0]); DQN_ASSERT(string[0] == codepoint); DQN_ASSERT(bytesUsed == 3); } @@ -294,315 +294,315 @@ void dqn_strings_test() { u32 codepoint = 0x10912; u32 string[1] = {}; - u32 bytesUsed = dqn_ucs_to_utf8(&string[0], codepoint); + u32 bytesUsed = Dqn_UCSToUTF8(&string[0], codepoint); DQN_ASSERT(bytesUsed == 4); DQN_ASSERT(string[0] == 0xF090A492); - bytesUsed = dqn_utf8_to_ucs(&string[0], string[0]); + bytesUsed = Dqn_UTF8ToUCS(&string[0], string[0]); DQN_ASSERT(string[0] == codepoint); DQN_ASSERT(bytesUsed == 4); } { u32 codepoint = 0x10912; - u32 bytesUsed = dqn_ucs_to_utf8(NULL, codepoint); + u32 bytesUsed = Dqn_UCSToUTF8(NULL, codepoint); DQN_ASSERT(bytesUsed == 0); - bytesUsed = dqn_utf8_to_ucs(NULL, codepoint); + bytesUsed = Dqn_UTF8ToUCS(NULL, codepoint); DQN_ASSERT(bytesUsed == 0); } - printf("dqn_strings_test(): ucs <-> utf8: Completed successfully\n"); + printf("StringsTest(): ucs <-> utf8: Completed successfully\n"); } - printf("dqn_strings_test(): Completed successfully\n"); + printf("StringsTest(): Completed successfully\n"); } #include "Windows.h" #define WIN32_LEAN_AND_MEAN -void dqn_other_test() +void OtherTest() { { // Test Win32 Sleep // NOTE: Win32 Sleep is not granular to a certain point so sleep excessively u32 sleepInMs = 1000; - f64 startInMs = dqn_time_now_in_ms(); + f64 startInMs = DqnTime_NowInMs(); Sleep(sleepInMs); - f64 endInMs = dqn_time_now_in_ms(); + f64 endInMs = DqnTime_NowInMs(); DQN_ASSERT(startInMs < endInMs); - printf("dqn_other_test(): time_now: Completed successfully\n"); + printf("OtherTest(): TimeNow: Completed successfully\n"); } - printf("dqn_other_test(): Completed successfully\n"); + printf("OtherTest(): Completed successfully\n"); } -void dqn_random_test() { +void RandomTest() { DqnRandPCGState pcg; - dqn_rnd_pcg_init(&pcg); + DqnRnd_PCGInit(&pcg); for (i32 i = 0; i < 10; i++) { i32 min = -100; i32 max = 100000; - i32 result = dqn_rnd_pcg_range(&pcg, min, max); + i32 result = DqnRnd_PCGRange(&pcg, min, max); DQN_ASSERT(result >= min && result <= max) - f32 randF32 = dqn_rnd_pcg_nextf(&pcg); + f32 randF32 = DqnRnd_PCGNextf(&pcg); DQN_ASSERT(randF32 >= 0.0f && randF32 <= 1.0f); - printf("dqn_random_test(): rnd_pcg: Completed successfully\n"); + printf("RandomTest(): RndPCG: Completed successfully\n"); } - printf("dqn_random_test(): Completed successfully\n"); + printf("RandomTest(): Completed successfully\n"); } -void dqn_math_test() +void MathTest() { { // Lerp { f32 start = 10; f32 t = 0.5f; f32 end = 20; - DQN_ASSERT(dqn_math_lerp(start, t, end) == 15); + DQN_ASSERT(DqnMath_Lerp(start, t, end) == 15); } { f32 start = 10; f32 t = 2.0f; f32 end = 20; - DQN_ASSERT(dqn_math_lerp(start, t, end) == 30); + DQN_ASSERT(DqnMath_Lerp(start, t, end) == 30); } - printf("dqn_math_test(): lerp: Completed successfully\n"); + printf("MathTest(): Lerp: Completed successfully\n"); } { // sqrtf - DQN_ASSERT(dqn_math_sqrtf(4.0f) == 2.0f); - printf("dqn_math_test(): sqrtf: Completed successfully\n"); + DQN_ASSERT(DqnMath_Sqrtf(4.0f) == 2.0f); + printf("MathTest(): Sqrtf: Completed successfully\n"); } - printf("dqn_math_test(): Completed successfully\n"); + printf("MathTest(): Completed successfully\n"); } -void dqn_vec_test() +void VecTest() { { // V2 // V2 Creating { - DqnV2 vec = dqn_v2(5.5f, 5.0f); + DqnV2 vec = DqnV2_2f(5.5f, 5.0f); DQN_ASSERT(vec.x == 5.5f && vec.y == 5.0f); DQN_ASSERT(vec.w == 5.5f && vec.h == 5.0f); } // V2i Creating { - DqnV2 vec = dqn_v2i(3, 5); + DqnV2 vec = DqnV2_2i(3, 5); DQN_ASSERT(vec.x == 3 && vec.y == 5.0f); DQN_ASSERT(vec.w == 3 && vec.h == 5.0f); } // V2 Arithmetic { - DqnV2 vecA = dqn_v2(5, 10); - DqnV2 vecB = dqn_v2i(2, 3); - DQN_ASSERT(dqn_v2_equals(vecA, vecB) == false); - DQN_ASSERT(dqn_v2_equals(vecA, dqn_v2(5, 10)) == true); - DQN_ASSERT(dqn_v2_equals(vecB, dqn_v2(2, 3)) == true); + DqnV2 vecA = DqnV2_2f(5, 10); + DqnV2 vecB = DqnV2_2i(2, 3); + DQN_ASSERT(DqnV2_Equals(vecA, vecB) == false); + DQN_ASSERT(DqnV2_Equals(vecA, DqnV2_2f(5, 10)) == true); + DQN_ASSERT(DqnV2_Equals(vecB, DqnV2_2f(2, 3)) == true); - DqnV2 result = dqn_v2_add(vecA, dqn_v2(5, 10)); - DQN_ASSERT(dqn_v2_equals(result, dqn_v2(10, 20)) == true); + DqnV2 result = DqnV2_Add(vecA, DqnV2_2f(5, 10)); + DQN_ASSERT(DqnV2_Equals(result, DqnV2_2f(10, 20)) == true); - result = dqn_v2_sub(result, dqn_v2(5, 10)); - DQN_ASSERT(dqn_v2_equals(result, dqn_v2(5, 10)) == true); + result = DqnV2_Sub(result, DqnV2_2f(5, 10)); + DQN_ASSERT(DqnV2_Equals(result, DqnV2_2f(5, 10)) == true); - result = dqn_v2_scale(result, 5); - DQN_ASSERT(dqn_v2_equals(result, dqn_v2(25, 50)) == true); + result = DqnV2_Scale(result, 5); + DQN_ASSERT(DqnV2_Equals(result, DqnV2_2f(25, 50)) == true); - result = dqn_v2_hadamard(result, dqn_v2(10, 0.5f)); - DQN_ASSERT(dqn_v2_equals(result, dqn_v2(250, 25)) == true); + result = DqnV2_Hadamard(result, DqnV2_2f(10, 0.5f)); + DQN_ASSERT(DqnV2_Equals(result, DqnV2_2f(250, 25)) == true); - f32 dotResult = dqn_v2_dot(dqn_v2(5, 10), dqn_v2(3, 4)); + f32 dotResult = DqnV2_Dot(DqnV2_2f(5, 10), DqnV2_2f(3, 4)); DQN_ASSERT(dotResult == 55); } // V2 Properties { - DqnV2 a = dqn_v2(0, 0); - DqnV2 b = dqn_v2(3, 4); + DqnV2 a = DqnV2_2f(0, 0); + DqnV2 b = DqnV2_2f(3, 4); - f32 lengthSq = dqn_v2_length_squared(a, b); + f32 lengthSq = DqnV2_LengthSquared(a, b); DQN_ASSERT(lengthSq == 25); - f32 length = dqn_v2_length(a, b); + f32 length = DqnV2_Length(a, b); DQN_ASSERT(length == 5); - DqnV2 normalised = dqn_v2_normalise(b); + DqnV2 normalised = DqnV2_Normalise(b); DQN_ASSERT(normalised.x == (b.x / 5.0f)); DQN_ASSERT(normalised.y == (b.y / 5.0f)); - DqnV2 c = dqn_v2(3.5f, 8.0f); - DQN_ASSERT(dqn_v2_overlaps(b, c) == true); - DQN_ASSERT(dqn_v2_overlaps(b, a) == false); + DqnV2 c = DqnV2_2f(3.5f, 8.0f); + DQN_ASSERT(DqnV2_Overlaps(b, c) == true); + DQN_ASSERT(DqnV2_Overlaps(b, a) == false); - DqnV2 d = dqn_v2_perpendicular(c); - DQN_ASSERT(dqn_v2_dot(c, d) == 0); + DqnV2 d = DqnV2_Perpendicular(c); + DQN_ASSERT(DqnV2_Dot(c, d) == 0); } { // constrain_to_ratio - DqnV2 ratio = dqn_v2(16, 9); - DqnV2 dim = dqn_v2(2000, 1080); - DqnV2 result = dqn_v2_constrain_to_ratio(dim, ratio); + DqnV2 ratio = DqnV2_2f(16, 9); + DqnV2 dim = DqnV2_2f(2000, 1080); + DqnV2 result = DqnV2_ConstrainToRatio(dim, ratio); DQN_ASSERT(result.w == 1920 && result.h == 1080); } - printf("dqn_vec_test(): vec2: Completed successfully\n"); + printf("VecTest(): Vec2: Completed successfully\n"); } { // V3 // V3i Creating { - DqnV3 vec = dqn_v3(5.5f, 5.0f, 5.875f); + DqnV3 vec = DqnV3_3f(5.5f, 5.0f, 5.875f); DQN_ASSERT(vec.x == 5.5f && vec.y == 5.0f && vec.z == 5.875f); DQN_ASSERT(vec.r == 5.5f && vec.g == 5.0f && vec.b == 5.875f); } // V3i Creating { - DqnV3 vec = dqn_v3i(3, 4, 5); + DqnV3 vec = DqnV3_3i(3, 4, 5); DQN_ASSERT(vec.x == 3 && vec.y == 4 && vec.z == 5); DQN_ASSERT(vec.r == 3 && vec.g == 4 && vec.b == 5); } // V3 Arithmetic { - DqnV3 vecA = dqn_v3(5, 10, 15); - DqnV3 vecB = dqn_v3(2, 3, 6); - DQN_ASSERT(dqn_v3_equals(vecA, vecB) == false); - DQN_ASSERT(dqn_v3_equals(vecA, dqn_v3(5, 10, 15)) == true); - DQN_ASSERT(dqn_v3_equals(vecB, dqn_v3(2, 3, 6)) == true); + DqnV3 vecA = DqnV3_3f(5, 10, 15); + DqnV3 vecB = DqnV3_3f(2, 3, 6); + DQN_ASSERT(DqnV3_Equals(vecA, vecB) == false); + DQN_ASSERT(DqnV3_Equals(vecA, DqnV3_3f(5, 10, 15)) == true); + DQN_ASSERT(DqnV3_Equals(vecB, DqnV3_3f(2, 3, 6)) == true); - DqnV3 result = dqn_v3_add(vecA, dqn_v3(5, 10, 15)); - DQN_ASSERT(dqn_v3_equals(result, dqn_v3(10, 20, 30)) == true); + DqnV3 result = DqnV3_Add(vecA, DqnV3_3f(5, 10, 15)); + DQN_ASSERT(DqnV3_Equals(result, DqnV3_3f(10, 20, 30)) == true); - result = dqn_v3_sub(result, dqn_v3(5, 10, 15)); - DQN_ASSERT(dqn_v3_equals(result, dqn_v3(5, 10, 15)) == true); + result = DqnV3_Sub(result, DqnV3_3f(5, 10, 15)); + DQN_ASSERT(DqnV3_Equals(result, DqnV3_3f(5, 10, 15)) == true); - result = dqn_v3_scale(result, 5); - DQN_ASSERT(dqn_v3_equals(result, dqn_v3(25, 50, 75)) == true); + result = DqnV3_Scale(result, 5); + DQN_ASSERT(DqnV3_Equals(result, DqnV3_3f(25, 50, 75)) == true); - result = dqn_v3_hadamard(result, dqn_v3(10.0f, 0.5f, 10.0f)); - DQN_ASSERT(dqn_v3_equals(result, dqn_v3(250, 25, 750)) == true); + result = DqnV3_Hadamard(result, DqnV3_3f(10.0f, 0.5f, 10.0f)); + DQN_ASSERT(DqnV3_Equals(result, DqnV3_3f(250, 25, 750)) == true); - f32 dotResult = dqn_v3_dot(dqn_v3(5, 10, 2), dqn_v3(3, 4, 6)); + f32 dotResult = DqnV3_Dot(DqnV3_3f(5, 10, 2), DqnV3_3f(3, 4, 6)); DQN_ASSERT(dotResult == 67); - DqnV3 cross = dqn_v3_cross(vecA, vecB); - DQN_ASSERT(dqn_v3_equals(cross, dqn_v3(15, 0, -5)) == true); + DqnV3 cross = DqnV3_Cross(vecA, vecB); + DQN_ASSERT(DqnV3_Equals(cross, DqnV3_3f(15, 0, -5)) == true); } - printf("dqn_vec_test(): vec3: Completed successfully\n"); + printf("VecTest(): Vec3: Completed successfully\n"); } { // V4 // V4 Creating { - DqnV4 vec = dqn_v4(5.5f, 5.0f, 5.875f, 5.928f); + DqnV4 vec = DqnV4_4f(5.5f, 5.0f, 5.875f, 5.928f); DQN_ASSERT(vec.x == 5.5f && vec.y == 5.0f && vec.z == 5.875f && vec.w == 5.928f); DQN_ASSERT(vec.r == 5.5f && vec.g == 5.0f && vec.b == 5.875f && vec.a == 5.928f); } // V4i Creating { - DqnV4 vec = dqn_v4i(3, 4, 5, 6); + DqnV4 vec = DqnV4_4i(3, 4, 5, 6); DQN_ASSERT(vec.x == 3 && vec.y == 4 && vec.z == 5 && vec.w == 6); DQN_ASSERT(vec.r == 3 && vec.g == 4 && vec.b == 5 && vec.a == 6); } // V4 Arithmetic { - DqnV4 vecA = dqn_v4(5, 10, 15, 20); - DqnV4 vecB = dqn_v4i(2, 3, 6, 8); - DQN_ASSERT(dqn_v4_equals(vecA, vecB) == false); - DQN_ASSERT(dqn_v4_equals(vecA, dqn_v4(5, 10, 15, 20)) == true); - DQN_ASSERT(dqn_v4_equals(vecB, dqn_v4(2, 3, 6, 8)) == true); + DqnV4 vecA = DqnV4_4f(5, 10, 15, 20); + DqnV4 vecB = DqnV4_4i(2, 3, 6, 8); + DQN_ASSERT(DqnV4_Equals(vecA, vecB) == false); + DQN_ASSERT(DqnV4_Equals(vecA, DqnV4_4f(5, 10, 15, 20)) == true); + DQN_ASSERT(DqnV4_Equals(vecB, DqnV4_4f(2, 3, 6, 8)) == true); - DqnV4 result = dqn_v4_add(vecA, dqn_v4(5, 10, 15, 20)); - DQN_ASSERT(dqn_v4_equals(result, dqn_v4(10, 20, 30, 40)) == true); + DqnV4 result = DqnV4_Add(vecA, DqnV4_4f(5, 10, 15, 20)); + DQN_ASSERT(DqnV4_Equals(result, DqnV4_4f(10, 20, 30, 40)) == true); - result = dqn_v4_sub(result, dqn_v4(5, 10, 15, 20)); - DQN_ASSERT(dqn_v4_equals(result, dqn_v4(5, 10, 15, 20)) == true); + result = DqnV4_Sub(result, DqnV4_4f(5, 10, 15, 20)); + DQN_ASSERT(DqnV4_Equals(result, DqnV4_4f(5, 10, 15, 20)) == true); - result = dqn_v4_scale(result, 5); - DQN_ASSERT(dqn_v4_equals(result, dqn_v4(25, 50, 75, 100)) == true); + result = DqnV4_Scale(result, 5); + DQN_ASSERT(DqnV4_Equals(result, DqnV4_4f(25, 50, 75, 100)) == true); - result = dqn_v4_hadamard(result, dqn_v4(10, 0.5f, 10, 0.25f)); - DQN_ASSERT(dqn_v4_equals(result, dqn_v4(250, 25, 750, 25)) == true); + result = DqnV4_Hadamard(result, DqnV4_4f(10, 0.5f, 10, 0.25f)); + DQN_ASSERT(DqnV4_Equals(result, DqnV4_4f(250, 25, 750, 25)) == true); - f32 dotResult = dqn_v4_dot(dqn_v4(5, 10, 2, 8), dqn_v4(3, 4, 6, 5)); + f32 dotResult = DqnV4_Dot(DqnV4_4f(5, 10, 2, 8), DqnV4_4f(3, 4, 6, 5)); DQN_ASSERT(dotResult == 107); } - printf("dqn_vec_test(): vec4: Completed successfully\n"); + printf("VecTest(): Vec4: Completed successfully\n"); } // Rect { - DqnRect rect = dqn_rect(dqn_v2(-10, -10), dqn_v2(20, 20)); - DQN_ASSERT(dqn_v2_equals(rect.min, dqn_v2(-10, -10))); - DQN_ASSERT(dqn_v2_equals(rect.max, dqn_v2(10, 10))); + DqnRect rect = DqnRect_Init(DqnV2_2f(-10, -10), DqnV2_2f(20, 20)); + DQN_ASSERT(DqnV2_Equals(rect.min, DqnV2_2f(-10, -10))); + DQN_ASSERT(DqnV2_Equals(rect.max, DqnV2_2f(10, 10))); f32 width, height; - dqn_rect_get_size_2f(rect, &width, &height); + DqnRect_GetSize2f(rect, &width, &height); DQN_ASSERT(width == 20); DQN_ASSERT(height == 20); - DqnV2 dim = dqn_rect_get_size_v2(rect); - DQN_ASSERT(dqn_v2_equals(dim, dqn_v2(20, 20))); + DqnV2 dim = DqnRect_GetSizeV2(rect); + DQN_ASSERT(DqnV2_Equals(dim, DqnV2_2f(20, 20))); - DqnV2 rectCenter = dqn_rect_get_centre(rect); - DQN_ASSERT(dqn_v2_equals(rectCenter, dqn_v2(0, 0))); + DqnV2 rectCenter = DqnRect_GetCentre(rect); + DQN_ASSERT(DqnV2_Equals(rectCenter, DqnV2_2f(0, 0))); // Test shifting rect - DqnRect shiftedRect = dqn_rect_move(rect, dqn_v2(10, 0)); - DQN_ASSERT(dqn_v2_equals(shiftedRect.min, dqn_v2(0, -10))); - DQN_ASSERT(dqn_v2_equals(shiftedRect.max, dqn_v2(20, 10))); + DqnRect shiftedRect = DqnRect_Move(rect, DqnV2_2f(10, 0)); + DQN_ASSERT(DqnV2_Equals(shiftedRect.min, DqnV2_2f(0, -10))); + DQN_ASSERT(DqnV2_Equals(shiftedRect.max, DqnV2_2f(20, 10))); - dqn_rect_get_size_2f(shiftedRect, &width, &height); + DqnRect_GetSize2f(shiftedRect, &width, &height); DQN_ASSERT(width == 20); DQN_ASSERT(height == 20); - dim = dqn_rect_get_size_v2(shiftedRect); - DQN_ASSERT(dqn_v2_equals(dim, dqn_v2(20, 20))); + dim = DqnRect_GetSizeV2(shiftedRect); + DQN_ASSERT(DqnV2_Equals(dim, DqnV2_2f(20, 20))); // Test rect contains p - DqnV2 inP = dqn_v2(5, 5); - DqnV2 outP = dqn_v2(100, 100); - DQN_ASSERT(dqn_rect_contains_p(shiftedRect, inP)); - DQN_ASSERT(!dqn_rect_contains_p(shiftedRect, outP)); + DqnV2 inP = DqnV2_2f(5, 5); + DqnV2 outP = DqnV2_2f(100, 100); + DQN_ASSERT(DqnRect_ContainsP(shiftedRect, inP)); + DQN_ASSERT(!DqnRect_ContainsP(shiftedRect, outP)); - printf("dqn_vec_test(): rect: Completed successfully\n"); + printf("VecTest(): Rect: Completed successfully\n"); } - printf("dqn_vec_test(): Completed successfully\n"); + printf("VecTest(): Completed successfully\n"); } -void dqn_array_test() +void ArrayTest() { { DqnArray array = {}; - DQN_ASSERT(dqn_array_init(&array, 1)); + DQN_ASSERT(DqnArray_Init(&array, 1)); DQN_ASSERT(array.capacity == 1); DQN_ASSERT(array.count == 0); // Test basic insert { - DqnV2 va = dqn_v2(5, 10); - DQN_ASSERT(dqn_array_push(&array, va)); + DqnV2 va = DqnV2_2f(5, 10); + DQN_ASSERT(DqnArray_Push(&array, va)); DqnV2 vb = array.data[0]; - DQN_ASSERT(dqn_v2_equals(va, vb)); + DQN_ASSERT(DqnV2_Equals(va, vb)); DQN_ASSERT(array.capacity == 1); DQN_ASSERT(array.count == 1); @@ -610,215 +610,215 @@ void dqn_array_test() // Test array resizing and freeing { - DqnV2 va = dqn_v2(10, 15); - DQN_ASSERT(dqn_array_push(&array, va)); + DqnV2 va = DqnV2_2f(10, 15); + DQN_ASSERT(DqnArray_Push(&array, va)); DqnV2 vb = array.data[0]; - DQN_ASSERT(dqn_v2_equals(va, vb) == false); + DQN_ASSERT(DqnV2_Equals(va, vb) == false); vb = array.data[1]; - DQN_ASSERT(dqn_v2_equals(va, vb) == true); + DQN_ASSERT(DqnV2_Equals(va, vb) == true); DQN_ASSERT(array.capacity == 2); DQN_ASSERT(array.count == 2); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 3); DQN_ASSERT(array.count == 3); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 4); DQN_ASSERT(array.count == 4); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 5); DQN_ASSERT(array.count == 5); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 6); DQN_ASSERT(array.count == 6); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 7); DQN_ASSERT(array.count == 7); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 8); DQN_ASSERT(array.count == 8); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 9); DQN_ASSERT(array.count == 9); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 10); DQN_ASSERT(array.count == 10); - DQN_ASSERT(dqn_array_push(&array, va)); + DQN_ASSERT(DqnArray_Push(&array, va)); DQN_ASSERT(array.capacity == 12); DQN_ASSERT(array.count == 11); - DqnV2 vc = dqn_v2(90, 100); - DQN_ASSERT(dqn_array_push(&array, vc)); + DqnV2 vc = DqnV2_2f(90, 100); + DQN_ASSERT(DqnArray_Push(&array, vc)); DQN_ASSERT(array.capacity == 12); DQN_ASSERT(array.count == 12); - DQN_ASSERT(dqn_v2_equals(vc, array.data[11])); + DQN_ASSERT(DqnV2_Equals(vc, array.data[11])); - DQN_ASSERT(dqn_array_free(&array) == true); + DQN_ASSERT(DqnArray_Free(&array) == true); } } { DqnArray array = {}; - DQN_ASSERT(dqn_array_init(&array, 1)); + DQN_ASSERT(DqnArray_Init(&array, 1)); DQN_ASSERT(array.capacity == 1); DQN_ASSERT(array.count == 0); - dqn_array_free(&array); + DqnArray_Free(&array); } { - DqnV2 a = dqn_v2(1, 2); - DqnV2 b = dqn_v2(3, 4); - DqnV2 c = dqn_v2(5, 6); - DqnV2 d = dqn_v2(7, 8); + DqnV2 a = DqnV2_2f(1, 2); + DqnV2 b = DqnV2_2f(3, 4); + DqnV2 c = DqnV2_2f(5, 6); + DqnV2 d = DqnV2_2f(7, 8); DqnArray array = {}; - DQN_ASSERT(dqn_array_init(&array, 16)); - DQN_ASSERT(dqn_array_remove(&array, 0) == false); + DQN_ASSERT(DqnArray_Init(&array, 16)); + DQN_ASSERT(DqnArray_Remove(&array, 0) == false); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 0); - DQN_ASSERT(dqn_array_clear(&array)); + DQN_ASSERT(DqnArray_Clear(&array)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 0); - DQN_ASSERT(dqn_array_push(&array, a)); - DQN_ASSERT(dqn_array_push(&array, b)); - DQN_ASSERT(dqn_array_push(&array, c)); - DQN_ASSERT(dqn_array_push(&array, d)); + DQN_ASSERT(DqnArray_Push(&array, a)); + DQN_ASSERT(DqnArray_Push(&array, b)); + DQN_ASSERT(DqnArray_Push(&array, c)); + DQN_ASSERT(DqnArray_Push(&array, d)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 4); - DQN_ASSERT(dqn_array_remove(&array, 0)); - DQN_ASSERT(dqn_v2_equals(array.data[0], d)); - DQN_ASSERT(dqn_v2_equals(array.data[1], b)); - DQN_ASSERT(dqn_v2_equals(array.data[2], c)); + DQN_ASSERT(DqnArray_Remove(&array, 0)); + DQN_ASSERT(DqnV2_Equals(array.data[0], d)); + DQN_ASSERT(DqnV2_Equals(array.data[1], b)); + DQN_ASSERT(DqnV2_Equals(array.data[2], c)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 3); - DQN_ASSERT(dqn_array_remove(&array, 2)); - DQN_ASSERT(dqn_v2_equals(array.data[0], d)); - DQN_ASSERT(dqn_v2_equals(array.data[1], b)); + DQN_ASSERT(DqnArray_Remove(&array, 2)); + DQN_ASSERT(DqnV2_Equals(array.data[0], d)); + DQN_ASSERT(DqnV2_Equals(array.data[1], b)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 2); - DQN_ASSERT(dqn_array_remove(&array, 100) == false); - DQN_ASSERT(dqn_v2_equals(array.data[0], d)); - DQN_ASSERT(dqn_v2_equals(array.data[1], b)); + DQN_ASSERT(DqnArray_Remove(&array, 100) == false); + DQN_ASSERT(DqnV2_Equals(array.data[0], d)); + DQN_ASSERT(DqnV2_Equals(array.data[1], b)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 2); - DQN_ASSERT(dqn_array_clear(&array)); + DQN_ASSERT(DqnArray_Clear(&array)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 0); - dqn_array_free(&array); + DqnArray_Free(&array); } { - DqnV2 a = dqn_v2(1, 2); - DqnV2 b = dqn_v2(3, 4); - DqnV2 c = dqn_v2(5, 6); - DqnV2 d = dqn_v2(7, 8); + DqnV2 a = DqnV2_2f(1, 2); + DqnV2 b = DqnV2_2f(3, 4); + DqnV2 c = DqnV2_2f(5, 6); + DqnV2 d = DqnV2_2f(7, 8); DqnArray array = {}; - DQN_ASSERT(dqn_array_init(&array, 16)); + DQN_ASSERT(DqnArray_Init(&array, 16)); - DQN_ASSERT(dqn_array_push(&array, a)); - DQN_ASSERT(dqn_array_push(&array, b)); - DQN_ASSERT(dqn_array_push(&array, c)); - DQN_ASSERT(dqn_array_push(&array, d)); + DQN_ASSERT(DqnArray_Push(&array, a)); + DQN_ASSERT(DqnArray_Push(&array, b)); + DQN_ASSERT(DqnArray_Push(&array, c)); + DQN_ASSERT(DqnArray_Push(&array, d)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 4); - dqn_array_remove_stable(&array, 0); - DQN_ASSERT(dqn_v2_equals(array.data[0], b)); - DQN_ASSERT(dqn_v2_equals(array.data[1], c)); - DQN_ASSERT(dqn_v2_equals(array.data[2], d)); + DqnArray_RemoveStable(&array, 0); + DQN_ASSERT(DqnV2_Equals(array.data[0], b)); + DQN_ASSERT(DqnV2_Equals(array.data[1], c)); + DQN_ASSERT(DqnV2_Equals(array.data[2], d)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 3); - dqn_array_remove_stable(&array, 1); - DQN_ASSERT(dqn_v2_equals(array.data[0], b)); - DQN_ASSERT(dqn_v2_equals(array.data[1], d)); + DqnArray_RemoveStable(&array, 1); + DQN_ASSERT(DqnV2_Equals(array.data[0], b)); + DQN_ASSERT(DqnV2_Equals(array.data[1], d)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 2); - dqn_array_remove_stable(&array, 1); - DQN_ASSERT(dqn_v2_equals(array.data[0], b)); + DqnArray_RemoveStable(&array, 1); + DQN_ASSERT(DqnV2_Equals(array.data[0], b)); DQN_ASSERT(array.capacity == 16); DQN_ASSERT(array.count == 1); - dqn_array_free(&array); + DqnArray_Free(&array); } - printf("dqn_array_test(): Completed successfully\n"); + printf("ArrayTest(): Completed successfully\n"); } -void dqn_file_test() +void FileTest() { // File i/o { { DqnFile file = {}; - DQN_ASSERT(dqn_file_open( + DQN_ASSERT(DqnFile_Open( ".clang-format", &file, (dqnfilepermissionflag_write | dqnfilepermissionflag_read), dqnfileaction_open_only)); DQN_ASSERT(file.size == 1320); u8 *buffer = (u8 *)calloc(1, (size_t)file.size * sizeof(u8)); - DQN_ASSERT(dqn_file_read(file, buffer, (u32)file.size) == file.size); + DQN_ASSERT(DqnFile_Read(file, buffer, (u32)file.size) == file.size); free(buffer); - dqn_file_close(&file); + DqnFile_Close(&file); DQN_ASSERT(!file.handle && file.size == 0 && file.permissionFlags == 0); } { DqnFile file = {}; - DQN_ASSERT(!dqn_file_open( + DQN_ASSERT(!DqnFile_Open( "asdljasdnel;kajdf", &file, (dqnfilepermissionflag_write | dqnfilepermissionflag_read), dqnfileaction_open_only)); DQN_ASSERT(file.size == 0); DQN_ASSERT(file.permissionFlags == 0); DQN_ASSERT(!file.handle); - printf("dqn_file_test(): file_io: Completed successfully\n"); + printf("FileTest(): FileIO: Completed successfully\n"); } } { u32 numFiles; - char **filelist = dqn_dir_read("*", &numFiles); - printf("dqn_file_test(): dir_read: Display read files\n"); + char **filelist = DqnDir_Read("*", &numFiles); + printf("FileTest(): DirRead: Display read files\n"); for (u32 i = 0; i < numFiles; i++) - printf("dqn_file_test(): dir_read: %s\n", filelist[i]); + printf("FileTest(): DirRead: %s\n", filelist[i]); - dqn_dir_read_free(filelist, numFiles); - printf("dqn_file_test(): dir_read: Completed successfully\n"); + DqnDir_ReadFree(filelist, numFiles); + printf("FileTest(): DirRead: Completed successfully\n"); } - printf("dqn_file_test(): Completed successfully\n"); + printf("FileTest(): Completed successfully\n"); } -void dqn_push_buffer_test() +void PushBufferTest() { size_t allocSize = DQN_KILOBYTE(1); DqnPushBuffer buffer = {}; const u32 ALIGNMENT = 4; - dqn_push_buffer_init(&buffer, allocSize, ALIGNMENT); + DqnPushBuffer_Init(&buffer, allocSize, ALIGNMENT); DQN_ASSERT(buffer.block && buffer.block->memory); DQN_ASSERT(buffer.block->size == allocSize); DQN_ASSERT(buffer.block->used == 0); @@ -826,7 +826,7 @@ void dqn_push_buffer_test() // Alocate A size_t sizeA = (size_t)(allocSize * 0.5f); - void *resultA = dqn_push_buffer_allocate(&buffer, sizeA); + void *resultA = DqnPushBuffer_Allocate(&buffer, sizeA); u64 resultAddrA = *((u64 *)resultA); DQN_ASSERT(resultAddrA % ALIGNMENT == 0); DQN_ASSERT(buffer.block && buffer.block->memory); @@ -842,7 +842,7 @@ void dqn_push_buffer_test() DqnPushBufferBlock *blockA = buffer.block; // Alocate B size_t sizeB = (size_t)(allocSize * 2.0f); - void *resultB = dqn_push_buffer_allocate(&buffer, sizeB); + void *resultB = DqnPushBuffer_Allocate(&buffer, sizeB); u64 resultAddrB = *((u64 *)resultB); DQN_ASSERT(resultAddrB % ALIGNMENT == 0); DQN_ASSERT(buffer.block && buffer.block->memory); @@ -866,9 +866,9 @@ void dqn_push_buffer_test() DqnPushBufferBlock *blockB = buffer.block; // Check temp regions work - DqnTempBuffer tempBuffer = dqn_push_buffer_begin_temp_region(&buffer); + DqnTempBuffer tempBuffer = DqnPushBuffer_BeginTempRegion(&buffer); size_t sizeC = 1024 + 1; - void *resultC = dqn_push_buffer_allocate(tempBuffer.buffer, sizeC); + void *resultC = DqnPushBuffer_Allocate(tempBuffer.buffer, sizeC); u64 resultAddrC = *((u64 *)resultC); DQN_ASSERT(resultAddrC % ALIGNMENT == 0); DQN_ASSERT(buffer.block != blockB && buffer.block != blockA); @@ -896,7 +896,7 @@ void dqn_push_buffer_test() DQN_ASSERT(ptrC[i] == 3); // End temp region which should revert back to 2 linked buffers, A and B - dqn_push_buffer_end_temp_region(tempBuffer); + DqnPushBuffer_EndTempRegion(tempBuffer); DQN_ASSERT(buffer.block && buffer.block->memory); DQN_ASSERT(buffer.block->size == sizeB); DQN_ASSERT(buffer.block->used >= sizeB + 0 && @@ -910,7 +910,7 @@ void dqn_push_buffer_test() DQN_ASSERT(buffer.alignment == ALIGNMENT); // Release the last linked buffer from the push buffer - dqn_push_buffer_free_last_buffer(&buffer); + DqnPushBuffer_FreeLastBuffer(&buffer); // Which should return back to the 1st allocation DQN_ASSERT(buffer.block == blockA); @@ -920,7 +920,7 @@ void dqn_push_buffer_test() DQN_ASSERT(buffer.alignment == ALIGNMENT); // Free once more to release buffer A memory - dqn_push_buffer_free_last_buffer(&buffer); + DqnPushBuffer_FreeLastBuffer(&buffer); DQN_ASSERT(!buffer.block); DQN_ASSERT(buffer.alignment == ALIGNMENT); DQN_ASSERT(buffer.tempBufferCount == 0); @@ -928,14 +928,14 @@ void dqn_push_buffer_test() int main(void) { - dqn_strings_test(); - dqn_random_test(); - dqn_math_test(); - dqn_vec_test(); - dqn_other_test(); - dqn_array_test(); - dqn_file_test(); - dqn_push_buffer_test(); + StringsTest(); + RandomTest(); + MathTest(); + VecTest(); + OtherTest(); + ArrayTest(); + FileTest(); + PushBufferTest(); printf("\nPress 'Enter' Key to Exit\n"); getchar();