Render test

This commit is contained in:
2025-06-10 17:09:33 -05:00
parent a2fd58fda7
commit 1b6db0c643
47 changed files with 219 additions and 370 deletions

View File

@@ -1,12 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
memory.c
string.c
random.c
)

View File

@@ -1,60 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "memory.h"
#include "assert/assert.h"
void memoryCopy(void *dest, const void *src, const size_t size) {
assertNotNull(dest, "Cannot copy to NULL memory.");
assertNotNull(src, "Cannot copy from NULL memory.");
assertTrue(size > 0, "Cannot copy 0 bytes of memory.");
assertTrue(dest != src, "Cannot copy memory to itself.");
memcpy(dest, src, size);
}
void memorySet(void *dest, const uint8_t value, const size_t size) {
assertNotNull(dest, "Cannot set NULL memory.");
assertTrue(size > 0, "Cannot set 0 bytes of memory.");
memset(dest, value, size);
}
void memoryZero(void *dest, const size_t size) {
memorySet(dest, 0, size);
}
void memoryCopyRangeSafe(
void *dest,
const void *start,
const void *end,
const size_t sizeMax
) {
assertFalse(start == end, "Start and end pointers are the same.");
assertTrue(end > start, "End pointer is not after start pointer.");
size_t copy = (size_t)end - (size_t)start;
assertTrue(copy <= sizeMax, "Size of memory to copy is too large.");
memoryCopy(dest, start, copy);
}
void memoryMove(void *dest, const void *src, const size_t size) {
assertNotNull(dest, "Cannot move to NULL memory.");
assertNotNull(src, "Cannot move from NULL memory.");
assertTrue(size > 0, "Cannot move 0 bytes of memory.");
assertTrue(dest != src, "Cannot move memory to itself.");
memmove(dest, src, size);
}
ssize_t memoryCompare(
const void *a,
const void *b,
const size_t size
) {
assertNotNull(a, "Cannot compare NULL memory.");
assertNotNull(b, "Cannot compare NULL memory.");
assertTrue(size > 0, "Cannot compare 0 bytes of memory.");
return memcmp(a, b, size);
}

View File

@@ -1,90 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
/**
* Allocates memory.
*
* @param size The size of the memory to allocate.
* @return The allocated memory.
*/
void * memoryAllocate(const size_t size);
/**
* Frees memory.
*
* @param ptr The memory to free.
*/
void memoryFree(void *ptr);
/**
* Copies memory.
*
* @param dest The destination to copy to.
* @param src The source to copy from.
* @param size The size of the memory to copy.
*/
void memoryCopy(void *dest, const void *src, const size_t size);
/**
* Sets memory.
*
* @param dest The destination to set.
* @param value The value to set.
* @param size The size of the memory to set.
*/
void memorySet(void *dest, const uint8_t value, const size_t size);
/**
* Zeroes memory.
*
* @param dest The destination to zero.
* @param size The size of the memory to zero.
*/
void memoryZero(void *dest, const size_t size);
/**
* Copies memory, ensuring that the memory range is as expected, typically this
* is done if you're trying to reshape data in a buffer. Extremely useful in
* copying data to a shader buffer.
*
* @param dest The destination to copy to.
* @param start The start of the source to copy from.
* @param end The end of the source to copy from.
* @param sizeMax The maximum size of the memory to copy.
*/
void memoryCopyRangeSafe(
void *dest,
const void *start,
const void *end,
const size_t sizeMax
);
/**
* Moves memory.
*
* @param dest The destination to move to.
* @param src The source to move from.
* @param size The size of the memory to move.
*/
void memoryMove(void *dest, const void *src, const size_t size);
/**
* Compares memory.
*
* @param a The first memory to compare.
* @param b The second memory to compare.
* @param size The size of the memory to compare.
* @return 0 if the memory is equal, < 0 if a < b, > 0 if a > b.
*/
ssize_t memoryCompare(
const void *a,
const void *b,
const size_t size
);

View File

@@ -1,12 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "random.h"
#include "assert/assert.h"
void randomInit() {
}

View File

@@ -1,18 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
/**
* Initializes the random number generator with a random seed.
*
* This function should be called once at the start of the program to
* initialize the random number generator with a random seed. It uses
* the current time to generate a seed.
*/
void randomInit();

View File

