summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteph Enders <smenders@gmail.com>2022-06-27 17:45:44 -0400
committerSteph Enders <smenders@gmail.com>2022-06-27 17:45:44 -0400
commit38d46b2dda0243cfa60bc6945859ebd587e0a851 (patch)
tree3af0286199c6075ad50c36f2218c1c303f9fa921
parent734ee0f6352fdb6077c142d90f191c11c32f98d2 (diff)
Update MacOS to compile w/ Boost
MacOS seems to rely on an older/different C++ stdlib than Windows or Linux. So replacing those with Boost equivalents. Mostly contained to the Resources thankfully!
-rw-r--r--.gitmodules4
-rw-r--r--CMakeLists.txt18
-rw-r--r--src/CApi.h9
-rw-r--r--src/main.cpp3
-rw-r--r--src/resources/Resources.cpp81
-rw-r--r--src/resources/Resources.h41
-rw-r--r--src/resources/macos/MacResources.cpp20
-rw-r--r--src/resources/macos/MacResources.h14
m---------thirdparty/boost0
-rw-r--r--thirdparty/thirdparty-licenses.txt28
10 files changed, 137 insertions, 81 deletions
diff --git a/.gitmodules b/.gitmodules
index 93b742b..1d578d9 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -6,3 +6,7 @@
path = thirdparty/lua
url = https://github.com/lua/lua
branch = v5.4.0-patch
+[submodule "thirdparty/boost"]
+ path = thirdparty/boost
+ url = https://github.com/s3nd3r5/boost
+ branch = v1.79.0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index acf9809..2445f08 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,9 @@ set(CMAKE_CXX_STANDARD 20)
if (WIN32)
set(CMAKE_CXX_FLAGS -static)
endif ()
+if (APPLE)
+ set(CMAKE_CXX_FLAGS -std=c++11) # why? Because apparently we can't modernize
+endif ()
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION})
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)
@@ -56,8 +59,17 @@ target_link_libraries(lauxlib lua)
set(LUA_LIBRARIES lua lualib lauxlib)
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/lua)
+# setup boost and other MacOS Libs
+set(MACOS_LIBS "")
+if (APPLE)
+ set(DNG_BOOST_DIR ${CMAKE_SOURCE_DIR}/thirdparty/boost)
+ set(BOOST_ROOT ${DNG_BOOST_DIR}/tools/cmake/include/)
+ add_subdirectory(${DNG_BOOST_DIR} EXCLUDE_FROM_ALL)
+ set(MACOS_LIBS ${MACOS_LIBS} Boost::filesystem Boost::optional)
+endif ()
+
# System specific includes
-if (UNIX AND NOT APPLE)
+if (UNIX AND NOT APPLE)
set(RES_LIB src/resources/Resources.cpp src/resources/Resources.h src/resources/linux/LinuxResources.cpp src/resources/linux/LinuxResources.h)
elseif (WIN32)
set(RES_LIB src/resources/Resources.cpp src/resources/Resources.h src/resources/windows/WindowsResources.cpp src/resources/windows/WindowsResources.h)
@@ -66,7 +78,6 @@ elseif (APPLE)
endif ()
add_executable(${PROJECT_NAME} src/main.cpp src/Level.cpp src/Level.h src/CApi.h src/Scene.h src/LuaApi.h src/MessageBox.h ${RES_LIB})
-target_link_libraries(${PROJECT_NAME} PUBLIC ${LUA_LIBRARIES})
# configure and link SFML
set(BUILD_SHARED_LIBS FALSE)
@@ -77,11 +88,10 @@ if (WIN32)
endif ()
set(SFML_USE_SYSTEM_DEPS ON)
add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/SFML EXCLUDE_FROM_ALL)
-target_link_libraries(${PROJECT_NAME} PUBLIC ${SFML_LIBRARIES} ${LUA_LIBRARIES})
+target_link_libraries(${PROJECT_NAME} PUBLIC ${SFML_LIBRARIES} ${LUA_LIBRARIES} ${MACOS_LIBS})
# Install Directives
-
if (UNIX)
set(SFML_INSTALL_PKGCONFIG_FILES FALSE)
endif ()
diff --git a/src/CApi.h b/src/CApi.h
index 21ad9eb..4d35939 100644
--- a/src/CApi.h
+++ b/src/CApi.h
@@ -203,7 +203,16 @@ static int c_get_treasures(lua_State *L) {
static int c_score_treasure(lua_State *L) {
int id = static_cast<int>(lua_tonumber(L, -1));
+#ifdef __APPLE__
+ for (int i = 0; i < lvl->treasurePositions.size(); i++) {
+ if (lvl->treasurePositions[i].id == id) {
+ lvl->treasurePositions.erase(lvl->treasurePositions.begin() + i);
+ break;
+ }
+ }
+#else
erase_if(lvl->treasurePositions, [id](Pos t) { return t.id == id; });
+#endif
return 1;
}
diff --git a/src/main.cpp b/src/main.cpp
index c8d7b2d..38208ec 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -59,6 +59,9 @@ int main(int argc, char **argv) {
#ifdef _WIN32
Resources *res = new WindowsResources();
#endif
+#ifdef __APPLE__
+ Resources *res = new MacResources();
+#endif
res->loadDefaultLuaFile();
res->loadFontFiles();
res->loadLevels();
diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp
index ee43002..60ea836 100644
--- a/src/resources/Resources.cpp
+++ b/src/resources/Resources.cpp
@@ -30,50 +30,50 @@
#include <iostream>
Resources::Resources() {
- this->font = std::make_shared<fs::path>();
- this->defaultsLua = std::make_shared<fs::path>();
+ this->font = std::make_shared<filesystem::path>();
+ this->defaultsLua = std::make_shared<filesystem::path>();
}
void Resources::loadFontFiles() {
// We will search 1 level deep
for (auto &base : this->fontSearchDirs()) {
- if (fs::exists(base) && fs::is_directory(base)) {
- for (auto &item : fs::directory_iterator(base)) {
+ if (filesystem::exists(base) && filesystem::is_directory(base)) {
+ for (auto &item : filesystem::directory_iterator(base)) {
// only 1 deep
- if (item.exists() && item.is_directory()) {
- for (auto &file : fs::directory_iterator(item)) {
- if (file.exists() && file.is_regular_file()) {
- auto ext = file.path().extension();
+ if (filesystem::exists(item) && filesystem::is_directory(item)) {
+ for (auto &file : filesystem::directory_iterator(item)) {
+ if (filesystem::exists(file) && filesystem::is_regular_file(file)) {
+ auto ext = filesystem::path(file).extension();
bool matched =
std::any_of(std::begin(FONT_TYPES), std::end(FONT_TYPES),
[ext](auto &supported) {
return supported == ext.generic_string();
});
if (matched) {
- fonts.push_back(file.path());
+ fonts.emplace_back(file);
// set default if not set
- if (!exists(*this->font) ||
- !is_regular_file(*this->font) &&
- file.path().filename() == DEFAULT_FONT) {
- *this->font = file.path();
+ if ((!filesystem::exists(*this->font) ||
+ !filesystem::is_regular_file(*this->font)) &&
+ filesystem::path(file).filename() == DEFAULT_FONT) {
+ *this->font = filesystem::path(file);
}
}
}
}
- } else if (item.is_regular_file()) {
- auto ext = item.path().extension();
+ } else if (filesystem::is_regular_file(item)) {
+ auto ext = filesystem::path(item).extension();
bool matched =
std::any_of(std::begin(FONT_TYPES), std::end(FONT_TYPES),
[ext](auto &supported) {
return supported == ext.generic_string();
});
if (matched) {
- fonts.push_back(item.path());
+ fonts.emplace_back(item);
// set default if not set
- if (!exists(*this->font) ||
- !is_regular_file(*this->font) &&
- item.path().filename() == DEFAULT_FONT) {
- *this->font = item.path();
+ if ((!filesystem::exists(*this->font) ||
+ !filesystem::is_regular_file(*this->font)) &&
+ filesystem::path(item).filename() == DEFAULT_FONT) {
+ *this->font = filesystem::path(item);
}
}
}
@@ -84,11 +84,11 @@ void Resources::loadFontFiles() {
void Resources::loadLevels() {
for (auto &base : this->levelSearchDirs()) {
- if (fs::exists(base) && fs::is_directory(base)) {
- for (auto &dir : fs::directory_iterator(base)) {
- if (dir.exists() && dir.is_directory()) {
- if (fs::exists(dir / DNG_MAP)) {
- this->levels.push_back(dir.path());
+ if (filesystem::exists(base) && filesystem::is_directory(base)) {
+ for (auto &dir : filesystem::directory_iterator(base)) {
+ if (filesystem::exists(dir) && filesystem::is_directory(dir)) {
+ if (filesystem::exists(dir / DNG_MAP)) {
+ this->levels.emplace_back(dir);
}
}
}
@@ -99,36 +99,43 @@ void Resources::loadLevels() {
void Resources::loadDefaultLuaFile() {
for (auto &base : this->defaultsSearchDirs()) {
auto f = base / DEFAULT_LUA;
- if (fs::exists(f)) {
+ if (filesystem::exists(f)) {
*this->defaultsLua = f;
break;
}
}
}
-std::vector<fs::path> Resources::getFontFiles() { return this->fonts; }
-std::vector<fs::path> Resources::getLevels() { return this->levels; }
-shared_ptr<fs::path> Resources::getFontFile() { return this->font; }
-shared_ptr<fs::path> Resources::updateFont(int idx) {
+std::vector<filesystem::path> Resources::getFontFiles() { return this->fonts; }
+std::vector<filesystem::path> Resources::getLevels() { return this->levels; }
+std::shared_ptr<filesystem::path> Resources::getFontFile() {
+ return this->font;
+}
+std::shared_ptr<filesystem::path> Resources::updateFont(int idx) {
auto f = this->fonts[idx];
*this->font = f;
return getFontFile();
}
-shared_ptr<fs::path> Resources::getDefaultsLuaFile() {
+std::shared_ptr<filesystem::path> Resources::getDefaultsLuaFile() {
return this->defaultsLua;
}
-shared_ptr<fs::path> Resources::getLevelMap(int idx) {
+std::shared_ptr<filesystem::path> Resources::getLevelMap(int idx) {
auto lvlBase = this->levels[idx];
- fs::path dngMap = lvlBase / DNG_MAP;
+ filesystem::path dngMap = lvlBase / DNG_MAP;
// existence of the level dng.map is asserted in the initializer
- assert(fs::exists(dngMap));
- return std::make_shared<fs::path>(dngMap);
+ assert(filesystem::exists(dngMap));
+ return std::make_shared<filesystem::path>(dngMap);
}
-std::optional<shared_ptr<fs::path>> Resources::getLevelProcLua(int idx) {
+optional<std::shared_ptr<filesystem::path>>
+Resources::getLevelProcLua(int idx) {
auto lvlBase = this->levels[idx];
auto procLua = lvlBase / PROC_LUA;
if (exists(procLua)) {
- return std::make_shared<fs::path>(procLua);
+ return std::make_shared<filesystem::path>(procLua);
} else {
+#ifdef __APPLE__
+ return boost::optional<std::shared_ptr<filesystem::path>>();
+#else
return nullopt;
+#endif
}
} \ No newline at end of file
diff --git a/src/resources/Resources.h b/src/resources/Resources.h
index 2e0e7c0..c307c1b 100644
--- a/src/resources/Resources.h
+++ b/src/resources/Resources.h
@@ -29,13 +29,15 @@
#define DNG_RESOURCES_H
#ifdef __APPLE__
-#include <experimental/filesystem>
-namespace fs = std::experimental::filesystem;
+#include "boost/filesystem.hpp"
+#include "boost/optional.hpp"
+using namespace boost;
#else
#include <filesystem>
-namespace fs = std::filesystem;
-#endif
#include <optional>
+using namespace std;
+#endif
+#include <memory>
#include <vector>
// struct LevelInfo {
@@ -43,9 +45,8 @@ namespace fs = std::filesystem;
// filesystem::path dngMap;
// optional<filesystem::path> procLua;
// };
-using namespace std;
-static const string FONT_TYPES[] = {".otf", ".ttf"};
+static const std::string FONT_TYPES[] = {".otf", ".ttf"};
static const filesystem::path DEFAULT_LUA{"defaults.lua"};
static const filesystem::path DNG_MAP{"dng.map"};
static const filesystem::path PROC_LUA{"proc.lua"};
@@ -54,26 +55,26 @@ static const char *DEFAULT_FONT = "PressStart2P-vaV7.ttf";
class Resources {
protected:
- shared_ptr<fs::path> font; // chosen font
- shared_ptr<filesystem::path> defaultsLua; // defaults lua file
- vector<filesystem::path> fonts; // all found maps
- vector<filesystem::path> levels; // all found maps
- virtual vector<filesystem::path> levelSearchDirs() = 0;
- virtual vector<filesystem::path> defaultsSearchDirs() = 0;
- virtual vector<filesystem::path> fontSearchDirs() = 0;
+ std::shared_ptr<filesystem::path> font; // chosen font
+ std::shared_ptr<filesystem::path> defaultsLua; // defaults lua file
+ std::vector<filesystem::path> fonts; // all found maps
+ std::vector<filesystem::path> levels; // all found maps
+ virtual std::vector<filesystem::path> levelSearchDirs() = 0;
+ virtual std::vector<filesystem::path> defaultsSearchDirs() = 0;
+ virtual std::vector<filesystem::path> fontSearchDirs() = 0;
public:
Resources();
void loadLevels();
void loadFontFiles();
void loadDefaultLuaFile();
- vector<filesystem::path> getFontFiles();
- vector<filesystem::path> getLevels();
- shared_ptr<fs::path> updateFont(int idx);
- shared_ptr<fs::path> getFontFile();
- shared_ptr<fs::path> getDefaultsLuaFile();
- shared_ptr<fs::path> getLevelMap(int idx);
- optional<shared_ptr<fs::path>> getLevelProcLua(int idx);
+ std::vector<filesystem::path> getFontFiles();
+ std::vector<filesystem::path> getLevels();
+ std::shared_ptr<filesystem::path> updateFont(int idx);
+ std::shared_ptr<filesystem::path> getFontFile();
+ std::shared_ptr<filesystem::path> getDefaultsLuaFile();
+ std::shared_ptr<filesystem::path> getLevelMap(int idx);
+ optional<std::shared_ptr<filesystem::path>> getLevelProcLua(int idx);
/* Helper method to convert any path to a const char *
* Windows uses wchar_t so this can help provide a common way to
* interact with files
diff --git a/src/resources/macos/MacResources.cpp b/src/resources/macos/MacResources.cpp
index 2b41daa..9ae3499 100644
--- a/src/resources/macos/MacResources.cpp
+++ b/src/resources/macos/MacResources.cpp
@@ -26,28 +26,26 @@
//========================================================================
#include "MacResources.h"
-namespace fs = std::experimental::filesystem;
MacResources::MacResources() : Resources() {
- this->workingDir = std::filesystem::current_path();
- this->exeDir = std::filesystem::canonical("/proc/self/exe").remove_filename();
+ this->workingDir = filesystem::current_path();
+ this->exeDir = filesystem::canonical("/proc/self/exe").remove_filename();
// set an initial value - will get hardset in load if found
- std::filesystem::path f =
- workingDir / "res" / DEFAULT_FONT; // default as fallback
- this->font = std::make_shared<std::filesystem::path>(f);
- this->defaultsLua = std::make_shared<std::filesystem::path>();
+ filesystem::path f = workingDir / "res" / DEFAULT_FONT; // default as fallback
+ this->font = std::make_shared<filesystem::path>(f);
+ this->defaultsLua = std::make_shared<filesystem::path>();
}
-std::vector<std::filesystem::path> MacResources::levelSearchDirs() {
+std::vector<filesystem::path> MacResources::levelSearchDirs() {
return {workingDir / "maps", exeDir / "maps"};
}
-std::vector<std::filesystem::path> MacResources::defaultsSearchDirs() {
+std::vector<filesystem::path> MacResources::defaultsSearchDirs() {
return {workingDir / "dnglib", exeDir / "dnglib"};
}
-std::vector<std::filesystem::path> MacResources::fontSearchDirs() {
+std::vector<filesystem::path> MacResources::fontSearchDirs() {
return {workingDir / "res", exeDir / "res"};
}
-const char *MacResources::convert_to_str(std::filesystem::path &path) {
+const char *MacResources::convert_to_str(filesystem::path &path) {
return path.c_str();
}
diff --git a/src/resources/macos/MacResources.h b/src/resources/macos/MacResources.h
index 1d19575..4cb66cd 100644
--- a/src/resources/macos/MacResources.h
+++ b/src/resources/macos/MacResources.h
@@ -29,21 +29,19 @@
#define DNG_MACRESOURCES_H
#include "../Resources.h"
-namespace fs = std::experimental::filesystem;
-
class MacResources : public Resources {
public:
MacResources();
protected:
public:
- const char *convert_to_str(fs::path &path) override;
+ const char *convert_to_str(filesystem::path &path) override;
protected:
- fs::path exeDir;
- fs::path workingDir;
- std::vector<fs::path> levelSearchDirs() override;
- std::vector<fs::path> defaultsSearchDirs() override;
- std::vector<fs::path> fontSearchDirs() override;
+ filesystem::path exeDir;
+ filesystem::path workingDir;
+ std::vector<filesystem::path> levelSearchDirs() override;
+ std::vector<filesystem::path> defaultsSearchDirs() override;
+ std::vector<filesystem::path> fontSearchDirs() override;
};
#endif // DNG_MACRESOURCES_H
diff --git a/thirdparty/boost b/thirdparty/boost
new file mode 160000
+Subproject fff1e12ce3b6af359c40ebafc2d8d05091ddbc8
diff --git a/thirdparty/thirdparty-licenses.txt b/thirdparty/thirdparty-licenses.txt
index 5e1adac..cf307e2 100644
--- a/thirdparty/thirdparty-licenses.txt
+++ b/thirdparty/thirdparty-licenses.txt
@@ -247,4 +247,30 @@ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
DEALINGS IN THE FONT SOFTWARE.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-
+dng uses Boost Filesystem on MacOS - licensed under boost software license
+-------------------------------------------------------------------------------
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+-------------------------------------------------------------------------------
+-------------------------------------------------------------------------------