mirror of
https://github.com/stenzek/duckstation.git
synced 2026-04-11 16:43:10 +00:00
Misc: Remove platform_misc.h completely
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
#include "util/cd_image.h"
|
||||
#include "util/http_downloader.h"
|
||||
#include "util/imgui_manager.h"
|
||||
#include "util/platform_misc.h"
|
||||
#include "util/state_wrapper.h"
|
||||
|
||||
#include "IconsEmoji.h"
|
||||
@@ -3274,6 +3273,8 @@ const Achievements::ProgressDatabase::Entry* Achievements::ProgressDatabase::Loo
|
||||
|
||||
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
|
||||
|
||||
#include "util/input_manager.h" // Host::GetTopLevelWindowInfo()
|
||||
|
||||
#include "common/windows_headers.h"
|
||||
|
||||
#include "rc_client_raintegration.h"
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "util/imgui_manager.h"
|
||||
#include "util/ini_settings_interface.h"
|
||||
#include "util/input_manager.h"
|
||||
#include "util/platform_misc.h"
|
||||
#include "util/sdl_input_source.h"
|
||||
#include "util/translation.h"
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
#include "util/cd_image.h"
|
||||
#include "util/gpu_device.h"
|
||||
#include "util/platform_misc.h"
|
||||
#include "util/translation.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
#include "util/imgui_manager.h"
|
||||
#include "util/ini_settings_interface.h"
|
||||
#include "util/input_manager.h"
|
||||
#include "util/platform_misc.h"
|
||||
#include "util/postprocessing.h"
|
||||
#include "util/translation.h"
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "core/gpu_thread.h"
|
||||
|
||||
#include "util/gpu_device.h"
|
||||
#include "util/platform_misc.h"
|
||||
|
||||
#include "common/error.h"
|
||||
#include "common/log.h"
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "util/gpu_device.h"
|
||||
#include "util/imgui_manager.h"
|
||||
#include "util/input_manager.h"
|
||||
#include "util/platform_misc.h"
|
||||
#include "util/translation.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
@@ -52,7 +52,6 @@ add_library(util
|
||||
media_capture.h
|
||||
page_fault_handler.cpp
|
||||
page_fault_handler.h
|
||||
platform_misc.h
|
||||
postprocessing.cpp
|
||||
postprocessing.h
|
||||
postprocessing_shader.cpp
|
||||
@@ -246,7 +245,6 @@ if(WIN32)
|
||||
dinput_source.cpp
|
||||
dinput_source.h
|
||||
http_downloader_winhttp.cpp
|
||||
platform_misc_win32.cpp
|
||||
win32_raw_input_source.cpp
|
||||
win32_raw_input_source.h
|
||||
xinput_source.cpp
|
||||
@@ -266,7 +264,6 @@ elseif(APPLE)
|
||||
metal_device.mm
|
||||
metal_stream_buffer.h
|
||||
metal_stream_buffer.mm
|
||||
platform_misc_mac.mm
|
||||
)
|
||||
set(METAL_SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/metal_shaders.metal"
|
||||
@@ -279,10 +276,6 @@ elseif(APPLE)
|
||||
target_link_libraries(util PRIVATE ${METAL_LIBRARY} ${QUARTZCORE_LIBRARY} ${IOK_LIBRARY})
|
||||
set_source_files_properties(${MAC_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
|
||||
elseif(NOT ANDROID)
|
||||
target_sources(util PRIVATE
|
||||
platform_misc_unix.cpp
|
||||
)
|
||||
|
||||
if(LINUX)
|
||||
target_link_libraries(util PRIVATE UDEV::UDEV)
|
||||
endif()
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include "dinput_source.h"
|
||||
#include "input_manager.h"
|
||||
#include "platform_misc.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/bitutils.h"
|
||||
|
||||
@@ -427,4 +427,7 @@ void OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier)
|
||||
/// Enables "relative" mouse mode, locking the cursor position and returning relative coordinates.
|
||||
void SetMouseMode(bool relative, bool hide_cursor);
|
||||
|
||||
/// Return the current window handle. Needed for DInput.
|
||||
std::optional<WindowInfo> GetTopLevelWindowInfo();
|
||||
|
||||
} // namespace Host
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#include "window_info.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
class Error;
|
||||
|
||||
namespace PlatformMisc {
|
||||
|
||||
bool InitializeSocketSupport(Error* error);
|
||||
|
||||
} // namespace PlatformMisc
|
||||
|
||||
namespace Host {
|
||||
|
||||
/// Return the current window handle. Needed for DInput.
|
||||
std::optional<WindowInfo> GetTopLevelWindowInfo();
|
||||
|
||||
} // namespace Host
|
||||
@@ -1,27 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
// Normally, system includes come last. But apparently some of our macro names are redefined...
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
#include <cinttypes>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "platform_misc.h"
|
||||
#include "window_info.h"
|
||||
|
||||
#include "common/error.h"
|
||||
#include "common/log.h"
|
||||
#include "common/small_string.h"
|
||||
|
||||
LOG_CHANNEL(PlatformMisc);
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
#error ARC should not be enabled.
|
||||
#endif
|
||||
|
||||
bool PlatformMisc::InitializeSocketSupport(Error* error)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors.
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#include "input_manager.h"
|
||||
#include "platform_misc.h"
|
||||
|
||||
#include "common/dynamic_library.h"
|
||||
#include "common/error.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
#include "common/scoped_guard.h"
|
||||
#include "common/small_string.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <mutex>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
LOG_CHANNEL(PlatformMisc);
|
||||
|
||||
bool PlatformMisc::InitializeSocketSupport(Error* error)
|
||||
{
|
||||
// Ignore SIGPIPE, we handle errors ourselves.
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||
{
|
||||
Error::SetErrno(error, "signal(SIGPIPE, SIG_IGN) failed: ", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#include "platform_misc.h"
|
||||
|
||||
#include "common/error.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/log.h"
|
||||
#include "common/small_string.h"
|
||||
#include "common/string_util.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
#include "common/windows_headers.h"
|
||||
#include <Psapi.h>
|
||||
#include <WinSock2.h>
|
||||
|
||||
LOG_CHANNEL(PlatformMisc);
|
||||
|
||||
static bool s_screensaver_suspended = false;
|
||||
static bool s_winsock_initialized = false;
|
||||
static std::once_flag s_winsock_initializer;
|
||||
|
||||
bool PlatformMisc::InitializeSocketSupport(Error* error)
|
||||
{
|
||||
std::call_once(
|
||||
s_winsock_initializer,
|
||||
[](Error* error) {
|
||||
WSADATA wsa = {};
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
{
|
||||
Error::SetSocket(error, "WSAStartup() failed: ", WSAGetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
s_winsock_initialized = true;
|
||||
std::atexit([]() { WSACleanup(); });
|
||||
return true;
|
||||
},
|
||||
error);
|
||||
|
||||
return s_winsock_initialized;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#include "sockets.h"
|
||||
#include "platform_misc.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/log.h"
|
||||
@@ -61,6 +60,76 @@ using nfds_t = ULONG;
|
||||
|
||||
LOG_CHANNEL(Sockets);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
namespace {
|
||||
class WinsockInitializer
|
||||
{
|
||||
public:
|
||||
~WinsockInitializer();
|
||||
|
||||
bool Initialize(Error* error);
|
||||
|
||||
private:
|
||||
bool m_initialized = false;
|
||||
std::once_flag m_init_flag;
|
||||
};
|
||||
|
||||
WinsockInitializer::~WinsockInitializer()
|
||||
{
|
||||
if (m_initialized)
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
bool WinsockInitializer::Initialize(Error* error)
|
||||
{
|
||||
std::call_once(
|
||||
m_init_flag,
|
||||
[this](Error* error) {
|
||||
WSADATA wsa = {};
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
Error::SetSocket(error, "WSAStartup() failed: ", WSAGetLastError());
|
||||
|
||||
m_initialized = true;
|
||||
},
|
||||
error);
|
||||
|
||||
if (error && !error->IsValid())
|
||||
error->SetStringView("Previous initialization failed.");
|
||||
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
static WinsockInitializer s_winsock_initializer;
|
||||
|
||||
}; // namespace
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
bool SocketMultiplexer::GlobalInitialize(Error* error)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
|
||||
return s_winsock_initializer.Initialize(error);
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
// Ignore SIGPIPE, we handle errors ourselves.
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||
{
|
||||
Error::SetErrno(error, "signal(SIGPIPE, SIG_IGN) failed: ", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
#else
|
||||
|
||||
return true;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool SetNonBlocking(SocketDescriptor sd, Error* error)
|
||||
{
|
||||
// switch to nonblocking mode
|
||||
@@ -244,7 +313,7 @@ SocketMultiplexer::~SocketMultiplexer()
|
||||
std::unique_ptr<SocketMultiplexer> SocketMultiplexer::Create(Error* error)
|
||||
{
|
||||
std::unique_ptr<SocketMultiplexer> ret;
|
||||
if (PlatformMisc::InitializeSocketSupport(error))
|
||||
if (GlobalInitialize(error))
|
||||
{
|
||||
ret = std::unique_ptr<SocketMultiplexer>(new SocketMultiplexer());
|
||||
if (!ret->Initialize(error))
|
||||
|
||||
@@ -100,6 +100,9 @@ public:
|
||||
public:
|
||||
~SocketMultiplexer();
|
||||
|
||||
// Process-wide setup. Can be called to use sockets in other libraries, otherwise will be called automatically.
|
||||
static bool GlobalInitialize(Error* error);
|
||||
|
||||
// Factory method.
|
||||
static std::unique_ptr<SocketMultiplexer> Create(Error* error);
|
||||
|
||||
|
||||
@@ -197,7 +197,6 @@
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="platform_misc_win32.cpp" />
|
||||
<ClCompile Include="postprocessing.cpp" />
|
||||
<ClCompile Include="postprocessing_shader.cpp" />
|
||||
<ClCompile Include="postprocessing_shader_fx.cpp" />
|
||||
|
||||
@@ -106,7 +106,6 @@
|
||||
<ClCompile Include="imgui_manager.cpp" />
|
||||
<ClCompile Include="postprocessing.cpp" />
|
||||
<ClCompile Include="postprocessing_shader.cpp" />
|
||||
<ClCompile Include="platform_misc_win32.cpp" />
|
||||
<ClCompile Include="sdl_input_source.cpp" />
|
||||
<ClCompile Include="win32_raw_input_source.cpp" />
|
||||
<ClCompile Include="xinput_source.cpp" />
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "win32_raw_input_source.h"
|
||||
#include "input_manager.h"
|
||||
#include "platform_misc.h"
|
||||
|
||||
#include "core/gpu_thread.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user