diff --git a/src/dawnshared/dawnsharedlibs.hpp b/src/dawnshared/dawnsharedlibs.hpp index c98a271b..5a0a039e 100644 --- a/src/dawnshared/dawnsharedlibs.hpp +++ b/src/dawnshared/dawnsharedlibs.hpp @@ -16,9 +16,9 @@ extern "C" { #include #include #include + #include typedef bool bool_t; - typedef float float_t; } #include diff --git a/src/dawn/util/array.hpp b/src/dawnshared/util/array.hpp similarity index 95% rename from src/dawn/util/array.hpp rename to src/dawnshared/util/array.hpp index d5c15715..ab64da5a 100644 --- a/src/dawn/util/array.hpp +++ b/src/dawnshared/util/array.hpp @@ -1,45 +1,45 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" -#include "assert/assert.hpp" - -namespace Dawn { - /** - * Append a list on to another list. - * - * @param list Pointer to list that is being appended to. - * @param append Pointer to list that will be appended. - */ - template - void vectorAppend(std::vector *list, std::vector *append) { - assertNotNull(list); - assertNotNull(append); - - auto it = append->begin(); - while(it != append->end()) { - list->push_back(*it); - ++it; - } - } - - /** - * Append a list on to another list. - * - * @param list Pointer to list that is being appended to. - * @param append List that will be appended. - */ - template - void vectorAppend(std::vector *list, std::vector append) { - assertNotNull(list); - - auto it = append.begin(); - while(it != append.end()) { - list->push_back(*it); - ++it; - } - } -} +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" +#include "assert/assert.hpp" + +namespace Dawn { + /** + * Append a list on to another list. + * + * @param list Pointer to list that is being appended to. + * @param append Pointer to list that will be appended. + */ + template + void vectorAppend(std::vector *list, std::vector *append) { + assertNotNull(list); + assertNotNull(append); + + auto it = append->begin(); + while(it != append->end()) { + list->push_back(*it); + ++it; + } + } + + /** + * Append a list on to another list. + * + * @param list Pointer to list that is being appended to. + * @param append List that will be appended. + */ + template + void vectorAppend(std::vector *list, std::vector append) { + assertNotNull(list); + + auto it = append.begin(); + while(it != append.end()) { + list->push_back(*it); + ++it; + } + } +} diff --git a/src/dawn/util/flag.hpp b/src/dawnshared/util/flag.hpp similarity index 95% rename from src/dawn/util/flag.hpp rename to src/dawnshared/util/flag.hpp index 735b47ef..669b0c8b 100644 --- a/src/dawn/util/flag.hpp +++ b/src/dawnshared/util/flag.hpp @@ -1,15 +1,15 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" - -typedef uint_fast8_t flag8_t; -typedef uint_fast16_t flag16_t; -typedef uint_fast32_t flag32_t; - -typedef flag32_t flag_t; - +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" + +typedef uint_fast8_t flag8_t; +typedef uint_fast16_t flag16_t; +typedef uint_fast32_t flag32_t; + +typedef flag32_t flag_t; + #define FLAG_DEFINE(n) (1 << n) \ No newline at end of file diff --git a/src/dawn/util/mathutils.hpp b/src/dawnshared/util/mathutils.hpp similarity index 100% rename from src/dawn/util/mathutils.hpp rename to src/dawnshared/util/mathutils.hpp diff --git a/src/dawn/util/memory.hpp b/src/dawnshared/util/memory.hpp similarity index 96% rename from src/dawn/util/memory.hpp rename to src/dawnshared/util/memory.hpp index 4388b705..2c25c249 100644 --- a/src/dawn/util/memory.hpp +++ b/src/dawnshared/util/memory.hpp @@ -1,108 +1,108 @@ -/** - * Copyright (c) 2022 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "dawnlibs.hpp" - -/** - * Allocate some space in memory to use for your needs. Memory allocation may - * change how it functions later on to keep things nice and efficient. For now - * this is just an API forward for malloc. - * - * @param size Size of the array you wish to buffer. - * @return Pointer to the space in memory to use. - */ -static inline void * memoryAllocate(const size_t size) { - return (void *)malloc(size); -} - -/** - * Allocate space in memory, where all values are set to 0 (in binary space). - * - * @param size Size of the array. - * @return Pointer to the space in memory to use. - */ -static inline void * memoryFillWithZero(const size_t size) { - return (void *)calloc(1, size); -} - - -/** - * Free some previously allocated memory space. - * @param pointer Pointer in memory to free. - */ -static inline void memoryFree(void *pointer) { - free(pointer); -} - -/** - * Copies data from one buffer to another. Typically used for array operations. - * - * @param source Source pointer. - * @param destination Destination buffer. - * @param size Size in bytes of data to copy. - */ -static inline void memoryCopy( - void *source, - void *destination, - size_t size -) { - memcpy(destination, source, size); -} - -/** - * Compares the data within two memory banks. Shorthand for memcpy. - * - * @param left Left item to compare. - * @param right Right item to compare. - * @param size Count of bytes to compare. - * @return 0 for equal, <0 for left being greater, >0 for right being greater. - */ -static inline int32_t memoryCompare( - const void *left, - const void *right, - const size_t size -) { - return memcmp(left, right, size); -} - -/** - * Fill destination with a repeating set of bytes. - * - * @param dest Destination pointer in memory. - * @param data Data byte to write. - * @param length How many times to write that byte. - */ -static inline void memorySet( - void *dest, - uint8_t data, - size_t length -) { - memset(dest, data, length); -} - -/** - * Reallocate a part of memory. Reallocation simply creates a new buffer that - * will take all of the existing contents and then free's the original buffer. - * - * @param pointer Pointer to pointer in memory that you wish to re-allocate. - * @param currentSize Current size of the buffer that the pointer points to. - * @param newSize The new size of the buffer. - * @return The new size param you provided. - */ -static inline size_t memoryReallocate( - void **pointer, - size_t currentSize, - size_t newSize -) { - // Create the new buffer - void *newBuffer = memoryAllocate(newSize); - memoryCopy(*pointer, newBuffer, currentSize); - memoryFree(*pointer); - *pointer = newBuffer; - return newSize; +/** + * Copyright (c) 2022 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dawnlibs.hpp" + +/** + * Allocate some space in memory to use for your needs. Memory allocation may + * change how it functions later on to keep things nice and efficient. For now + * this is just an API forward for malloc. + * + * @param size Size of the array you wish to buffer. + * @return Pointer to the space in memory to use. + */ +static inline void * memoryAllocate(const size_t size) { + return (void *)malloc(size); +} + +/** + * Allocate space in memory, where all values are set to 0 (in binary space). + * + * @param size Size of the array. + * @return Pointer to the space in memory to use. + */ +static inline void * memoryFillWithZero(const size_t size) { + return (void *)calloc(1, size); +} + + +/** + * Free some previously allocated memory space. + * @param pointer Pointer in memory to free. + */ +static inline void memoryFree(void *pointer) { + free(pointer); +} + +/** + * Copies data from one buffer to another. Typically used for array operations. + * + * @param source Source pointer. + * @param destination Destination buffer. + * @param size Size in bytes of data to copy. + */ +static inline void memoryCopy( + void *source, + void *destination, + size_t size +) { + memcpy(destination, source, size); +} + +/** + * Compares the data within two memory banks. Shorthand for memcpy. + * + * @param left Left item to compare. + * @param right Right item to compare. + * @param size Count of bytes to compare. + * @return 0 for equal, <0 for left being greater, >0 for right being greater. + */ +static inline int32_t memoryCompare( + const void *left, + const void *right, + const size_t size +) { + return memcmp(left, right, size); +} + +/** + * Fill destination with a repeating set of bytes. + * + * @param dest Destination pointer in memory. + * @param data Data byte to write. + * @param length How many times to write that byte. + */ +static inline void memorySet( + void *dest, + uint8_t data, + size_t length +) { + memset(dest, data, length); +} + +/** + * Reallocate a part of memory. Reallocation simply creates a new buffer that + * will take all of the existing contents and then free's the original buffer. + * + * @param pointer Pointer to pointer in memory that you wish to re-allocate. + * @param currentSize Current size of the buffer that the pointer points to. + * @param newSize The new size of the buffer. + * @return The new size param you provided. + */ +static inline size_t memoryReallocate( + void **pointer, + size_t currentSize, + size_t newSize +) { + // Create the new buffer + void *newBuffer = memoryAllocate(newSize); + memoryCopy(*pointer, newBuffer, currentSize); + memoryFree(*pointer); + *pointer = newBuffer; + return newSize; } \ No newline at end of file diff --git a/src/dawn/util/random.hpp b/src/dawnshared/util/random.hpp similarity index 100% rename from src/dawn/util/random.hpp rename to src/dawnshared/util/random.hpp diff --git a/src/dawn/util/string.hpp b/src/dawnshared/util/string.hpp similarity index 96% rename from src/dawn/util/string.hpp rename to src/dawnshared/util/string.hpp index 0ef9b954..99f26ada 100644 --- a/src/dawn/util/string.hpp +++ b/src/dawnshared/util/string.hpp @@ -1,35 +1,35 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "assert/assert.hpp" - -/** - * Finds the next instance of a character within a string, safely (with a - * limit). The returned pointer will be NULL if not found, or a pointer to a - * point within the string where the instance is. - * - * @param haystack String to search. - * @param needle Character to search for. - * @param limit Max length you want to search for to limit yourself to. - * @return Pointer to the character found, or NULL if not found. - */ -static inline char * stringFindNext( - char *haystack, - char needle, - size_t limit -) { - char *p; - - assertNotNull(haystack); - assertTrue(limit > 0); - - for(p = haystack; (size_t)(p - haystack) < limit; p++) { - if(*p == needle) return p; - assertFalse(*p == '\0');// We don't allow you to have a limit > strlen - } - - return NULL; +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "assert/assert.hpp" + +/** + * Finds the next instance of a character within a string, safely (with a + * limit). The returned pointer will be NULL if not found, or a pointer to a + * point within the string where the instance is. + * + * @param haystack String to search. + * @param needle Character to search for. + * @param limit Max length you want to search for to limit yourself to. + * @return Pointer to the character found, or NULL if not found. + */ +static inline char * stringFindNext( + char *haystack, + char needle, + size_t limit +) { + char *p; + + assertNotNull(haystack); + assertTrue(limit > 0); + + for(p = haystack; (size_t)(p - haystack) < limit; p++) { + if(*p == needle) return p; + assertFalse(*p == '\0');// We don't allow you to have a limit > strlen + } + + return NULL; } \ No newline at end of file diff --git a/src/dawntools/audio/audiogen/main.cpp b/src/dawntools/audio/audiogen/main.cpp index f8e77fbc..aa9eaaef 100644 --- a/src/dawntools/audio/audiogen/main.cpp +++ b/src/dawntools/audio/audiogen/main.cpp @@ -3,7 +3,7 @@ // This software is released under the MIT License. // https://opensource.org/licenses/MIT -#include "../../utils/common.hpp" +#include "dawnsharedlibs.hpp" #include "../../utils/file.hpp" #include "AudioFile.h" diff --git a/src/dawntools/display/texturegen/main.cpp b/src/dawntools/display/texturegen/main.cpp index 8089b09b..2ba4c120 100644 --- a/src/dawntools/display/texturegen/main.cpp +++ b/src/dawntools/display/texturegen/main.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "../../utils/common.hpp" +#include "dawnsharedlibs.hpp" #include "../../utils/file.hpp" #include "../../utils/image.hpp" diff --git a/src/dawntools/display/tilesetgen/main.cpp b/src/dawntools/display/tilesetgen/main.cpp index 86fb00c6..9fa18d80 100644 --- a/src/dawntools/display/tilesetgen/main.cpp +++ b/src/dawntools/display/tilesetgen/main.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "../../utils/common.hpp" +#include "dawnsharedlibs.hpp" #include "../../utils/file.hpp" #include "../../utils/image.hpp" diff --git a/src/dawntools/display/truetypegen/main.cpp b/src/dawntools/display/truetypegen/main.cpp index f22d85c3..5923d4b1 100644 --- a/src/dawntools/display/truetypegen/main.cpp +++ b/src/dawntools/display/truetypegen/main.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "../../utils/common.hpp" +#include "dawnsharedlibs.hpp" #include "../../utils/file.hpp" #include "../../utils/image.hpp" #ifndef STB_TRUETYPE_IMPLEMENTATION diff --git a/src/dawntools/locale/languagegen/main.cpp b/src/dawntools/locale/languagegen/main.cpp index 1e41f95e..b5fa6c48 100644 --- a/src/dawntools/locale/languagegen/main.cpp +++ b/src/dawntools/locale/languagegen/main.cpp @@ -5,7 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include "../../utils/common.hpp" +#include "dawnsharedlibs.hpp" #include "../../utils/file.hpp" #include "../../utils/csv.hpp" #include "../../utils/xml.hpp" diff --git a/src/dawntools/utils/common.hpp b/src/dawntools/utils/common.hpp deleted file mode 100644 index 3d5af9d3..00000000 --- a/src/dawntools/utils/common.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "dawnsharedlibs.hpp" - -#include -#include -#include -#include -#include -#include \ No newline at end of file diff --git a/src/dawntools/utils/csv.hpp b/src/dawntools/utils/csv.hpp index fa3b844d..1cc6306f 100644 --- a/src/dawntools/utils/csv.hpp +++ b/src/dawntools/utils/csv.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "common.hpp" +#include "dawnsharedlibs.hpp" #include "string.h" #define CSV_ROW_COUNT_MAX 128 diff --git a/src/dawntools/utils/file.hpp b/src/dawntools/utils/file.hpp index 2b761be6..67e21157 100644 --- a/src/dawntools/utils/file.hpp +++ b/src/dawntools/utils/file.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "common.hpp" +#include "dawnsharedlibs.hpp" #define FILE_CHILD_TYPE_DIR 0x00 #define FILE_CHILD_TYPE_FILE 0x01 diff --git a/src/dawntools/utils/image.hpp b/src/dawntools/utils/image.hpp index 99264a94..763ee856 100644 --- a/src/dawntools/utils/image.hpp +++ b/src/dawntools/utils/image.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "common.hpp" +#include "dawnsharedlibs.hpp" #include "file.hpp" #include diff --git a/src/dawntools/utils/string.hpp b/src/dawntools/utils/string.hpp index d60e4eb8..a7e67025 100644 --- a/src/dawntools/utils/string.hpp +++ b/src/dawntools/utils/string.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "common.hpp" +#include "dawnsharedlibs.hpp" static inline void stringRemoveAll(char *string, char remove) { size_t len = strlen(string); diff --git a/src/dawntools/utils/xml.hpp b/src/dawntools/utils/xml.hpp index 28b9a80c..353a5c0e 100644 --- a/src/dawntools/utils/xml.hpp +++ b/src/dawntools/utils/xml.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include "common.hpp" +#include "dawnsharedlibs.hpp" #include "file.hpp" #define XML_DOING_NOTHING 0x00