From d5ec9594499266a00f9a36c0eca3e455843e302a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 1 Jun 2022 10:34:53 +0300 Subject: [PATCH] Create platform component for platform specific things --- apps/bulletobjecttool/main.cpp | 4 ++++ apps/launcher/main.cpp | 3 +++ apps/navmeshtool/main.cpp | 4 ++++ apps/opencs/main.cpp | 3 +++ apps/openmw/main.cpp | 3 +++ components/CMakeLists.txt | 4 ++++ components/platform/platform.cpp | 23 +++++++++++++++++++++++ components/platform/platform.hpp | 10 ++++++++++ 8 files changed, 54 insertions(+) create mode 100644 components/platform/platform.cpp create mode 100644 components/platform/platform.hpp diff --git a/apps/bulletobjecttool/main.cpp b/apps/bulletobjecttool/main.cpp index 973ec3ee8b..aad8c5e082 100644 --- a/apps/bulletobjecttool/main.cpp +++ b/apps/bulletobjecttool/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -26,6 +27,7 @@ #include #include + namespace { namespace bpo = boost::program_options; @@ -106,6 +108,8 @@ namespace int runBulletObjectTool(int argc, char *argv[]) { + Platform::init(); + bpo::options_description desc = makeOptionsDescription(); bpo::parsed_options options = bpo::command_line_parser(argc, argv) diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 4e054867f4..57b8ee4b78 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #ifdef MAC_OS_X_VERSION_MIN_REQUIRED #undef MAC_OS_X_VERSION_MIN_REQUIRED @@ -16,6 +17,8 @@ int runLauncher(int argc, char *argv[]) { + Platform::init(); + try { QApplication app(argc, argv); diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index 9b49fa2fff..c1f8a8e90a 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -36,6 +37,7 @@ #include #endif + namespace NavMeshTool { namespace @@ -102,6 +104,8 @@ namespace NavMeshTool int runNavMeshTool(int argc, char *argv[]) { + Platform::init(); + bpo::options_description desc = makeOptionsDescription(); bpo::parsed_options options = bpo::command_line_parser(argc, argv) diff --git a/apps/opencs/main.cpp b/apps/opencs/main.cpp index 1e6e718983..a15ab17fa2 100644 --- a/apps/opencs/main.cpp +++ b/apps/opencs/main.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "model/doc/messages.hpp" #include "model/world/universalid.hpp" @@ -43,6 +44,8 @@ class Application : public QApplication int runApplication(int argc, char *argv[]) { + Platform::init(); + #ifdef Q_OS_MAC setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0); #endif diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index e73dac113c..730342cacb 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "mwgui/debugwindow.hpp" @@ -207,6 +208,8 @@ namespace int runApplication(int argc, char *argv[]) { + Platform::init(); + #ifdef __APPLE__ std::filesystem::path binary_path = std::filesystem::system_complete(std::filesystem::path(argv[0])); std::filesystem::current_path(binary_path.parent_path()); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 1465d9c3f2..779c8d28f5 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -335,6 +335,10 @@ add_component_dir(navmeshtool protocol ) +add_component_dir(platform + platform + ) + set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui ) diff --git a/components/platform/platform.cpp b/components/platform/platform.cpp new file mode 100644 index 0000000000..9044ba3792 --- /dev/null +++ b/components/platform/platform.cpp @@ -0,0 +1,23 @@ +#include "platform.hpp" + +#include + +namespace Platform { + + static void increaseFileHandleLimit() + { +#ifdef WIN32 + // Increase limit for open files at the stream I/O level, see + // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmaxstdio?view=msvc-170#remarks + _setmaxstdio(8192); +#else + // No-op on any other platform. +#endif + } + + void init() + { + increaseFileHandleLimit(); + } + +} diff --git a/components/platform/platform.hpp b/components/platform/platform.hpp new file mode 100644 index 0000000000..d8f2058217 --- /dev/null +++ b/components/platform/platform.hpp @@ -0,0 +1,10 @@ +#ifndef OPENMW_COMPONENTS_PLATFORM_PLATFORM_HPP +#define OPENMW_COMPONENTS_PLATFORM_PLATFORM_HPP + +namespace Platform { + + void init(); + +} + +#endif // OPENMW_COMPONENTS_PLATFORM_PLATFORM_HPP