From de7cc1f12273ae80f4d972b0dbfc48066f851684 Mon Sep 17 00:00:00 2001 From: Stephen Enders <84310577289916ceefd4132143fb36b63a5f0c71> Date: Fri, 24 Jun 2022 21:35:03 -0400 Subject: Fix compilation for Windows I left a few changes undone in the Windows API. This should be cross platform now --- src/resources/Resources.cpp | 5 +++ src/resources/Resources.h | 1 + src/resources/windows/WindowsResources.cpp | 52 ++++++++++++++++-------------- src/resources/windows/WindowsResources.h | 4 +++ 4 files changed, 38 insertions(+), 24 deletions(-) (limited to 'src/resources') diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp index 11f762f..3ae93f4 100644 --- a/src/resources/Resources.cpp +++ b/src/resources/Resources.cpp @@ -29,6 +29,11 @@ #include #include +Resources::Resources() { + this->font = std::make_shared(); + this->defaultsLua = std::make_shared(); +} + void Resources::loadFontFiles() { // We will search 1 level deep for (auto &base : this->fontSearchDirs()) { diff --git a/src/resources/Resources.h b/src/resources/Resources.h index 194c031..6e1a95f 100644 --- a/src/resources/Resources.h +++ b/src/resources/Resources.h @@ -56,6 +56,7 @@ protected: virtual vector fontSearchDirs() = 0; public: + Resources(); void loadLevels(); void loadFontFiles(); void loadDefaultLuaFile(); diff --git a/src/resources/windows/WindowsResources.cpp b/src/resources/windows/WindowsResources.cpp index cfe264f..4ef0e2e 100644 --- a/src/resources/windows/WindowsResources.cpp +++ b/src/resources/windows/WindowsResources.cpp @@ -23,32 +23,36 @@ // distribution. // //======================================================================== -#include "../Resources.h" +#include "WindowsResources.h" #include #define MAX_BUF_SIZE 1024 -class WindowsResources : public Resources { +std::filesystem::path exeDir; +std::filesystem::path workingDir; -protected: - std::filesystem::path exeDir; - std::filesystem::path workingDir; +std::vector WindowsResources::levelSearchDirs() { + return {workingDir / "maps", exeDir / "maps"}; +} +std::vector WindowsResources::defaultsSearchDirs() { + return {workingDir / "dnglib", exeDir / "dnglib"}; +} +std::vector WindowsResources::fontSearchDirs() { + return {workingDir / "res", exeDir / "res"}; +} +WindowsResources::WindowsResources() : Resources() { + this->workingDir = std::filesystem::current_path(); + this->font = std::make_shared(workingDir / "res" / + DEFAULT_FONT); - std::vector levelSearchDirs() override { - return {workingDir / "maps", exeDir / "maps"}; - } - std::vector defaultsSearchDirs() override { - return {workingDir / "dnglib", exeDir / "dnglib"}; - } - std::vector fontSearchDirs() override { - return {workingDir / "res", exeDir / "res"}; - } + char exe_dir_str[255]; + GetModuleFileNameA(nullptr, exe_dir_str, 255); + this->exeDir = std::filesystem::path{exe_dir_str}.remove_filename(); +} -public: - const char *convert_to_str(std::filesystem::path &path) override { - std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support? - const wchar_t *wstr = path.c_str(); - size_t len = std::wcslen(wstr) + 1; // gotta get that \0 - char *ret = static_cast(malloc(sizeof(char) * len)); // buffered - std::wcstombs(ret, path.c_str(), len); - return ret; - } -}; \ No newline at end of file +const char *WindowsResources::convert_to_str(std::filesystem::path &path) { + std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support? + const wchar_t *wstr = path.c_str(); + size_t len = std::wcslen(wstr) + 1; // gotta get that \0 + char *ret = static_cast(malloc(sizeof(char) * len)); // buffered + std::wcstombs(ret, path.c_str(), len); + return ret; +} diff --git a/src/resources/windows/WindowsResources.h b/src/resources/windows/WindowsResources.h index b6a1cd6..5ca662b 100644 --- a/src/resources/windows/WindowsResources.h +++ b/src/resources/windows/WindowsResources.h @@ -29,6 +29,10 @@ #include "../Resources.h" class WindowsResources : public Resources { +public: + WindowsResources(); + const char *convert_to_str(std::filesystem::path &path) override; + protected: std::filesystem::path exeDir; std::filesystem::path workingDir; -- cgit v1.2.3-54-g00ecf