Browse Source

basic

master
Nick Hayashi 1 year ago
parent
commit
766d092b54
  1. 8
      array.hpp
  2. 22
      config.h
  3. 29
      print.cpp
  4. 14
      serialize.cpp
  5. 2
      serialize.h
  6. 2
      string.h
  7. 1
      table.hpp
  8. 9
      util.h

8
array.hpp

@ -235,7 +235,7 @@ struct Array {
}; };
#ifdef ULE_CONFIG_OPTION_SERIALIZATION #ifdef ULE_CONFIG_OPTION_SERIALIZATION
extern template <typename T>
template <typename T>
static void serialize(String* str, Array<T> array) { static void serialize(String* str, Array<T> array) {
ULE_TYPES_H_FTAG; ULE_TYPES_H_FTAG;
serialize(str, array.length); serialize(str, array.length);
@ -245,7 +245,7 @@ static void serialize(String* str, Array<T> array) {
} }
} }
extern template <typename T>
template <typename T>
static void serialize(String* str, Array<T>* array) { static void serialize(String* str, Array<T>* array) {
ULE_TYPES_H_FTAG; ULE_TYPES_H_FTAG;
SERIALIZE_HANDLE_NULL(str, array); SERIALIZE_HANDLE_NULL(str, array);
@ -256,7 +256,7 @@ static void serialize(String* str, Array<T>* array) {
} }
} }
extern template <typename T>
template <typename T>
static void deserialize(char** buffer, Array<T>* array) { static void deserialize(char** buffer, Array<T>* array) {
ULE_TYPES_H_FTAG; ULE_TYPES_H_FTAG;
deserialize(buffer, &array->length); deserialize(buffer, &array->length);
@ -266,7 +266,7 @@ static void deserialize(char** buffer, Array<T>* array) {
} }
} }
extern template <typename T>
template <typename T>
static void deserialize(char** buffer, Array<T>** array) { static void deserialize(char** buffer, Array<T>** array) {
ULE_TYPES_H_FTAG; ULE_TYPES_H_FTAG;
DESERIALIZE_HANDLE_NULL(buffer, array); DESERIALIZE_HANDLE_NULL(buffer, array);

22
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 // define this macro to include the serialization code `serialize.h/.cpp`, as well as serialization
// for the hashtable(s) and array implementations. // 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. // 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. // this is for use by an instrusive profiler, though could be used for whatever purpose.
//#define ULE_CONFIG_OPTION_FTAG ZoneScoped
#include <Tracy.hpp>
#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 <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#define ULE_CONFIG_OPTION_USE_GLM
#endif
#define ULE_CONFIG_OPTION_PRINT_OUTPUT_USE_ANSI_COLOR_CODES

29
print.cpp

@ -194,6 +194,35 @@ void setCustomDieBehavior(void (*dieBehavior)(const char* string)) {
customDie = dieBehavior; customDie = dieBehavior;
} }
#ifdef _WIN32
#include <Minidumpapiset.h>
#include <tchar.h>
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. // 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' // 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 // it's unclear when you should use asserts vs. die actually. idk man

14
serialize.cpp

@ -1,8 +1,12 @@
#include "config.h"
#ifdef ULE_CONFIG_OPTION_SERIALIZATION #ifdef ULE_CONFIG_OPTION_SERIALIZATION
#include <fast_float/fast_float.h> #include <fast_float/fast_float.h>
#include "types.h" #include "types.h"
#include "serialize.h" #include "serialize.h"
#include "string.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(char* v) { ULE_TYPES_H_FTAG; return "\"%s\"\n"; }
static inline const char* getFormatStringOut(const 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<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<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"; } 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<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<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"; } 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 #endif
#define SERIALIZE_H_FUNC_BODY str->appendf(getFormatStringOut(v), v); #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, float v) { ULE_TYPES_H_FTAG; SERIALIZE_H_FUNC_BODY }
void serialize(String* str, double 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<typename T> // @TODO do not use a template for this.
template<typename T> // @TODO do not use a template for this.
static inline void deserializeInteger(char** buffer, T* v) { static inline void deserializeInteger(char** buffer, T* v) {
ULE_TYPES_H_FTAG; ULE_TYPES_H_FTAG;
char* _buffer = *buffer; char* _buffer = *buffer;
@ -227,7 +230,7 @@ void deserialize(char** buffer, const char** v) {
*v = String::cpy(SERIALIZE_SCRATCH_BUFFER, (u32) i); *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, // 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 // 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 // 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); deserialize(buffer, m + i);
} }
} }
#endif // ULE_CONFIG_OPTION_USE_GLM
#undef SERIALIZE_H_FUNC_BODY #undef SERIALIZE_H_FUNC_BODY
#undef SERIALIZE_H_DESERIALIZE_FUNC_BODY #undef SERIALIZE_H_DESERIALIZE_FUNC_BODY
#endif #endif
#endif

2
serialize.h

@ -189,7 +189,7 @@ extern void serialize(String* str, size_t v);
extern void deserialize(char** buffer, size_t* v); extern void deserialize(char** buffer, size_t* v);
#endif #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<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<3, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::vec<4, float, (glm::qualifier) 3> v); extern void serialize(String* str, glm::vec<4, float, (glm::qualifier) 3> v);

2
string.h

@ -6,7 +6,7 @@
#include "types.h" #include "types.h"
#include "alloc.h" #include "alloc.h"
//#include <string.h> // @TODO remove this
#include <string.h> // @TODO remove this
#define STB_SPRINTF_IMPLEMENTATION #define STB_SPRINTF_IMPLEMENTATION
#define STB_SPRINTF_STATIC #define STB_SPRINTF_STATIC

1
table.hpp

@ -720,3 +720,4 @@ struct CacheTable {
}; };
#endif #endif

9
util.h

@ -5,6 +5,15 @@
#define STATIC_ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0])) #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 #endif
Loading…
Cancel
Save