Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main_wiiu
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Jun 3, 2024
2 parents 606190d + 88da619 commit b5c2fa0
Show file tree
Hide file tree
Showing 48 changed files with 832 additions and 497 deletions.
2 changes: 0 additions & 2 deletions cmake/cvars.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set(CVAR_VSYNC_ENABLED "gVsyncEnabled" CACHE STRING "")
set(CVAR_Z_FIGHTING_MODE "gZFightingMode" CACHE STRING "")
set(CVAR_DISABLE_CLOSE_COLOR_WRAP "gDisableCloseColorWrap" CACHE STRING "")
set(CVAR_NEW_FILE_DROPPED "gNewFileDropped" CACHE STRING "")
set(CVAR_DROPPED_FILE "gDroppedFile" CACHE STRING "")
set(CVAR_INTERNAL_RESOLUTION "gInternalResolution" CACHE STRING "")
Expand All @@ -24,7 +23,6 @@ set(CVAR_PREFIX_ADVANCED_RESOLUTION "gAdvancedResolution" CACHE STRING "")
add_compile_definitions(
CVAR_VSYNC_ENABLED="${CVAR_VSYNC_ENABLED}"
CVAR_Z_FIGHTING_MODE="${CVAR_Z_FIGHTING_MODE}"
CVAR_DISABLE_CLOSE_COLOR_WRAP="${CVAR_DISABLE_CLOSE_COLOR_WRAP}"
CVAR_NEW_FILE_DROPPED="${CVAR_NEW_FILE_DROPPED}"
CVAR_DROPPED_FILE="${CVAR_DROPPED_FILE}"
CVAR_INTERNAL_RESOLUTION="${CVAR_INTERNAL_RESOLUTION}"
Expand Down
34 changes: 13 additions & 21 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <unordered_map>
#include <any>
#include "utils/StringHelper.h"
#include "Context.h"

#ifdef __APPLE__
#include "graphic/Fast3D/gfx_metal.h"
Expand Down Expand Up @@ -245,50 +246,41 @@ void Config::SetAudioBackend(AudioBackend backend) {

WindowBackend Config::GetWindowBackend() {
WindowBackend backend;
int backendId = GetInt("Window.Backend.Id", -1);
if (backendId != -1 && backendId < static_cast<int>(WindowBackend::BACKEND_COUNT)) {
auto backendId = GetInt("Window.Backend.Id", -1);
if (Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(backendId)) {
return static_cast<WindowBackend>(backendId);
}

SPDLOG_TRACE("Could not find WindowBackend matching id from config file ({}). Returning default WindowBackend.",
backendId);
#ifdef ENABLE_DX12
return WindowBackend::DX12;
#endif
SPDLOG_TRACE(
"Could not find available WindowBackend matching id from config file ({}). Returning default WindowBackend.",
backendId);
#ifdef ENABLE_DX11
return WindowBackend::DX11;
return WindowBackend::FAST3D_DXGI_DX11;
#endif
#ifdef __WIIU__
return WindowBackend::GX2;
return WindowBackend::FAST3D_WIIU_GX2;
#endif
#ifdef __APPLE__
if (Metal_IsSupported()) {
return WindowBackend::SDL_METAL;
return WindowBackend::FAST3D_SDL_METAL;
}
#endif
return WindowBackend::SDL_OPENGL;
return WindowBackend::FAST3D_SDL_OPENGL;
}

void Config::SetWindowBackend(WindowBackend backend) {
SetInt("Window.Backend.Id", static_cast<int>(backend));

switch (backend) {
case WindowBackend::DX11:
case WindowBackend::FAST3D_DXGI_DX11:
SetString("Window.Backend.Name", "DirectX 11");
break;
case WindowBackend::DX12:
SetString("Window.Backend.Name", "DirectX 12");
break;
case WindowBackend::GLX_OPENGL:
case WindowBackend::SDL_OPENGL:
case WindowBackend::FAST3D_SDL_OPENGL:
SetString("Window.Backend.Name", "OpenGL");
break;
case WindowBackend::SDL_METAL:
case WindowBackend::FAST3D_SDL_METAL:
SetString("Window.Backend.Name", "Metal");
break;
case WindowBackend::GX2:
SetString("Window.Backend.Name", "GX2");
break;
default:
SetString("Window.Backend.Name", "");
}
Expand Down
10 changes: 5 additions & 5 deletions src/config/ConsoleVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void ConsoleVariable::RegisterColor24(const char* name, Color_RGB8 defaultValue)
}

void ConsoleVariable::ClearVariable(const char* name) {
std::shared_ptr<Config> conf = Ship::Context::GetInstance()->GetConfig();
std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();
auto var = Get(name);
if (var != nullptr) {
bool color = var->Type == ConsoleVariableType::Color || var->Type == ConsoleVariableType::Color24;
Expand All @@ -192,7 +192,7 @@ void ConsoleVariable::ClearVariable(const char* name) {
}

void ConsoleVariable::ClearBlock(const char* name) {
std::shared_ptr<Config> conf = Ship::Context::GetInstance()->GetConfig();
std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();
conf->EraseBlock(StringHelper::Sprintf("CVars.%s", name));
Load();
}
Expand Down Expand Up @@ -228,7 +228,7 @@ void ConsoleVariable::CopyVariable(const char* from, const char* to) {
}

void ConsoleVariable::Save() {
std::shared_ptr<Config> conf = Ship::Context::GetInstance()->GetConfig();
std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();

for (const auto& variable : mVariables) {
const std::string key = StringHelper::Sprintf("CVars.%s", variable.first.c_str());
Expand Down Expand Up @@ -264,7 +264,7 @@ void ConsoleVariable::Save() {
}

void ConsoleVariable::Load() {
std::shared_ptr<Config> conf = Ship::Context::GetInstance()->GetConfig();
std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();
conf->Reload();
if (!mVariables.empty()) {
mVariables.clear();
Expand Down Expand Up @@ -324,7 +324,7 @@ void ConsoleVariable::LoadFromPath(
}
}
void ConsoleVariable::LoadLegacy() {
auto conf = Ship::Context::GetPathRelativeToAppDirectory("cvars.cfg");
auto conf = Context::GetPathRelativeToAppDirectory("cvars.cfg");
if (DiskFile::Exists(conf)) {
const auto lines = DiskFile::ReadAllLines(conf);

Expand Down
2 changes: 1 addition & 1 deletion src/controller/controldeck/ControlDeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ControlDeck {
bool IsSinglePlayerMappingMode();

#ifndef __WIIU__
bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
#endif

std::shared_ptr<ShipDeviceIndexMappingManager> GetDeviceIndexMappingManager();
Expand Down
2 changes: 1 addition & 1 deletion src/controller/controldevice/controller/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void Controller::ReadToPad(OSContPad* pad) {
}

#ifndef __WIIU__
bool Controller::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) {
bool Controller::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) {
bool result = false;
for (auto [bitmask, button] : GetAllButtons()) {
result = button->ProcessKeyboardEvent(eventType, scancode) || result;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/controldevice/controller/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Controller : public ControlDevice {
std::vector<std::shared_ptr<ControllerMapping>> GetAllMappings();

#ifndef __WIIU__
bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
#endif

bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi
return true;
}

bool ControllerButton::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) {
bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) {
if (mUseKeydownEventToCreateNewMapping && eventType == LUS_KB_EVENT_KEY_DOWN) {
mKeyboardScancodeForNewMapping = scancode;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/controldevice/controller/ControllerButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ControllerButton {
void UpdatePad(CONTROLLERBUTTONS_T& padButtons);

#ifndef __WIIU__
bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
#endif

bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void ControllerStick::UpdatePad(int8_t& x, int8_t& y) {
}

#ifndef __WIIU__
bool ControllerStick::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) {
bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) {
if (mUseKeydownEventToCreateNewMapping && eventType == LUS_KB_EVENT_KEY_DOWN) {
mKeyboardScancodeForNewMapping = scancode;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/controldevice/controller/ControllerStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ControllerStick {
bool NotchSnapAngleIsDefault();

#ifndef __WIIU__
bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
#endif

bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::string KeyboardKeyToAnyMapping::GetPhysicalInputName() {
return Context::GetInstance()->GetWindow()->GetKeyName(mKeyboardScancode);
}

bool KeyboardKeyToAnyMapping::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) {
bool KeyboardKeyToAnyMapping::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) {
if (eventType == KbEventType::LUS_KB_EVENT_ALL_KEYS_UP) {
mKeyPressed = false;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class KeyboardKeyToAnyMapping : virtual public ControllerInputMapping {
KeyboardKeyToAnyMapping(KbScancode scancode);
~KeyboardKeyToAnyMapping();
std::string GetPhysicalInputName() override;
bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
std::string GetPhysicalDeviceName() override;
bool PhysicalDeviceIsConnected() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SDLMapping::~SDLMapping() {

bool SDLMapping::OpenController() {
auto deviceIndexMapping = std::static_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(
Ship::Context::GetInstance()
Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
->GetDeviceIndexMappingFromShipDeviceIndex(mShipDeviceIndex));
Expand Down Expand Up @@ -116,7 +116,7 @@ bool SDLMapping::UsesGameCubeLayout() {

int32_t SDLMapping::GetSDLDeviceIndex() {
auto deviceIndexMapping = std::static_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(
Ship::Context::GetInstance()
Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
->GetDeviceIndexMappingFromShipDeviceIndex(mShipDeviceIndex));
Expand All @@ -130,7 +130,7 @@ int32_t SDLMapping::GetSDLDeviceIndex() {
}

std::string SDLMapping::GetSDLControllerName() {
return Ship::Context::GetInstance()
return Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
->GetSDLControllerNameFromShipDeviceIndex(mShipDeviceIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void ShipDeviceIndexMappingManager::HandlePhysicalDeviceConnect(int32_t sdlDevic
}

if (Context::GetInstance()->GetControlDeck()->IsSinglePlayerMappingMode()) {
std::set<Ship::ShipDeviceIndex> alreadyConnectedDevices;
std::set<ShipDeviceIndex> alreadyConnectedDevices;
for (auto mapping : Context::GetInstance()->GetControlDeck()->GetControllerByPort(0)->GetAllMappings()) {
auto sdlMapping = std::dynamic_pointer_cast<SDLMapping>(mapping);
if (sdlMapping == nullptr) {
Expand Down
28 changes: 14 additions & 14 deletions src/debug/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void CrashHandler::PrintRegisters(ucontext_t* ctx) {
}

static void ErrorHandler(int sig, siginfo_t* sigInfo, void* data) {
std::shared_ptr<CrashHandler> crashHandler = Ship::Context::GetInstance()->GetCrashHandler();
std::shared_ptr<CrashHandler> crashHandler = Context::GetInstance()->GetCrashHandler();
char intToCharBuffer[16];

std::array<void*, 4096> arr;
Expand Down Expand Up @@ -189,15 +189,15 @@ static void ErrorHandler(int sig, siginfo_t* sigInfo, void* data) {
snprintf(intToCharBuffer, sizeof(intToCharBuffer), "%i ", (int)i);
WRITE_VAR_LINE(crashHandler, intToCharBuffer, functionName.c_str());
}
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, (Ship::Context::GetInstance()->GetName() + " has crashed").c_str(),
(Ship::Context::GetInstance()->GetName() +
" has crashed. Please upload the logs to the support channel in discord.")
.c_str(),
nullptr);
SDL_ShowSimpleMessageBox(
SDL_MESSAGEBOX_ERROR, (Context::GetInstance()->GetName() + " has crashed").c_str(),
(Context::GetInstance()->GetName() + " has crashed. Please upload the logs to the support channel in discord.")
.c_str(),
nullptr);
free(symbols);
crashHandler->PrintCommon();

Ship::Context::GetInstance()->GetLogger()->flush();
Context::GetInstance()->GetLogger()->flush();
spdlog::shutdown();
exit(1);
}
Expand Down Expand Up @@ -385,23 +385,23 @@ void CrashHandler::PrintStack(CONTEXT* ctx) {
}
}
PrintCommon();
Ship::Context::GetInstance()->GetLogger()->flush();
Context::GetInstance()->GetLogger()->flush();
spdlog::shutdown();
}

extern "C" LONG WINAPI seh_filter(PEXCEPTION_POINTERS ex) {
char exceptionString[20];
std::shared_ptr<CrashHandler> crashHandler = Ship::Context::GetInstance()->GetCrashHandler();
std::shared_ptr<CrashHandler> crashHandler = Context::GetInstance()->GetCrashHandler();

snprintf(exceptionString, std::size(exceptionString), "0x%x", ex->ExceptionRecord->ExceptionCode);

WRITE_VAR_LINE(crashHandler, "Exception: ", exceptionString);
crashHandler->PrintStack(ex->ContextRecord);
MessageBoxA(nullptr,
(Ship::Context::GetInstance()->GetName() +
" has crashed. Please upload the logs to the support channel in discord.")
.c_str(),
"Crash", MB_OK | MB_ICONERROR);
MessageBoxA(
nullptr,
(Context::GetInstance()->GetName() + " has crashed. Please upload the logs to the support channel in discord.")
.c_str(),
"Crash", MB_OK | MB_ICONERROR);

return EXCEPTION_EXECUTE_HANDLER;
}
Expand Down
23 changes: 9 additions & 14 deletions src/graphic/Fast3D/Fast3dWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Fast3dWindow::Fast3dWindow(std::vector<std::shared_ptr<Ship::GuiWindow>> guiWind
mRenderingApi = nullptr;

#ifdef _WIN32
AddAvailableWindowBackend(Ship::WindowBackend::DX11);
AddAvailableWindowBackend(Ship::WindowBackend::FAST3D_DXGI_DX11);
#endif
#ifdef __APPLE__
if (Metal_IsSupported()) {
AddAvailableWindowBackend(Ship::WindowBackend::SDL_METAL);
AddAvailableWindowBackend(Ship::WindowBackend::FAST3D_SDL_METAL);
}
#endif
AddAvailableWindowBackend(Ship::WindowBackend::SDL_OPENGL);
AddAvailableWindowBackend(Ship::WindowBackend::FAST3D_SDL_OPENGL);
}

Fast3dWindow::~Fast3dWindow() {
Expand Down Expand Up @@ -107,31 +107,25 @@ void Fast3dWindow::InitWindowManager() {

switch (GetWindowBackend()) {
#ifdef ENABLE_DX11
case Ship::WindowBackend::DX11:
case Ship::WindowBackend::FAST3D_DXGI_DX11:
mRenderingApi = &gfx_direct3d11_api;
mWindowManagerApi = &gfx_dxgi_api;
break;
#endif
#ifdef ENABLE_DX12
case Ship::WindowBackend::DX12:
mRenderingApi = &gfx_direct3d12_api;
mWindowManagerApi = &gfx_dxgi_api;
break;
#endif
#ifdef ENABLE_OPENGL
case Ship::WindowBackend::SDL_OPENGL:
case Ship::WindowBackend::FAST3D_SDL_OPENGL:
mRenderingApi = &gfx_opengl_api;
mWindowManagerApi = &gfx_sdl;
break;
#endif
#ifdef __APPLE__
case Ship::WindowBackend::SDL_METAL:
case Ship::WindowBackend::FAST3D_SDL_METAL:
mRenderingApi = &gfx_metal_api;
mWindowManagerApi = &gfx_sdl;
break;
#endif
#ifdef __WIIU__
case Ship::WindowBackend::GX2:
case Ship::WindowBackend::FAST3D_WIIU_GX2:
mRenderingApi = &gfx_gx2_api;
mWindowManagerApi = &gfx_wiiu;
break;
Expand Down Expand Up @@ -200,7 +194,8 @@ uint32_t Fast3dWindow::GetCurrentRefreshRate() {
}

bool Fast3dWindow::SupportsWindowedFullscreen() {
if (GetWindowBackend() == Ship::WindowBackend::SDL_OPENGL || GetWindowBackend() == Ship::WindowBackend::SDL_METAL) {
if (GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_OPENGL ||
GetWindowBackend() == Ship::WindowBackend::FAST3D_SDL_METAL) {
return true;
}

Expand Down
Loading

0 comments on commit b5c2fa0

Please sign in to comment.