@@ -1,127 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "string.h"
#include "assert/assert.h"
#include "util/memory.h"
bool_t stringIsWhitespace(const char_t c) {
return isspace(c);
}
void stringCopy(char_t *dest, const char_t *src, const size_t destSize) {
assertNotNull(dest, "dest must not be NULL");
assertNotNull(src, "src must not be NULL");
assertTrue(destSize > 0, "destSize must be greater than 0");
assertStrLenMax(src, destSize, "src is too long");
memoryCopy(dest, src, strlen(src) + 1);
}
int stringCompare(const char_t *str1, const char_t *str2) {
assertNotNull(str1, "str1 must not be NULL");
assertNotNull(str2, "str2 must not be NULL");
return strcmp(str1, str2);
}
void stringTrim(char_t *str) {
assertNotNull(str, "str must not be NULL");
// Trim leading whitespace
char_t *start = str;
while(stringIsWhitespace(*start)) start++;
// Trim trailing whitespace
char_t *end = start + strlen(start) - 1;
while (end >= start && stringIsWhitespace(*end)) end--;
// Null-terminate the string
*(end + 1) = '\0';
// Move trimmed string to the original buffer
if (start != str) memmove(str, start, end - start + 2);
}
char_t * stringToken(char_t *str, const char_t *delim) {
assertNotNull(str, "str must not be NULL");
assertNotNull(delim, "delim must not be NULL");
return strtok(str, delim);
}
int32_t stringFormat(
char_t *dest,
const size_t destSize,
char_t *format,
...
) {
assertNotNull(dest, "dest must not be NULL");
assertNotNull(format, "format must not be NULL");
assertTrue(destSize > 0, "destSize must be greater than 0");
va_list args;
va_start(args, format);
int32_t result = stringFormatVA(dest, destSize, format, args);
va_end(args);
return result;
}
int32_t stringFormatVA(
char_t *dest,
const size_t destSize,
const char_t *format,
va_list args
) {
assertNotNull(dest, "dest must not be NULL");
assertNotNull(format, "format must not be NULL");
assertTrue(destSize > 0, "destSize must be greater than 0");
int32_t ret = vsnprintf(dest, destSize, format, args);
assertTrue(ret >= 0, "Failed to format string.");
assertTrue(ret < destSize, "Formatted string is too long.");
return ret;
}
bool_t stringToI32(const char_t *str, int32_t *out) {
assertNotNull(str, "str must not be NULL");
assertNotNull(out, "out must not be NULL");
char_t *endptr;
errno = 0;
long int result = strtol(str, &endptr, 10);
if (errno != 0 || *endptr != '\0') {
return false;
}
*out = (int32_t)result;
return true;
}
bool_t stringToI64(const char_t *str, int64_t *out) {
assertNotNull(str, "str must not be NULL");
assertNotNull(out, "out must not be NULL");
char_t *endptr;
errno = 0;
long long int result = strtoll(str, &endptr, 10);
if (errno != 0 || *endptr != '\0') {
return false;
}
*out = (int64_t)result;
return true;
}
bool_t stringToU16(const char_t *str, uint16_t *out) {
assertNotNull(str, "str must not be NULL");
assertNotNull(out, "out must not be NULL");
char_t *endptr;
errno = 0;
unsigned long int result = strtoul(str, &endptr, 10);
if (errno != 0 || *endptr != '\0' || result > UINT16_MAX) {
return false;
}
*out = (uint16_t)result;
return true;
}

View File

@@ -1,109 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
/**
* Determines if a character is whitespace.
*
* @param c The character to check.
* @return TRUE if the character is whitespace, FALSE otherwise.
*/
bool_t stringIsWhitespace(const char_t c);
/**
* Copies a string from src to dest, ensuring the dest string is null-terminated
* and does not exceed the specified size.
*
* @param dest The destination string.
* @param src The source string.
* @param destSize The size of the destination string exc. null terminator.
*/
void stringCopy(char_t *dest, const char_t *src, const size_t destSize);
/**
* Compares two strings.
*
* @param str1 The first string.
* @param str2 The second string.
* @return 0 if the strings are equal, -1 if str1 is less than str2, 1 if str1
* is greater than str2.
*/
int stringCompare(const char_t *str1, const char_t *str2);
/**
* Trims whitespace from the beginning and end of a string.
*
* @param str The string to trim.
*/
void stringTrim(char_t *str);
/**
* Gets the next token in a string using a delimiter.
* e.g. input: "Hello, World, Happy Monday!" with stringToken(input, ",") will
* return "Hello" then " World" then " Happy Monday!" on each subsequent call.
*
* @param str The string to split.
* @param delim The delimiter to split by.
* @return A pointer to the next token in the string.
*/
char_t * stringToken(char_t *str, const char_t *delim);
/**
* Formats a string.
*
* @param dest The destination string.
* @param destSize The size of the destination string exc. null terminator.
* @param format The format string.
* @param ... The arguments to format.
* @return The number of characters written.
*/
int32_t stringFormat(char_t *dest, const size_t destSize, char_t *format, ...);
/**
* Formats a string using a va_list.
*
* @param dest The destination string.
* @param destSize The size of the destination string exc. null terminator.
* @param format The format string.
* @param args The va_list of arguments.
* @return The number of characters written.
*/
int32_t stringFormatVA(
char_t *dest,
const size_t destSize,
const char_t *format,
va_list args
);
/**
* Converts a string to an integer.
*
* @param str The string to convert.
* @param out The output integer.
* @return TRUE if the conversion was successful, FALSE otherwise.
*/
bool_t stringToI32(const char_t *str, int32_t *out);
/**
* Converts a string to a signed 16-bit integer.
*
* @param str The string to convert.
* @param out The output signed integer.
* @return TRUE if the conversion was successful, FALSE otherwise.
*/
bool_t stringToI16(const char_t *str, int16_t *out);
/**
* Converts a string to an unsigned 16-bit integer.
*
* @param str The string to convert.
* @param out The output unsigned integer.
* @return TRUE if the conversion was successful, FALSE otherwise.
*/
bool_t stringToU16(const char_t *str, uint16_t *out);