From 766d092b542eacaecaa4f54f6b73cbd230c32e39 Mon Sep 17 00:00:00 2001 From: Nick Hayashi <43279719+churchianity@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:26:32 -0400 Subject: [PATCH] basic --- array.hpp | 8 ++++---- config.h | 22 +++++++++++++++------- print.cpp | 29 +++++++++++++++++++++++++++++ serialize.cpp | 14 +++++++++----- serialize.h | 2 +- string.h | 2 +- table.hpp | 1 + util.h | 9 +++++++++ 8 files changed, 69 insertions(+), 18 deletions(-) diff --git a/array.hpp b/array.hpp index 899c97f..68ef720 100644 --- a/array.hpp +++ b/array.hpp @@ -235,7 +235,7 @@ struct Array { }; #ifdef ULE_CONFIG_OPTION_SERIALIZATION -extern template +template static void serialize(String* str, Array array) { ULE_TYPES_H_FTAG; serialize(str, array.length); @@ -245,7 +245,7 @@ static void serialize(String* str, Array array) { } } -extern template +template static void serialize(String* str, Array* array) { ULE_TYPES_H_FTAG; SERIALIZE_HANDLE_NULL(str, array); @@ -256,7 +256,7 @@ static void serialize(String* str, Array* array) { } } -extern template +template static void deserialize(char** buffer, Array* array) { ULE_TYPES_H_FTAG; deserialize(buffer, &array->length); @@ -266,7 +266,7 @@ static void deserialize(char** buffer, Array* array) { } } -extern template +template static void deserialize(char** buffer, Array** array) { ULE_TYPES_H_FTAG; DESERIALIZE_HANDLE_NULL(buffer, array); diff --git a/config.h b/config.h index aba3317..dae9b3b 100644 --- a/config.h +++ b/config.h @@ -1,15 +1,23 @@ -#pragma once -#ifndef ULE_CONFIG_H -#define ULE_CONFIG_H - // define this macro to include the serialization code `serialize.h/.cpp`, as well as serialization // for the hashtable(s) and array implementations. -//#define ULE_CONFIG_OPTION_SERIALIZATION +#define ULE_CONFIG_OPTION_SERIALIZATION // all functions in the library will invoke a semicolon-terminated macro as their first line of execution. // this is for use by an instrusive profiler, though could be used for whatever purpose. -//#define ULE_CONFIG_OPTION_FTAG ZoneScoped +#include +#define ULE_CONFIG_OPTION_FTAG ZoneScoped + +// use glm for vector and matrix types and operations. +// if this is defined, you will also need to include 'glm'. make sure the following headers can be found on your system. +// the way this is done currently hurts compile times. Eventually we will have a glm replacement and this problem goes away. +// You can also compile ULE into a static lib to avoid this issue. +#include +#include +#include +#include +#define ULE_CONFIG_OPTION_USE_GLM + -#endif +#define ULE_CONFIG_OPTION_PRINT_OUTPUT_USE_ANSI_COLOR_CODES diff --git a/print.cpp b/print.cpp index e9f189f..3b3d157 100644 --- a/print.cpp +++ b/print.cpp @@ -194,6 +194,35 @@ void setCustomDieBehavior(void (*dieBehavior)(const char* string)) { customDie = dieBehavior; } +#ifdef _WIN32 +#include +#include +static void writeMinidump(EXCEPTION_POINTERS* pep) { + // create a file + HANDLE hFile = CreateFile(_T("MiniDump.dmp"), GENERIC_READ | GENERIC_WRITE, 0, null, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, null); + + if ((hFile != null) && (hFile != INVALID_HANDLE_VALUE)) { + // carry on with creating the minidump + MINIDUMP_EXCEPTION_INFORMATION mdei; + mdei.ThreadId = GetCurrentThreadId(); + mdei.ExceptionPointers = pep; + mdei.ClientPointers = FALSE; + + MINIDUMP_TYPE mdt = MiniDumpNormal; + BOOL rv = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, mdt, (pep != 0) ? &mdei : 0, 0, 0); + if (!rv) { + println(_T("MiniDumpWriteDump failed. Error: %u"), GetLastError()); + } else { + println(_T("MiniDump created.")); + } + + CloseHandle(hFile); + } else { + println(_T("Failed to CreateFile for MiniDump. Error: %u"), GetLastError()); + } +} +#endif + // for fatal errors which may occur at runtime, even on a release binary. // if a fatal error should not occur at runtime on a release binary, consider preferring 'massert' // it's unclear when you should use asserts vs. die actually. idk man diff --git a/serialize.cpp b/serialize.cpp index 258d9a2..1b10d4e 100644 --- a/serialize.cpp +++ b/serialize.cpp @@ -1,8 +1,12 @@ +#include "config.h" + #ifdef ULE_CONFIG_OPTION_SERIALIZATION + #include + #include "types.h" #include "serialize.h" #include "string.h" @@ -29,7 +33,7 @@ static inline const char* getFormatStringOut(double v) { ULE_TYPES_H_FTAG; retur static inline const char* getFormatStringOut(char* v) { ULE_TYPES_H_FTAG; return "\"%s\"\n"; } static inline const char* getFormatStringOut(const char* v) { ULE_TYPES_H_FTAG; return "\"%s\"\n"; } -#ifdef _USING_GLM_TYPES__ +#ifdef ULE_CONFIG_OPTION_USE_GLM static inline const char* getFormatStringOut(glm::vec<2, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f\n"; } static inline const char* getFormatStringOut(glm::vec<3, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f\n"; } static inline const char* getFormatStringOut(glm::vec<4, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; } @@ -37,7 +41,6 @@ static inline const char* getFormatStringOut(glm::vec<4, float, (glm::qualifier) static inline const char* getFormatStringOut(glm::mat<2, 2, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; } static inline const char* getFormatStringOut(glm::mat<3, 3, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f\n"; } static inline const char* getFormatStringOut(glm::mat<4, 4, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n"; } - #endif #define SERIALIZE_H_FUNC_BODY str->appendf(getFormatStringOut(v), v); @@ -52,7 +55,7 @@ void serialize(String* str, s64 v) { ULE_TYPES_H_FTAG; SERIALIZE_H_FUNC_BODY void serialize(String* str, float v) { ULE_TYPES_H_FTAG; SERIALIZE_H_FUNC_BODY } void serialize(String* str, double v) { ULE_TYPES_H_FTAG; SERIALIZE_H_FUNC_BODY } -extern template // @TODO do not use a template for this. +template // @TODO do not use a template for this. static inline void deserializeInteger(char** buffer, T* v) { ULE_TYPES_H_FTAG; char* _buffer = *buffer; @@ -227,7 +230,7 @@ void deserialize(char** buffer, const char** v) { *v = String::cpy(SERIALIZE_SCRATCH_BUFFER, (u32) i); } -#ifdef _USING_GLM_TYPES__ +#ifdef ULE_CONFIG_OPTION_USE_GLM // I have no fucking idea why, but the declarations of glm types here resolve to a type, // that has a template parameter == 0, but all other instances of those types in my program // have that template parameter == 3, so everything below becomes unresolved symbols if @@ -310,10 +313,11 @@ void deserialize(char** buffer, glm::mat<4, 4, float, (glm::qualifier) 3>* v) { deserialize(buffer, m + i); } } +#endif // ULE_CONFIG_OPTION_USE_GLM #undef SERIALIZE_H_FUNC_BODY #undef SERIALIZE_H_DESERIALIZE_FUNC_BODY #endif -#endif + diff --git a/serialize.h b/serialize.h index 88c66f1..b0d5b94 100644 --- a/serialize.h +++ b/serialize.h @@ -189,7 +189,7 @@ extern void serialize(String* str, size_t v); extern void deserialize(char** buffer, size_t* v); #endif -#ifdef _USING_GLM_TYPES__ +#ifdef ULE_CONFIG_OPTION_USE_GLM extern void serialize(String* str, glm::vec<2, float, (glm::qualifier) 3> v); extern void serialize(String* str, glm::vec<3, float, (glm::qualifier) 3> v); extern void serialize(String* str, glm::vec<4, float, (glm::qualifier) 3> v); diff --git a/string.h b/string.h index 5d20deb..6ec3177 100644 --- a/string.h +++ b/string.h @@ -6,7 +6,7 @@ #include "types.h" #include "alloc.h" -//#include // @TODO remove this +#include // @TODO remove this #define STB_SPRINTF_IMPLEMENTATION #define STB_SPRINTF_STATIC diff --git a/table.hpp b/table.hpp index 09de137..1384b50 100644 --- a/table.hpp +++ b/table.hpp @@ -720,3 +720,4 @@ struct CacheTable { }; #endif + diff --git a/util.h b/util.h index cc594bb..34a9e6d 100644 --- a/util.h +++ b/util.h @@ -5,6 +5,15 @@ #define STATIC_ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0])) +// GCC & CLang +//#define FORCE_INLINE inline __attribute__((__always_inline)) +//#define NEVER_INLINE __attribute__((__noinline__)) + + +// VC++ +#define FORCE_INLINE __forceinline +#define NEVER_INLINE __declspec(noinline) + #endif