Just refactored tools to C++

This commit is contained in:
2023-02-06 22:16:47 -08:00
parent dda126d338
commit c70c4fe6c4
29 changed files with 779 additions and 767 deletions

View File

@ -3,6 +3,9 @@
# This software is released under the MIT License. # This software is released under the MIT License.
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# Include shared libs
add_subdirectory(dawnshared)
# Include tools # Include tools
add_subdirectory(dawntools) add_subdirectory(dawntools)

View File

@ -13,6 +13,7 @@ target_link_libraries(${DAWN_TARGET_NAME}
# Includes # Includes
target_include_directories(${DAWN_TARGET_NAME} target_include_directories(${DAWN_TARGET_NAME}
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -6,36 +6,9 @@
*/ */
#pragma once #pragma once
#include "dawnsharedlibs.hpp"
// Static Libs
extern "C" {
// Standard Libs
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
typedef bool bool_t;
typedef float float_t;
}
#include <vector>
#include <iostream>
#include <thread>
#include <map>
#include <array>
#include <stb_truetype.h> #include <stb_truetype.h>
#include <memory>
#include <algorithm>
#include <sstream>
// #include <iterator>
// #include <algorithm>
// #include <string>
// #include <sstream>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/vec3.hpp> #include <glm/vec3.hpp>

View File

@ -0,0 +1,13 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Includes
set(
DAWN_SHARED_INCLUDES
${CMAKE_CURRENT_LIST_DIR}
CACHE INTERNAL
${DAWN_CACHE_TARGET}
)

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
// Static Libs
extern "C" {
// Standard Libs
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
typedef bool bool_t;
typedef float float_t;
}
#include <vector>
#include <iostream>
#include <thread>
#include <map>
#include <array>
#include <memory>
#include <algorithm>
#include <sstream>

View File

@ -9,10 +9,11 @@ add_executable(audiogen)
target_sources(audiogen target_sources(audiogen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
) )
target_include_directories(audiogen target_include_directories(audiogen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -3,10 +3,8 @@
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
extern "C" { #include "../../utils/common.hpp"
#include "../../utils/common.h" #include "../../utils/file.hpp"
#include "../../utils/file.h"
}
#include "AudioFile.h" #include "AudioFile.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

View File

@ -9,11 +9,12 @@ add_executable(texturegen)
target_sources(texturegen target_sources(texturegen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/image.c ../../utils/image.cpp
) )
target_include_directories(texturegen target_include_directories(texturegen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -5,11 +5,9 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
extern "C" { #include "../../utils/common.hpp"
#include "../../utils/common.h" #include "../../utils/file.hpp"
#include "../../utils/file.h" #include "../../utils/image.hpp"
#include "../../utils/image.h"
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
FILE *file; FILE *file;

View File

@ -9,11 +9,12 @@ add_executable(tilesetgen)
target_sources(tilesetgen target_sources(tilesetgen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/image.c ../../utils/image.cpp
) )
target_include_directories(tilesetgen target_include_directories(tilesetgen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -5,11 +5,9 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
extern "C" { #include "../../utils/common.hpp"
#include "../../utils/common.h" #include "../../utils/file.hpp"
#include "../../utils/file.h" #include "../../utils/image.hpp"
#include "../../utils/image.h"
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char *in; char *in;

View File

@ -9,11 +9,12 @@ add_executable(truetypegen)
target_sources(truetypegen target_sources(truetypegen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/image.c ../../utils/image.cpp
) )
target_include_directories(truetypegen target_include_directories(truetypegen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -5,15 +5,13 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
extern "C" { #include "../../utils/common.hpp"
#include "../../utils/common.h" #include "../../utils/file.hpp"
#include "../../utils/file.h" #include "../../utils/image.hpp"
#include "../../utils/image.h" #ifndef STB_TRUETYPE_IMPLEMENTATION
#ifndef STB_TRUETYPE_IMPLEMENTATION
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
#include <stb_truetype.h> #include <stb_truetype.h>
#endif #endif
}
#define TRUETYPE_FIRST_CHAR 32 #define TRUETYPE_FIRST_CHAR 32
#define TRUETYPE_NUM_CHARS 96 #define TRUETYPE_NUM_CHARS 96

View File

@ -9,11 +9,12 @@ add_executable(uigen)
target_sources(uigen target_sources(uigen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/xml.c ../../utils/xml.cpp
) )
target_include_directories(uigen target_include_directories(uigen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -5,11 +5,8 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
extern "C" { #include "../../utils/xml.hpp"
#include "../../utils/xml.h" #include "../../utils/file.hpp"
#include "../../utils/file.h"
#include <memory.h>
}
#include <iostream> #include <iostream>
#include <vector> #include <vector>

View File

@ -9,12 +9,13 @@ add_executable(languagegen)
target_sources(languagegen target_sources(languagegen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/csv.c ../../utils/csv.cpp
../../utils/xml.c ../../utils/xml.cpp
) )
target_include_directories(languagegen target_include_directories(languagegen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -5,14 +5,10 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
extern "C" { #include "../../utils/common.hpp"
#include "../../utils/common.h" #include "../../utils/file.hpp"
#include "../../utils/file.h" #include "../../utils/csv.hpp"
#include "../../utils/csv.h" #include "../../utils/xml.hpp"
#include "../../utils/xml.h"
#include <memory.h>
}
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <vector> #include <vector>

View File

@ -6,6 +6,8 @@
*/ */
#pragma once #pragma once
#include "dawnsharedlibs.hpp"
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "csv.h" #include "csv.hpp"
char * csvGetCell(csv_t *csv, int32_t row, int32_t cell) { char * csvGetCell(csv_t *csv, int32_t row, int32_t cell) {
return csv->rows[(row * CSV_COLUMN_COUNT_MAX) + cell]; return csv->rows[(row * CSV_COLUMN_COUNT_MAX) + cell];
@ -18,9 +18,9 @@ void csvParse(char *string, csv_t *csv) {
int32_t rowCellCount; int32_t rowCellCount;
length = strlen(string); length = strlen(string);
csv->buffer = malloc(sizeof(char) * (length+1) * CSV_COLUMN_COUNT_MAX * CSV_ROW_COUNT_MAX); csv->buffer = (char *)malloc(sizeof(char) * (length+1) * CSV_COLUMN_COUNT_MAX * CSV_ROW_COUNT_MAX);
csv->cellCounts = malloc(sizeof(int32_t) * CSV_ROW_COUNT_MAX); csv->cellCounts = (int32_t *)malloc(sizeof(int32_t) * CSV_ROW_COUNT_MAX);
csv->rows = malloc(sizeof(char*) * CSV_ROW_COUNT_MAX * CSV_COLUMN_COUNT_MAX); csv->rows = (char**)malloc(sizeof(char*) * CSV_ROW_COUNT_MAX * CSV_COLUMN_COUNT_MAX);
i = 0; i = 0;
j = 0; j = 0;

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.h" #include "common.hpp"
#include "string.h" #include "string.h"
#define CSV_ROW_COUNT_MAX 128 #define CSV_ROW_COUNT_MAX 128

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "file.h" #include "file.hpp"
void fileNormalizeSlashes(char *string) { void fileNormalizeSlashes(char *string) {
char c; char c;

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.h" #include "common.hpp"
#define FILE_CHILD_TYPE_DIR 0x00 #define FILE_CHILD_TYPE_DIR 0x00
#define FILE_CHILD_TYPE_FILE 0x01 #define FILE_CHILD_TYPE_FILE 0x01

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "image.h" #include "image.hpp"
#ifndef STB_IMAGE_IMPLEMENTATION #ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION

View File

@ -6,8 +6,8 @@
*/ */
#pragma once #pragma once
#include "common.h" #include "common.hpp"
#include "file.h" #include "file.hpp"
#include <stb_image.h> #include <stb_image.h>
#include <stb_image_resize.h> #include <stb_image_resize.h>

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.h" #include "common.hpp"
static inline void stringRemoveAll(char *string, char remove) { static inline void stringRemoveAll(char *string, char remove) {
size_t len = strlen(string); size_t len = strlen(string);

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "xml.h" #include "xml.hpp"
int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) { int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
char c; char c;
@ -13,13 +13,13 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
uint8_t doing = XML_DOING_NOTHING; uint8_t doing = XML_DOING_NOTHING;
uint8_t doingBeforeComment; uint8_t doingBeforeComment;
bool insideTag = false; bool insideTag = false;
char* buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX); char* buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
int32_t bufferLength = 0; int32_t bufferLength = 0;
xml->value = NULL; xml->value = NULL;
xml->attributeCount = 0; xml->attributeCount = 0;
xml->children = malloc(sizeof(xml_t) * XML_CHILD_COUNT_MAX); xml->children = (xml_t *)malloc(sizeof(xml_t) * XML_CHILD_COUNT_MAX);
xml->childrenCount = 0; xml->childrenCount = 0;
while(c = data[i++]) { while(c = data[i++]) {
@ -54,7 +54,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
if(xmlIsWhitespace(c) || c == '>' || c == '/') { if(xmlIsWhitespace(c) || c == '>' || c == '/') {
buffer[bufferLength] = '\0'; buffer[bufferLength] = '\0';
xml->node = buffer; xml->node = buffer;
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX); buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
bufferLength = 0; bufferLength = 0;
if(c == '/') { if(c == '/') {
level--; level--;
@ -88,7 +88,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
buffer[bufferLength] = '\0'; buffer[bufferLength] = '\0';
xml->attributeNames[xml->attributeCount++] = buffer; xml->attributeNames[xml->attributeCount++] = buffer;
xml->attributeDatas[xml->attributeCount] = NULL; xml->attributeDatas[xml->attributeCount] = NULL;
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX); buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
bufferLength = 0; bufferLength = 0;
} }
continue; continue;
@ -116,7 +116,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
doing = XML_LOOKING_FOR_ATTRIBUTE; doing = XML_LOOKING_FOR_ATTRIBUTE;
buffer[bufferLength] = '\0'; buffer[bufferLength] = '\0';
xml->attributeDatas[xml->attributeCount - 1] = buffer; xml->attributeDatas[xml->attributeCount - 1] = buffer;
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX); buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
bufferLength = 0; bufferLength = 0;
continue; continue;
} }
@ -132,7 +132,7 @@ int32_t xmlLoadChild(xml_t *xml, char *data, int32_t i) {
buffer[bufferLength] = '\0'; buffer[bufferLength] = '\0';
bufferLength = 0; bufferLength = 0;
xml->value = buffer; xml->value = buffer;
buffer = malloc(sizeof(char) * XML_TEXT_BUFFER_MAX); buffer = (char *)malloc(sizeof(char) * XML_TEXT_BUFFER_MAX);
continue; continue;
} }

View File

@ -6,8 +6,8 @@
*/ */
#pragma once #pragma once
#include "common.h" #include "common.hpp"
#include "file.h" #include "file.hpp"
#define XML_DOING_NOTHING 0x00 #define XML_DOING_NOTHING 0x00
#define XML_PARSING_TAG_NAME 0x01 #define XML_PARSING_TAG_NAME 0x01

View File

@ -9,11 +9,12 @@ add_executable(vnscenegen)
target_sources(vnscenegen target_sources(vnscenegen
PRIVATE PRIVATE
main.cpp main.cpp
../../utils/file.c ../../utils/file.cpp
../../utils/xml.c ../../utils/xml.cpp
) )
target_include_directories(vnscenegen target_include_directories(vnscenegen
PUBLIC PUBLIC
${DAWN_SHARED_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/../../ ${CMAKE_CURRENT_LIST_DIR}/../../
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )

View File

@ -3,11 +3,8 @@
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
extern "C" { #include "../../utils/file.hpp"
#include "../../utils/file.h" #include "../../utils/xml.hpp"
#include "../../utils/xml.h"
#include <memory.h>
}
#include <iostream> #include <iostream>
#include <vector> #include <vector>