Begin refactor.
This commit is contained in:
@ -6,7 +6,16 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Definition of a callback that is used to sort an array.
|
||||
*
|
||||
* @param left The left element in the array.
|
||||
* @param right The right element in the array.
|
||||
* @return -1 for Left priority, 1 for Right and 0 for Equal.
|
||||
*/
|
||||
typedef int32_t arraysort_t(const void*, const void*);
|
||||
|
||||
/**
|
||||
* Retreive the pointer to an elment within the array of unknown type.
|
||||
|
@ -6,9 +6,24 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
#include "array.h"
|
||||
|
||||
/** Custom Array Definition */
|
||||
typedef struct {
|
||||
/** The data storage */
|
||||
void *data;
|
||||
|
||||
/** Size of each element within the array */
|
||||
size_t size;
|
||||
|
||||
/** The count of elements currently in the array */
|
||||
int32_t length;
|
||||
|
||||
/** Total count of elements the array can hold */
|
||||
int32_t total;
|
||||
} dynarray_t;
|
||||
|
||||
/**
|
||||
* Create a dynamic array. Dynamic arrays are a more highlevel array style that
|
||||
* can offer great flexibility and ease-of-use, at the cost of memory, memory
|
||||
|
26
src/util/flags.h
Normal file
26
src/util/flags.h
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Create a flag definition.
|
||||
*
|
||||
* @param n The flag number.
|
||||
* @return The bitwise flag for that number.
|
||||
*/
|
||||
#define flagDefine(n) (1 << n)
|
||||
|
||||
/**
|
||||
* Turns a flag off in a state.
|
||||
*
|
||||
* @param state State to update.
|
||||
* @param flag Flag to turn off.
|
||||
* @return The updated state.
|
||||
*/
|
||||
#define flagOff(state, flag) (state & ~flag)
|
@ -4,7 +4,31 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Entry within a given linked list.
|
||||
* @param data* The pointer to the data that is within the entry.
|
||||
* @param prev* Pointer to the previous entry in the list.
|
||||
* @param next* Pointer to the next entry in the list.
|
||||
*/
|
||||
typedef struct listentry_t {
|
||||
void *data;
|
||||
struct listentry_t *prev;
|
||||
struct listentry_t *next;
|
||||
} listentry_t;
|
||||
|
||||
/**
|
||||
* Linked List of elements, Doubly Linked.
|
||||
* @param size The count of elements currently within the list
|
||||
* @param start* First element within the list.
|
||||
* @param end* Last element within the list.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t size;
|
||||
listentry_t *start;
|
||||
listentry_t *end;
|
||||
} list_t;
|
||||
|
||||
/**
|
||||
* Creates a new linked list
|
||||
|
76
src/util/math.h
Normal file
76
src/util/math.h
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MATH_PI ((float)M_PI)
|
||||
|
||||
/**
|
||||
* Returns the modulous a result for b. Consdiders negative numbers correctly.
|
||||
* @param a Number to modulo against. (a % b)
|
||||
* @param b Number to modulo with. (a % b)
|
||||
* @returns The modulo result.
|
||||
*/
|
||||
#define mathMod(a,b) ((a)%(b)+(b))%(b)
|
||||
|
||||
/**
|
||||
* Returns the modulous a result for b. Works for floating point numbers.
|
||||
* @param a Number to modulo against. (a % b)
|
||||
* @param b Number to modulo with. (a % b)
|
||||
* @returns The modulo result.
|
||||
*/
|
||||
#define mathModFloat(a, b) (float)fmod(a, b)
|
||||
|
||||
/**
|
||||
* Returns the maximum of two numbers.
|
||||
* @param a Number A.
|
||||
* @param b Number B.
|
||||
* @returns B if greater than A, otherwise B.
|
||||
*/
|
||||
#define mathMax(a,b) (a<b?b:a)
|
||||
|
||||
/**
|
||||
* Returns the minimum of two numbers.
|
||||
* @param a Number A.
|
||||
* @param b Number B.
|
||||
* @returns B if smaller than A, otherwise A.
|
||||
*/
|
||||
#define mathMin(a,b) (a>b?b:a)
|
||||
|
||||
/**
|
||||
* Clamp a number between two numbers.
|
||||
* @param val Value to clamp.
|
||||
* @param min The minimum number to clamp to.
|
||||
* @param max The maximum number to clamp to.
|
||||
*/
|
||||
#define mathClamp(val,min,max) mathMin(mathMax(val,min),max)
|
||||
|
||||
/**
|
||||
* Returns the absolute value. This will make -n equal n and y equal y.
|
||||
* @param n Number to abs.
|
||||
* @returns The absolute number.
|
||||
*/
|
||||
#define mathAbs(n) (n<0?-n:n)
|
||||
|
||||
/**
|
||||
* Convert degrees to radians.
|
||||
* @param n Degrees to convert.
|
||||
* @returns The number in radians.
|
||||
*/
|
||||
#define mathDeg2Rad(n) (n * MATH_PI / 180.0f)
|
||||
|
||||
/**
|
||||
* Convert radians to degrees.
|
||||
* @param n Radians to convert.
|
||||
* @returns The number in degrees.
|
||||
*/
|
||||
#define mathRad2Deg(n) (n * 180.0f / MATH_PI)
|
||||
|
||||
/**
|
||||
* Sign the given number, essentially clamps > 0 to 1, and < 0 to -1.
|
||||
* @param n Number to sign.
|
||||
* @returns The signed number.
|
||||
*/
|
||||
#define mathSign(n) (n>=0 ? 1.0f : -1.0f)
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Resizes a buffer to hold new amounts of data. Essentially a 3 step process of
|
||||
|
50
src/util/rand.h
Normal file
50
src/util/rand.h
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "math.h"
|
||||
|
||||
/**
|
||||
* Generates a random int32_t.
|
||||
* @returns A random int32_t number.
|
||||
*/
|
||||
#define randInt32() ((int32_t)rand())
|
||||
|
||||
/**
|
||||
* Generates a random floating point number.
|
||||
* @returns A random floating point number.
|
||||
*/
|
||||
#define randFloat() (((float)randInt32()) * MATH_PI)
|
||||
|
||||
/**
|
||||
* Generates a random uint32_t
|
||||
* @returns A random uint32_t number.
|
||||
*/
|
||||
#define randUint32() (uint32_t)randInt32()
|
||||
|
||||
/**
|
||||
* Generates a random uint8_t
|
||||
* @returns A random uint8_t number.
|
||||
*/
|
||||
#define randUint8() (uint8_t)randInt32()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Clamps a random number generation.
|
||||
* @param n Number that has been generated from the random.
|
||||
* @param min Minimum value to generate from. (Inclusive)
|
||||
* @param max Maximum value to generate to. (Exclusive)
|
||||
* @return Random number between min and max.
|
||||
*/
|
||||
#define randRange(n, min, max) (mathMod(n, (max-min)) + min)
|
||||
|
||||
#define randInt32Range(min, max) randRange(randInt32(), min, max)
|
||||
#define randFloatRange(min, max) (fmod(randFloat(), max- min) + min)
|
||||
#define randUint32Range(min, max) randRange(randUint32(), min, max)
|
||||
#define randUint8Range(min, max) randRange(randUint8(), min, max)
|
@ -4,9 +4,33 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
#include "array.h"
|
||||
|
||||
#define STRING_HANDLEBAR_KEY_MAXLENGTH 32
|
||||
|
||||
#define STRING_STACK_STRING_SIZE 256
|
||||
#define STRING_STACK_STRING_COUNT 128
|
||||
#define STRING_STACK_BUFFER STRING_STACK_STRING_SIZE * STRING_STACK_STRING_COUNT
|
||||
|
||||
/** Representation of a String Handlebar Variable */
|
||||
typedef struct {
|
||||
/** The key to use to replace in the source */
|
||||
char *key;
|
||||
/** The value to replace it with */
|
||||
char *value;
|
||||
} stringhandlebarvariable_t;
|
||||
|
||||
/** Definition of a string stack to push and pop strings from. */
|
||||
typedef struct {
|
||||
/** Raw char buffer, for holding strings */
|
||||
char buffer[STRING_STACK_BUFFER];
|
||||
/** Strings themselves */
|
||||
char *strings[STRING_STACK_STRING_COUNT];
|
||||
/** How many strings are on the stack */
|
||||
int32_t size;
|
||||
} stringstack_t;
|
||||
|
||||
/**
|
||||
* Replaces handlebars within the string with items from the list of variables.
|
||||
* Output of replacement is stored in the buffer provided. Handlebars within the
|
||||
|
Reference in New Issue
Block a user