refactor: Enhance service architecture by introducing IPlatformService and updating dependencies

- Removed core/platform.hpp and core/vulkan_utils.cpp, integrating their functionality into new platform_service implementations.
- Updated service registrations to utilize IPlatformService for improved modularity.
- Refactored event bus usage across services to leverage IEventBus interface.
- Enhanced buffer management in BufferService with detailed logging and error handling.
- Updated GUI rendering services to utilize buffer service for resource management.
- Cleaned up includes and improved overall code organization for better maintainability.
This commit is contained in:
2026-01-04 17:43:18 +00:00
parent 1e6be869e0
commit 00a359d85f
23 changed files with 254 additions and 220 deletions

View File

@@ -0,0 +1,80 @@
#include "platform_service.hpp"
#include <cstdlib>
#include <utility>
#ifdef _WIN32
#include <windows.h>
#endif
namespace sdl3cpp::services::impl {
PlatformService::PlatformService(std::shared_ptr<ILogger> logger)
: logger_(std::move(logger)) {
}
std::optional<std::filesystem::path> PlatformService::GetUserConfigDirectory() const {
if (logger_) {
logger_->Trace("PlatformService", "GetUserConfigDirectory");
}
#ifdef _WIN32
if (const char* appData = std::getenv("APPDATA")) {
return std::filesystem::path(appData) / "sdl3cpp";
}
#else
if (const char* xdgConfig = std::getenv("XDG_CONFIG_HOME")) {
return std::filesystem::path(xdgConfig) / "sdl3cpp";
}
if (const char* home = std::getenv("HOME")) {
return std::filesystem::path(home) / ".config" / "sdl3cpp";
}
#endif
return std::nullopt;
}
#ifdef _WIN32
std::string PlatformService::FormatWin32Error(unsigned long errorCode) const {
if (errorCode == ERROR_SUCCESS) {
return "ERROR_SUCCESS";
}
LPSTR buffer = nullptr;
DWORD length = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&buffer),
0,
nullptr
);
std::string message;
if (length > 0 && buffer != nullptr) {
message = std::string(buffer, length);
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
message.pop_back();
}
LocalFree(buffer);
} else {
message = "(FormatMessage failed)";
}
return message;
}
#endif
std::string PlatformService::GetPlatformError() const {
if (logger_) {
logger_->Trace("PlatformService", "GetPlatformError");
}
#ifdef _WIN32
DWORD win32Error = ::GetLastError();
if (win32Error != ERROR_SUCCESS) {
return "Win32 error " + std::to_string(win32Error) + ": " + FormatWin32Error(win32Error);
}
return "No platform error";
#else
return "No platform error";
#endif
}
} // namespace sdl3cpp::services::impl