From 31f0e3181275f8a774cc94d50c635c6c0cb4abec Mon Sep 17 00:00:00 2001 From: kungfooman Date: Tue, 31 Oct 2017 08:10:29 +0100 Subject: [PATCH] vs2017 support --- include/radix/Radix.hpp | 11 ++++ include/radix/SoundManager.hpp | 2 +- include/radix/Window.hpp | 2 +- include/radix/core/math/Vector2ui.hpp | 4 -- include/radix/env/Config.hpp | 2 + include/radix/input/InputSource.hpp | 2 +- source/BaseGame.cpp | 2 +- source/SoundManager.cpp | 3 +- source/{Entity.cpp => SourceEntity.cpp} | 4 ++ source/core/diag/AnsiConsoleLogger.cpp | 6 +++ source/core/diag/LogInput.cpp | 1 + source/core/diag/StdoutLogger.cpp | 3 +- source/core/event/EventDispatcher.cpp | 2 +- source/core/math/Vector2f.cpp | 1 + source/core/math/Vector3f.cpp | 1 + source/core/math/Vector4f.cpp | 1 + source/data/screen/XmlScreenLoader.cpp | 1 + source/data/shader/ShaderLoader.cpp | 52 ++++++++++++------- .../{Player.cpp => EntitiesPlayer.cpp} | 2 +- source/entities/traits/HealthTrait.cpp | 1 + source/env/OperatingSystem.cpp | 2 +- source/env/Util.cpp | 2 +- .../physics/KinematicCharacterController.cpp | 1 + .../{Player.cpp => SimulationPlayer.cpp} | 0 source/util/sdl/Fps.cpp | 2 +- 25 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 include/radix/Radix.hpp rename source/{Entity.cpp => SourceEntity.cpp} (96%) rename source/entities/{Player.cpp => EntitiesPlayer.cpp} (99%) rename source/simulation/{Player.cpp => SimulationPlayer.cpp} (100%) diff --git a/include/radix/Radix.hpp b/include/radix/Radix.hpp new file mode 100644 index 00000000..f890ab07 --- /dev/null +++ b/include/radix/Radix.hpp @@ -0,0 +1,11 @@ +#ifndef RADIX_HPP +#define RADIX_HPP + +#ifdef _WIN32 + // Visual Studio 2017 doesn't support these keywords + #define and && + #define not ! + #define or || +#endif + +#endif \ No newline at end of file diff --git a/include/radix/SoundManager.hpp b/include/radix/SoundManager.hpp index 58a0a09b..95e6bbfb 100644 --- a/include/radix/SoundManager.hpp +++ b/include/radix/SoundManager.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include diff --git a/include/radix/Window.hpp b/include/radix/Window.hpp index 8a683de9..7cc8633a 100644 --- a/include/radix/Window.hpp +++ b/include/radix/Window.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include diff --git a/include/radix/core/math/Vector2ui.hpp b/include/radix/core/math/Vector2ui.hpp index c7c29568..83c15a3e 100644 --- a/include/radix/core/math/Vector2ui.hpp +++ b/include/radix/core/math/Vector2ui.hpp @@ -39,10 +39,6 @@ struct Vector2ui { return x != v.x || y != v.y; } - constexpr Vector2ui operator-() const { - return Vector2ui(-x, -y); - } - constexpr Vector2ui operator+(const Vector2ui& v) const { return Vector2ui(x + v.x, y + v.y); } diff --git a/include/radix/env/Config.hpp b/include/radix/env/Config.hpp index ef108b76..1c7dffa1 100644 --- a/include/radix/env/Config.hpp +++ b/include/radix/env/Config.hpp @@ -8,6 +8,8 @@ #include using namespace json11; +#include + namespace radix { class ArgumentsParser; diff --git a/include/radix/input/InputSource.hpp b/include/radix/input/InputSource.hpp index 712c17b3..73d60241 100644 --- a/include/radix/input/InputSource.hpp +++ b/include/radix/input/InputSource.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include diff --git a/source/BaseGame.cpp b/source/BaseGame.cpp index a0572ebf..5fde2341 100644 --- a/source/BaseGame.cpp +++ b/source/BaseGame.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/source/SoundManager.cpp b/source/SoundManager.cpp index 4260523a..6a6b66da 100644 --- a/source/SoundManager.cpp +++ b/source/SoundManager.cpp @@ -1,6 +1,7 @@ #include +#include -#include +#include namespace radix { diff --git a/source/Entity.cpp b/source/SourceEntity.cpp similarity index 96% rename from source/Entity.cpp rename to source/SourceEntity.cpp index c2ee8d7c..42b5d934 100644 --- a/source/Entity.cpp +++ b/source/SourceEntity.cpp @@ -11,6 +11,10 @@ namespace radix { Entity::Entity(const CreationParams &cp) : world(cp.world), id(cp.id) { } + +entity::Entity::~Entity() { +} + Entity::~Entity() { } diff --git a/source/core/diag/AnsiConsoleLogger.cpp b/source/core/diag/AnsiConsoleLogger.cpp index f572e71d..fe23a38d 100644 --- a/source/core/diag/AnsiConsoleLogger.cpp +++ b/source/core/diag/AnsiConsoleLogger.cpp @@ -1,8 +1,12 @@ #include +#include #include #include + +#ifndef _WIN32 #include +#endif using std::cout; @@ -27,6 +31,7 @@ static const struct LogLevelOutputInfo { AnsiConsoleLogger::AnsiConsoleLogger() : enableColors(true), enableBackground(false) { +#ifndef _WIN32 const auto term = getenv("TERM"); const bool tty = isatty(fileno(stdout)); if (not tty or @@ -35,6 +40,7 @@ AnsiConsoleLogger::AnsiConsoleLogger() : // This is also what's reported by some IDEs' output window which aren't full fledged terminals enableColors = false; } +#endif } const char* AnsiConsoleLogger::getName() const { diff --git a/source/core/diag/LogInput.cpp b/source/core/diag/LogInput.cpp index fdfa614e..55379d43 100644 --- a/source/core/diag/LogInput.cpp +++ b/source/core/diag/LogInput.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace radix { diff --git a/source/core/diag/StdoutLogger.cpp b/source/core/diag/StdoutLogger.cpp index 9445e08d..0b646948 100644 --- a/source/core/diag/StdoutLogger.cpp +++ b/source/core/diag/StdoutLogger.cpp @@ -1,10 +1,11 @@ #include +#include #include namespace radix { -const char* StdoutLogger::getName() const { +const char *StdoutLogger::getName() const { return "stdout logger"; } diff --git a/source/core/event/EventDispatcher.cpp b/source/core/event/EventDispatcher.cpp index a89e97fe..f0401b69 100644 --- a/source/core/event/EventDispatcher.cpp +++ b/source/core/event/EventDispatcher.cpp @@ -1,6 +1,6 @@ #include - #include +#include static const char *Tag = "EventDispatcher"; diff --git a/source/core/math/Vector2f.cpp b/source/core/math/Vector2f.cpp index 5e5f4cd9..6e9df5b6 100644 --- a/source/core/math/Vector2f.cpp +++ b/source/core/math/Vector2f.cpp @@ -10,6 +10,7 @@ ** -------------------------------------------------------------------------*/ #include +#include #include #include diff --git a/source/core/math/Vector3f.cpp b/source/core/math/Vector3f.cpp index 0ce36bf1..021624d6 100644 --- a/source/core/math/Vector3f.cpp +++ b/source/core/math/Vector3f.cpp @@ -10,6 +10,7 @@ ** -------------------------------------------------------------------------*/ #include +#include #include #include diff --git a/source/core/math/Vector4f.cpp b/source/core/math/Vector4f.cpp index 5cd38caa..266246b5 100644 --- a/source/core/math/Vector4f.cpp +++ b/source/core/math/Vector4f.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace radix { diff --git a/source/data/screen/XmlScreenLoader.cpp b/source/data/screen/XmlScreenLoader.cpp index e1e07924..2926dbb0 100644 --- a/source/data/screen/XmlScreenLoader.cpp +++ b/source/data/screen/XmlScreenLoader.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace tinyxml2; diff --git a/source/data/shader/ShaderLoader.cpp b/source/data/shader/ShaderLoader.cpp index 602d1179..c85b9d43 100644 --- a/source/data/shader/ShaderLoader.cpp +++ b/source/data/shader/ShaderLoader.cpp @@ -149,37 +149,49 @@ void ShaderLoader::checkShader(unsigned int shader, const std::string &path, Sha } } + +int file_get_contents(const char *path, char **buffer, size_t *out_filesize) { + + FILE *file = fopen(path, "rb"); + if (file == NULL) { + *buffer = NULL; + *out_filesize = 0; + return 0; + } + size_t filesize; + fseek(file, 0, SEEK_END); + filesize = ftell(file); + *buffer = (char *)malloc(filesize + 1); // no matter what, add \0 at end + fseek(file, 0L, SEEK_SET); + fread(*buffer, filesize, 1, file); + fclose(file); + (*buffer)[filesize] = 0; // end string + if (out_filesize) + *out_filesize = filesize; + return 1; +} + unsigned int ShaderLoader::loadShader(const std::string &path, Shader::Type type) { - // Read file and point to end of file - std::ifstream file(path, std::ifstream::ate); - if (not file.is_open()) { - Util::Log(Error, "ShaderLoader") << "Could not find shader file " << path; - } - // Get file size - auto fileSize = static_cast(file.tellg()); - // Point back to beginning of the file - file.seekg(std::ifstream::beg); - - // Create buffer with file size + 1 - std::unique_ptr file_contents(new char[fileSize+1]); - // Get pointer to the buffer - char *buffer = file_contents.get(); - // Read file to buffer - file.read(buffer, static_cast(fileSize)); - // Set end of buffer to 0 - file_contents[fileSize] = 0; - // Create GL Shader GLuint shader = glCreateShader(getGlShaderType(type)); + + char *filecontent; + size_t filecontent_bytes; + int ret = file_get_contents(path.c_str(), &filecontent, &filecontent_bytes); + if (not ret) + Util::Log(Error, "ShaderLoader") << "Could not find shader file " << path; + // Read buffer to OpenGL Driver - glShaderSource(shader, 1, &buffer, NULL); + glShaderSource(shader, 1, &filecontent, NULL); // Compile Shader glCompileShader(shader); // Error checking checkShader(shader, path, type); + free(filecontent); + return shader; } diff --git a/source/entities/Player.cpp b/source/entities/EntitiesPlayer.cpp similarity index 99% rename from source/entities/Player.cpp rename to source/entities/EntitiesPlayer.cpp index 3561aea0..cdc35737 100644 --- a/source/entities/Player.cpp +++ b/source/entities/EntitiesPlayer.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include #include diff --git a/source/entities/traits/HealthTrait.cpp b/source/entities/traits/HealthTrait.cpp index 4c69a05e..757ab380 100644 --- a/source/entities/traits/HealthTrait.cpp +++ b/source/entities/traits/HealthTrait.cpp @@ -3,6 +3,7 @@ #include #include +#include namespace radix { namespace entities { diff --git a/source/env/OperatingSystem.cpp b/source/env/OperatingSystem.cpp index c313aad2..93637fb2 100644 --- a/source/env/OperatingSystem.cpp +++ b/source/env/OperatingSystem.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace radix { diff --git a/source/env/Util.cpp b/source/env/Util.cpp index bbc67e78..dcfd0029 100644 --- a/source/env/Util.cpp +++ b/source/env/Util.cpp @@ -61,7 +61,7 @@ static void WinSetThreadName(uint32_t dwThreadID, const char **threadName) { } void Util::SetCurrentThreadName(const char *name) { - DWORD threadId = ::GetThreadId(static_cast(GetCurrentThreadId())); + DWORD threadId = ::GetThreadId((HANDLE)(GetCurrentThreadId())); WinSetThreadName(threadId, &name); } #elif __APPLE__ diff --git a/source/physics/KinematicCharacterController.cpp b/source/physics/KinematicCharacterController.cpp index c1c363a1..ddf60244 100644 --- a/source/physics/KinematicCharacterController.cpp +++ b/source/physics/KinematicCharacterController.cpp @@ -30,6 +30,7 @@ what we need. #include #include +#include namespace radix { diff --git a/source/simulation/Player.cpp b/source/simulation/SimulationPlayer.cpp similarity index 100% rename from source/simulation/Player.cpp rename to source/simulation/SimulationPlayer.cpp diff --git a/source/util/sdl/Fps.cpp b/source/util/sdl/Fps.cpp index 4ee1036e..ad84d0ad 100644 --- a/source/util/sdl/Fps.cpp +++ b/source/util/sdl/Fps.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace radix {