Fix windows!

v1
Paragon-Win 2023-04-07 00:02:21 -04:00
parent 89df343e4f
commit a6a2ee966c
8 changed files with 82 additions and 18 deletions

View File

@ -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()

41
CMakeSettings.json Normal file
View File

@ -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"
}
]
}
]
}

View File

@ -9,6 +9,11 @@
#include <blt/math/vectors.h>
#ifndef M_PI
// MSVC does not have M_PI
# define M_PI 3.14159265358979323846
#endif
namespace blt {
class mat4x4 {

View File

@ -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<typename T, uint32_t size>
#else
// STFINAE is broken in MSVC?
template<typename T, uint32_t size, typename std::enable_if<std::is_arithmetic<T>::value>::type* = nullptr>
#endif
struct vec {
private:
T elements[size]{};
@ -78,7 +86,7 @@ namespace blt {
}
[[nodiscard]] inline vec<T, size> normalize() const {
auto mag = this->magnitude();
T mag = this->magnitude();
if (mag == 0)
return vec<T, size>(*this);
return *this / mag;
@ -160,8 +168,8 @@ namespace blt {
}
static inline constexpr vec<T, size> project(const vec<T, size>& u, const vec<T, size>& 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<typename T, uint32_t size>
inline constexpr vec<T, size> operator+(const vec<T, size>& left, float f) {
inline constexpr vec<T, size> operator+(const vec<T, size>& 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<typename T, uint32_t size>
inline constexpr vec<T, size> operator-(const vec<T, size>& left, float f) {
inline constexpr vec<T, size> operator-(const vec<T, size>& 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<typename T, uint32_t size>
inline constexpr vec<T, size> operator+(float f, const vec<T, size>& right) {
inline constexpr vec<T, size> operator+(T f, const vec<T, size>& right) {
T initializer[size];
for (uint32_t i = 0; i < size; i++)
initializer[i] = f + right[i];
@ -207,7 +215,7 @@ namespace blt {
}
template<typename T, uint32_t size>
inline constexpr vec<T, size> operator-(float f, const vec<T, size>& right) {
inline constexpr vec<T, size> operator-(T f, const vec<T, size>& right) {
T initializer[size];
for (uint32_t i = 0; i < size; i++)
initializer[i] = f - right[i];
@ -223,7 +231,7 @@ namespace blt {
}
template<typename T, uint32_t size>
inline constexpr vec<T, size> operator*(const vec<T, size>& left, float f) {
inline constexpr vec<T, size> operator*(const vec<T, size>& 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<typename T, uint32_t size>
inline constexpr vec<T, size> operator*(float f, const vec<T, size>& right) {
inline constexpr vec<T, size> operator*(T f, const vec<T, size>& right) {
T initializer[size];
for (uint32_t i = 0; i < size; i++)
initializer[i] = f * right[i];
@ -239,7 +247,7 @@ namespace blt {
}
template<typename T, uint32_t size>
inline constexpr vec<T, size> operator/(const vec<T, size>& left, float f) {
inline constexpr vec<T, size> operator/(const vec<T, size>& left, T f) {
T initializer[size];
for (uint32_t i = 0; i < size; i++)
initializer[i] = left[i] / f;

View File

@ -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

View File

@ -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++) {

View File

@ -24,6 +24,7 @@ std::vector<std::string> 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<std::string> 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();
}
}

View File

@ -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);