diff --git a/CMakeLists.txt b/CMakeLists.txt index 399012e..8451829 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ if(${ZLIB_FOUND}) endif() if(MSVC) - target_compile_options(BLT PRIVATE /W4) + #target_compile_options(BLT PRIVATE /W4) else() # perhaps we should warn on usused variables, but BLT will have lots of them. target_compile_options(BLT PRIVATE -Wall -Wextra -Wpedantic) @@ -64,8 +64,10 @@ message("BLT ${CMAKE_PROJECT_VERSION} Successfully included!") if(${BUILD_TESTS}) project(BLT_TESTS) - add_compile_options(-fsanitize=address) - add_link_options(-fsanitize=address) + if(${CMAKE_BUILD_TYPE} MATCHES Debug AND LINUX) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) + endif() file(GLOB_RECURSE TESTS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/*.cpp") @@ -74,7 +76,10 @@ if(${BUILD_TESTS}) target_link_libraries(BLT_TESTS PUBLIC BLT) if(MSVC) - target_compile_options(BLT_TESTS PRIVATE /W4) + #target_compile_options(BLT_TESTS PRIVATE /W4) + if(${CMAKE_BUILD_TYPE} MATCHES Debug) + target_link_options(BLT_TESTS PRIVATE /DEBUG) + endif() else() target_compile_options(BLT_TESTS PRIVATE -Wall -Wextra -Wpedantic) endif() diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..2cf1e6a --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,41 @@ +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Visual Studio 17 2022 Win64", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "variables": [ + { + "name": "BUILD_TESTS", + "value": "True", + "type": "BOOL" + } + ] + }, + { + "name": "x64-Release", + "generator": "Visual Studio 17 2022 Win64", + "configurationType": "Release", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "intelliSenseMode": "windows-msvc-x64", + "variables": [ + { + "name": "BUILD_TESTS", + "value": "True", + "type": "BOOL" + } + ] + } + ] +} \ No newline at end of file diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h index e43ba69..ccec5d2 100644 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -9,6 +9,11 @@ #include +#ifndef M_PI +// MSVC does not have M_PI +# define M_PI 3.14159265358979323846 +#endif + namespace blt { class mat4x4 { diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index cd0fe68..4362fcf 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -19,8 +19,16 @@ namespace blt { static inline constexpr bool f_equal(float v1, float v2) { return v1 >= v2 - EPSILON && v1 <= v2 + EPSILON; } + +#define MSVC_COMPILER (!defined(__GNUC__) && !defined(__clang__)) + +#ifdef MSVC_COMPILER + template +#else + // STFINAE is broken in MSVC? template::value>::type* = nullptr> +#endif struct vec { private: T elements[size]{}; @@ -78,7 +86,7 @@ namespace blt { } [[nodiscard]] inline vec normalize() const { - auto mag = this->magnitude(); + T mag = this->magnitude(); if (mag == 0) return vec(*this); return *this / mag; @@ -160,8 +168,8 @@ namespace blt { } static inline constexpr vec project(const vec& u, const vec& v){ - float du = dot(u); - float dv = dot(v); + T du = dot(u); + T dv = dot(v); return (du / dv) * v; } }; @@ -183,7 +191,7 @@ namespace blt { } template - inline constexpr vec operator+(const vec& left, float f) { + inline constexpr vec operator+(const vec& left, T f) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = left[i] + f; @@ -191,7 +199,7 @@ namespace blt { } template - inline constexpr vec operator-(const vec& left, float f) { + inline constexpr vec operator-(const vec& left, T f) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = left[i] + f; @@ -199,7 +207,7 @@ namespace blt { } template - inline constexpr vec operator+(float f, const vec& right) { + inline constexpr vec operator+(T f, const vec& right) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = f + right[i]; @@ -207,7 +215,7 @@ namespace blt { } template - inline constexpr vec operator-(float f, const vec& right) { + inline constexpr vec operator-(T f, const vec& right) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = f - right[i]; @@ -223,7 +231,7 @@ namespace blt { } template - inline constexpr vec operator*(const vec& left, float f) { + inline constexpr vec operator*(const vec& left, T f) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = left[i] * f; @@ -231,7 +239,7 @@ namespace blt { } template - inline constexpr vec operator*(float f, const vec& right) { + inline constexpr vec operator*(T f, const vec& right) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = f * right[i]; @@ -239,7 +247,7 @@ namespace blt { } template - inline constexpr vec operator/(const vec& left, float f) { + inline constexpr vec operator/(const vec& left, T f) { T initializer[size]; for (uint32_t i = 0; i < size; i++) initializer[i] = left[i] / f; diff --git a/include/blt/std/filesystem.h b/include/blt/std/filesystem.h index 67c72af..70d1ee5 100644 --- a/include/blt/std/filesystem.h +++ b/include/blt/std/filesystem.h @@ -25,7 +25,7 @@ namespace blt::fs { // 32768 block size seems the fastest on my system unsigned long m_bufferSize; public: - explicit block_reader(unsigned long bufferSize): m_bufferSize(bufferSize) {} + explicit block_reader(size_t bufferSize): m_bufferSize(bufferSize) {} /** * Reads bytes from the internal filesystem implementation diff --git a/include/blt/std/format.h b/include/blt/std/format.h index c76dfd3..d29e3aa 100644 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -88,7 +88,7 @@ namespace blt::string { // taken from java, adapted for c++. static inline utf8_string createUTFString(const std::string& str) { - const unsigned int strlen = str.size(); + const unsigned int strlen = (unsigned int) str.size(); unsigned int utflen = strlen; for (unsigned int i = 0; i < strlen; i++) { diff --git a/src/blt/std/loader.cpp b/src/blt/std/loader.cpp index fe7e42d..099e32d 100644 --- a/src/blt/std/loader.cpp +++ b/src/blt/std/loader.cpp @@ -24,6 +24,7 @@ std::vector blt::fs::getLinesFromFile(const std::string& path) { shaderSource = shaderStream.str(); } catch (std::ifstream::failure& e) { BLT_WARN("Unable to read file '%s'!\n", path.c_str()); + BLT_WARN("Exception: %s", e.what()); throw std::runtime_error("Failed to read file!\n"); } @@ -63,6 +64,7 @@ std::vector blt::fs::recursiveShaderInclude(const std::string& path includes.insert({i, recursiveShaderInclude((pathOnly + "/" + file))}); } catch (std::exception& e) { BLT_FATAL("Shader file contains an invalid #include statement. (Missing < or \")\n"); + BLT_FATAL("Exception: %s", e.what()); std::abort(); } } diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp index 97705e0..cd13e11 100644 --- a/src/blt/std/logging.cpp +++ b/src/blt/std/logging.cpp @@ -166,8 +166,11 @@ namespace blt::logging { std::string formattedString; applyFormatting(format, formattedString, args); - - bool hasEndingLinefeed = formattedString[formattedString.length()-1] == '\n'; + + bool hasEndingLinefeed = false; + + if (formattedString.length() > 0) + hasEndingLinefeed = formattedString[formattedString.length() - 1] == '\n'; if (hasEndingLinefeed) formattedString = formattedString.substr(0, formattedString.length()-1);