From 04066deb10aa735f5fe2235d0e01988221ba2045 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:54:51 -0400 Subject: [PATCH] Remove Wii U (#528) --- extern/CMakeLists.txt | 20 +- extern/spdlog/include/spdlog/details/os-inl.h | 2 +- include/libultraship/classes.h | 3 - src/CMakeLists.txt | 62 +- src/Context.cpp | 12 +- src/config/Config.cpp | 3 - src/controller/controldeck/ControlDeck.cpp | 6 - src/controller/controldeck/ControlDeck.h | 2 - .../controldevice/controller/Controller.cpp | 2 - .../controldevice/controller/Controller.h | 2 - .../controller/ControllerButton.cpp | 34 - .../controller/ControllerButton.h | 2 - .../controller/ControllerGyro.cpp | 20 - .../controller/ControllerLED.cpp | 18 - .../controller/ControllerRumble.cpp | 33 - .../controller/ControllerStick.cpp | 40 - .../controller/ControllerStick.h | 2 - .../factories/AxisDirectionMappingFactory.cpp | 291 ------ .../factories/AxisDirectionMappingFactory.h | 8 - .../factories/ButtonMappingFactory.cpp | 408 -------- .../mapping/factories/ButtonMappingFactory.h | 7 - .../mapping/factories/GyroMappingFactory.cpp | 58 +- .../mapping/factories/GyroMappingFactory.h | 4 - .../mapping/factories/LEDMappingFactory.cpp | 6 - .../mapping/factories/LEDMappingFactory.h | 2 - .../factories/RumbleMappingFactory.cpp | 138 --- .../mapping/factories/RumbleMappingFactory.h | 6 - ...iiUAxisDirectionToAxisDirectionMapping.cpp | 185 ---- .../WiiUAxisDirectionToAxisDirectionMapping.h | 31 - .../mapping/wiiu/WiiUButtonToAnyMapping.cpp | 300 ------ .../mapping/wiiu/WiiUButtonToAnyMapping.h | 31 - .../wiiu/WiiUButtonToAxisDirectionMapping.cpp | 63 -- .../wiiu/WiiUButtonToAxisDirectionMapping.h | 19 - .../wiiu/WiiUButtonToButtonMapping.cpp | 64 -- .../mapping/wiiu/WiiUButtonToButtonMapping.h | 17 - .../mapping/wiiu/WiiUGyroMapping.cpp | 97 -- .../controller/mapping/wiiu/WiiUGyroMapping.h | 25 - .../controller/mapping/wiiu/WiiUMapping.cpp | 113 -- .../controller/mapping/wiiu/WiiUMapping.h | 30 - .../mapping/wiiu/WiiURumbleMapping.cpp | 102 -- .../mapping/wiiu/WiiURumbleMapping.h | 28 - .../ControllerDisconnectedWindow.cpp | 87 -- .../ControllerDisconnectedWindow.h | 5 - .../ControllerReorderingWindow.cpp | 125 --- .../deviceindex/ControllerReorderingWindow.h | 5 - .../ShipDeviceIndexMappingManager.cpp | 199 ---- .../ShipDeviceIndexMappingManager.h | 17 - ...hipDeviceIndexToWiiUDeviceIndexMapping.cpp | 102 -- .../ShipDeviceIndexToWiiUDeviceIndexMapping.h | 38 - src/graphic/Fast3D/gfx_gx2.cpp | 878 ---------------- src/graphic/Fast3D/gfx_gx2.h | 16 - src/graphic/Fast3D/gfx_pc.cpp | 21 +- src/graphic/Fast3D/gfx_wiiu.cpp | 487 --------- src/graphic/Fast3D/gfx_wiiu.h | 38 - src/graphic/Fast3D/gx2_shader_gen.c | 983 ------------------ src/graphic/Fast3D/gx2_shader_gen.h | 31 - src/graphic/Fast3D/gx2_shader_inl.h | 650 ------------ src/port/wiiu/WiiUImpl.cpp | 225 ---- src/port/wiiu/WiiUImpl.h | 27 - src/public/libultra/os.cpp | 2 - src/resource/ResourceManager.cpp | 2 +- src/window/Window.cpp | 19 +- src/window/Window.h | 2 - src/window/gui/ConsoleWindow.cpp | 9 +- src/window/gui/GameOverlay.cpp | 2 +- src/window/gui/Gui.cpp | 65 -- src/window/gui/InputEditorWindow.cpp | 126 --- src/window/gui/StatsWindow.cpp | 2 - 68 files changed, 19 insertions(+), 6440 deletions(-) delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.h delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.cpp delete mode 100644 src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.h delete mode 100644 src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.cpp delete mode 100644 src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h delete mode 100644 src/graphic/Fast3D/gfx_gx2.cpp delete mode 100644 src/graphic/Fast3D/gfx_gx2.h delete mode 100644 src/graphic/Fast3D/gfx_wiiu.cpp delete mode 100644 src/graphic/Fast3D/gfx_wiiu.h delete mode 100644 src/graphic/Fast3D/gx2_shader_gen.c delete mode 100644 src/graphic/Fast3D/gx2_shader_gen.h delete mode 100644 src/graphic/Fast3D/gx2_shader_inl.h delete mode 100644 src/port/wiiu/WiiUImpl.cpp delete mode 100644 src/port/wiiu/WiiUImpl.h diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 79e1764a3..cb05e55df 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -48,13 +48,11 @@ if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") target_include_directories(ImGui PRIVATE ${DEVKITPRO}/portlibs/switch/include/) endif() -if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_sources(ImGui - PRIVATE - ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp - ${IMGUI_DIR}/backends/imgui_impl_sdl2.cpp - ) -endif() +target_sources(ImGui + PRIVATE + ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp + ${IMGUI_DIR}/backends/imgui_impl_sdl2.cpp +) if (CMAKE_SYSTEM_NAME STREQUAL "Windows") target_sources(ImGui @@ -67,12 +65,6 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") PRIVATE ${IMGUI_DIR}/backends/imgui_impl_metal.mm ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_sources(ImGui - PRIVATE - ${IMGUI_DIR}/backends/wiiu/imgui_impl_wiiu.cpp - ${IMGUI_DIR}/backends/wiiu/imgui_impl_gx2.cpp - ) endif() target_include_directories(ImGui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS}) @@ -86,8 +78,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") target_link_libraries(ImGui PUBLIC SDL2::SDL2 SDL2::SDL2main) elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") target_link_libraries(ImGui PUBLIC SDL2::SDL2-static SDL2::SDL2main) -elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_link_libraries(ImGui PUBLIC SDL2::SDL2-static) else() target_link_libraries(ImGui PUBLIC SDL2::SDL2) endif() diff --git a/extern/spdlog/include/spdlog/details/os-inl.h b/extern/spdlog/include/spdlog/details/os-inl.h index bf413f028..b9bab53ce 100644 --- a/extern/spdlog/include/spdlog/details/os-inl.h +++ b/extern/spdlog/include/spdlog/details/os-inl.h @@ -286,7 +286,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) return offset; #else -# if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE)) || defined(__WIIU__) +# if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE)) // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris struct helper { diff --git a/include/libultraship/classes.h b/include/libultraship/classes.h index 21e1b9e0e..c940a4226 100644 --- a/include/libultraship/classes.h +++ b/include/libultraship/classes.h @@ -41,8 +41,5 @@ #ifdef __SWITCH__ #include "port/switch/SwitchImpl.h" #endif -#ifdef __WIIU__ -#include "port/wiiu/WiiUImpl.h" -#endif #endif #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d7aab3c97..2577bf1d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,15 +36,6 @@ target_sources(libultraship PRIVATE ${Source_Files__Audio}) file(GLOB_RECURSE Source_Files__Controller RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "controller/*.h" "controller/*.cpp") -if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/keyboard/*") - list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/sdl/*") - list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.*") -else() - list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/wiiu/*") - list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.*") -endif() - source_group("controller" FILES ${Source_Files__Controller}) target_sources(libultraship PRIVATE ${Source_Files__Controller}) @@ -120,12 +111,7 @@ target_sources(libultraship PRIVATE ${Source_Files__Utils__BinaryTools}) #=================== Port =================== -if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - set(Source_Files__Port - ${CMAKE_CURRENT_SOURCE_DIR}/port/wiiu/WiiUImpl.h - ${CMAKE_CURRENT_SOURCE_DIR}/port/wiiu/WiiUImpl.cpp - ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") +if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") set(Source_Files__Port ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.h ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.cpp @@ -175,14 +161,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "iOS") list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_opengl*") endif() -if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_wiiu*") - list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gx2*") -else() - list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_opengl*") - list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_sdl*") -endif() - source_group("graphic" FILES ${Source_Files__Graphic}) target_sources(libultraship PRIVATE ${Source_Files__Graphic}) @@ -192,19 +170,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") target_include_directories(libultraship PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern/metal-cpp) endif() -#=================== STB =================== -# hack: no idea why wii u doesn't want to link this when we build it -# as a separate static lib -if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - set(Source_Files__Lib__stb - "${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_image.h" - "${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_image_write.h" - "${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb/stb_impl.c" - ) - source_group("extern/stb" FILES ${Source_Files__Lib__stb}) - target_sources(libultraship PRIVATE ${Source_Files__Lib__stb}) -endif() - #=================== Packages & Includes =================== target_include_directories(libultraship @@ -212,15 +177,9 @@ target_include_directories(libultraship PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb ${ADDITIONAL_LIB_INCLUDES} ) -if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_include_directories(${PROJECT_NAME} PRIVATE - ${DEVKITPRO}/portlibs/wiiu/include/ - ) -endif() - #=================== Linking =================== -if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") +if (NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") target_link_libraries(libultraship PUBLIC "$") else() target_link_libraries(libultraship PUBLIC storm) @@ -230,11 +189,7 @@ target_link_libraries(libultraship PUBLIC ZAPDUtils ImGui tinyxml2 ) -# hack cont.: wii u just includes these files, everyone -# else handles linking it just fine -if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_link_libraries(libultraship PRIVATE stb) -endif() +target_link_libraries(libultraship PRIVATE stb) if (GFX_DEBUG_DISASSEMBLER) target_link_libraries(libultraship PRIVATE libgfxd) @@ -287,16 +242,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") ) endif() -if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") - target_compile_definitions(libultraship PRIVATE - $<$:_DEBUG> - $<$>:NDEBUG> - SPDLOG_NO_THREAD_ID - SPDLOG_NO_TLS - STBI_NO_THREAD_LOCALS - SPDLOG_ACTIVE_LEVEL=3 - ) -elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS") +if (CMAKE_SYSTEM_NAME STREQUAL "iOS") target_compile_definitions(libultraship PRIVATE $<$:_DEBUG> $<$>:NDEBUG> diff --git a/src/Context.cpp b/src/Context.cpp index deae0c66c..3abfc9663 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -15,8 +15,6 @@ #include "utils/AppleFolderManager.h" #elif defined(__SWITCH__) #include "port/switch/SwitchImpl.h" -#elif defined(__WIIU__) -#include "port/wiiu/WiiUImpl.h" #endif namespace Ship { @@ -100,7 +98,7 @@ void Context::InitLogging() { spdlog::init_thread_pool(8192, 1); std::vector sinks; -#if (!defined(_WIN32) && !defined(__WIIU__)) || defined(_DEBUG) +#if (!defined(_WIN32)) || defined(_DEBUG) #if defined(_DEBUG) && defined(_WIN32) // LLVM on Windows allocs a hidden console in its entrypoint function. // We free that console here to create our own. @@ -137,7 +135,6 @@ void Context::InitLogging() { sinks.push_back(systemConsoleSink); #endif -#ifndef __WIIU__ auto logPath = GetPathRelativeToAppDirectory(("logs/" + GetName() + ".log")); auto fileSink = std::make_shared(logPath, 1024 * 1024 * 10, 10); #ifdef _DEBUG @@ -146,7 +143,6 @@ void Context::InitLogging() { fileSink->set_level(spdlog::level::debug); #endif sinks.push_back(fileSink); -#endif mLogger = std::make_shared(GetName(), sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block); @@ -160,11 +156,7 @@ void Context::InitLogging() { GetLogger()->flush_on(spdlog::level::trace); #endif -#ifndef __WIIU__ GetLogger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%@] [%l] %v"); -#else - GetLogger()->set_pattern("[%s:%#] [%l] %v"); -#endif spdlog::register_logger(GetLogger()); spdlog::set_default_logger(GetLogger()); @@ -210,8 +202,6 @@ void Context::InitResourceManager(const std::vector& otrFiles, if (!GetResourceManager()->DidLoadSuccessfully()) { #if defined(__SWITCH__) printf("Main OTR file not found!\n"); -#elif defined(__WIIU__) - Ship::WiiU::ThrowMissingOTR(mMainPath.c_str()); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OTR file not found", "Main OTR file not found. Please generate one", nullptr); diff --git a/src/config/Config.cpp b/src/config/Config.cpp index c60ca3dfe..c49783ad6 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -225,9 +225,6 @@ WindowBackend Config::GetWindowBackend() { #ifdef ENABLE_DX11 return WindowBackend::DX11; #endif -#ifdef __WIIU__ - return WindowBackend::GX2; -#endif #ifdef __APPLE__ if (Metal_IsSupported()) { return WindowBackend::SDL_METAL; diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 2bb828b8d..5e0a55e9d 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -38,17 +38,14 @@ void ControlDeck::Init(uint8_t* controllerBits) { } } -#ifndef __WIIU__ // if we don't have a config for controller 1, set default keyboard bindings if (!mPorts[0]->GetConnectedController()->HasConfig()) { mPorts[0]->GetConnectedController()->AddDefaultMappings(ShipDeviceIndex::Keyboard); } -#endif Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Controller Reordering")->Show(); } -#ifndef __WIIU__ bool ControlDeck::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { bool result = false; for (auto port : mPorts) { @@ -61,7 +58,6 @@ bool ControlDeck::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancod return result; } -#endif bool ControlDeck::AllGameInputBlocked() { return !mGameInputBlockers.empty(); @@ -78,9 +74,7 @@ bool ControlDeck::KeyboardGameInputBlocked() { } void ControlDeck::WriteToPad(OSContPad* pad) { -#ifndef __WIIU__ SDL_PumpEvents(); -#endif if (AllGameInputBlocked()) { return; diff --git a/src/controller/controldeck/ControlDeck.h b/src/controller/controldeck/ControlDeck.h index 1b43e2fe1..eacf42f5a 100644 --- a/src/controller/controldeck/ControlDeck.h +++ b/src/controller/controldeck/ControlDeck.h @@ -26,9 +26,7 @@ class ControlDeck { void SetSinglePlayerMappingMode(bool singlePlayer); bool IsSinglePlayerMappingMode(); -#ifndef __WIIU__ bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode); -#endif std::shared_ptr GetDeviceIndexMappingManager(); diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index 68315e341..4cf7a6738 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -173,7 +173,6 @@ void Controller::ReadToPad(OSContPad* pad) { } } -#ifndef __WIIU__ bool Controller::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) { bool result = false; for (auto [bitmask, button] : GetAllButtons()) { @@ -183,7 +182,6 @@ bool Controller::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScanc result = GetRightStick()->ProcessKeyboardEvent(eventType, scancode) || result; return result; } -#endif bool Controller::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { for (auto [bitmask, button] : GetAllButtons()) { diff --git a/src/controller/controldevice/controller/Controller.h b/src/controller/controldevice/controller/Controller.h index 27051dea6..c0cf0ab1f 100644 --- a/src/controller/controldevice/controller/Controller.h +++ b/src/controller/controldevice/controller/Controller.h @@ -48,9 +48,7 @@ class Controller : public ControlDevice { uint8_t GetPortIndex(); std::vector> GetAllMappings(); -#ifndef __WIIU__ bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode); -#endif bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); void MoveMappingsToDifferentController(std::shared_ptr newController, ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 8d407e7c6..302e7fd90 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -170,39 +170,6 @@ bool ControllerButton::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { [lusIndex](const auto& mapping) { return mapping.second->GetShipDeviceIndex() == lusIndex; }); } -#ifdef __WIIU__ -bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id) { - std::shared_ptr mapping = - ButtonMappingFactory::CreateButtonMappingFromWiiUInput(mPortIndex, bitmask); - - if (mapping == nullptr) { - return false; - } - - if (id != "") { - ClearButtonMapping(id); - } - - AddButtonMapping(mapping); - mapping->SaveToConfig(); - SaveButtonMappingIdsToConfig(); - const std::string hasConfigCvarKey = StringHelper::Sprintf("gControllers.Port%d.HasConfig", mPortIndex + 1); - CVarSetInteger(hasConfigCvarKey.c_str(), true); - CVarSave(); - return true; -} - -void ControllerButton::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { - for (auto mapping : ButtonMappingFactory::CreateDefaultWiiUButtonMappings(shipDeviceIndex, mPortIndex, mBitmask)) { - AddButtonMapping(mapping); - } - - for (auto [id, mapping] : mButtonMappings) { - mapping->SaveToConfig(); - } - SaveButtonMappingIdsToConfig(); -} -#else bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id) { std::shared_ptr mapping = nullptr; @@ -270,5 +237,4 @@ void ControllerButton::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { } SaveButtonMappingIdsToConfig(); } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index c4bfafc71..b6ecb535e 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -36,9 +36,7 @@ class ControllerButton { void UpdatePad(CONTROLLERBUTTONS_T& padButtons); -#ifndef __WIIU__ bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode); -#endif bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/ControllerGyro.cpp b/src/controller/controldevice/controller/ControllerGyro.cpp index 2dd821994..46a72ca8f 100644 --- a/src/controller/controldevice/controller/ControllerGyro.cpp +++ b/src/controller/controldevice/controller/ControllerGyro.cpp @@ -19,25 +19,6 @@ void ControllerGyro::SetGyroMapping(std::shared_ptr mappi mGyroMapping = mapping; } -#ifdef __WIIU__ -bool ControllerGyro::SetGyroMappingFromRawPress() { - std::shared_ptr mapping = nullptr; - - mapping = GyroMappingFactory::CreateGyroMappingFromWiiUInput(mPortIndex); - - if (mapping == nullptr) { - return false; - } - - SetGyroMapping(mapping); - mapping->SaveToConfig(); - SaveGyroMappingIdToConfig(); - const std::string hasConfigCvarKey = StringHelper::Sprintf("gControllers.Port%d.HasConfig", mPortIndex + 1); - CVarSetInteger(hasConfigCvarKey.c_str(), true); - CVarSave(); - return true; -} -#else bool ControllerGyro::SetGyroMappingFromRawPress() { std::shared_ptr mapping = nullptr; @@ -55,7 +36,6 @@ bool ControllerGyro::SetGyroMappingFromRawPress() { CVarSave(); return true; } -#endif void ControllerGyro::UpdatePad(float& x, float& y) { if (mGyroMapping == nullptr) { diff --git a/src/controller/controldevice/controller/ControllerLED.cpp b/src/controller/controldevice/controller/ControllerLED.cpp index aa852376e..183c3ff79 100644 --- a/src/controller/controldevice/controller/ControllerLED.cpp +++ b/src/controller/controldevice/controller/ControllerLED.cpp @@ -109,23 +109,6 @@ std::unordered_map> Controlle return mLEDMappings; } -#ifdef __WIIU__ -bool ControllerLED::AddLEDMappingFromRawPress() { - return false; - // std::shared_ptr mapping = nullptr; - - // mapping = LEDMappingFactory::CreateLEDMappingFromSDLInput(mPortIndex); - - // if (mapping == nullptr) { - // return false; - // } - - // AddLEDMapping(mapping); - // mapping->SaveToConfig(); - // SaveLEDMappingIdsToConfig(); - // return true; -} -#else bool ControllerLED::AddLEDMappingFromRawPress() { std::shared_ptr mapping = nullptr; @@ -143,7 +126,6 @@ bool ControllerLED::AddLEDMappingFromRawPress() { CVarSave(); return true; } -#endif bool ControllerLED::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { return std::any_of(mLEDMappings.begin(), mLEDMappings.end(), diff --git a/src/controller/controldevice/controller/ControllerRumble.cpp b/src/controller/controldevice/controller/ControllerRumble.cpp index e5739d578..acdb32849 100644 --- a/src/controller/controldevice/controller/ControllerRumble.cpp +++ b/src/controller/controldevice/controller/ControllerRumble.cpp @@ -85,18 +85,6 @@ void ControllerRumble::ClearAllMappingsForDevice(ShipDeviceIndex shipDeviceIndex SaveRumbleMappingIdsToConfig(); } -#ifdef __WIIU__ -void ControllerRumble::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { - for (auto mapping : RumbleMappingFactory::CreateDefaultWiiURumbleMappings(shipDeviceIndex, mPortIndex)) { - AddRumbleMapping(mapping); - } - - for (auto [id, mapping] : mRumbleMappings) { - mapping->SaveToConfig(); - } - SaveRumbleMappingIdsToConfig(); -} -#else void ControllerRumble::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { for (auto mapping : RumbleMappingFactory::CreateDefaultSDLRumbleMappings(shipDeviceIndex, mPortIndex)) { AddRumbleMapping(mapping); @@ -107,7 +95,6 @@ void ControllerRumble::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { } SaveRumbleMappingIdsToConfig(); } -#endif void ControllerRumble::LoadRumbleMappingFromConfig(std::string id) { auto mapping = RumbleMappingFactory::CreateRumbleMappingFromConfig(mPortIndex, id); @@ -140,25 +127,6 @@ std::unordered_map> Contro return mRumbleMappings; } -#ifdef __WIIU__ -bool ControllerRumble::AddRumbleMappingFromRawPress() { - std::shared_ptr mapping = nullptr; - - mapping = RumbleMappingFactory::CreateRumbleMappingFromWiiUInput(mPortIndex); - - if (mapping == nullptr) { - return false; - } - - AddRumbleMapping(mapping); - mapping->SaveToConfig(); - SaveRumbleMappingIdsToConfig(); - const std::string hasConfigCvarKey = StringHelper::Sprintf("gControllers.Port%d.HasConfig", mPortIndex + 1); - CVarSetInteger(hasConfigCvarKey.c_str(), true); - CVarSave(); - return true; -} -#else bool ControllerRumble::AddRumbleMappingFromRawPress() { std::shared_ptr mapping = nullptr; @@ -176,7 +144,6 @@ bool ControllerRumble::AddRumbleMappingFromRawPress() { CVarSave(); return true; } -#endif bool ControllerRumble::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { return std::any_of(mRumbleMappings.begin(), mRumbleMappings.end(), diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 830e7ff9c..136d04160 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -120,21 +120,7 @@ void ControllerStick::AddAxisDirectionMapping(Direction direction, std::shared_ptr mapping) { mAxisDirectionMappings[direction][mapping->GetAxisDirectionMappingId()] = mapping; } -#ifdef __WIIU__ -void ControllerStick::AddDefaultMappings(ShipDeviceIndex lusIndex) { - for (auto mapping : - AxisDirectionMappingFactory::CreateDefaultWiiUAxisDirectionMappings(lusIndex, mPortIndex, mStick)) { - AddAxisDirectionMapping(mapping->GetDirection(), mapping); - } - for (auto [direction, directionMappings] : mAxisDirectionMappings) { - for (auto [id, mapping] : directionMappings) { - mapping->SaveToConfig(); - } - } - SaveAxisDirectionMappingIdsToConfig(); -} -#else void ControllerStick::AddDefaultMappings(ShipDeviceIndex lusIndex) { for (auto mapping : AxisDirectionMappingFactory::CreateDefaultSDLAxisDirectionMappings(lusIndex, mPortIndex, mStick)) { @@ -155,7 +141,6 @@ void ControllerStick::AddDefaultMappings(ShipDeviceIndex lusIndex) { } SaveAxisDirectionMappingIdsToConfig(); } -#endif void ControllerStick::LoadAxisDirectionMappingFromConfig(std::string id) { auto mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(mPortIndex, mStick, id); @@ -277,28 +262,6 @@ void ControllerStick::Process(int8_t& x, int8_t& y) { y = copysign(uy, sy); } -#ifdef __WIIU__ -bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direction, std::string id) { - std::shared_ptr mapping = - AxisDirectionMappingFactory::CreateAxisDirectionMappingFromWiiUInput(mPortIndex, mStick, direction); - - if (mapping == nullptr) { - return false; - } - - if (id != "") { - ClearAxisDirectionMapping(direction, id); - } - - AddAxisDirectionMapping(direction, mapping); - mapping->SaveToConfig(); - SaveAxisDirectionMappingIdsToConfig(); - const std::string hasConfigCvarKey = StringHelper::Sprintf("gControllers.Port%d.HasConfig", mPortIndex + 1); - CVarSetInteger(hasConfigCvarKey.c_str(), true); - CVarSave(); - return true; -} -#else bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direction, std::string id) { std::shared_ptr mapping = nullptr; @@ -331,7 +294,6 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct CVarSave(); return true; } -#endif std::shared_ptr ControllerStick::GetAxisDirectionMappingById(Direction direction, std::string id) { @@ -351,7 +313,6 @@ void ControllerStick::UpdatePad(int8_t& x, int8_t& y) { Process(x, y); } -#ifndef __WIIU__ bool ControllerStick::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode) { if (mUseKeydownEventToCreateNewMapping && eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; @@ -372,7 +333,6 @@ bool ControllerStick::ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::Kb } return result; } -#endif void ControllerStick::SetSensitivity(uint8_t sensitivityPercentage) { mSensitivityPercentage = sensitivityPercentage; diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index bc7c1037d..a4d6a4da0 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -51,9 +51,7 @@ class ControllerStick { uint8_t GetNotchSnapAngle(); bool NotchSnapAngleIsDefault(); -#ifndef __WIIU__ bool ProcessKeyboardEvent(Ship::KbEventType eventType, Ship::KbScancode scancode); -#endif bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); Stick LeftOrRightStick(); diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index dfaa7c9fb..6a7a6aef0 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -1,13 +1,8 @@ #include "AxisDirectionMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.h" -#include "controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.h" -#else #include "controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h" -#endif #include "public/bridge/consolevariablebridge.h" #include @@ -21,53 +16,6 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn const std::string mappingClass = CVarGetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), ""); -#ifdef __WIIU__ - if (mappingClass == "WiiUAxisDirectionToAxisDirectionMapping") { - int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - int32_t wiiuControllerAxis = - CVarGetInteger(StringHelper::Sprintf("%s.WiiUControllerAxis", mappingCvarKey.c_str()).c_str(), -1); - int32_t axisDirection = - CVarGetInteger(StringHelper::Sprintf("%s.AxisDirection", mappingCvarKey.c_str()).c_str(), 0); - - if ((direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) || shipDeviceIndex < 0 || - wiiuControllerAxis == -1 || (axisDirection != NEGATIVE && axisDirection != POSITIVE)) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - - return std::make_shared( - static_cast(shipDeviceIndex), portIndex, stick, static_cast(direction), - wiiuControllerAxis, axisDirection); - } - - if (mappingClass == "WiiUButtonToAxisDirectionMapping") { - int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - bool isClassic = CVarGetInteger( - StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str(), false); - bool isNunchuk = - CVarGetInteger(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str(), false); - int32_t wiiuControllerButton = - CVarGetInteger(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str(), -1); - - if ((direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) || shipDeviceIndex < 0 || - wiiuControllerButton == -1) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - - return std::make_shared(static_cast(shipDeviceIndex), - portIndex, stick, static_cast(direction), - isNunchuk, isClassic, wiiuControllerButton); - } -#else if (mappingClass == "SDLAxisDirectionToAxisDirectionMapping") { int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); int32_t shipDeviceIndex = @@ -125,248 +73,10 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn return std::make_shared(portIndex, stick, static_cast(direction), static_cast(scancode)); } -#endif return nullptr; } -#ifdef __WIIU__ -std::vector> -AxisDirectionMappingFactory::CreateDefaultWiiUAxisDirectionMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, - Stick stick) { - auto wiiuIndexMapping = std::dynamic_pointer_cast( - Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetDeviceIndexMappingFromShipDeviceIndex(shipDeviceIndex)); - if (wiiuIndexMapping == nullptr) { - return std::vector>(); - } - - if (wiiuIndexMapping->GetExtensionType() == WPAD_EXT_CORE || - wiiuIndexMapping->GetExtensionType() == WPAD_EXT_MPLUS) { - return std::vector>(); - } - - if (wiiuIndexMapping->GetExtensionType() == WPAD_EXT_NUNCHUK || - wiiuIndexMapping->GetExtensionType() == WPAD_EXT_MPLUS_NUNCHUK) { - if (stick == RIGHT_STICK) { - return std::vector>(); - } - - std::vector> mappings = { - std::make_shared(shipDeviceIndex, portIndex, stick, LEFT, 4, -1), - std::make_shared(shipDeviceIndex, portIndex, stick, RIGHT, 4, 1), - std::make_shared(shipDeviceIndex, portIndex, stick, UP, 5, -1), - std::make_shared(shipDeviceIndex, portIndex, stick, DOWN, 5, 1) - }; - return mappings; - } - - std::vector> mappings = { - std::make_shared(shipDeviceIndex, portIndex, stick, LEFT, - stick == LEFT_STICK ? 0 : 2, -1), - std::make_shared(shipDeviceIndex, portIndex, stick, RIGHT, - stick == LEFT_STICK ? 0 : 2, 1), - std::make_shared(shipDeviceIndex, portIndex, stick, UP, - stick == LEFT_STICK ? 1 : 3, -1), - std::make_shared(shipDeviceIndex, portIndex, stick, DOWN, - stick == LEFT_STICK ? 1 : 3, 1) - }; - return mappings; -} - -std::shared_ptr -AxisDirectionMappingFactory::CreateAxisDirectionMappingFromWiiUInput(uint8_t portIndex, Stick stick, - Direction direction) { - for (auto [lusIndex, indexMapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::dynamic_pointer_cast(indexMapping); - - if (wiiuIndexMapping == nullptr) { - continue; - } - - if (wiiuIndexMapping->IsWiiUGamepad()) { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus == nullptr || verror != VPAD_READ_SUCCESS) { - continue; - } - - for (uint32_t i = VPAD_BUTTON_SYNC; i <= VPAD_STICK_L_EMULATION_LEFT; i <<= 1) { - if (!(vstatus->hold & i)) { - continue; - } - - switch (i) { - case VPAD_STICK_L_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, -1); - case VPAD_STICK_L_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, 1); - case VPAD_STICK_L_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, -1); - case VPAD_STICK_L_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, 1); - case VPAD_STICK_R_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, -1); - case VPAD_STICK_R_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, 1); - case VPAD_STICK_R_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, -1); - case VPAD_STICK_R_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, 1); - default: - return std::make_shared(lusIndex, portIndex, stick, direction, - false, false, i); - } - } - - continue; - } - - KPADError kerror; - KPADStatus* kstatus = - Ship::WiiU::GetKPADStatus(static_cast(wiiuIndexMapping->GetDeviceChannel()), &kerror); - - if (kstatus == nullptr || kerror != KPAD_ERROR_OK) { - continue; - } - - if (wiiuIndexMapping->GetExtensionType() == WPAD_EXT_PRO_CONTROLLER) { - for (uint32_t i = WPAD_PRO_BUTTON_UP; i <= WPAD_PRO_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->pro.hold & i)) { - continue; - } - - switch (i) { - case WPAD_PRO_STICK_L_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, -1); - case WPAD_PRO_STICK_L_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, 1); - case WPAD_PRO_STICK_L_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, -1); - case WPAD_PRO_STICK_L_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, 1); - case WPAD_PRO_STICK_R_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, -1); - case WPAD_PRO_STICK_R_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, 1); - case WPAD_PRO_STICK_R_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, -1); - case WPAD_PRO_STICK_R_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, 1); - default: - return std::make_shared(lusIndex, portIndex, stick, direction, - false, false, i); - } - } - - continue; - } - - switch (wiiuIndexMapping->GetExtensionType()) { - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - for (auto i : { WPAD_NUNCHUK_STICK_EMULATION_LEFT, WPAD_NUNCHUK_STICK_EMULATION_RIGHT, - WPAD_NUNCHUK_STICK_EMULATION_DOWN, WPAD_NUNCHUK_STICK_EMULATION_UP, - WPAD_NUNCHUK_BUTTON_Z, WPAD_NUNCHUK_BUTTON_C }) { - if (!(kstatus->nunchuck.hold & i)) { - continue; - } - - switch (i) { - case WPAD_NUNCHUK_STICK_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 4, -1); - case WPAD_NUNCHUK_STICK_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 4, 1); - case WPAD_NUNCHUK_STICK_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 5, 1); - case WPAD_NUNCHUK_STICK_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 5, -1); - default: - // todo: figure out why held nunchuk buttons aren't getting set - return std::make_shared(lusIndex, portIndex, stick, - direction, true, false, i); - } - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - for (uint32_t i = WPAD_CLASSIC_BUTTON_UP; i <= WPAD_CLASSIC_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->classic.hold & i)) { - continue; - } - - switch (i) { - case WPAD_CLASSIC_STICK_L_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, -1); - case WPAD_CLASSIC_STICK_L_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 0, 1); - case WPAD_CLASSIC_STICK_L_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, -1); - case WPAD_CLASSIC_STICK_L_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 1, 1); - case WPAD_CLASSIC_STICK_R_EMULATION_LEFT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, -1); - case WPAD_CLASSIC_STICK_R_EMULATION_RIGHT: - return std::make_shared(lusIndex, portIndex, stick, - direction, 2, 1); - case WPAD_CLASSIC_STICK_R_EMULATION_UP: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, -1); - case WPAD_CLASSIC_STICK_R_EMULATION_DOWN: - return std::make_shared(lusIndex, portIndex, stick, - direction, 3, 1); - default: - return std::make_shared(lusIndex, portIndex, stick, - direction, false, true, i); - } - } - break; - } - - for (auto i : { WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT, WPAD_BUTTON_DOWN, WPAD_BUTTON_UP, WPAD_BUTTON_PLUS, - WPAD_BUTTON_2, WPAD_BUTTON_1, WPAD_BUTTON_B, WPAD_BUTTON_A, WPAD_BUTTON_MINUS, WPAD_BUTTON_Z, - WPAD_BUTTON_C, WPAD_BUTTON_HOME }) { - if (!(kstatus->hold & i)) { - continue; - } - - return std::make_shared(lusIndex, portIndex, stick, direction, false, - false, i); - } - } - - return nullptr; -} -#else std::vector> AxisDirectionMappingFactory::CreateDefaultKeyboardAxisDirectionMappings(uint8_t portIndex, Stick stick) { std::vector> mappings = { @@ -468,5 +178,4 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t port return mapping; } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h index 789d585dc..126b5736d 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h @@ -11,13 +11,6 @@ class AxisDirectionMappingFactory { static std::shared_ptr CreateAxisDirectionMappingFromConfig(uint8_t portIndex, Stick stick, std::string id); -#ifdef __WIIU__ - static std::vector> - CreateDefaultWiiUAxisDirectionMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, Stick stick); - - static std::shared_ptr - CreateAxisDirectionMappingFromWiiUInput(uint8_t portIndex, Stick stick, Direction direction); -#else static std::vector> CreateDefaultKeyboardAxisDirectionMappings(uint8_t portIndex, Stick stick); @@ -26,6 +19,5 @@ class AxisDirectionMappingFactory { static std::shared_ptr CreateAxisDirectionMappingFromSDLInput(uint8_t portIndex, Stick stick, Direction direction); -#endif }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index c4c7d8e60..24a909cd9 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -3,15 +3,10 @@ #include #include "libultraship/libultra/controller.h" #include "Context.h" -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.h" -#include "controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h" -#else #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" -#endif namespace Ship { std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromConfig(uint8_t portIndex, @@ -28,28 +23,6 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return nullptr; } -#ifdef __WIIU__ - if (mappingClass == "WiiUButtonToButtonMapping") { - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - bool isClassic = CVarGetInteger( - StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str(), false); - bool isNunchuk = - CVarGetInteger(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str(), false); - int32_t wiiuControllerButton = - CVarGetInteger(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str(), -1); - - if (shipDeviceIndex < 0 || wiiuControllerButton == -1) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - - return std::make_shared(static_cast(shipDeviceIndex), portIndex, - bitmask, isNunchuk, isClassic, wiiuControllerButton); - } -#else if (mappingClass == "SDLButtonToButtonMapping") { int32_t shipDeviceIndex = CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); @@ -92,390 +65,10 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return std::make_shared(portIndex, bitmask, static_cast(scancode)); } -#endif return nullptr; } -#ifdef __WIIU__ -std::vector> -ButtonMappingFactory::CreateDefaultWiiUButtonMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, - CONTROLLERBUTTONS_T bitmask) { - std::vector> mappings; - - auto wiiuIndexMapping = std::dynamic_pointer_cast( - Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetDeviceIndexMappingFromShipDeviceIndex(shipDeviceIndex)); - if (wiiuIndexMapping == nullptr) { - return std::vector>(); - } - - if (wiiuIndexMapping->IsWiiUGamepad()) { - switch (bitmask) { - case BTN_A: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_A, false, - false, VPAD_BUTTON_A)); - break; - case BTN_B: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_B, false, - false, VPAD_BUTTON_B)); - break; - case BTN_L: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_L, false, - false, VPAD_BUTTON_L)); - break; - case BTN_R: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_R, false, - false, VPAD_BUTTON_ZR)); - break; - case BTN_Z: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_Z, false, - false, VPAD_BUTTON_ZL)); - break; - case BTN_START: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_START, - false, false, VPAD_BUTTON_PLUS)); - break; - case BTN_CUP: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CUP, false, false, VPAD_STICK_R_EMULATION_UP)); - break; - case BTN_CDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CDOWN, false, false, VPAD_STICK_R_EMULATION_DOWN)); - break; - case BTN_CLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CLEFT, false, false, VPAD_STICK_R_EMULATION_LEFT)); - break; - case BTN_CRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CRIGHT, false, false, VPAD_STICK_R_EMULATION_RIGHT)); - break; - case BTN_DUP: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DUP, - false, false, VPAD_BUTTON_UP)); - break; - case BTN_DDOWN: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DDOWN, - false, false, VPAD_BUTTON_DOWN)); - break; - case BTN_DLEFT: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DLEFT, - false, false, VPAD_BUTTON_LEFT)); - break; - case BTN_DRIGHT: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DRIGHT, - false, false, VPAD_BUTTON_RIGHT)); - break; - } - - return mappings; - } - - switch (wiiuIndexMapping->GetExtensionType()) { - case WPAD_EXT_PRO_CONTROLLER: - switch (bitmask) { - case BTN_A: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_A, - false, false, WPAD_PRO_BUTTON_A)); - break; - case BTN_B: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_B, - false, false, WPAD_PRO_BUTTON_B)); - break; - case BTN_L: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_L, - false, false, WPAD_PRO_TRIGGER_L)); - break; - case BTN_R: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_R, - false, false, WPAD_PRO_TRIGGER_ZR)); - break; - case BTN_Z: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_Z, - false, false, WPAD_PRO_TRIGGER_ZL)); - break; - case BTN_START: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_START, false, false, WPAD_PRO_BUTTON_PLUS)); - break; - case BTN_CUP: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CUP, false, false, WPAD_PRO_STICK_R_EMULATION_UP)); - break; - case BTN_CDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CDOWN, false, false, WPAD_PRO_STICK_R_EMULATION_DOWN)); - break; - case BTN_CLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CLEFT, false, false, WPAD_PRO_STICK_R_EMULATION_LEFT)); - break; - case BTN_CRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CRIGHT, false, false, WPAD_PRO_STICK_R_EMULATION_RIGHT)); - break; - case BTN_DUP: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DUP, - false, false, WPAD_PRO_BUTTON_UP)); - break; - case BTN_DDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DDOWN, false, false, WPAD_PRO_BUTTON_DOWN)); - break; - case BTN_DLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DLEFT, false, false, WPAD_PRO_BUTTON_LEFT)); - break; - case BTN_DRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DRIGHT, false, false, WPAD_PRO_BUTTON_RIGHT)); - break; - } - return mappings; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - switch (bitmask) { - case BTN_A: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_A, - false, true, WPAD_CLASSIC_BUTTON_A)); - break; - case BTN_B: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_B, - false, true, WPAD_CLASSIC_BUTTON_B)); - break; - case BTN_L: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_L, - false, true, WPAD_CLASSIC_BUTTON_L)); - break; - case BTN_R: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_R, false, true, WPAD_CLASSIC_BUTTON_ZR)); - break; - case BTN_Z: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_Z, false, true, WPAD_CLASSIC_BUTTON_ZL)); - break; - case BTN_START: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_START, false, true, WPAD_CLASSIC_BUTTON_PLUS)); - break; - case BTN_CUP: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CUP, false, true, WPAD_CLASSIC_STICK_R_EMULATION_UP)); - break; - case BTN_CDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CDOWN, false, true, WPAD_CLASSIC_STICK_R_EMULATION_DOWN)); - break; - case BTN_CLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CLEFT, false, true, WPAD_CLASSIC_STICK_R_EMULATION_LEFT)); - break; - case BTN_CRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CRIGHT, false, true, WPAD_CLASSIC_STICK_R_EMULATION_RIGHT)); - break; - case BTN_DUP: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DUP, false, true, WPAD_CLASSIC_BUTTON_UP)); - break; - case BTN_DDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DDOWN, false, true, WPAD_CLASSIC_BUTTON_DOWN)); - break; - case BTN_DLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DLEFT, false, true, WPAD_CLASSIC_BUTTON_LEFT)); - break; - case BTN_DRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DRIGHT, false, true, WPAD_CLASSIC_BUTTON_RIGHT)); - break; - } - return mappings; - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - switch (bitmask) { - case BTN_A: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_A, - false, false, WPAD_BUTTON_A)); - break; - case BTN_B: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_B, - false, false, WPAD_BUTTON_B)); - break; - case BTN_L: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_L, - true, false, WPAD_NUNCHUK_BUTTON_C)); - break; - case BTN_Z: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_Z, false, false, WPAD_NUNCHUK_BUTTON_Z)); - break; - case BTN_START: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_START, false, false, WPAD_BUTTON_PLUS)); - break; - case BTN_CUP: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_CUP, - false, false, WPAD_BUTTON_UP)); - break; - case BTN_CDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CDOWN, false, false, WPAD_BUTTON_DOWN)); - break; - case BTN_CLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CLEFT, false, false, WPAD_BUTTON_LEFT)); - break; - case BTN_CRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_CRIGHT, false, false, WPAD_BUTTON_RIGHT)); - break; - } - return mappings; - case WPAD_EXT_MPLUS: - case WPAD_EXT_CORE: - switch (bitmask) { - case BTN_A: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_A, - false, false, WPAD_BUTTON_A)); - break; - case BTN_B: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_B, - false, false, WPAD_BUTTON_B)); - break; - case BTN_L: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_L, - false, false, WPAD_BUTTON_2)); - break; - case BTN_R: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_R, - false, false, WPAD_BUTTON_1)); - break; - case BTN_START: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_START, false, false, WPAD_BUTTON_PLUS)); - break; - case BTN_DUP: - mappings.push_back(std::make_shared(shipDeviceIndex, portIndex, BTN_DUP, - false, false, WPAD_BUTTON_UP)); - break; - case BTN_DDOWN: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DDOWN, false, false, WPAD_BUTTON_DOWN)); - break; - case BTN_DLEFT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DLEFT, false, false, WPAD_BUTTON_LEFT)); - break; - case BTN_DRIGHT: - mappings.push_back(std::make_shared( - shipDeviceIndex, portIndex, BTN_DRIGHT, false, false, WPAD_BUTTON_RIGHT)); - break; - } - return mappings; - default: - return mappings; - } -} - -std::shared_ptr -ButtonMappingFactory::CreateButtonMappingFromWiiUInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) { - for (auto [shipDeviceIndex, indexMapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::dynamic_pointer_cast(indexMapping); - - if (wiiuIndexMapping == nullptr) { - continue; - } - - if (wiiuIndexMapping->IsWiiUGamepad()) { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus == nullptr || verror != VPAD_READ_SUCCESS) { - continue; - } - - for (uint32_t i = VPAD_BUTTON_SYNC; i <= VPAD_STICK_L_EMULATION_LEFT; i <<= 1) { - if (!(vstatus->hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, bitmask, false, false, - i); - } - - continue; - } - - KPADError kerror; - KPADStatus* kstatus = - Ship::WiiU::GetKPADStatus(static_cast(wiiuIndexMapping->GetDeviceChannel()), &kerror); - - if (kstatus == nullptr || kerror != KPAD_ERROR_OK) { - continue; - } - - if (wiiuIndexMapping->GetExtensionType() == WPAD_EXT_PRO_CONTROLLER) { - for (uint32_t i = WPAD_PRO_BUTTON_UP; i <= WPAD_PRO_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->pro.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, bitmask, false, false, - i); - } - - continue; - } - - switch (wiiuIndexMapping->GetExtensionType()) { - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - for (auto i : { WPAD_NUNCHUK_STICK_EMULATION_LEFT, WPAD_NUNCHUK_STICK_EMULATION_RIGHT, - WPAD_NUNCHUK_STICK_EMULATION_DOWN, WPAD_NUNCHUK_STICK_EMULATION_UP, - WPAD_NUNCHUK_BUTTON_Z, WPAD_NUNCHUK_BUTTON_C }) { - if (!(kstatus->nunchuck.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, bitmask, true, false, - i); - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - for (uint32_t i = WPAD_CLASSIC_BUTTON_UP; i <= WPAD_CLASSIC_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->classic.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, bitmask, false, true, - i); - } - break; - } - - for (auto i : { WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT, WPAD_BUTTON_DOWN, WPAD_BUTTON_UP, WPAD_BUTTON_PLUS, - WPAD_BUTTON_2, WPAD_BUTTON_1, WPAD_BUTTON_B, WPAD_BUTTON_A, WPAD_BUTTON_MINUS, WPAD_BUTTON_Z, - WPAD_BUTTON_C, WPAD_BUTTON_HOME }) { - if (!(kstatus->hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, bitmask, false, false, i); - } - } - - return nullptr; -} -#else std::vector> ButtonMappingFactory::CreateDefaultKeyboardButtonMappings(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) { std::vector> mappings; @@ -689,5 +282,4 @@ ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROL return mapping; } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h index 72c0d8d61..1a11b3312 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h @@ -9,13 +9,7 @@ namespace Ship { class ButtonMappingFactory { public: static std::shared_ptr CreateButtonMappingFromConfig(uint8_t portIndex, std::string id); -#ifdef __WIIU__ - static std::vector> - CreateDefaultWiiUButtonMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); - static std::shared_ptr CreateButtonMappingFromWiiUInput(uint8_t portIndex, - CONTROLLERBUTTONS_T bitmask); -#else static std::vector> CreateDefaultKeyboardButtonMappings(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); @@ -24,6 +18,5 @@ class ButtonMappingFactory { static std::shared_ptr CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); -#endif }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.cpp index 9c8155530..1052d8006 100644 --- a/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.cpp @@ -1,9 +1,5 @@ #include "GyroMappingFactory.h" -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.h" -#else #include "controller/controldevice/controller/mapping/sdl/SDLGyroMapping.h" -#endif #include "public/bridge/consolevariablebridge.h" #include #include "libultraship/libultra/controller.h" @@ -24,27 +20,7 @@ std::shared_ptr GyroMappingFactory::CreateGyroMappingFrom CVarSave(); return nullptr; } -#ifdef __WIIU__ - if (mappingClass == "WiiUGyroMapping") { - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - - if (shipDeviceIndex < 0) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - float neutralPitch = - CVarGetFloat(StringHelper::Sprintf("%s.NeutralPitch", mappingCvarKey.c_str()).c_str(), 0.0f); - float neutralYaw = CVarGetFloat(StringHelper::Sprintf("%s.NeutralYaw", mappingCvarKey.c_str()).c_str(), 0.0f); - float neutralRoll = CVarGetFloat(StringHelper::Sprintf("%s.NeutralRoll", mappingCvarKey.c_str()).c_str(), 0.0f); - - return std::make_shared(static_cast(shipDeviceIndex), portIndex, sensitivity, - neutralPitch, neutralYaw, neutralRoll); - } -#else if (mappingClass == "SDLGyroMapping") { int32_t shipDeviceIndex = CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); @@ -64,41 +40,10 @@ std::shared_ptr GyroMappingFactory::CreateGyroMappingFrom return std::make_shared(static_cast(shipDeviceIndex), portIndex, sensitivity, neutralPitch, neutralYaw, neutralRoll); } -#endif - return nullptr; -} - -#ifdef __WIIU__ -std::shared_ptr GyroMappingFactory::CreateGyroMappingFromWiiUInput(uint8_t portIndex) { - for (auto [lusIndex, indexMapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::dynamic_pointer_cast(indexMapping); - - if (wiiuIndexMapping == nullptr) { - continue; - } - - if (wiiuIndexMapping->IsWiiUGamepad()) { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus == nullptr || verror != VPAD_READ_SUCCESS) { - continue; - } - - for (uint32_t i = VPAD_BUTTON_SYNC; i <= VPAD_STICK_L_EMULATION_LEFT; i <<= 1) { - if (!(vstatus->hold & i)) { - continue; - } - - return std::make_shared(lusIndex, portIndex, 1.0f, 0.0f, 0.0f, 0.0f); - } - } - } return nullptr; } -#else + std::shared_ptr GyroMappingFactory::CreateGyroMappingFromSDLInput(uint8_t portIndex) { std::unordered_map sdlControllersWithGyro; std::shared_ptr mapping = nullptr; @@ -165,5 +110,4 @@ std::shared_ptr GyroMappingFactory::CreateGyroMappingFrom return mapping; } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.h index b5efe6f53..97a0fb388 100644 --- a/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/GyroMappingFactory.h @@ -8,10 +8,6 @@ namespace Ship { class GyroMappingFactory { public: static std::shared_ptr CreateGyroMappingFromConfig(uint8_t portIndex, std::string id); -#ifdef __WIIU__ - static std::shared_ptr CreateGyroMappingFromWiiUInput(uint8_t portIndex); -#else static std::shared_ptr CreateGyroMappingFromSDLInput(uint8_t portIndex); -#endif }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.cpp index f9de37aa7..3f3f79554 100644 --- a/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.cpp @@ -1,7 +1,5 @@ #include "LEDMappingFactory.h" -#ifndef __WIIU__ #include "controller/controldevice/controller/mapping/sdl/SDLLEDMapping.h" -#endif #include "public/bridge/consolevariablebridge.h" #include #include "libultraship/libultra/controller.h" @@ -10,7 +8,6 @@ namespace Ship { std::shared_ptr LEDMappingFactory::CreateLEDMappingFromConfig(uint8_t portIndex, std::string id) { -#ifndef __WIIU__ const std::string mappingCvarKey = "gControllers.LEDMappings." + id; const std::string mappingClass = CVarGetString(StringHelper::Sprintf("%s.LEDMappingClass", mappingCvarKey.c_str()).c_str(), ""); @@ -41,12 +38,10 @@ std::shared_ptr LEDMappingFactory::CreateLEDMappingFromCon return std::make_shared(static_cast(shipDeviceIndex), portIndex, colorSource, savedColor); } -#endif return nullptr; } -#ifndef __WIIU__ std::shared_ptr LEDMappingFactory::CreateLEDMappingFromSDLInput(uint8_t portIndex) { std::unordered_map sdlControllersWithLEDs; std::shared_ptr mapping = nullptr; @@ -111,5 +106,4 @@ std::shared_ptr LEDMappingFactory::CreateLEDMappingFromSDL return mapping; } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.h index 96e2ec5c3..b129c2e20 100644 --- a/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/LEDMappingFactory.h @@ -9,8 +9,6 @@ namespace Ship { class LEDMappingFactory { public: static std::shared_ptr CreateLEDMappingFromConfig(uint8_t portIndex, std::string id); -#ifndef __WIIU__ static std::shared_ptr CreateLEDMappingFromSDLInput(uint8_t portIndex); -#endif }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.cpp index 04b7652a5..f405b49d0 100644 --- a/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.cpp @@ -1,9 +1,5 @@ #include "RumbleMappingFactory.h" -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.h" -#else #include "controller/controldevice/controller/mapping/sdl/SDLRumbleMapping.h" -#endif #include "public/bridge/consolevariablebridge.h" #include #include "libultraship/libultra/controller.h" @@ -30,22 +26,6 @@ std::shared_ptr RumbleMappingFactory::CreateRumbleMappi return nullptr; } -#ifdef __WIIU__ - if (mappingClass == "WiiURumbleMapping") { - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - - if (shipDeviceIndex < 0) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - - return std::make_shared(static_cast(shipDeviceIndex), portIndex, - lowFrequencyIntensityPercentage, highFrequencyIntensityPercentage); - } -#else if (mappingClass == "SDLRumbleMapping") { int32_t shipDeviceIndex = CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); @@ -60,127 +40,10 @@ std::shared_ptr RumbleMappingFactory::CreateRumbleMappi return std::make_shared(static_cast(shipDeviceIndex), portIndex, lowFrequencyIntensityPercentage, highFrequencyIntensityPercentage); } -#endif return nullptr; } -#ifdef __WIIU__ -std::vector> -RumbleMappingFactory::CreateDefaultWiiURumbleMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex) { - auto wiiuIndexMapping = std::dynamic_pointer_cast( - Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetDeviceIndexMappingFromShipDeviceIndex(shipDeviceIndex)); - if (wiiuIndexMapping == nullptr) { - return std::vector>(); - } - - std::vector> mappings = { std::make_shared( - shipDeviceIndex, portIndex, DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE) }; - - return mappings; -} - -std::shared_ptr RumbleMappingFactory::CreateRumbleMappingFromWiiUInput(uint8_t portIndex) { - for (auto [shipDeviceIndex, indexMapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::dynamic_pointer_cast(indexMapping); - - if (wiiuIndexMapping == nullptr) { - continue; - } - - if (wiiuIndexMapping->IsWiiUGamepad()) { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus == nullptr || verror != VPAD_READ_SUCCESS) { - continue; - } - - for (uint32_t i = VPAD_BUTTON_SYNC; i <= VPAD_STICK_L_EMULATION_LEFT; i <<= 1) { - if (!(vstatus->hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, - DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE); - } - - continue; - } - - KPADError kerror; - KPADStatus* kstatus = - Ship::WiiU::GetKPADStatus(static_cast(wiiuIndexMapping->GetDeviceChannel()), &kerror); - - if (kstatus == nullptr || kerror != KPAD_ERROR_OK) { - continue; - } - - if (wiiuIndexMapping->GetExtensionType() == WPAD_EXT_PRO_CONTROLLER) { - for (uint32_t i = WPAD_PRO_BUTTON_UP; i <= WPAD_PRO_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->pro.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, - DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE); - } - - continue; - } - - switch (wiiuIndexMapping->GetExtensionType()) { - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - for (auto i : { WPAD_NUNCHUK_STICK_EMULATION_LEFT, WPAD_NUNCHUK_STICK_EMULATION_RIGHT, - WPAD_NUNCHUK_STICK_EMULATION_DOWN, WPAD_NUNCHUK_STICK_EMULATION_UP, - WPAD_NUNCHUK_BUTTON_Z, WPAD_NUNCHUK_BUTTON_C }) { - if (!(kstatus->nunchuck.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, - DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE); - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - for (uint32_t i = WPAD_CLASSIC_BUTTON_UP; i <= WPAD_CLASSIC_STICK_R_EMULATION_UP; i <<= 1) { - if (!(kstatus->classic.hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, - DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE); - } - break; - } - - for (auto i : { WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT, WPAD_BUTTON_DOWN, WPAD_BUTTON_UP, WPAD_BUTTON_PLUS, - WPAD_BUTTON_2, WPAD_BUTTON_1, WPAD_BUTTON_B, WPAD_BUTTON_A, WPAD_BUTTON_MINUS, WPAD_BUTTON_Z, - WPAD_BUTTON_C, WPAD_BUTTON_HOME }) { - if (!(kstatus->hold & i)) { - continue; - } - - return std::make_shared(shipDeviceIndex, portIndex, - DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE, - DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE); - } - } - - return nullptr; -} -#else std::vector> RumbleMappingFactory::CreateDefaultSDLRumbleMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex) { auto sdlIndexMapping = std::dynamic_pointer_cast( @@ -271,5 +134,4 @@ std::shared_ptr RumbleMappingFactory::CreateRumbleMappi return mapping; } -#endif } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.h index 14c56cfcd..cb412a6dd 100644 --- a/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/RumbleMappingFactory.h @@ -10,15 +10,9 @@ class RumbleMappingFactory { public: static std::shared_ptr CreateRumbleMappingFromConfig(uint8_t portIndex, std::string id); -#ifdef __WIIU__ - static std::vector> - CreateDefaultWiiURumbleMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex); - static std::shared_ptr CreateRumbleMappingFromWiiUInput(uint8_t portIndex); -#else static std::vector> CreateDefaultSDLRumbleMappings(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex); static std::shared_ptr CreateRumbleMappingFromSDLInput(uint8_t portIndex); -#endif }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.cpp deleted file mode 100644 index 41403120f..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUAxisDirectionToAxisDirectionMapping.h" -#include -#include -#include "window/gui/IconsFontAwesome4.h" -#include "public/bridge/consolevariablebridge.h" -#include "Context.h" - -namespace Ship { -WiiUAxisDirectionToAxisDirectionMapping::WiiUAxisDirectionToAxisDirectionMapping(ShipDeviceIndex shipDeviceIndex, - uint8_t portIndex, Stick stick, - Direction direction, - int32_t wiiuControllerAxis, - int32_t axisDirection) - : ControllerInputMapping(shipDeviceIndex), - ControllerAxisDirectionMapping(shipDeviceIndex, portIndex, stick, direction), WiiUMapping(shipDeviceIndex), - mControllerAxis(wiiuControllerAxis) { - mAxisDirection = static_cast(axisDirection); -} - -float WiiUAxisDirectionToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { - if (Context::GetInstance()->GetControlDeck()->GamepadGameInputBlocked()) { - return 0.0f; - } - - float wiiUAxisValue = 0.0f; - - if (IsGamepad()) { - VPADReadError error; - VPADStatus* status = Ship::WiiU::GetVPADStatus(&error); - if (status == nullptr) { - return 0.0f; - } - - switch (mControllerAxis) { - case WII_U_AXIS_LEFT_STICK_X: - wiiUAxisValue = status->leftStick.x; - break; - case WII_U_AXIS_LEFT_STICK_Y: - wiiUAxisValue = status->leftStick.y * -1.0; - break; - case WII_U_AXIS_RIGHT_STICK_X: - wiiUAxisValue = status->rightStick.x; - break; - case WII_U_AXIS_RIGHT_STICK_Y: - wiiUAxisValue = status->rightStick.y * -1.0; - break; - } - } else { - KPADError error; - KPADStatus* status = Ship::WiiU::GetKPADStatus(static_cast(GetWiiUDeviceChannel()), &error); - if (status == nullptr || error != KPAD_ERROR_OK) { - return 0.0f; - } - - if (status->extensionType != ExtensionType()) { - return 0.0f; - } - - switch (ExtensionType()) { - case WPAD_EXT_PRO_CONTROLLER: - switch (mControllerAxis) { - case WII_U_AXIS_LEFT_STICK_X: - wiiUAxisValue = status->pro.leftStick.x; - break; - case WII_U_AXIS_LEFT_STICK_Y: - wiiUAxisValue = status->pro.leftStick.y * -1.0; - break; - case WII_U_AXIS_RIGHT_STICK_X: - wiiUAxisValue = status->pro.rightStick.x; - break; - case WII_U_AXIS_RIGHT_STICK_Y: - wiiUAxisValue = status->pro.rightStick.y * -1.0; - break; - } - break; - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - switch (mControllerAxis) { - case WII_U_AXIS_NUNCHUK_STICK_X: - wiiUAxisValue = status->nunchuck.stick.x; - break; - case WII_U_AXIS_NUNCHUK_STICK_Y: - wiiUAxisValue = status->nunchuck.stick.y * -1.0; - break; - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - switch (mControllerAxis) { - case WII_U_AXIS_LEFT_STICK_X: - wiiUAxisValue = status->classic.leftStick.x; - break; - case WII_U_AXIS_LEFT_STICK_Y: - wiiUAxisValue = status->classic.leftStick.y; - break; - case WII_U_AXIS_RIGHT_STICK_X: - wiiUAxisValue = status->classic.rightStick.x; - break; - case WII_U_AXIS_RIGHT_STICK_Y: - wiiUAxisValue = status->classic.rightStick.y; - break; - } - break; - } - } - - if ((mAxisDirection == POSITIVE && wiiUAxisValue < 0) || (mAxisDirection == NEGATIVE && wiiUAxisValue > 0)) { - return 0.0f; - } - - // scale {-1.0 ... +1.0} to {-MAX_AXIS_RANGE ... +MAX_AXIS_RANGE} - // and return the absolute value of it - return fabs(wiiUAxisValue * MAX_AXIS_RANGE); -} - -std::string WiiUAxisDirectionToAxisDirectionMapping::GetAxisDirectionMappingId() { - return StringHelper::Sprintf("P%d-S%d-D%d-LUSI%d-A%d-AD%s", mPortIndex, mStick, mDirection, - ControllerInputMapping::mShipDeviceIndex, mControllerAxis, - mAxisDirection == 1 ? "P" : "N"); -} - -void WiiUAxisDirectionToAxisDirectionMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.AxisDirectionMappings." + GetAxisDirectionMappingId(); - CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), - "WiiUAxisDirectionToAxisDirectionMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStick); - CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), - ControllerInputMapping::mShipDeviceIndex); - CVarSetInteger(StringHelper::Sprintf("%s.WiiUControllerAxis", mappingCvarKey.c_str()).c_str(), mControllerAxis); - CVarSetInteger(StringHelper::Sprintf("%s.AxisDirection", mappingCvarKey.c_str()).c_str(), mAxisDirection); - CVarSave(); -} - -void WiiUAxisDirectionToAxisDirectionMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.AxisDirectionMappings." + GetAxisDirectionMappingId(); - CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.WiiUControllerAxis", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.AxisDirection", mappingCvarKey.c_str()).c_str()); - CVarSave(); -} - -uint8_t WiiUAxisDirectionToAxisDirectionMapping::GetMappingType() { - return MAPPING_TYPE_GAMEPAD; -} - -std::string WiiUAxisDirectionToAxisDirectionMapping::GetPhysicalInputName() { - switch (mControllerAxis) { - case WII_U_AXIS_LEFT_STICK_X: - return StringHelper::Sprintf("Left Stick %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_LEFT : ICON_FA_ARROW_RIGHT); - case WII_U_AXIS_LEFT_STICK_Y: - return StringHelper::Sprintf("Left Stick %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_UP : ICON_FA_ARROW_DOWN); - case WII_U_AXIS_RIGHT_STICK_X: - return StringHelper::Sprintf("Right Stick %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_LEFT : ICON_FA_ARROW_RIGHT); - case WII_U_AXIS_RIGHT_STICK_Y: - return StringHelper::Sprintf("Right Stick %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_UP : ICON_FA_ARROW_DOWN); - case WII_U_AXIS_NUNCHUK_STICK_X: - return StringHelper::Sprintf("Nunchuk %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_LEFT : ICON_FA_ARROW_RIGHT); - case WII_U_AXIS_NUNCHUK_STICK_Y: - return StringHelper::Sprintf("Nunchuk %s", - mAxisDirection == NEGATIVE ? ICON_FA_ARROW_UP : ICON_FA_ARROW_DOWN); - } - - return StringHelper::Sprintf("Axis %d %s", mControllerAxis, - mAxisDirection == NEGATIVE ? ICON_FA_MINUS : ICON_FA_PLUS); -} - -std::string WiiUAxisDirectionToAxisDirectionMapping::GetPhysicalDeviceName() { - return GetWiiUDeviceName(); -} - -bool WiiUAxisDirectionToAxisDirectionMapping::PhysicalDeviceIsConnected() { - return WiiUDeviceIsConnected(); -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.h deleted file mode 100644 index 160cfd96d..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUAxisDirectionToAxisDirectionMapping.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" -#include "WiiUMapping.h" - -#define WII_U_AXIS_LEFT_STICK_X 0 -#define WII_U_AXIS_LEFT_STICK_Y 1 -#define WII_U_AXIS_RIGHT_STICK_X 2 -#define WII_U_AXIS_RIGHT_STICK_Y 3 -#define WII_U_AXIS_NUNCHUK_STICK_X 4 -#define WII_U_AXIS_NUNCHUK_STICK_Y 5 - -namespace Ship { -class WiiUAxisDirectionToAxisDirectionMapping final : public ControllerAxisDirectionMapping, public WiiUMapping { - public: - WiiUAxisDirectionToAxisDirectionMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, Stick stick, - Direction direction, int32_t wiiuControllerAxis, int32_t axisDirection); - float GetNormalizedAxisDirectionValue() override; - std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; - void SaveToConfig() override; - void EraseFromConfig() override; - std::string GetPhysicalInputName() override; - std::string GetPhysicalDeviceName() override; - bool PhysicalDeviceIsConnected() override; - - private: - int32_t mControllerAxis; - AxisDirection mAxisDirection; -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.cpp deleted file mode 100644 index 0d59572f8..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.cpp +++ /dev/null @@ -1,300 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUButtonToAnyMapping.h" - -#include -#include "window/gui/IconsFontAwesome4.h" - -namespace Ship { -WiiUButtonToAnyMapping::WiiUButtonToAnyMapping(ShipDeviceIndex shipDeviceIndex, bool isNunchuk, bool isClassic, - uint32_t wiiuControllerButton) - : ControllerInputMapping(shipDeviceIndex), WiiUMapping(shipDeviceIndex), mIsNunchukButton(isNunchuk), - mControllerButton(wiiuControllerButton) { -} - -WiiUButtonToAnyMapping::~WiiUButtonToAnyMapping() { -} - -std::string WiiUButtonToAnyMapping::GetGamepadButtonName() { - switch (mControllerButton) { - case VPAD_BUTTON_A: - return "A"; - case VPAD_BUTTON_B: - return "B"; - case VPAD_BUTTON_X: - return "X"; - case VPAD_BUTTON_Y: - return "Y"; - case VPAD_BUTTON_LEFT: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_LEFT); - case VPAD_BUTTON_RIGHT: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_RIGHT); - case VPAD_BUTTON_UP: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_UP); - case VPAD_BUTTON_DOWN: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_DOWN); - case VPAD_BUTTON_ZL: - return "ZL"; - case VPAD_BUTTON_ZR: - return "ZR"; - case VPAD_BUTTON_L: - return "L"; - case VPAD_BUTTON_R: - return "R"; - case VPAD_BUTTON_PLUS: - return StringHelper::Sprintf("%s", ICON_FA_PLUS); - case VPAD_BUTTON_MINUS: - return StringHelper::Sprintf("%s", ICON_FA_MINUS); - case VPAD_BUTTON_HOME: - return StringHelper::Sprintf("%s", ICON_FA_HOME); - case VPAD_BUTTON_SYNC: - return "Sync"; - case VPAD_BUTTON_STICK_R: - return "Right Stick Press"; // it seems the official term is just long for these - case VPAD_BUTTON_STICK_L: - return "Left Stick Press"; // it seems the official term is just long for these - case VPAD_BUTTON_TV: - return "TV"; - case VPAD_STICK_R_EMULATION_LEFT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_LEFT); - case VPAD_STICK_R_EMULATION_RIGHT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_RIGHT); - case VPAD_STICK_R_EMULATION_UP: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_UP); - case VPAD_STICK_R_EMULATION_DOWN: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_DOWN); - case VPAD_STICK_L_EMULATION_LEFT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_LEFT); - case VPAD_STICK_L_EMULATION_RIGHT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_RIGHT); - case VPAD_STICK_L_EMULATION_UP: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_UP); - case VPAD_STICK_L_EMULATION_DOWN: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_DOWN); - default: - return "Unknown"; - } -} - -std::string WiiUButtonToAnyMapping::GetWiiRemoteButtonName() { - switch (mControllerButton) { - case WPAD_BUTTON_LEFT: - return StringHelper::Sprintf("D-Pad %s (Wii Remote)", ICON_FA_ARROW_LEFT); - case WPAD_BUTTON_RIGHT: - return StringHelper::Sprintf("D-Pad %s (Wii Remote)", ICON_FA_ARROW_RIGHT); - case WPAD_BUTTON_DOWN: - return StringHelper::Sprintf("D-Pad %s (Wii Remote)", ICON_FA_ARROW_DOWN); - case WPAD_BUTTON_UP: - return StringHelper::Sprintf("D-Pad %s (Wii Remote)", ICON_FA_ARROW_UP); - case WPAD_BUTTON_PLUS: - return StringHelper::Sprintf("%s", ICON_FA_PLUS); - case WPAD_BUTTON_2: - return "2"; - case WPAD_BUTTON_1: - return "1"; - case WPAD_BUTTON_B: - return "B (Wii Remote)"; - case WPAD_BUTTON_A: - return "A (Wii Remote)"; - case WPAD_BUTTON_MINUS: - return StringHelper::Sprintf("%s", ICON_FA_MINUS); - case WPAD_BUTTON_Z: - return "Z"; - case WPAD_BUTTON_C: - return "C"; - case WPAD_BUTTON_HOME: - return StringHelper::Sprintf("%s", ICON_FA_HOME); - default: - return "Unknown"; - } -} - -std::string WiiUButtonToAnyMapping::GetNunchukButtonName() { - switch (mControllerButton) { - case WPAD_NUNCHUK_STICK_EMULATION_LEFT: - return StringHelper::Sprintf("Nunchuk %s", ICON_FA_ARROW_LEFT); - case WPAD_NUNCHUK_STICK_EMULATION_RIGHT: - return StringHelper::Sprintf("Nunchuk %s", ICON_FA_ARROW_RIGHT); - case WPAD_NUNCHUK_STICK_EMULATION_DOWN: - return StringHelper::Sprintf("Nunchuk %s", ICON_FA_ARROW_DOWN); - case WPAD_NUNCHUK_STICK_EMULATION_UP: - return StringHelper::Sprintf("Nunchuk %s", ICON_FA_ARROW_UP); - case WPAD_NUNCHUK_BUTTON_Z: - return "Z"; - case WPAD_NUNCHUK_BUTTON_C: - return "C"; - default: - return "Unknown"; - } -} - -std::string WiiUButtonToAnyMapping::GetClassicControllerButtonName() { - switch (mControllerButton) { - case WPAD_CLASSIC_BUTTON_UP: - return StringHelper::Sprintf("D-Pad %s (Classic)", ICON_FA_ARROW_UP); - case WPAD_CLASSIC_BUTTON_LEFT: - return StringHelper::Sprintf("D-Pad %s (Classic)", ICON_FA_ARROW_LEFT); - case WPAD_CLASSIC_BUTTON_ZR: - return "ZR"; - case WPAD_CLASSIC_BUTTON_X: - return "X"; - case WPAD_CLASSIC_BUTTON_A: - return "A (Classic)"; - case WPAD_CLASSIC_BUTTON_Y: - return "Y"; - case WPAD_CLASSIC_BUTTON_B: - return "B (Classic)"; - case WPAD_CLASSIC_BUTTON_ZL: - return "ZL"; - case WPAD_CLASSIC_BUTTON_R: - return "R"; - case WPAD_CLASSIC_BUTTON_PLUS: - return StringHelper::Sprintf("%s", ICON_FA_PLUS); - case WPAD_CLASSIC_BUTTON_HOME: - return StringHelper::Sprintf("%s", ICON_FA_HOME); - case WPAD_CLASSIC_BUTTON_MINUS: - return StringHelper::Sprintf("%s", ICON_FA_MINUS); - case WPAD_CLASSIC_BUTTON_L: - return "L"; - case WPAD_CLASSIC_BUTTON_DOWN: - return StringHelper::Sprintf("Classic D-Pad %s", ICON_FA_ARROW_DOWN); - case WPAD_CLASSIC_BUTTON_RIGHT: - return StringHelper::Sprintf("Classic D-Pad %s", ICON_FA_ARROW_RIGHT); - case WPAD_CLASSIC_STICK_L_EMULATION_LEFT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_LEFT); - case WPAD_CLASSIC_STICK_L_EMULATION_RIGHT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_RIGHT); - case WPAD_CLASSIC_STICK_L_EMULATION_DOWN: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_DOWN); - case WPAD_CLASSIC_STICK_L_EMULATION_UP: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_UP); - case WPAD_CLASSIC_STICK_R_EMULATION_LEFT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_LEFT); - case WPAD_CLASSIC_STICK_R_EMULATION_RIGHT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_RIGHT); - case WPAD_CLASSIC_STICK_R_EMULATION_DOWN: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_DOWN); - case WPAD_CLASSIC_STICK_R_EMULATION_UP: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_UP); - default: - return "Unknown"; - } -} - -std::string WiiUButtonToAnyMapping::GetProControllerButtonName() { - switch (mControllerButton) { - case WPAD_PRO_BUTTON_UP: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_UP); - case WPAD_PRO_BUTTON_LEFT: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_LEFT); - case WPAD_PRO_TRIGGER_ZR: - return "ZR"; - case WPAD_PRO_BUTTON_X: - return "X"; - case WPAD_PRO_BUTTON_A: - return "A"; - case WPAD_PRO_BUTTON_Y: - return "Y"; - case WPAD_PRO_BUTTON_B: - return "B"; - case WPAD_PRO_TRIGGER_ZL: - return "ZL"; - case WPAD_PRO_TRIGGER_R: - return "R"; - case WPAD_PRO_BUTTON_PLUS: - return StringHelper::Sprintf("%s", ICON_FA_PLUS); - case WPAD_PRO_BUTTON_HOME: - return StringHelper::Sprintf("%s", ICON_FA_HOME); - case WPAD_PRO_BUTTON_MINUS: - return StringHelper::Sprintf("%s", ICON_FA_MINUS); - case WPAD_PRO_TRIGGER_L: - return "L"; - case WPAD_PRO_BUTTON_DOWN: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_DOWN); - case WPAD_PRO_BUTTON_RIGHT: - return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_RIGHT); - case WPAD_PRO_BUTTON_STICK_R: - return "Right Stick Press"; // it seems the official term is just long for these - case WPAD_PRO_BUTTON_STICK_L: - return "Left Stick Press"; // it seems the official term is just long for these - case WPAD_PRO_STICK_L_EMULATION_UP: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_UP); - case WPAD_PRO_STICK_L_EMULATION_DOWN: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_DOWN); - case WPAD_PRO_STICK_L_EMULATION_LEFT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_LEFT); - case WPAD_PRO_STICK_L_EMULATION_RIGHT: - return StringHelper::Sprintf("Left Stick %s", ICON_FA_ARROW_RIGHT); - case WPAD_PRO_STICK_R_EMULATION_UP: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_UP); - case WPAD_PRO_STICK_R_EMULATION_DOWN: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_DOWN); - case WPAD_PRO_STICK_R_EMULATION_LEFT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_LEFT); - case WPAD_PRO_STICK_R_EMULATION_RIGHT: - return StringHelper::Sprintf("Right Stick %s", ICON_FA_ARROW_RIGHT); - default: - return "Unknown"; - } -} - -std::string WiiUButtonToAnyMapping::GetPhysicalInputName() { - if (IsGamepad()) { - return GetGamepadButtonName(); - } - - if (ExtensionType() == WPAD_EXT_PRO_CONTROLLER) { - return GetProControllerButtonName(); - } - - if (mIsClassicControllerButton) { - return GetClassicControllerButtonName(); - } - - if (mIsNunchukButton) { - return GetNunchukButtonName(); - } - - return GetWiiRemoteButtonName(); -} - -std::string WiiUButtonToAnyMapping::GetPhysicalDeviceName() { - return GetWiiUDeviceName(); -} - -bool WiiUButtonToAnyMapping::PhysicalDeviceIsConnected() { - return WiiUDeviceIsConnected(); -} - -bool WiiUButtonToAnyMapping::PhysicalButtonIsPressed() { - if (IsGamepad()) { - VPADReadError error; - VPADStatus* status = Ship::WiiU::GetVPADStatus(&error); - if (status == nullptr) { - return false; - } - - return status->hold & mControllerButton; - } - - KPADError error; - KPADStatus* status = Ship::WiiU::GetKPADStatus(static_cast(GetWiiUDeviceChannel()), &error); - if (status == nullptr || error != KPAD_ERROR_OK) { - return false; - } - - if (ExtensionType() == WPAD_EXT_PRO_CONTROLLER) { - return status->pro.hold & mControllerButton; - } - - if (mIsClassicControllerButton) { - return status->classic.hold & mControllerButton; - } - - if (mIsNunchukButton) { - return status->nunchuck.hold & mControllerButton; - } - - return status->hold & mControllerButton; -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.h deleted file mode 100644 index 280a4b537..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAnyMapping.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef __WIIU__ -#pragma once - -#include "WiiUMapping.h" -#include "controller/controldevice/controller/mapping/ControllerInputMapping.h" - -namespace Ship { -class WiiUButtonToAnyMapping : virtual public ControllerInputMapping, public WiiUMapping { - public: - WiiUButtonToAnyMapping(ShipDeviceIndex shipDeviceIndex, bool isNunchuk, bool isClassic, - uint32_t wiiuControllerButton); - ~WiiUButtonToAnyMapping(); - std::string GetPhysicalInputName() override; - std::string GetPhysicalDeviceName() override; - bool PhysicalDeviceIsConnected() override; - - protected: - bool mIsNunchukButton; - bool mIsClassicControllerButton; - uint32_t mControllerButton; - bool PhysicalButtonIsPressed(); - - private: - std::string GetGamepadButtonName(); - std::string GetWiiRemoteButtonName(); - std::string GetNunchukButtonName(); - std::string GetClassicControllerButtonName(); - std::string GetProControllerButtonName(); -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.cpp deleted file mode 100644 index 24a8b04df..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUButtonToAxisDirectionMapping.h" -#include -#include -#include "window/gui/IconsFontAwesome4.h" -#include "public/bridge/consolevariablebridge.h" -#include "Context.h" - -namespace Ship { -WiiUButtonToAxisDirectionMapping::WiiUButtonToAxisDirectionMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, - Stick stick, Direction direction, bool isNunchuk, - bool isClassic, uint32_t wiiuControllerButton) - : ControllerInputMapping(shipDeviceIndex), - ControllerAxisDirectionMapping(shipDeviceIndex, portIndex, stick, direction), - WiiUButtonToAnyMapping(shipDeviceIndex, isNunchuk, isClassic, wiiuControllerButton) { -} - -float WiiUButtonToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { - if (!Context::GetInstance()->GetControlDeck()->GamepadGameInputBlocked() && PhysicalButtonIsPressed()) { - return MAX_AXIS_RANGE; - } - - return 0.0f; -} - -std::string WiiUButtonToAxisDirectionMapping::GetAxisDirectionMappingId() { - return StringHelper::Sprintf("P%d-S%d-D%d-LUSI%d-N%d-C%d-B%d", mPortIndex, mStick, mDirection, - ControllerInputMapping::mShipDeviceIndex, mIsNunchukButton, mIsClassicControllerButton, - mControllerButton); -} - -void WiiUButtonToAxisDirectionMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.AxisDirectionMappings." + GetAxisDirectionMappingId(); - CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), - "WiiUButtonToAxisDirectionMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStick); - CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), - ControllerInputMapping::mShipDeviceIndex); - CVarSetInteger(StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str(), - mIsClassicControllerButton); - CVarSetInteger(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str(), mIsNunchukButton); - CVarSetInteger(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str(), mControllerButton); - CVarSave(); -} - -void WiiUButtonToAxisDirectionMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.AxisDirectionMappings." + GetAxisDirectionMappingId(); - CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str()); - CVarSave(); -} - -uint8_t WiiUButtonToAxisDirectionMapping::GetMappingType() { - return MAPPING_TYPE_GAMEPAD; -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.h deleted file mode 100644 index 3b497d229..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToAxisDirectionMapping.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" -#include "WiiUButtonToAnyMapping.h" - -namespace Ship { -class WiiUButtonToAxisDirectionMapping final : public ControllerAxisDirectionMapping, public WiiUButtonToAnyMapping { - public: - WiiUButtonToAxisDirectionMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, Stick stick, - Direction direction, bool isNunchuk, bool isClassic, - uint32_t wiiuControllerButton); - - float GetNormalizedAxisDirectionValue() override; - std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; - void SaveToConfig() override; - void EraseFromConfig() override; -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.cpp deleted file mode 100644 index 6d58fc2d0..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUButtonToButtonMapping.h" -#include -#include -#include "window/gui/IconsFontAwesome4.h" -#include "public/bridge/consolevariablebridge.h" -#include "Context.h" - -namespace Ship { -WiiUButtonToButtonMapping::WiiUButtonToButtonMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, - CONTROLLERBUTTONS_T bitmask, bool isNunchuk, bool isClassic, - uint32_t wiiuControllerButton) - : ControllerInputMapping(shipDeviceIndex), ControllerButtonMapping(shipDeviceIndex, portIndex, bitmask), - WiiUButtonToAnyMapping(shipDeviceIndex, isNunchuk, isClassic, wiiuControllerButton) { -} - -void WiiUButtonToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { - if (Context::GetInstance()->GetControlDeck()->GamepadGameInputBlocked()) { - return; - } - - if (PhysicalButtonIsPressed()) { - padButtons |= mBitmask; - } -} - -uint8_t WiiUButtonToButtonMapping::GetMappingType() { - return MAPPING_TYPE_GAMEPAD; -} - -std::string WiiUButtonToButtonMapping::GetButtonMappingId() { - return StringHelper::Sprintf("P%d-B%d-LUSI%d-N%d-C%d-B%d", mPortIndex, mBitmask, - ControllerInputMapping::mShipDeviceIndex, mIsNunchukButton ? 1 : 0, - mIsClassicControllerButton ? 1 : 0, mControllerButton); -} - -void WiiUButtonToButtonMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.ButtonMappings." + GetButtonMappingId(); - CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), - "WiiUButtonToButtonMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), - ControllerInputMapping::mShipDeviceIndex); - CVarSetInteger(StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str(), - mIsNunchukButton ? 1 : 0); - CVarSetInteger(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str(), - mIsClassicControllerButton ? 1 : 0); - CVarSetInteger(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str(), mControllerButton); - CVarSave(); -} - -void WiiUButtonToButtonMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.ButtonMappings." + GetButtonMappingId(); - - CVarClear(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.IsClassicControllerButton", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.IsNunchukButton", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.WiiUControllerButton", mappingCvarKey.c_str()).c_str()); - CVarSave(); -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.h deleted file mode 100644 index d4aa8d6b4..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUButtonToButtonMapping.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" -#include "WiiUButtonToAnyMapping.h" - -namespace Ship { -class WiiUButtonToButtonMapping final : public WiiUButtonToAnyMapping, public ControllerButtonMapping { - public: - WiiUButtonToButtonMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, - bool isNunchuk, bool isClassic, uint32_t wiiuControllerButton); - void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; - uint8_t GetMappingType() override; - std::string GetButtonMappingId() override; - void SaveToConfig() override; - void EraseFromConfig() override; -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.cpp deleted file mode 100644 index ef1a6cb19..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUGyroMapping.h" -#include "controller/controldevice/controller/mapping/ControllerGyroMapping.h" -#include -#include "Context.h" - -#include "public/bridge/consolevariablebridge.h" -#include - -namespace Ship { -WiiUGyroMapping::WiiUGyroMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, float sensitivity, - float neutralPitch, float neutralYaw, float neutralRoll) - : ControllerInputMapping(shipDeviceIndex), ControllerGyroMapping(shipDeviceIndex, portIndex, sensitivity), - mNeutralPitch(neutralPitch), WiiUMapping(shipDeviceIndex), mNeutralYaw(neutralYaw), mNeutralRoll(neutralRoll) { -} - -void WiiUGyroMapping::Recalibrate() { - if (!IsGamepad()) { - mNeutralPitch = 0; - mNeutralYaw = 0; - mNeutralRoll = 0; - return; - } - - VPADReadError error; - VPADStatus* status = Ship::WiiU::GetVPADStatus(&error); - if (status == nullptr) { - mNeutralPitch = 0; - mNeutralYaw = 0; - mNeutralRoll = 0; - return; - } - - mNeutralPitch = status->gyro.x * -8.0f; - mNeutralYaw = status->gyro.z * 8.0f; - mNeutralRoll = status->gyro.y * 8.0f; -} - -void WiiUGyroMapping::UpdatePad(float& x, float& y) { - if (!IsGamepad() || Context::GetInstance()->GetControlDeck()->GamepadGameInputBlocked()) { - x = 0; - y = 0; - return; - } - - VPADReadError error; - VPADStatus* status = Ship::WiiU::GetVPADStatus(&error); - if (status == nullptr) { - x = 0; - y = 0; - return; - } - - x = ((status->gyro.x * -8.0f) - mNeutralPitch) * mSensitivity; - y = ((status->gyro.z * 8.0f) - mNeutralYaw) * mSensitivity; -} - -std::string WiiUGyroMapping::GetGyroMappingId() { - return StringHelper::Sprintf("P%d-LUSI%d", mPortIndex, ControllerInputMapping::mShipDeviceIndex); -} - -void WiiUGyroMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.GyroMappings." + GetGyroMappingId(); - - CVarSetString(StringHelper::Sprintf("%s.GyroMappingClass", mappingCvarKey.c_str()).c_str(), "WiiUGyroMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), - ControllerInputMapping::mShipDeviceIndex); - CVarSetFloat(StringHelper::Sprintf("%s.Sensitivity", mappingCvarKey.c_str()).c_str(), mSensitivity); - CVarSetFloat(StringHelper::Sprintf("%s.NeutralPitch", mappingCvarKey.c_str()).c_str(), mNeutralPitch); - CVarSetFloat(StringHelper::Sprintf("%s.NeutralYaw", mappingCvarKey.c_str()).c_str(), mNeutralYaw); - CVarSetFloat(StringHelper::Sprintf("%s.NeutralRoll", mappingCvarKey.c_str()).c_str(), mNeutralRoll); - - CVarSave(); -} - -void WiiUGyroMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.GyroMappings." + GetGyroMappingId(); - - CVarClear(StringHelper::Sprintf("%s.GyroMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.Sensitivity", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.NeutralPitch", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.NeutralYaw", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.NeutralRoll", mappingCvarKey.c_str()).c_str()); - - CVarSave(); -} - -std::string WiiUGyroMapping::GetPhysicalDeviceName() { - return GetWiiUDeviceName(); -} - -bool WiiUGyroMapping::PhysicalDeviceIsConnected() { - return WiiUDeviceIsConnected(); -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.h deleted file mode 100644 index a2b8120b9..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUGyroMapping.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/ControllerGyroMapping.h" -#include "WiiUMapping.h" - -namespace Ship { -class WiiUGyroMapping final : public ControllerGyroMapping, public WiiUMapping { - public: - WiiUGyroMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, float sensitivity, float neutralPitch, - float neutralYaw, float neutralRoll); - void UpdatePad(float& x, float& y) override; - void SaveToConfig() override; - void EraseFromConfig() override; - void Recalibrate() override; - std::string GetGyroMappingId() override; - - std::string GetPhysicalDeviceName() override; - bool PhysicalDeviceIsConnected() override; - - private: - float mNeutralPitch; - float mNeutralYaw; - float mNeutralRoll; -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.cpp deleted file mode 100644 index ff86c66b9..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUMapping.h" -#include -#include "Context.h" -#include "controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h" - -#include - -namespace Ship { -WiiUMapping::WiiUMapping(ShipDeviceIndex shipDeviceIndex) : ControllerMapping(shipDeviceIndex) { -} - -WiiUMapping::~WiiUMapping() { -} - -int32_t WiiUMapping::GetWiiUDeviceChannel() { - auto deviceIndexMapping = std::static_pointer_cast( - Ship::Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetDeviceIndexMappingFromShipDeviceIndex(mShipDeviceIndex)); - - if (deviceIndexMapping == nullptr) { - // we don't have a wii u device for this LUS device index - return -1; - } - - return deviceIndexMapping->GetDeviceChannel(); -} - -std::string WiiUMapping::GetWiiUControllerName() { - auto [isGamepad, extensionType] = Ship::Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetWiiUDeviceTypeFromShipDeviceIndex(mShipDeviceIndex); - - if (isGamepad) { - return "Wii U Gamepad"; - } - - switch (extensionType) { - case WPAD_EXT_CORE: - return "Wii Remote"; - case WPAD_EXT_NUNCHUK: - return "Wii Remote + Nunchuk"; - case WPAD_EXT_MPLUS_CLASSIC: - case WPAD_EXT_CLASSIC: - return "Wii Classic Controller"; - case WPAD_EXT_MPLUS: - return "Motion Plus Wii Remote"; - case WPAD_EXT_MPLUS_NUNCHUK: - return "Motion Plus Wii Remote + Nunchuk"; - case WPAD_EXT_PRO_CONTROLLER: - return "Wii U Pro Controller"; - default: - return "Unknown"; - } -} - -bool WiiUMapping::IsGamepad() { - auto [isGamepad, extensionType] = Ship::Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetWiiUDeviceTypeFromShipDeviceIndex(mShipDeviceIndex); - - return isGamepad; -} - -int32_t WiiUMapping::ExtensionType() { - auto [isGamepad, extensionType] = Ship::Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetWiiUDeviceTypeFromShipDeviceIndex(mShipDeviceIndex); - - return extensionType; -} - -std::string WiiUMapping::GetWiiUDeviceName() { - std::string deviceName = GetWiiUControllerName(); - - if (!WiiUDeviceIsConnected()) { - deviceName += " (Disconnected)"; - return deviceName; - } - - if (IsGamepad()) { - return deviceName; - } - - return StringHelper::Sprintf("%s (%d)", deviceName.c_str(), GetWiiUDeviceChannel() + 1); -} - -bool WiiUMapping::WiiUDeviceIsConnected() { - if (IsGamepad()) { - VPADReadError error; - VPADStatus* status = Ship::WiiU::GetVPADStatus(&error); - if (status == nullptr) { - return false; - } - - return true; - } - - KPADError error; - KPADStatus* status = Ship::WiiU::GetKPADStatus(static_cast(GetWiiUDeviceChannel()), &error); - if (status == nullptr || error != KPAD_ERROR_OK) { - return false; - } - - return true; -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.h deleted file mode 100644 index 7f60e19ac..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiUMapping.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifdef __WIIU__ -#pragma once - -#include -#include -#include -#include "controller/controldevice/controller/mapping/ControllerMapping.h" -#include -#include -#include "port/wiiu/WiiUImpl.h" - -namespace Ship { -enum Axis { X = 0, Y = 1 }; -enum AxisDirection { NEGATIVE = -1, POSITIVE = 1 }; - -class WiiUMapping : public ControllerMapping { - public: - WiiUMapping(ShipDeviceIndex shipDeviceIndex); - ~WiiUMapping(); - - protected: - std::string GetWiiUDeviceName(); - int32_t GetWiiUDeviceChannel(); - bool IsGamepad(); - int32_t ExtensionType(); - std::string GetWiiUControllerName(); - bool WiiUDeviceIsConnected(); -}; -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.cpp b/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.cpp deleted file mode 100644 index 8f999bbfe..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#ifdef __WIIU__ -#include "WiiURumbleMapping.h" - -#include "public/bridge/consolevariablebridge.h" -#include - -namespace Ship { -WiiURumbleMapping::WiiURumbleMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, - uint8_t lowFrequencyIntensityPercentage, uint8_t highFrequencyIntensityPercentage) - : ControllerRumbleMapping(shipDeviceIndex, portIndex, lowFrequencyIntensityPercentage, - highFrequencyIntensityPercentage), - WiiUMapping(shipDeviceIndex) { - SetLowFrequencyIntensity(lowFrequencyIntensityPercentage); - SetHighFrequencyIntensity(highFrequencyIntensityPercentage); -} - -void WiiURumbleMapping::StartRumble() { - if (IsGamepad()) { - int32_t patternSize = sizeof(mRumblePattern) * 8; - VPADControlMotor(VPAD_CHAN_0, mRumblePattern, patternSize); - return; - } - - WPADControlMotor(static_cast(GetWiiUDeviceChannel()), true); -} - -void WiiURumbleMapping::StopRumble() { - if (IsGamepad()) { - VPADControlMotor(VPAD_CHAN_0, mRumblePattern, 0); - return; - } - - WPADControlMotor(static_cast(GetWiiUDeviceChannel()), false); -} - -void WiiURumbleMapping::SetIntensity(uint8_t intensityPercentage) { - if (!IsGamepad()) { - intensityPercentage = 100; - mLowFrequencyIntensityPercentage = 100; - mHighFrequencyIntensityPercentage = 100; - return; - } - - mLowFrequencyIntensityPercentage = intensityPercentage; - mHighFrequencyIntensityPercentage = intensityPercentage; - - int32_t patternSize = sizeof(mRumblePattern) * 8; - memset(mRumblePattern, 0, sizeof(mRumblePattern)); - - // distribute wanted amount of bits equally in pattern - float scale = ((intensityPercentage / 100.0f) * (1.0f - 0.3f)) + 0.3f; - int32_t bitcnt = patternSize * scale; - for (int32_t i = 0; i < bitcnt; i++) { - int32_t bitpos = ((i * patternSize) / bitcnt) % patternSize; - mRumblePattern[bitpos / 8] |= 1 << (bitpos % 8); - } -} - -void WiiURumbleMapping::SetLowFrequencyIntensity(uint8_t intensityPercentage) { - SetIntensity(intensityPercentage); -} - -void WiiURumbleMapping::SetHighFrequencyIntensity(uint8_t intensityPercentage) { - SetIntensity(intensityPercentage); -} - -std::string WiiURumbleMapping::GetRumbleMappingId() { - return StringHelper::Sprintf("P%d-LUSI%d", mPortIndex, ControllerRumbleMapping::mShipDeviceIndex); -} - -void WiiURumbleMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.RumbleMappings." + GetRumbleMappingId(); - CVarSetString(StringHelper::Sprintf("%s.RumbleMappingClass", mappingCvarKey.c_str()).c_str(), "WiiURumbleMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), - ControllerRumbleMapping::mShipDeviceIndex); - CVarSetInteger(StringHelper::Sprintf("%s.LowFrequencyIntensity", mappingCvarKey.c_str()).c_str(), - mLowFrequencyIntensityPercentage); - CVarSetInteger(StringHelper::Sprintf("%s.HighFrequencyIntensity", mappingCvarKey.c_str()).c_str(), - mHighFrequencyIntensityPercentage); - CVarSave(); -} - -void WiiURumbleMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.RumbleMappings." + GetRumbleMappingId(); - - CVarClear(StringHelper::Sprintf("%s.RumbleMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.LowFrequencyIntensity", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.HighFrequencyIntensity", mappingCvarKey.c_str()).c_str()); - - CVarSave(); -} - -std::string WiiURumbleMapping::GetPhysicalDeviceName() { - return GetWiiUDeviceName(); -} - -bool WiiURumbleMapping::PhysicalDeviceIsConnected() { - return WiiUDeviceIsConnected(); -} -} // namespace Ship -#endif diff --git a/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.h b/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.h deleted file mode 100644 index 671097335..000000000 --- a/src/controller/controldevice/controller/mapping/wiiu/WiiURumbleMapping.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/ControllerRumbleMapping.h" -#include "WiiUMapping.h" - -namespace Ship { -class WiiURumbleMapping final : public ControllerRumbleMapping, public WiiUMapping { - public: - WiiURumbleMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, uint8_t lowFrequencyIntensityPercentage, - uint8_t highFrequencyIntensityPercentage); - - void StartRumble() override; - void StopRumble() override; - void SetLowFrequencyIntensity(uint8_t intensityPercentage) override; - void SetHighFrequencyIntensity(uint8_t intensityPercentage) override; - - std::string GetRumbleMappingId() override; - void SaveToConfig() override; - void EraseFromConfig() override; - - std::string GetPhysicalDeviceName() override; - bool PhysicalDeviceIsConnected() override; - - private: - void SetIntensity(uint8_t intensityPercentage); - uint8_t mRumblePattern[15]; -}; -} // namespace Ship -#endif diff --git a/src/controller/deviceindex/ControllerDisconnectedWindow.cpp b/src/controller/deviceindex/ControllerDisconnectedWindow.cpp index 46b4045da..493905771 100644 --- a/src/controller/deviceindex/ControllerDisconnectedWindow.cpp +++ b/src/controller/deviceindex/ControllerDisconnectedWindow.cpp @@ -3,11 +3,6 @@ #include #include #include "Context.h" -#ifdef __WIIU__ -#include -#include -#include "port/wiiu/WiiUImpl.h" -#endif namespace Ship { @@ -19,7 +14,6 @@ void ControllerDisconnectedWindow::InitElement() { } void ControllerDisconnectedWindow::UpdateElement() { -#ifndef __WIIU__ SDL_PumpEvents(); SDL_Event event; while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED) > 0) { @@ -35,55 +29,8 @@ void ControllerDisconnectedWindow::UpdateElement() { Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->HandlePhysicalDeviceDisconnect( event.cdevice.which); } -#endif } -#ifdef __WIIU__ -bool ControllerDisconnectedWindow::AnyWiiUDevicesAreConnected() { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus != nullptr && verror == VPAD_READ_SUCCESS) { - return true; - } - - for (uint32_t channel = 0; channel < 4; channel++) { - KPADError kerror; - KPADStatus* kstatus = Ship::WiiU::GetKPADStatus(static_cast(channel), &kerror); - - if (kstatus != nullptr && kerror == KPAD_ERROR_OK) { - return true; - } - } - - return false; -} - -int32_t ControllerDisconnectedWindow::GetWiiUDeviceFromWiiUInput() { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus != nullptr && verror == VPAD_READ_SUCCESS) { - if (vstatus->hold) { - // todo: don't just use INT32_MAX to mean gamepad - return INT32_MAX; - } - } - - for (int32_t channel = 0; channel < 4; channel++) { - KPADError kerror; - KPADStatus* kstatus = Ship::WiiU::GetKPADStatus(static_cast(channel), &kerror); - - if (kstatus != nullptr && kerror == KPAD_ERROR_OK) { - if (kstatus->hold) { - return channel; - } - } - } - - return -1; -} -#else int32_t ControllerDisconnectedWindow::GetSDLIndexFromSDLInput() { int32_t sdlDeviceIndex = -1; @@ -122,9 +69,7 @@ int32_t ControllerDisconnectedWindow::GetSDLIndexFromSDLInput() { return sdlDeviceIndex; } -#endif -#ifndef __WIIU__ void ControllerDisconnectedWindow::DrawKnownControllerDisconnected() { ImGui::Text("Controller for port %d disconnected.\nPress any button or move any axis\non an unused controller " "for port %d.", @@ -166,23 +111,7 @@ void ControllerDisconnectedWindow::DrawKnownControllerDisconnected() { Hide(); } } -#endif -#ifdef __WIIU__ -void ControllerDisconnectedWindow::DrawUnknownOrMultipleControllersDisconnected() { - ImGui::Text("Connected controller(s) have been added/removed/modified."); - - if (AnyWiiUDevicesAreConnected() && ImGui::Button("Reorder controllers###reorderControllersButton")) { - auto reorderingWindow = Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Controller Reordering"); - if (reorderingWindow != nullptr) { - mPortIndexOfDisconnectedController = UINT8_MAX; - ImGui::CloseCurrentPopup(); - reorderingWindow->Show(); - Hide(); - } - } -} -#else void ControllerDisconnectedWindow::DrawUnknownOrMultipleControllersDisconnected() { ImGui::Text("Controller(s) disconnected."); @@ -203,22 +132,7 @@ void ControllerDisconnectedWindow::DrawUnknownOrMultipleControllersDisconnected( Hide(); } } -#endif - -#ifdef __WIIU__ -void ControllerDisconnectedWindow::DrawElement() { - // todo: don't use UINT8_MAX to mean we don't have a disconnected controller - if (mPortIndexOfDisconnectedController == UINT8_MAX) { - return; - } - ImGui::OpenPopup("Connected Controllers Changed"); - if (ImGui::BeginPopupModal("Connected Controllers Changed", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { - DrawUnknownOrMultipleControllersDisconnected(); - ImGui::EndPopup(); - } -} -#else void ControllerDisconnectedWindow::DrawElement() { // todo: don't use UINT8_MAX to mean we don't have a disconnected controller if (mPortIndexOfDisconnectedController == UINT8_MAX) { @@ -236,7 +150,6 @@ void ControllerDisconnectedWindow::DrawElement() { ImGui::EndPopup(); } } -#endif void ControllerDisconnectedWindow::SetPortIndexOfDisconnectedController(uint8_t portIndex) { // todo: don't use UINT8_MAX to mean we don't have a disconnected controller diff --git a/src/controller/deviceindex/ControllerDisconnectedWindow.h b/src/controller/deviceindex/ControllerDisconnectedWindow.h index fb760447c..2c8ed02a7 100644 --- a/src/controller/deviceindex/ControllerDisconnectedWindow.h +++ b/src/controller/deviceindex/ControllerDisconnectedWindow.h @@ -27,13 +27,8 @@ class ControllerDisconnectedWindow : public GuiWindow { private: void DrawUnknownOrMultipleControllersDisconnected(); -#ifdef __WIIU__ - int32_t GetWiiUDeviceFromWiiUInput(); - bool AnyWiiUDevicesAreConnected(); -#else void DrawKnownControllerDisconnected(); int32_t GetSDLIndexFromSDLInput(); -#endif uint8_t mPortIndexOfDisconnectedController; }; diff --git a/src/controller/deviceindex/ControllerReorderingWindow.cpp b/src/controller/deviceindex/ControllerReorderingWindow.cpp index d3f02b0e5..0134191ac 100644 --- a/src/controller/deviceindex/ControllerReorderingWindow.cpp +++ b/src/controller/deviceindex/ControllerReorderingWindow.cpp @@ -3,11 +3,6 @@ #include #include #include "Context.h" -#ifdef __WIIU__ -#include -#include -#include "port/wiiu/WiiUImpl.h" -#endif namespace Ship { @@ -22,125 +17,6 @@ void ControllerReorderingWindow::InitElement() { void ControllerReorderingWindow::UpdateElement() { } -#ifdef __WIIU__ -std::vector ControllerReorderingWindow::GetConnectedWiiUDevices() { - std::vector connectedDevices; - - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus != nullptr && verror == VPAD_READ_SUCCESS) { - connectedDevices.push_back(INT32_MAX); - } - - for (uint32_t channel = 0; channel < 4; channel++) { - KPADError kerror; - KPADStatus* kstatus = Ship::WiiU::GetKPADStatus(static_cast(channel), &kerror); - - if (kstatus != nullptr && kerror == KPAD_ERROR_OK) { - connectedDevices.push_back(channel); - } - } - - return connectedDevices; -} - -int32_t ControllerReorderingWindow::GetWiiUDeviceFromWiiUInput() { - VPADReadError verror; - VPADStatus* vstatus = Ship::WiiU::GetVPADStatus(&verror); - - if (vstatus != nullptr && verror == VPAD_READ_SUCCESS) { - if (vstatus->hold) { - // todo: don't just use INT32_MAX to mean gamepad - return INT32_MAX; - } - // todo: use this for getting buttons, - // for (uint32_t i = VPAD_BUTTON_SYNC; i <= VPAD_STICK_L_EMULATION_LEFT; i <<= 1) { - // if (vstatus->hold == i) { - - // } - // } - } - - for (int32_t channel = 0; channel < 4; channel++) { - KPADError kerror; - KPADStatus* kstatus = Ship::WiiU::GetKPADStatus(static_cast(channel), &kerror); - - if (kstatus != nullptr && kerror == KPAD_ERROR_OK) { - if (kstatus->hold) { - return channel; - } - - switch (kstatus->extensionType) { - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - if (kstatus->nunchuck.hold) { - return channel; - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - if (kstatus->classic.hold) { - return channel; - } - break; - case WPAD_EXT_PRO_CONTROLLER: - if (kstatus->pro.hold) { - return channel; - } - break; - } - } - } - - return -1; -} - -void ControllerReorderingWindow::DrawElement() { - // if we don't have more than one controller, just close the window - auto connectedDevices = GetConnectedWiiUDevices(); - - if (connectedDevices.size() <= 1) { - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->InitializeMappingsMultiplayer( - connectedDevices); - Hide(); - return; - } - - // we have more than one controller, prompt the user for order - if (mCurrentPortNumber <= std::min(connectedDevices.size(), static_cast(MAXCONTROLLERS))) { - ImGui::OpenPopup("Set Controller"); - if (ImGui::BeginPopupModal("Set Controller", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text("Press any button or move any axis\non the controller for port %d", mCurrentPortNumber); - - auto index = GetWiiUDeviceFromWiiUInput(); - if (index != -1 && std::find(mDeviceIndices.begin(), mDeviceIndices.end(), index) == mDeviceIndices.end()) { - mDeviceIndices.push_back(index); - mCurrentPortNumber++; - ImGui::CloseCurrentPopup(); - } - - if (mCurrentPortNumber > 1 && - ImGui::Button(StringHelper::Sprintf("Play with %d controller%s", mCurrentPortNumber - 1, - mCurrentPortNumber > 2 ? "s" : "") - .c_str())) { - mCurrentPortNumber = - MAXCONTROLLERS + 1; // stop showing modals, it will be reset to 1 after the mapping init stuff - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } - return; - } - - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->InitializeMappingsMultiplayer( - mDeviceIndices); - mDeviceIndices.clear(); - mCurrentPortNumber = 1; - Hide(); -} -#else int32_t ControllerReorderingWindow::GetSDLIndexFromSDLInput() { int32_t sdlDeviceIndex = -1; @@ -234,5 +110,4 @@ void ControllerReorderingWindow::DrawElement() { mCurrentPortNumber = 1; Hide(); } -#endif } // namespace Ship \ No newline at end of file diff --git a/src/controller/deviceindex/ControllerReorderingWindow.h b/src/controller/deviceindex/ControllerReorderingWindow.h index 3b05d42b6..ea9234c58 100644 --- a/src/controller/deviceindex/ControllerReorderingWindow.h +++ b/src/controller/deviceindex/ControllerReorderingWindow.h @@ -24,12 +24,7 @@ class ControllerReorderingWindow : public GuiWindow { void UpdateElement() override; private: -#ifdef __WIIU__ - std::vector GetConnectedWiiUDevices(); - int32_t GetWiiUDeviceFromWiiUInput(); -#else int32_t GetSDLIndexFromSDLInput(); -#endif std::vector mDeviceIndices; uint8_t mCurrentPortNumber; }; diff --git a/src/controller/deviceindex/ShipDeviceIndexMappingManager.cpp b/src/controller/deviceindex/ShipDeviceIndexMappingManager.cpp index 98eb515d8..26c49f462 100644 --- a/src/controller/deviceindex/ShipDeviceIndexMappingManager.cpp +++ b/src/controller/deviceindex/ShipDeviceIndexMappingManager.cpp @@ -7,216 +7,18 @@ #include "ControllerDisconnectedWindow.h" #include "ControllerReorderingWindow.h" -#ifdef __WIIU__ -#include "controller/controldevice/controller/mapping/wiiu/WiiUMapping.h" -#include "port/wiiu/WiiUImpl.h" -#else #include "controller/controldevice/controller/mapping/sdl/SDLMapping.h" -#endif #include namespace Ship { ShipDeviceIndexMappingManager::ShipDeviceIndexMappingManager() : mIsInitialized(false) { -#ifdef __WIIU__ - UpdateExtensionTypesFromConfig(); -#else UpdateControllerNamesFromConfig(); -#endif } ShipDeviceIndexMappingManager::~ShipDeviceIndexMappingManager() { } -#ifdef __WIIU__ -void ShipDeviceIndexMappingManager::InitializeMappingsMultiplayer(std::vector wiiuDeviceChannels) { - mShipDeviceIndexToPhysicalDeviceIndexMappings.clear(); - uint8_t port = 0; - for (auto channel : wiiuDeviceChannels) { - // todo: don't just use INT32_MAX to mean gamepad - if (channel == INT32_MAX) { - InitializeWiiUMappingsForPort(port, true, channel); - } else { - InitializeWiiUMappingsForPort(port, false, channel); - } - port++; - } - mIsInitialized = true; - Ship::WiiU::SetControllersInitialized(); -} - -void ShipDeviceIndexMappingManager::InitializeWiiUMappingsForPort(uint8_t n64port, bool isGamepad, - int32_t wiiuChannel) { - KPADError error; - KPADStatus* status = !isGamepad ? Ship::WiiU::GetKPADStatus(static_cast(wiiuChannel), &error) : nullptr; - - if (!isGamepad && status == nullptr) { - return; - } - - std::vector matchingLusIndices; - auto mappings = GetAllDeviceIndexMappingsFromConfig(); - for (auto [lusIndex, mapping] : mappings) { - auto wiiuMapping = std::dynamic_pointer_cast(mapping); - if (wiiuMapping == nullptr) { - continue; - } - - if (isGamepad) { - if (wiiuMapping->IsWiiUGamepad()) { - matchingLusIndices.push_back(lusIndex); - } - continue; - } - - if (wiiuMapping->HasEquivalentExtensionType(status->extensionType)) { - matchingLusIndices.push_back(lusIndex); - } - } - - // set this device to the lowest available lus index with a compatable extension type - for (auto lusIndex : matchingLusIndices) { - if (GetDeviceIndexMappingFromShipDeviceIndex(lusIndex) != nullptr) { - // we already loaded this one - continue; - } - - auto mapping = mappings[lusIndex]; - auto wiiuMapping = std::dynamic_pointer_cast(mapping); - - if (!isGamepad) { - wiiuMapping->SetDeviceChannel(wiiuChannel); - } - SetShipDeviceIndexToPhysicalDeviceIndexMapping(wiiuMapping); - - // if we have mappings for this LUS device on this port, we're good and don't need to move any mappings - if (Context::GetInstance()->GetControlDeck()->GetControllerByPort(n64port)->HasMappingsForShipDeviceIndex( - lusIndex)) { - return; - } - - // move mappings from other port to this one - for (uint8_t portIndex = 0; portIndex < 4; portIndex++) { - if (portIndex == n64port) { - continue; - } - - if (!Context::GetInstance() - ->GetControlDeck() - ->GetControllerByPort(portIndex) - ->HasMappingsForShipDeviceIndex(lusIndex)) { - continue; - } - - Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->MoveMappingsToDifferentController( - Context::GetInstance()->GetControlDeck()->GetControllerByPort(n64port), lusIndex); - return; - } - - // we shouldn't get here - return; - } - - // if we didn't find a mapping, make defaults - auto lusIndex = GetLowestShipDeviceIndexWithNoAssociatedButtonOrAxisDirectionMappings(); - auto deviceIndexMapping = std::make_shared( - lusIndex, wiiuChannel, isGamepad, !isGamepad ? status->extensionType : -1); - mShipDeviceIndexToWiiUDeviceTypes[lusIndex] = { isGamepad, !isGamepad ? status->extensionType : -1 }; - deviceIndexMapping->SaveToConfig(); - SetShipDeviceIndexToPhysicalDeviceIndexMapping(deviceIndexMapping); - SaveMappingIdsToConfig(); - Context::GetInstance()->GetControlDeck()->GetControllerByPort(n64port)->AddDefaultMappings(lusIndex); -} - -bool ShipDeviceIndexMappingManager::IsValidWiiUExtensionType(int32_t extensionType) { - switch (extensionType) { - case WPAD_EXT_CORE: - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS: - case WPAD_EXT_MPLUS_NUNCHUK: - case WPAD_EXT_MPLUS_CLASSIC: - case WPAD_EXT_PRO_CONTROLLER: - return true; - default: - return false; - } -} - -std::shared_ptr -ShipDeviceIndexMappingManager::CreateDeviceIndexMappingFromConfig(std::string id) { - const std::string mappingCvarKey = "gControllers.DeviceMappings." + id; - const std::string mappingClass = - CVarGetString(StringHelper::Sprintf("%s.DeviceMappingClass", mappingCvarKey.c_str()).c_str(), ""); - - if (mappingClass == "ShipDeviceIndexToWiiUDeviceIndexMapping") { - int32_t shipDeviceIndex = - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1); - - bool isGamepad = CVarGetInteger(StringHelper::Sprintf("%s.IsGamepad", mappingCvarKey.c_str()).c_str(), false); - - int32_t wiiuDeviceChannel = - CVarGetInteger(StringHelper::Sprintf("%s.WiiUDeviceChannel", mappingCvarKey.c_str()).c_str(), -1); - - int32_t wiiuExtensionType = - CVarGetInteger(StringHelper::Sprintf("%s.WiiUDeviceExtensionType", mappingCvarKey.c_str()).c_str(), -1); - - if (shipDeviceIndex < 0 || (!isGamepad && !IsValidWiiUExtensionType(wiiuExtensionType))) { - // something about this mapping is invalid - CVarClear(mappingCvarKey.c_str()); - CVarSave(); - return nullptr; - } - - return std::make_shared( - static_cast(shipDeviceIndex), isGamepad, wiiuDeviceChannel, wiiuExtensionType); - } - - return nullptr; -} - -void ShipDeviceIndexMappingManager::InitializeMappingsSinglePlayer() { -} - -void ShipDeviceIndexMappingManager::UpdateExtensionTypesFromConfig() { - // todo: this efficently (when we build out cvar array support?) - // i don't expect it to really be a problem with the small number of mappings we have - // for each controller (especially compared to include/exclude locations in rando), and - // the audio editor pattern doesn't work for this because that looks for ids that are either - // hardcoded or provided by an otr file - std::stringstream mappingIdsStringStream(CVarGetString("gControllers.DeviceMappingIds", "")); - std::string mappingIdString; - while (getline(mappingIdsStringStream, mappingIdString, ',')) { - const std::string mappingCvarKey = "gControllers.DeviceMappings." + mappingIdString; - const std::string mappingClass = - CVarGetString(StringHelper::Sprintf("%s.DeviceMappingClass", mappingCvarKey.c_str()).c_str(), ""); - - if (mappingClass == "ShipDeviceIndexToWiiUDeviceIndexMapping") { - mShipDeviceIndexToWiiUDeviceTypes[static_cast( - CVarGetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), -1))] = { - CVarGetInteger(StringHelper::Sprintf("%s.IsGamepad", mappingCvarKey.c_str()).c_str(), -1), - CVarGetInteger(StringHelper::Sprintf("%s.WiiUDeviceExtensionType", mappingCvarKey.c_str()).c_str(), -1) - }; - } - } -} - -std::pair ShipDeviceIndexMappingManager::GetWiiUDeviceTypeFromShipDeviceIndex(ShipDeviceIndex index) { - return mShipDeviceIndexToWiiUDeviceTypes[index]; -} - -void ShipDeviceIndexMappingManager::HandlePhysicalDevicesChanged() { - auto controllerDisconnectedWindow = std::dynamic_pointer_cast( - Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Controller Disconnected")); - if (controllerDisconnectedWindow != nullptr) { - // todo: don't use UINT8_MAX-1 to mean we don't know what controller was disconnected - controllerDisconnectedWindow->SetPortIndexOfDisconnectedController(UINT8_MAX - 1); - controllerDisconnectedWindow->Show(); - } else { - // todo: log error - } -} -#else void ShipDeviceIndexMappingManager::InitializeMappingsMultiplayer(std::vector sdlIndices) { for (uint8_t portIndex = 0; portIndex < 4; portIndex++) { for (auto mapping : @@ -762,7 +564,6 @@ ShipDeviceIndexMappingManager::GetShipDeviceIndexOfDisconnectedPhysicalDevice(in // couldn't find one return ShipDeviceIndex::Max; } -#endif ShipDeviceIndex ShipDeviceIndexMappingManager::GetLowestShipDeviceIndexWithNoAssociatedButtonOrAxisDirectionMappings() { for (uint8_t lusIndex = ShipDeviceIndex::Blue; lusIndex < ShipDeviceIndex::Max; lusIndex++) { diff --git a/src/controller/deviceindex/ShipDeviceIndexMappingManager.h b/src/controller/deviceindex/ShipDeviceIndexMappingManager.h index fa094306a..dc8e3474a 100644 --- a/src/controller/deviceindex/ShipDeviceIndexMappingManager.h +++ b/src/controller/deviceindex/ShipDeviceIndexMappingManager.h @@ -1,10 +1,6 @@ #pragma once -#ifdef __WIIU__ -#include "ShipDeviceIndexToWiiUDeviceIndexMapping.h" -#else #include "ShipDeviceIndexToSDLDeviceIndexMapping.h" -#endif #include #include @@ -16,14 +12,6 @@ class ShipDeviceIndexMappingManager { ShipDeviceIndexMappingManager(); ~ShipDeviceIndexMappingManager(); -#ifdef __WIIU__ - void InitializeMappingsMultiplayer(std::vector wiiuDeviceChannels); - void InitializeWiiUMappingsForPort(uint8_t n64port, bool isGamepad, int32_t wiiuChannel); - bool IsValidWiiUExtensionType(int32_t extensionType); - void UpdateExtensionTypesFromConfig(); - std::pair GetWiiUDeviceTypeFromShipDeviceIndex(ShipDeviceIndex index); - void HandlePhysicalDevicesChanged(); -#else void InitializeMappingsMultiplayer(std::vector sdlIndices); void InitializeSDLMappingsForPort(uint8_t n64port, int32_t sdlIndex); void UpdateControllerNamesFromConfig(); @@ -31,7 +19,6 @@ class ShipDeviceIndexMappingManager { void HandlePhysicalDeviceConnect(int32_t sdlDeviceIndex); void HandlePhysicalDeviceDisconnect(int32_t sdlJoystickInstanceId); ShipDeviceIndex GetShipDeviceIndexFromSDLDeviceIndex(int32_t sdlIndex); -#endif std::shared_ptr CreateDeviceIndexMappingFromConfig(std::string id); @@ -55,15 +42,11 @@ class ShipDeviceIndexMappingManager { bool mIsInitialized; std::unordered_map> mShipDeviceIndexToPhysicalDeviceIndexMappings; -#ifdef __WIIU__ - std::unordered_map> mShipDeviceIndexToWiiUDeviceTypes; -#else std::unordered_map mShipDeviceIndexToSDLControllerNames; int32_t GetNewSDLDeviceIndexFromShipDeviceIndex(ShipDeviceIndex lusIndex); ShipDeviceIndex GetShipDeviceIndexOfDisconnectedPhysicalDevice(int32_t sdlJoystickInstanceId); uint8_t GetPortIndexOfDisconnectedPhysicalDevice(int32_t sdlJoystickInstanceId); void HandlePhysicalDeviceDisconnectSinglePlayer(int32_t sdlJoystickInstanceId); void HandlePhysicalDeviceDisconnectMultiplayer(int32_t sdlJoystickInstanceId); -#endif }; } // namespace Ship diff --git a/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.cpp b/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.cpp deleted file mode 100644 index 1fdbd951c..000000000 --- a/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#ifdef __WIIU__ -#include "ShipDeviceIndexToWiiUDeviceIndexMapping.h" -#include -#include "public/bridge/consolevariablebridge.h" - -namespace Ship { -ShipDeviceIndexToWiiUDeviceIndexMapping::ShipDeviceIndexToWiiUDeviceIndexMapping(ShipDeviceIndex shipDeviceIndex, - bool isGamepad, int32_t deviceChannel, - int32_t extensionType) - : ShipDeviceIndexToPhysicalDeviceIndexMapping(shipDeviceIndex), mIsWiiUGamepad(isGamepad), - mDeviceChannel(deviceChannel), mExtensionType(extensionType) { -} - -ShipDeviceIndexToWiiUDeviceIndexMapping::~ShipDeviceIndexToWiiUDeviceIndexMapping() { -} - -bool ShipDeviceIndexToWiiUDeviceIndexMapping::IsWiiUGamepad() { - return mIsWiiUGamepad; -} - -int32_t ShipDeviceIndexToWiiUDeviceIndexMapping::GetDeviceChannel() { - return mDeviceChannel; -} - -void ShipDeviceIndexToWiiUDeviceIndexMapping::SetDeviceChannel(int32_t channel) { - mDeviceChannel = channel; -} - -int32_t ShipDeviceIndexToWiiUDeviceIndexMapping::GetExtensionType() { - return mExtensionType; -} - -void ShipDeviceIndexToWiiUDeviceIndexMapping::SetExtensionType(int32_t extensionType) { - mExtensionType = extensionType; -} - -bool ShipDeviceIndexToWiiUDeviceIndexMapping::HasEquivalentExtensionType(int32_t extensionType) { - switch (extensionType) { - case WPAD_EXT_CORE: // Wii Remote with no extension - case WPAD_EXT_MPLUS: // Wii remote with motion plus - return mExtensionType == WPAD_EXT_CORE || mExtensionType == WPAD_EXT_MPLUS; - case WPAD_EXT_NUNCHUK: // Wii Remote with nunchuk - case WPAD_EXT_MPLUS_NUNCHUK: // Wii remote with motion plus and nunchuk - return mExtensionType == WPAD_EXT_NUNCHUK || mExtensionType == WPAD_EXT_MPLUS_NUNCHUK; - case WPAD_EXT_CLASSIC: // Wii Remote with Classic Controller - case WPAD_EXT_MPLUS_CLASSIC: // Wii Remote with motion plus and Classic Controller - return mExtensionType == WPAD_EXT_CLASSIC || mExtensionType == WPAD_EXT_MPLUS_CLASSIC; - case WPAD_EXT_PRO_CONTROLLER: // Wii U Pro Controller - return mExtensionType == WPAD_EXT_PRO_CONTROLLER; - default: - return false; - } -} - -std::string ShipDeviceIndexToWiiUDeviceIndexMapping::GetWiiUControllerName() { - if (IsWiiUGamepad()) { - return "Wii U Gamepad"; - } - - switch (GetExtensionType()) { - case WPAD_EXT_CORE: - return "Wii Remote"; - case WPAD_EXT_NUNCHUK: - return "Wii Remote + Nunchuk"; - case WPAD_EXT_MPLUS_CLASSIC: - case WPAD_EXT_CLASSIC: - return "Wii Classic Controller"; - case WPAD_EXT_MPLUS: - return "Motion Plus Wii Remote"; - case WPAD_EXT_MPLUS_NUNCHUK: - return "Motion Plus Wii Remote + Nunchuk"; - case WPAD_EXT_PRO_CONTROLLER: - return "Wii U Pro Controller"; - default: - return "Unknown"; - } -} - -void ShipDeviceIndexToWiiUDeviceIndexMapping::SaveToConfig() { - const std::string mappingCvarKey = "gControllers.DeviceMappings." + GetMappingId(); - CVarSetString(StringHelper::Sprintf("%s.DeviceMappingClass", mappingCvarKey.c_str()).c_str(), - "ShipDeviceIndexToWiiUDeviceIndexMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str(), mShipDeviceIndex); - CVarSetInteger(StringHelper::Sprintf("%s.IsGamepad", mappingCvarKey.c_str()).c_str(), mIsWiiUGamepad); - CVarSetInteger(StringHelper::Sprintf("%s.WiiUDeviceChannel", mappingCvarKey.c_str()).c_str(), mDeviceChannel); - CVarSetInteger(StringHelper::Sprintf("%s.WiiUDeviceExtensionType", mappingCvarKey.c_str()).c_str(), mExtensionType); - CVarSave(); -} - -void ShipDeviceIndexToWiiUDeviceIndexMapping::EraseFromConfig() { - const std::string mappingCvarKey = "gControllers.DeviceMappings." + GetMappingId(); - - CVarClear(StringHelper::Sprintf("%s.DeviceMappingClass", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.ShipDeviceIndex", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.IsGamepad", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.WiiUDeviceChannel", mappingCvarKey.c_str()).c_str()); - CVarClear(StringHelper::Sprintf("%s.WiiUDeviceExtensionType", mappingCvarKey.c_str()).c_str()); - - CVarSave(); -} -} // namespace Ship -#endif diff --git a/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h b/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h deleted file mode 100644 index 97852049f..000000000 --- a/src/controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __WIIU__ -#pragma once - -#include -#include -#include "ShipDeviceIndexToPhysicalDeviceIndexMapping.h" -#include - -namespace Ship { - -class ShipDeviceIndexToWiiUDeviceIndexMapping : public ShipDeviceIndexToPhysicalDeviceIndexMapping { - public: - ShipDeviceIndexToWiiUDeviceIndexMapping(ShipDeviceIndex shipDeviceIndex, bool isGamepad, int32_t deviceChannel, - int32_t extensionType); - ~ShipDeviceIndexToWiiUDeviceIndexMapping(); - - void SaveToConfig() override; - void EraseFromConfig() override; - - bool IsWiiUGamepad(); - - int32_t GetDeviceChannel(); - void SetDeviceChannel(int32_t channel); - - int32_t GetExtensionType(); - void SetExtensionType(int32_t extensionType); - - bool HasEquivalentExtensionType(int32_t extensionType); - - std::string GetWiiUControllerName(); - - private: - bool mIsWiiUGamepad; - int32_t mDeviceChannel; - int32_t mExtensionType; -}; -} // namespace Ship -#endif diff --git a/src/graphic/Fast3D/gfx_gx2.cpp b/src/graphic/Fast3D/gfx_gx2.cpp deleted file mode 100644 index ce5b2f61a..000000000 --- a/src/graphic/Fast3D/gfx_gx2.cpp +++ /dev/null @@ -1,878 +0,0 @@ -/* gfx_gx2.cpp - Fast3D GX2 backend for libultraship - - Created in 2022 by GaryOderNichts -*/ -#ifdef __WIIU__ - -#include "window/Window.h" - -#include -#include -#include -#include - -#include - -#ifndef _LANGUAGE_C -#define _LANGUAGE_C -#endif -#include "libultraship/libultra/gbi.h" -#include - -#include "gfx_cc.h" -#include "gfx_rendering_api.h" -#include "gfx_pc.h" -#include "gfx_wiiu.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "gx2_shader_gen.h" - -#include -#include - -#include - -#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1)) - -struct ShaderProgram { - struct ShaderGroup group; - uint8_t num_inputs; - bool used_textures[2]; - bool used_noise; - uint32_t window_params_offset; - int32_t samplers_location[SHADER_MAX_TEXTURES]; -}; - -struct Texture { - GX2Texture texture; - bool texture_uploaded; - - GX2Sampler sampler; - bool sampler_set; - - // For ImGui rendering - ImGui_ImplGX2_Texture imtex; -}; - -struct Framebuffer { - GX2ColorBuffer color_buffer; - bool colorBufferMem1; - GX2DepthBuffer depth_buffer; - bool depthBufferMem1; - - GX2Texture texture; - GX2Sampler sampler; - - // For ImGui rendering - ImGui_ImplGX2_Texture imtex; -}; - -static struct Framebuffer main_framebuffer; -static GX2DepthBuffer depthReadBuffer; -static struct Framebuffer* current_framebuffer; - -static std::map, struct ShaderProgram> shader_program_pool; -static struct ShaderProgram* current_shader_program; - -static struct Texture* current_texture; -static int current_tile; - -// 96 Mb (should be more than enough to draw everything without waiting for the GPU) -#define DRAW_BUFFER_SIZE 0x6000000 -static uint8_t* draw_buffer = nullptr; -static uint8_t* draw_ptr = nullptr; - -static uint32_t frame_count; -static float current_noise_scale; -static FilteringMode current_filter_mode = FILTER_LINEAR; - -static BOOL current_depth_test = TRUE; -static BOOL current_depth_write = TRUE; -static GX2CompareFunction current_depth_compare_function = GX2_COMPARE_FUNC_LESS; - -static float current_viewport_x = 0.0f; -static float current_viewport_y = 0.0f; -static float current_viewport_width = WIIU_DEFAULT_FB_WIDTH; -static float current_viewport_height = WIIU_DEFAULT_FB_HEIGHT; - -static uint32_t current_scissor_x = 0; -static uint32_t current_scissor_y = 0; -static uint32_t current_scissor_width = WIIU_DEFAULT_FB_WIDTH; -static uint32_t current_scissor_height = WIIU_DEFAULT_FB_HEIGHT; - -static bool current_zmode_decal = false; -static bool current_SSDB = -2.0f; -static bool current_use_alpha = false; - -static inline GX2SamplerVar* GX2GetPixelSamplerVar(const GX2PixelShader* shader, const char* name) { - for (uint32_t i = 0; i < shader->samplerVarCount; ++i) { - if (strcmp(name, shader->samplerVars[i].name) == 0) { - return &shader->samplerVars[i]; - } - } - - return nullptr; -} - -static inline int32_t GX2GetPixelSamplerVarLocation(const GX2PixelShader* shader, const char* name) { - GX2SamplerVar* sampler = GX2GetPixelSamplerVar(shader, name); - return sampler ? sampler->location : -1; -} - -static inline int32_t GX2GetPixelUniformVarOffset(const GX2PixelShader* shader, const char* name) { - GX2UniformVar* uniform = GX2GetPixelUniformVar(shader, name); - return uniform ? uniform->offset : -1; -} - -static const char* gfx_gx2_get_name() { - return "GX2"; -} - -static int gfx_gx2_get_max_texture_size() { - // TODO: This should be a define from the Wii U toolchain, but there isn't one yet - return 8192; -} - -static void gfx_gx2_init_framebuffer(struct Framebuffer* buffer, uint32_t width, uint32_t height) { - memset(&buffer->color_buffer, 0, sizeof(GX2ColorBuffer)); - buffer->color_buffer.surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV; - buffer->color_buffer.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D; - buffer->color_buffer.surface.width = width; - buffer->color_buffer.surface.height = height; - buffer->color_buffer.surface.depth = 1; - buffer->color_buffer.surface.mipLevels = 1; - buffer->color_buffer.surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; - buffer->color_buffer.surface.aa = GX2_AA_MODE1X; - buffer->color_buffer.surface.tileMode = GX2_TILE_MODE_DEFAULT; - buffer->color_buffer.viewNumSlices = 1; - - memset(&buffer->depth_buffer, 0, sizeof(GX2DepthBuffer)); - buffer->depth_buffer.surface.use = GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE; - buffer->depth_buffer.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D; - buffer->depth_buffer.surface.width = width; - buffer->depth_buffer.surface.height = height; - buffer->depth_buffer.surface.depth = 1; - buffer->depth_buffer.surface.mipLevels = 1; - buffer->depth_buffer.surface.format = GX2_SURFACE_FORMAT_FLOAT_R32; - buffer->depth_buffer.surface.aa = GX2_AA_MODE1X; - buffer->depth_buffer.surface.tileMode = GX2_TILE_MODE_DEFAULT; - buffer->depth_buffer.viewNumSlices = 1; - buffer->depth_buffer.depthClear = 1.0f; -} - -static struct GfxClipParameters gfx_gx2_get_clip_parameters(void) { - return { false, false }; -} - -static void gfx_gx2_set_uniforms(struct ShaderProgram* prg) { - float window_params_array[4] = { current_noise_scale, (float)frame_count, 0.0f, 0.0f }; - - GX2SetPixelUniformReg(prg->window_params_offset, 4, window_params_array); -} - -static void gfx_gx2_unload_shader(struct ShaderProgram* old_prg) { - current_shader_program = nullptr; -} - -static void gfx_gx2_load_shader(struct ShaderProgram* new_prg) { - current_shader_program = new_prg; - - GX2SetFetchShader(&new_prg->group.fetchShader); - GX2SetVertexShader(&new_prg->group.vertexShader); - GX2SetPixelShader(&new_prg->group.pixelShader); - - gfx_gx2_set_uniforms(new_prg); -} - -static struct ShaderProgram* gfx_gx2_create_and_load_new_shader(uint64_t shader_id0, uint32_t shader_id1) { - struct CCFeatures cc_features; - gfx_cc_get_features(shader_id0, shader_id1, &cc_features); - - struct ShaderProgram* prg = &shader_program_pool[std::make_pair(shader_id0, shader_id1)]; - - printf("Generating shader: %016llx-%08x\n", shader_id0, shader_id1); - if (gx2GenerateShaderGroup(&prg->group, &cc_features) != 0) { - printf("Failed to generate shader\n"); - current_shader_program = nullptr; - return nullptr; - } - - prg->num_inputs = cc_features.num_inputs; - prg->used_textures[0] = cc_features.used_textures[0]; - prg->used_textures[1] = cc_features.used_textures[1]; - - gfx_gx2_load_shader(prg); - - prg->window_params_offset = GX2GetPixelUniformVarOffset(&prg->group.pixelShader, "window_params"); - prg->samplers_location[0] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTex0"); - prg->samplers_location[1] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTex1"); - prg->samplers_location[2] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTexMask0"); - prg->samplers_location[3] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTexMask1"); - prg->samplers_location[4] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTexBlend0"); - prg->samplers_location[5] = GX2GetPixelSamplerVarLocation(&prg->group.pixelShader, "uTexBlend1"); - - prg->used_noise = cc_features.opt_alpha && cc_features.opt_noise; - - printf("Generated and loaded shader\n"); - - return prg; -} - -static struct ShaderProgram* gfx_gx2_lookup_shader(uint64_t shader_id0, uint32_t shader_id1) { - auto it = shader_program_pool.find(std::make_pair(shader_id0, shader_id1)); - return it == shader_program_pool.end() ? nullptr : &it->second; -} - -static void gfx_gx2_shader_get_info(struct ShaderProgram* prg, uint8_t* num_inputs, bool used_textures[2]) { - *num_inputs = prg->num_inputs; - used_textures[0] = prg->used_textures[0]; - used_textures[1] = prg->used_textures[1]; -} - -static uint32_t gfx_gx2_new_texture(void) { - // some 32-bit trickery :P - struct Texture* tex = (struct Texture*)calloc(1, sizeof(struct Texture)); - - tex->imtex.Texture = &tex->texture; - tex->imtex.Sampler = &tex->sampler; - - return (uint32_t)tex; -} - -static void gfx_gx2_delete_texture(uint32_t texture_id) { - struct Texture* tex = (struct Texture*)texture_id; - - if (tex->texture.surface.image) { - free(tex->texture.surface.image); - } - - free((void*)tex); -} - -static void gfx_gx2_select_texture(int tile, uint32_t texture_id) { - struct Texture* tex = (struct Texture*)texture_id; - current_texture = tex; - current_tile = tile; - - if (current_shader_program) { - int32_t sampler_location = current_shader_program->samplers_location[tile]; - if (sampler_location != -1) { - if (tex->texture_uploaded) { - GX2SetPixelTexture(&tex->texture, sampler_location); - } - - if (tex->sampler_set) { - GX2SetPixelSampler(&tex->sampler, sampler_location); - } - } - } -} - -static void gfx_gx2_upload_texture(const uint8_t* rgba32_buf, uint32_t width, uint32_t height) { - struct Texture* tex = current_texture; - assert(tex); - - if ((tex->texture.surface.width != width) || (tex->texture.surface.height != height) || - !tex->texture.surface.image) { - - if (tex->texture.surface.image) { - free(tex->texture.surface.image); - tex->texture.surface.image = nullptr; - } - - memset(&tex->texture, 0, sizeof(GX2Texture)); - tex->texture.surface.use = GX2_SURFACE_USE_TEXTURE; - tex->texture.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D; - tex->texture.surface.width = width; - tex->texture.surface.height = height; - tex->texture.surface.depth = 1; - tex->texture.surface.mipLevels = 1; - tex->texture.surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; - tex->texture.surface.aa = GX2_AA_MODE1X; - tex->texture.surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED; - tex->texture.viewFirstMip = 0; - tex->texture.viewNumMips = 1; - tex->texture.viewFirstSlice = 0; - tex->texture.viewNumSlices = 1; - tex->texture.compMap = GX2_COMP_MAP(GX2_SQ_SEL_R, GX2_SQ_SEL_G, GX2_SQ_SEL_B, GX2_SQ_SEL_A); - - GX2CalcSurfaceSizeAndAlignment(&tex->texture.surface); - GX2InitTextureRegs(&tex->texture); - - tex->texture.surface.image = memalign(tex->texture.surface.alignment, tex->texture.surface.imageSize); - } - - uint8_t* buf = (uint8_t*)tex->texture.surface.image; - assert(buf); - - for (uint32_t y = 0; y < height; ++y) { - memcpy(buf + (y * tex->texture.surface.pitch * 4), rgba32_buf + (y * width * 4), width * 4); - } - - GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, tex->texture.surface.image, tex->texture.surface.imageSize); - - if (current_shader_program && current_shader_program->samplers_location[current_tile] != -1) { - GX2SetPixelTexture(&tex->texture, current_shader_program->samplers_location[current_tile]); - } - - tex->texture_uploaded = true; -} - -static GX2TexClampMode gfx_cm_to_gx2(uint32_t val) { - switch (val) { - case G_TX_NOMIRROR | G_TX_CLAMP: - return GX2_TEX_CLAMP_MODE_CLAMP; - case G_TX_MIRROR | G_TX_WRAP: - return GX2_TEX_CLAMP_MODE_MIRROR; - case G_TX_MIRROR | G_TX_CLAMP: - return GX2_TEX_CLAMP_MODE_MIRROR_ONCE; - case G_TX_NOMIRROR | G_TX_WRAP: - return GX2_TEX_CLAMP_MODE_WRAP; - } - - return GX2_TEX_CLAMP_MODE_WRAP; -} - -static void gfx_gx2_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) { - struct Texture* tex = current_texture; - assert(tex); - - current_tile = tile; - - GX2InitSampler(&tex->sampler, GX2_TEX_CLAMP_MODE_CLAMP, - (linear_filter && current_filter_mode == FILTER_LINEAR) ? GX2_TEX_XY_FILTER_MODE_LINEAR - : GX2_TEX_XY_FILTER_MODE_POINT); - - GX2InitSamplerClamping(&tex->sampler, gfx_cm_to_gx2(cms), gfx_cm_to_gx2(cmt), GX2_TEX_CLAMP_MODE_WRAP); - - if (current_shader_program && current_shader_program->samplers_location[tile] != -1) { - GX2SetPixelSampler(&tex->sampler, current_shader_program->samplers_location[tile]); - } - - tex->sampler_set = true; -} - -static void gfx_gx2_set_depth_test_and_mask(bool depth_test, bool z_upd) { - current_depth_test = depth_test || z_upd; - current_depth_write = z_upd; - current_depth_compare_function = depth_test ? GX2_COMPARE_FUNC_LEQUAL : GX2_COMPARE_FUNC_ALWAYS; - - GX2SetDepthOnlyControl(current_depth_test, current_depth_write, current_depth_compare_function); -} - -static void gfx_gx2_set_zmode_decal(bool zmode_decal) { - current_zmode_decal = zmode_decal; - if (zmode_decal) { - // SSDB = SlopeScaledDepthBias 120 leads to -2 at 240p which is the same as N64 mode which has very little - // fighting - const int n64modeFactor = 120; - const int noVanishFactor = 100; - float SSDB = -2.0f; - switch (CVarGetInteger("gZFightingMode", 0)) { - // scaled z-fighting (N64 mode like) - case 1: - if (current_framebuffer) { - SSDB = -1.0f * (float)current_framebuffer->color_buffer.surface.height / n64modeFactor; - } - break; - // no vanishing paths - case 2: - if (current_framebuffer) { - SSDB = -1.0f * (float)current_framebuffer->color_buffer.surface.height / noVanishFactor; - } - break; - // disabled - case 0: - default: - SSDB = -2.0f; - } - - current_SSDB = SSDB; - GX2SetPolygonOffset(SSDB, SSDB, SSDB, SSDB, 0.0f); - GX2SetPolygonControl(GX2_FRONT_FACE_CCW, FALSE, FALSE, TRUE, GX2_POLYGON_MODE_TRIANGLE, - GX2_POLYGON_MODE_TRIANGLE, TRUE, TRUE, FALSE); - } else { - GX2SetPolygonOffset(0.0f, 0.0f, 0.0f, 0.0f, 0.0f); - GX2SetPolygonControl(GX2_FRONT_FACE_CCW, FALSE, FALSE, FALSE, GX2_POLYGON_MODE_TRIANGLE, - GX2_POLYGON_MODE_TRIANGLE, FALSE, FALSE, FALSE); - } -} - -static void gfx_gx2_set_viewport(int x, int y, int width, int height) { - uint32_t buffer_height = current_framebuffer->color_buffer.surface.height; - - current_viewport_x = x; - current_viewport_y = buffer_height - y - height; - current_viewport_width = width; - current_viewport_height = height; - - GX2SetViewport(current_viewport_x, current_viewport_y, current_viewport_width, current_viewport_height, 0.0f, 1.0f); -} - -static void gfx_gx2_set_scissor(int x, int y, int width, int height) { - uint32_t buffer_height = current_framebuffer->color_buffer.surface.height; - uint32_t buffer_width = current_framebuffer->color_buffer.surface.width; - - current_scissor_x = std::min((uint32_t)width, (uint32_t)x); - current_scissor_y = std::min((uint32_t)height, buffer_height - y - height); - current_scissor_width = std::min((uint32_t)width, buffer_width); - current_scissor_height = std::min((uint32_t)height, buffer_height); - - GX2SetScissor(current_scissor_x, current_scissor_y, current_scissor_width, current_scissor_height); -} - -static void gfx_gx2_set_use_alpha(bool use_alpha) { - current_use_alpha = use_alpha; - GX2SetColorControl(GX2_LOGIC_OP_COPY, use_alpha ? 0xff : 0, FALSE, TRUE); -} - -static void gfx_gx2_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris) { - if (!current_shader_program) { - return; - } - - size_t vbo_len = sizeof(float) * buf_vbo_len; - - if (draw_ptr + vbo_len >= draw_buffer + DRAW_BUFFER_SIZE) { - printf("Waiting on GPU!!!\n"); - GX2DrawDone(); - draw_ptr = draw_buffer; - } - - float* new_vbo = (float*)draw_ptr; - draw_ptr += ALIGN(vbo_len, GX2_VERTEX_BUFFER_ALIGNMENT); - - OSBlockMove(new_vbo, buf_vbo, vbo_len, FALSE); - GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, new_vbo, vbo_len); - - GX2SetAttribBuffer(0, vbo_len, current_shader_program->group.stride, new_vbo); - GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 3 * buf_vbo_num_tris, 0, 1); -} - -static void gfx_gx2_init(void) { - // Init the default framebuffer - gfx_gx2_init_framebuffer(&main_framebuffer, WIIU_DEFAULT_FB_WIDTH, WIIU_DEFAULT_FB_HEIGHT); - - GX2CalcSurfaceSizeAndAlignment(&main_framebuffer.color_buffer.surface); - GX2InitColorBufferRegs(&main_framebuffer.color_buffer); - - main_framebuffer.color_buffer.surface.image = gfx_wiiu_alloc_mem1(main_framebuffer.color_buffer.surface.imageSize, - main_framebuffer.color_buffer.surface.alignment); - assert(main_framebuffer.color_buffer.surface.image); - - GX2CalcSurfaceSizeAndAlignment(&main_framebuffer.depth_buffer.surface); - GX2InitDepthBufferRegs(&main_framebuffer.depth_buffer); - - main_framebuffer.depth_buffer.surface.image = gfx_wiiu_alloc_mem1(main_framebuffer.depth_buffer.surface.imageSize, - main_framebuffer.depth_buffer.surface.alignment); - assert(main_framebuffer.depth_buffer.surface.image); - - main_framebuffer.imtex.Texture = &main_framebuffer.texture; - main_framebuffer.imtex.Sampler = &main_framebuffer.sampler; - - // create a linear aligned copy of the depth buffer to read pixels to - memcpy(&depthReadBuffer, &main_framebuffer.depth_buffer, sizeof(GX2DepthBuffer)); - - depthReadBuffer.surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED; - depthReadBuffer.surface.width = 32; - depthReadBuffer.surface.height = 1; - - GX2CalcSurfaceSizeAndAlignment(&depthReadBuffer.surface); - - depthReadBuffer.surface.image = - gfx_wiiu_alloc_mem1(depthReadBuffer.surface.alignment, depthReadBuffer.surface.imageSize); - assert(depthReadBuffer.surface.image); - GX2Invalidate(GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_DEPTH_BUFFER, depthReadBuffer.surface.image, - depthReadBuffer.surface.imageSize); - - GX2SetColorBuffer(&main_framebuffer.color_buffer, GX2_RENDER_TARGET_0); - GX2SetDepthBuffer(&main_framebuffer.depth_buffer); - - current_framebuffer = &main_framebuffer; - - // allocate draw buffer - draw_buffer = (uint8_t*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, DRAW_BUFFER_SIZE); - assert(draw_buffer); - draw_ptr = draw_buffer; - - GX2SetRasterizerClipControl(TRUE, FALSE); - - GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, - GX2_BLEND_COMBINE_MODE_ADD, FALSE, GX2_BLEND_MODE_ZERO, GX2_BLEND_MODE_ZERO, - GX2_BLEND_COMBINE_MODE_ADD); -} - -void gfx_gx2_shutdown(void) { - if (has_foreground) { - GX2DrawDone(); - - if (depthReadBuffer.surface.image) { - gfx_wiiu_free_mem1(depthReadBuffer.surface.image); - depthReadBuffer.surface.image = nullptr; - } - - if (main_framebuffer.color_buffer.surface.image) { - gfx_wiiu_free_mem1(main_framebuffer.color_buffer.surface.image); - main_framebuffer.color_buffer.surface.image = nullptr; - } - - if (main_framebuffer.depth_buffer.surface.image) { - gfx_wiiu_free_mem1(main_framebuffer.depth_buffer.surface.image); - main_framebuffer.depth_buffer.surface.image = nullptr; - } - } - - if (draw_buffer) { - free(draw_buffer); - draw_buffer = nullptr; - draw_ptr = nullptr; - } -} - -static void gfx_gx2_on_resize(void) { -} - -static void gfx_gx2_start_frame(void) { - // Restore state since ImGui modified it when rendering - GX2SetViewport(current_viewport_x, current_viewport_y, current_viewport_width, current_viewport_height, 0.0f, 1.0f); - GX2SetScissor(current_scissor_x, current_scissor_y, current_scissor_width, current_scissor_height); - - GX2SetColorControl(GX2_LOGIC_OP_COPY, current_use_alpha ? 0xff : 0, FALSE, TRUE); - - GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, - GX2_BLEND_COMBINE_MODE_ADD, FALSE, GX2_BLEND_MODE_ZERO, GX2_BLEND_MODE_ZERO, - GX2_BLEND_COMBINE_MODE_ADD); - - GX2SetDepthOnlyControl(current_depth_test, current_depth_write, current_depth_compare_function); - - if (current_zmode_decal) { - GX2SetPolygonOffset(current_SSDB, current_SSDB, current_SSDB, current_SSDB, 0.0f); - GX2SetPolygonControl(GX2_FRONT_FACE_CCW, FALSE, FALSE, TRUE, GX2_POLYGON_MODE_TRIANGLE, - GX2_POLYGON_MODE_TRIANGLE, TRUE, TRUE, FALSE); - } else { - GX2SetPolygonOffset(0.0f, 0.0f, 0.0f, 0.0f, 0.0f); - GX2SetPolygonControl(GX2_FRONT_FACE_CCW, FALSE, FALSE, FALSE, GX2_POLYGON_MODE_TRIANGLE, - GX2_POLYGON_MODE_TRIANGLE, FALSE, FALSE, FALSE); - } - - frame_count++; -} - -static void gfx_gx2_end_frame(void) { - draw_ptr = draw_buffer; - - GX2CopyColorBufferToScanBuffer(&main_framebuffer.color_buffer, GX2_SCAN_TARGET_TV); - GX2CopyColorBufferToScanBuffer(&main_framebuffer.color_buffer, GX2_SCAN_TARGET_DRC); -} - -static void gfx_gx2_finish_render(void) { -} - -static int gfx_gx2_create_framebuffer(void) { - struct Framebuffer* buffer = (struct Framebuffer*)calloc(1, sizeof(struct Framebuffer)); - assert(buffer); - - GX2InitSampler(&buffer->sampler, GX2_TEX_CLAMP_MODE_WRAP, GX2_TEX_XY_FILTER_MODE_LINEAR); - - buffer->imtex.Texture = &buffer->texture; - buffer->imtex.Sampler = &buffer->sampler; - - // some more 32-bit shenanigans :D - return (int)buffer; -} - -static void gfx_gx2_update_framebuffer_parameters(int fb, uint32_t width, uint32_t height, uint32_t msaa_level, - bool opengl_invert_y, bool render_target, bool has_depth_buffer, - bool can_extract_depth) { - struct Framebuffer* buffer = (struct Framebuffer*)fb; - - // we don't support updating the main buffer (fb 0) - if (!buffer) { - return; - } - - if (buffer->texture.surface.width == width && buffer->texture.surface.height == height) { - return; - } - - // make sure the GPU no longer writes to the buffer - GX2DrawDone(); - - if (buffer->texture.surface.image) { - if (buffer->colorBufferMem1) { - gfx_wiiu_free_mem1(buffer->texture.surface.image); - } else { - free(buffer->texture.surface.image); - } - buffer->texture.surface.image = nullptr; - } - - if (buffer->depth_buffer.surface.image) { - if (buffer->depthBufferMem1) { - gfx_wiiu_free_mem1(buffer->depth_buffer.surface.image); - } else { - free(buffer->depth_buffer.surface.image); - } - buffer->depth_buffer.surface.image = nullptr; - } - - gfx_gx2_init_framebuffer(buffer, width, height); - - GX2CalcSurfaceSizeAndAlignment(&buffer->depth_buffer.surface); - GX2InitDepthBufferRegs(&buffer->depth_buffer); - - buffer->depth_buffer.surface.image = - gfx_wiiu_alloc_mem1(buffer->depth_buffer.surface.imageSize, buffer->depth_buffer.surface.alignment); - // fall back to mem2 - if (!buffer->depth_buffer.surface.image) { - buffer->depth_buffer.surface.image = - memalign(buffer->depth_buffer.surface.alignment, buffer->depth_buffer.surface.imageSize); - buffer->depthBufferMem1 = false; - } else { - buffer->depthBufferMem1 = true; - } - assert(buffer->depth_buffer.surface.image); - - GX2CalcSurfaceSizeAndAlignment(&buffer->color_buffer.surface); - GX2InitColorBufferRegs(&buffer->color_buffer); - - memset(&buffer->texture, 0, sizeof(GX2Texture)); - buffer->texture.surface.use = GX2_SURFACE_USE_TEXTURE; - buffer->texture.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D; - buffer->texture.surface.width = width; - buffer->texture.surface.height = height; - buffer->texture.surface.depth = 1; - buffer->texture.surface.mipLevels = 1; - buffer->texture.surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; - buffer->texture.surface.aa = GX2_AA_MODE1X; - buffer->texture.surface.tileMode = GX2_TILE_MODE_DEFAULT; - buffer->texture.viewFirstMip = 0; - buffer->texture.viewNumMips = 1; - buffer->texture.viewFirstSlice = 0; - buffer->texture.viewNumSlices = 1; - buffer->texture.compMap = GX2_COMP_MAP(GX2_SQ_SEL_R, GX2_SQ_SEL_G, GX2_SQ_SEL_B, GX2_SQ_SEL_A); - - GX2CalcSurfaceSizeAndAlignment(&buffer->texture.surface); - GX2InitTextureRegs(&buffer->texture); - - // the texture and color buffer share a buffer - assert(buffer->color_buffer.surface.imageSize == buffer->texture.surface.imageSize); - - buffer->texture.surface.image = - gfx_wiiu_alloc_mem1(buffer->texture.surface.imageSize, buffer->texture.surface.alignment); - // fall back to mem2 - if (!buffer->texture.surface.image) { - buffer->texture.surface.image = memalign(buffer->texture.surface.alignment, buffer->texture.surface.imageSize); - buffer->colorBufferMem1 = false; - } else { - buffer->colorBufferMem1 = true; - } - assert(buffer->texture.surface.image); - - buffer->color_buffer.surface.image = buffer->texture.surface.image; -} - -void gfx_gx2_start_draw_to_framebuffer(int fb, float noise_scale) { - struct Framebuffer* buffer = (struct Framebuffer*)fb; - - // fb 0 = main buffer - if (!buffer) { - buffer = &main_framebuffer; - } - - if (noise_scale != 0.0f) { - current_noise_scale = 1.0f / noise_scale; - } - - GX2SetColorBuffer(&buffer->color_buffer, GX2_RENDER_TARGET_0); - GX2SetDepthBuffer(&buffer->depth_buffer); - - current_framebuffer = buffer; -} - -void gfx_gx2_clear_framebuffer(void) { - struct Framebuffer* buffer = current_framebuffer; - - GX2ClearColor(&buffer->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f); - GX2ClearDepthStencilEx(&buffer->depth_buffer, buffer->depth_buffer.depthClear, buffer->depth_buffer.stencilClear, - GX2_CLEAR_FLAGS_BOTH); - - gfx_wiiu_set_context_state(); -} - -void gfx_gx2_resolve_msaa_color_buffer(int fb_id_target, int fb_id_source) { - struct Framebuffer* src_buffer = (struct Framebuffer*)fb_id_source; - struct Framebuffer* target_buffer = (struct Framebuffer*)fb_id_target; - - // fb 0 = main buffer - if (!src_buffer) { - src_buffer = &main_framebuffer; - } - if (!target_buffer) { - target_buffer = &main_framebuffer; - } - - if (src_buffer->color_buffer.surface.aa == GX2_AA_MODE1X) { - GX2CopySurface(&src_buffer->color_buffer.surface, src_buffer->color_buffer.viewMip, - src_buffer->color_buffer.viewFirstSlice, &target_buffer->color_buffer.surface, - target_buffer->color_buffer.viewMip, target_buffer->color_buffer.viewFirstSlice); - } else { - GX2ResolveAAColorBuffer(&src_buffer->color_buffer, &target_buffer->color_buffer.surface, - target_buffer->color_buffer.viewMip, target_buffer->color_buffer.viewFirstSlice); - } -} - -void* gfx_gx2_get_framebuffer_texture_id(int fb_id) { - struct Framebuffer* buffer = (struct Framebuffer*)fb_id; - - // fb 0 = main buffer - if (!buffer) { - buffer = &main_framebuffer; - } - - return &buffer->imtex; -} - -void gfx_gx2_select_texture_fb(int fb) { - struct Framebuffer* buffer = (struct Framebuffer*)fb; - assert(buffer); - - assert(current_shader_program); - uint32_t location = current_shader_program->samplers_location[0]; - GX2SetPixelTexture(&buffer->texture, location); - GX2SetPixelSampler(&buffer->sampler, location); -} - -void gfx_gx2_copy_framebuffer(int fb_dst_id, int fb_src_id, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, - int dstY0, int dstX1, int dstY1) { - // TODO: Implement framebuffer texture copy -} - -void gfx_gx2_read_framebuffer_to_cpu(int fb_id, uint32_t width, uint32_t height, uint16_t* rgba16_buf) { - // TODO: Implement framebuffer copy to CPU -} - -static std::unordered_map, uint16_t, hash_pair_ff> -gfx_gx2_get_pixel_depth(int fb_id, const std::set>& coordinates) { - struct Framebuffer* buffer = (struct Framebuffer*)fb_id; - - // fb 0 = main buffer - if (!buffer) { - buffer = &main_framebuffer; - } - - std::unordered_map, uint16_t, hash_pair_ff> res; - GX2Rect srcRects[25]; - GX2Point dstPoints[25]; - size_t num_coordinates = coordinates.size(); - while (num_coordinates > 0) { - size_t numRects = 25; - if (num_coordinates < numRects) { - numRects = num_coordinates; - } - num_coordinates -= numRects; - - // initialize rects and points - for (size_t i = 0; i < numRects; ++i) { - const auto& c = *std::next(coordinates.begin(), num_coordinates + i); - const int32_t x = (int32_t)std::clamp(c.first, 0.0f, (float)(buffer->depth_buffer.surface.width - 1)); - const int32_t y = (int32_t)std::clamp(c.second, 0.0f, (float)(buffer->depth_buffer.surface.height - 1)); - - srcRects[i] = GX2Rect{ x, (int32_t)buffer->depth_buffer.surface.height - y, x + 1, - (int32_t)(buffer->depth_buffer.surface.height - y) + 1 }; - - // dst points will be spread over the x-axis of the buffer - dstPoints[i] = GX2Point{ i, 0 }; - } - - // Invalidate the buffer first - GX2Invalidate(GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_DEPTH_BUFFER, depthReadBuffer.surface.image, - depthReadBuffer.surface.imageSize); - - // Perform the copy - GX2CopySurfaceEx(&buffer->depth_buffer.surface, 0, 0, &depthReadBuffer.surface, 0, 0, numRects, srcRects, - dstPoints); - - // Wait for draws to be done and restore context, in case GPU was used - GX2DrawDone(); - gfx_wiiu_set_context_state(); - - // read the pixels from the depthReadBuffer - for (size_t i = 0; i < numRects; ++i) { - uint32_t tmp = __builtin_bswap32(*((uint32_t*)depthReadBuffer.surface.image + i)); - float val = *(float*)&tmp; - - const auto& c = *std::next(coordinates.begin(), num_coordinates + i); - res.emplace(c, val * 65532.0f); - } - } - - return res; -} - -void gfx_gx2_set_texture_filter(FilteringMode mode) { - // three-point is not implemented in the shaders yet - if (mode == FILTER_THREE_POINT) { - mode = FILTER_LINEAR; - } - - current_filter_mode = mode; - gfx_texture_cache_clear(); -} - -FilteringMode gfx_gx2_get_texture_filter(void) { - return current_filter_mode; -} - -ImGui_ImplGX2_Texture* gfx_gx2_texture_for_imgui(uint32_t texture_id) { - struct Texture* tex = (struct Texture*)texture_id; - return &tex->imtex; -} - -struct GfxRenderingAPI gfx_gx2_api = { gfx_gx2_get_name, - gfx_gx2_get_max_texture_size, - gfx_gx2_get_clip_parameters, - gfx_gx2_unload_shader, - gfx_gx2_load_shader, - gfx_gx2_create_and_load_new_shader, - gfx_gx2_lookup_shader, - gfx_gx2_shader_get_info, - gfx_gx2_new_texture, - gfx_gx2_select_texture, - gfx_gx2_upload_texture, - gfx_gx2_set_sampler_parameters, - gfx_gx2_set_depth_test_and_mask, - gfx_gx2_set_zmode_decal, - gfx_gx2_set_viewport, - gfx_gx2_set_scissor, - gfx_gx2_set_use_alpha, - gfx_gx2_draw_triangles, - gfx_gx2_init, - gfx_gx2_on_resize, - gfx_gx2_start_frame, - gfx_gx2_end_frame, - gfx_gx2_finish_render, - gfx_gx2_create_framebuffer, - gfx_gx2_update_framebuffer_parameters, - gfx_gx2_start_draw_to_framebuffer, - gfx_gx2_copy_framebuffer, - gfx_gx2_clear_framebuffer, - gfx_gx2_read_framebuffer_to_cpu, - gfx_gx2_resolve_msaa_color_buffer, - gfx_gx2_get_pixel_depth, - gfx_gx2_get_framebuffer_texture_id, - gfx_gx2_select_texture_fb, - gfx_gx2_delete_texture, - gfx_gx2_set_texture_filter, - gfx_gx2_get_texture_filter }; - -#endif diff --git a/src/graphic/Fast3D/gfx_gx2.h b/src/graphic/Fast3D/gfx_gx2.h deleted file mode 100644 index 336e3ca3f..000000000 --- a/src/graphic/Fast3D/gfx_gx2.h +++ /dev/null @@ -1,16 +0,0 @@ -/* gfx_gx2.h - Fast3D GX2 backend for libultraship - - Created in 2022 by GaryOderNichts -*/ -#ifndef GFX_GX2_H -#define GFX_GX2_H - -#include "gfx_rendering_api.h" - -void gfx_gx2_shutdown(void); - -struct ImGui_ImplGX2_Texture* gfx_gx2_texture_for_imgui(uint32_t texture_id); - -extern struct GfxRenderingAPI gfx_gx2_api; - -#endif diff --git a/src/graphic/Fast3D/gfx_pc.cpp b/src/graphic/Fast3D/gfx_pc.cpp index 5f6553133..f52d563fb 100644 --- a/src/graphic/Fast3D/gfx_pc.cpp +++ b/src/graphic/Fast3D/gfx_pc.cpp @@ -1627,19 +1627,10 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo if (clampS) { buf_vbo[buf_vbo_len++] = (tex_width2[t] - 0.5f) / tex_width[t]; } -#ifdef __WIIU__ - else { - buf_vbo[buf_vbo_len++] = 0.0f; - } -#endif + if (clampT) { buf_vbo[buf_vbo_len++] = (tex_height2[t] - 0.5f) / tex_height[t]; } -#ifdef __WIIU__ - else { - buf_vbo[buf_vbo_len++] = 0.0f; - } -#endif } if (use_fog) { @@ -1717,12 +1708,6 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo buf_vbo[buf_vbo_len++] = color->r / 255.0f; buf_vbo[buf_vbo_len++] = color->g / 255.0f; buf_vbo[buf_vbo_len++] = color->b / 255.0f; -#ifdef __WIIU__ - // padding - if (!use_alpha) { - buf_vbo[buf_vbo_len++] = 1.0f; - } -#endif } else { if (use_fog && color == &v_arr[i]->color) { // Shade alpha is 100% for fog @@ -3769,10 +3754,10 @@ void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, co gfx_current_dimensions.internal_mul = CVarGetFloat("gInternalResolution", 1); #endif gfx_msaa_level = CVarGetInteger("gMSAAValue", 1); -#ifndef __WIIU__ // Wii U overrides dimentions in gfx_wapi->init to match framebuffer size + gfx_current_dimensions.width = width; gfx_current_dimensions.height = height; -#endif + game_framebuffer = gfx_rapi->create_framebuffer(); game_framebuffer_msaa_resolved = gfx_rapi->create_framebuffer(); diff --git a/src/graphic/Fast3D/gfx_wiiu.cpp b/src/graphic/Fast3D/gfx_wiiu.cpp deleted file mode 100644 index 4f6fc9cb0..000000000 --- a/src/graphic/Fast3D/gfx_wiiu.cpp +++ /dev/null @@ -1,487 +0,0 @@ -#ifdef __WIIU__ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#ifndef _LANGUAGE_C -#define _LANGUAGE_C -#endif - -#include "gfx_window_manager_api.h" -#include "gfx_pc.h" -#include "gfx_gx2.h" -#include "gfx_wiiu.h" - -#include -#include "port/wiiu/WiiUImpl.h" -#include "libultraship/classes.h" - -static MEMHeapHandle heap_MEM1 = nullptr; -static MEMHeapHandle heap_foreground = nullptr; - -bool has_foreground = false; -static void* mem1_storage = nullptr; -static void* command_buffer_pool = nullptr; -GX2ContextState* context_state = nullptr; - -static GX2TVRenderMode tv_render_mode; -static void* tv_scan_buffer = nullptr; -static uint32_t tv_scan_buffer_size = 0; -static uint32_t tv_width; -static uint32_t tv_height; - -static GX2DrcRenderMode drc_render_mode; -static void* drc_scan_buffer = nullptr; -static uint32_t drc_scan_buffer_size = 0; - -static int frame_divisor = 1; - -// for ImGui DeltaTime -// (initialized to 1 to not trigger imguis assert on initial draw) -uint32_t frametime = 1; - -bool gfx_wiiu_init_mem1(void) { - MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1); - uint32_t size; - void* base; - - size = MEMGetAllocatableSizeForFrmHeapEx(heap, 4); - if (!size) { - printf("%s: MEMGetAllocatableSizeForFrmHeapEx == 0", __FUNCTION__); - return false; - } - - base = MEMAllocFromFrmHeapEx(heap, size, 4); - if (!base) { - printf("%s: MEMAllocFromFrmHeapEx(heap, 0x%X, 4) failed", __FUNCTION__, size); - return false; - } - - heap_MEM1 = MEMCreateExpHeapEx(base, size, 0); - if (!heap_MEM1) { - printf("%s: MEMCreateExpHeapEx(%p, 0x%X, 0) failed", __FUNCTION__, base, size); - return false; - } - - return true; -} - -void gfx_wiiu_close(void) { -} - -void gfx_wiiu_destroy_mem1(void) { - MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1); - - if (heap_MEM1) { - MEMDestroyExpHeap(heap_MEM1); - heap_MEM1 = NULL; - } -} - -bool gfx_wiiu_init_foreground(void) { - MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_FG); - uint32_t size; - void* base; - - size = MEMGetAllocatableSizeForFrmHeapEx(heap, 4); - if (!size) { - printf("%s: MEMAllocFromFrmHeapEx(heap, 0x%X, 4)", __FUNCTION__, size); - return false; - } - - base = MEMAllocFromFrmHeapEx(heap, size, 4); - if (!base) { - printf("%s: MEMGetAllocatableSizeForFrmHeapEx == 0", __FUNCTION__); - return false; - } - - heap_foreground = MEMCreateExpHeapEx(base, size, 0); - if (!heap_foreground) { - printf("%s: MEMCreateExpHeapEx(%p, 0x%X, 0)", __FUNCTION__, base, size); - return false; - } - - return true; -} - -void gfx_wiiu_destroy_foreground(void) { - MEMHeapHandle foreground = MEMGetBaseHeapHandle(MEM_BASE_HEAP_FG); - - if (heap_foreground) { - MEMDestroyExpHeap(heap_foreground); - heap_foreground = NULL; - } - - MEMFreeToFrmHeap(foreground, MEM_FRM_HEAP_FREE_ALL); -} - -void* gfx_wiiu_alloc_mem1(uint32_t size, uint32_t alignment) { - void* block; - - if (!heap_MEM1) { - return NULL; - } - - if (alignment < 4) { - alignment = 4; - } - - block = MEMAllocFromExpHeapEx(heap_MEM1, size, alignment); - return block; -} - -void gfx_wiiu_free_mem1(void* block) { - if (!heap_MEM1) { - return; - } - - MEMFreeToExpHeap(heap_MEM1, block); -} - -void* gfx_wiiu_alloc_foreground(uint32_t size, uint32_t alignment) { - void* block; - - if (!heap_foreground) { - return NULL; - } - - if (alignment < 4) { - alignment = 4; - } - - block = MEMAllocFromExpHeapEx(heap_foreground, size, alignment); - return block; -} - -void gfx_wiiu_free_foreground(void* block) { - if (!heap_foreground) { - return; - } - - MEMFreeToExpHeap(heap_foreground, block); -} - -static uint32_t gfx_wiiu_proc_callback_acquired(void* context) { - has_foreground = true; - - bool result = gfx_wiiu_init_foreground(); - assert(result); - - tv_scan_buffer = gfx_wiiu_alloc_foreground(tv_scan_buffer_size, GX2_SCAN_BUFFER_ALIGNMENT); - assert(tv_scan_buffer); - - GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tv_scan_buffer, tv_scan_buffer_size); - GX2SetTVBuffer(tv_scan_buffer, tv_scan_buffer_size, tv_render_mode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, - GX2_BUFFERING_MODE_DOUBLE); - - drc_scan_buffer = gfx_wiiu_alloc_foreground(drc_scan_buffer_size, GX2_SCAN_BUFFER_ALIGNMENT); - assert(drc_scan_buffer); - - GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drc_scan_buffer, drc_scan_buffer_size); - GX2SetDRCBuffer(drc_scan_buffer, drc_scan_buffer_size, drc_render_mode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, - GX2_BUFFERING_MODE_DOUBLE); - - return 0; -} - -static uint32_t gfx_wiiu_proc_callback_released(void* context) { - if (tv_scan_buffer) { - gfx_wiiu_free_foreground(tv_scan_buffer); - tv_scan_buffer = nullptr; - } - - if (drc_scan_buffer) { - gfx_wiiu_free_foreground(drc_scan_buffer); - drc_scan_buffer = nullptr; - } - - gfx_wiiu_destroy_foreground(); - - has_foreground = false; - - return 0; -} - -static void gfx_wiiu_init(const char* game_name, const char* gfx_api_name, bool start_in_fullscreen, uint32_t width, - uint32_t height, int32_t posX, int32_t posY) { - WHBProcInit(); - - uint32_t mem1_addr, mem1_size; - OSGetMemBound(OS_MEM1, &mem1_addr, &mem1_size); - mem1_storage = memalign(0x40, mem1_size); - assert(mem1_storage); - - ProcUISetMEM1Storage(mem1_storage, mem1_size); - - bool result = gfx_wiiu_init_mem1(); - assert(result); - - command_buffer_pool = memalign(GX2_COMMAND_BUFFER_ALIGNMENT, 0x400000); - assert(command_buffer_pool); - - uint32_t initAttribs[] = { GX2_INIT_CMD_BUF_BASE, - (uintptr_t)command_buffer_pool, - GX2_INIT_CMD_BUF_POOL_SIZE, - 0x400000, - GX2_INIT_ARGC, - 0, - GX2_INIT_ARGV, - 0, - GX2_INIT_END }; - GX2Init(initAttribs); - - switch (GX2GetSystemTVScanMode()) { - case GX2_TV_SCAN_MODE_480I: - case GX2_TV_SCAN_MODE_480P: - tv_render_mode = GX2_TV_RENDER_MODE_WIDE_480P; - tv_width = 854; - tv_height = 480; - break; - case GX2_TV_SCAN_MODE_1080I: - case GX2_TV_SCAN_MODE_1080P: - tv_render_mode = GX2_TV_RENDER_MODE_WIDE_1080P; - tv_width = 1920; - tv_height = 1080; - break; - case GX2_TV_SCAN_MODE_720P: - default: - tv_render_mode = GX2_TV_RENDER_MODE_WIDE_720P; - tv_width = 1280; - tv_height = 720; - break; - } - - drc_render_mode = GX2GetSystemDRCScanMode(); - - uint32_t unk; - GX2CalcTVSize(tv_render_mode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &tv_scan_buffer_size, - &unk); - GX2CalcDRCSize(drc_render_mode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, - &drc_scan_buffer_size, &unk); - - ProcUIRegisterCallback(PROCUI_CALLBACK_ACQUIRE, gfx_wiiu_proc_callback_acquired, nullptr, 100); - ProcUIRegisterCallback(PROCUI_CALLBACK_RELEASE, gfx_wiiu_proc_callback_released, nullptr, 100); - - gfx_wiiu_proc_callback_acquired(nullptr); - - context_state = (GX2ContextState*)memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState)); - assert(context_state); - - GX2SetupContextStateEx(context_state, TRUE); - GX2SetContextState(context_state); - - GX2SetTVScale(WIIU_DEFAULT_FB_WIDTH, WIIU_DEFAULT_FB_HEIGHT); - GX2SetDRCScale(WIIU_DEFAULT_FB_WIDTH, WIIU_DEFAULT_FB_HEIGHT); - - GX2SetSwapInterval(frame_divisor); - - gfx_current_dimensions.width = gfx_current_game_window_viewport.width = WIIU_DEFAULT_FB_WIDTH; - gfx_current_dimensions.height = gfx_current_game_window_viewport.height = WIIU_DEFAULT_FB_HEIGHT; - - Ship::GuiWindowInitData window_impl; - window_impl.Gx2.Width = WIIU_DEFAULT_FB_WIDTH; - window_impl.Gx2.Height = WIIU_DEFAULT_FB_HEIGHT; - Ship::Context::GetInstance()->GetWindow()->GetGui()->Init(window_impl); -} - -static void gfx_wiiu_shutdown(void) { - if (has_foreground) { - gfx_wiiu_proc_callback_released(nullptr); - gfx_wiiu_destroy_mem1(); - } - - GX2Shutdown(); - - if (context_state) { - free(context_state); - context_state = nullptr; - } - - if (command_buffer_pool) { - free(command_buffer_pool); - command_buffer_pool = nullptr; - } - - ProcUISetMEM1Storage(nullptr, 0); - free(mem1_storage); -} - -void gfx_wiiu_set_context_state(void) { - GX2SetContextState(context_state); -} - -static void gfx_wiiu_set_fullscreen_changed_callback(void (*on_fullscreen_changed)(bool is_now_fullscreen)) { -} - -static void gfx_wiiu_set_fullscreen(bool enable) { -} - -static void gfx_wiiu_get_active_window_refresh_rate(uint32_t* refresh_rate) { - *refresh_rate = 60; -} - -static void gfx_wiiu_show_cursor(bool hide) { -} - -static void gfx_wiiu_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bool (*on_key_up)(int scancode), - void (*on_all_keys_up)(void)) { -} - -static void gfx_wiiu_main_loop(void (*run_one_game_iter)(void)) { - while (WHBProcIsRunning()) { - run_one_game_iter(); - } - - Ship::WiiU::Exit(); - - gfx_gx2_shutdown(); - gfx_wiiu_shutdown(); - WHBProcShutdown(); -} - -static void gfx_wiiu_get_dimensions(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY) { - *width = WIIU_DEFAULT_FB_WIDTH; - *height = WIIU_DEFAULT_FB_HEIGHT; - *posX = 0; - *posY = 0; -} - -static void gfx_wiiu_handle_events(void) { - Ship::WiiU::Update(); - - ImGui_ImplWiiU_ControllerInput input{}; - - VPADReadError vpad_error; - input.vpad = Ship::WiiU::GetVPADStatus(&vpad_error); - if (vpad_error != VPAD_READ_SUCCESS) { - input.vpad = nullptr; - } - - KPADError kpad_error; - for (int i = 0; i < 4; i++) { - input.kpad[i] = Ship::WiiU::GetKPADStatus((WPADChan)i, &kpad_error); - if (kpad_error != KPAD_ERROR_OK) { - input.kpad[i] = nullptr; - } - } - - Ship::WindowEvent event_impl; - event_impl.Gx2.Input = &input; - Ship::Context::GetInstance()->GetWindow()->GetGui()->Update(event_impl); -} - -static bool gfx_wiiu_start_frame(void) { - uint32_t swap_count, flip_count; - OSTime last_flip, last_vsync; - uint32_t wait_count = 0; - - while (true) { - GX2GetSwapStatus(&swap_count, &flip_count, &last_flip, &last_vsync); - - if (flip_count >= swap_count) { - break; - } - - if (wait_count >= 10) { - // GPU timed out, drop frame - return false; - } - - wait_count++; - GX2WaitForVsync(); - } - - return true; -} - -static void gfx_wiiu_swap_buffers_begin(void) { - GX2SwapScanBuffers(); - GX2Flush(); - - gfx_wiiu_set_context_state(); - - GX2SetTVEnable(TRUE); - GX2SetDRCEnable(TRUE); -} - -static void gfx_wiiu_swap_buffers_end(void) { - static OSTick tick = 0; - frametime = OSTicksToMicroseconds(OSGetSystemTick() - tick); - tick = OSGetSystemTick(); -} - -static double gfx_wiiu_get_time(void) { - return 0.0; -} - -static void gfx_wiiu_set_target_fps(int fps) { - // use the nearest divisor - int divisor = 60 / fps; - if (divisor < 1) { - divisor = 1; - } - - if (frame_divisor != divisor) { - GX2SetSwapInterval(divisor); - frame_divisor = divisor; - } -} - -static void gfx_wiiu_set_maximum_frame_latency(int latency) { -} - -static const char* gfx_wiiu_get_key_name(int scancode) { - return ""; -} - -bool gfx_wiiu_can_disable_vsync() { - return false; -} - -struct GfxWindowManagerAPI gfx_wiiu = { - gfx_wiiu_init, - gfx_wiiu_close, - gfx_wiiu_set_keyboard_callbacks, - gfx_wiiu_set_fullscreen_changed_callback, - gfx_wiiu_set_fullscreen, - gfx_wiiu_get_active_window_refresh_rate, - gfx_wiiu_show_cursor, - gfx_wiiu_main_loop, - gfx_wiiu_get_dimensions, - gfx_wiiu_handle_events, - gfx_wiiu_start_frame, - gfx_wiiu_swap_buffers_begin, - gfx_wiiu_swap_buffers_end, - gfx_wiiu_get_time, - gfx_wiiu_set_target_fps, - gfx_wiiu_set_maximum_frame_latency, - gfx_wiiu_get_key_name, - gfx_wiiu_can_disable_vsync, -}; - -#endif diff --git a/src/graphic/Fast3D/gfx_wiiu.h b/src/graphic/Fast3D/gfx_wiiu.h deleted file mode 100644 index ee0aaeaa9..000000000 --- a/src/graphic/Fast3D/gfx_wiiu.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GFX_WIIU_H -#define GFX_WIIU_H -#ifdef __WIIU__ - -#include -#include - -#include "gfx_window_manager_api.h" - -// make the default fb always 1080p to not mess with scaling -#define WIIU_DEFAULT_FB_WIDTH 1920 -#define WIIU_DEFAULT_FB_HEIGHT 1080 - -extern bool has_foreground; -extern uint32_t frametime; - -bool gfx_wiiu_init_mem1(void); - -void gfx_wiiu_destroy_mem1(void); - -bool gfx_wiiu_init_foreground(void); - -void gfx_wiiu_destroy_foreground(void); - -void* gfx_wiiu_alloc_mem1(uint32_t size, uint32_t alignment); - -void gfx_wiiu_free_mem1(void* block); - -void* gfx_wiiu_alloc_foreground(uint32_t size, uint32_t alignment); - -void gfx_wiiu_free_foreground(void* block); - -void gfx_wiiu_set_context_state(void); - -extern struct GfxWindowManagerAPI gfx_wiiu; - -#endif -#endif diff --git a/src/graphic/Fast3D/gx2_shader_gen.c b/src/graphic/Fast3D/gx2_shader_gen.c deleted file mode 100644 index 931ca8bff..000000000 --- a/src/graphic/Fast3D/gx2_shader_gen.c +++ /dev/null @@ -1,983 +0,0 @@ -/* gx2_shader_gen.c - Fast3D GX2 shader generator for libultraship - - Created in 2022 by GaryOderNichts -*/ -#ifdef __WIIU__ - -#include "gx2_shader_gen.h" -#include "gx2_shader_inl.h" - -#include -#include - -#define ROUNDUP(x, align) (((x) + ((align) -1)) & ~((align) -1)) - -#define FRAG_COORD_REG _R0 -#define TEXEL_REG _R1 -#define FOG_REG _R3 -#define GRAYSCALE_REG _R4 - -enum { - SHADER_TEXINFO0 = SHADER_NOISE + 1, - SHADER_TEXINFO1, - SHADER_MASKTEX0, - SHADER_MASKTEX1, - SHADER_BLENDTEX0, - SHADER_BLENDTEX1, - SHADER_MAX, -}; - -#define REG_TABLE_UNUSED 0xff -#define REG_TABLE_RESERVED 0xfe - -struct RegTable { - uint8_t used; - uint8_t regs[128]; -}; - -static inline int reg_table_find_free(struct RegTable* tbl, bool reuse_texinfo) { - for (int i = 0; i < 128; i++) { - // this is to make sure that things like mask and blend don't overwrite - // texinfo while sampling which is needed for later textures - if (reuse_texinfo && (i == 1 || i == 2)) { - continue; - } - - if (tbl->regs[i] == REG_TABLE_UNUSED) { - return i; - } - } - - return -1; -} - -static void reg_table_build(struct RegTable* tbl, struct CCFeatures *cc_features, bool needs_noise) { - tbl->used = 0; - memset(tbl->regs, REG_TABLE_UNUSED, 128); - - // reg1 is used for the current texel value - tbl->regs[TEXEL_REG] = SHADER_COMBINED; - - // frag coords will always be placed in R0, and is afterwards used - // for storing the noise data - if (needs_noise) { - tbl->regs[FRAG_COORD_REG] = SHADER_NOISE; - } - - if (cc_features->opt_fog) { - tbl->regs[FOG_REG] = REG_TABLE_RESERVED; - } - - if (cc_features->opt_grayscale) { - tbl->regs[GRAYSCALE_REG] = REG_TABLE_RESERVED; - } - - for (int i = 0; i < cc_features->num_inputs; i++) { - tbl->regs[5 + i] = SHADER_INPUT_1 + i; - } - - // for the rest of regs we find unused ones - if (cc_features->used_textures[0]) { - int reg = reg_table_find_free(tbl, false); - assert(reg != -1); - tbl->regs[reg] = SHADER_TEXEL0; - } - - if (cc_features->used_textures[1]) { - int reg = reg_table_find_free(tbl, false); - assert(reg != -1); - tbl->regs[reg] = SHADER_TEXEL1; - } - - if (cc_features->used_masks[0]) { - int reg = reg_table_find_free(tbl, true); - assert(reg != -1); - tbl->regs[reg] = SHADER_MASKTEX0; - } - - if (cc_features->used_masks[1]) { - int reg = reg_table_find_free(tbl, true); - assert(reg != -1); - tbl->regs[reg] = SHADER_MASKTEX1; - } - - if (cc_features->used_blend[0]) { - int reg = reg_table_find_free(tbl, true); - assert(reg != -1); - tbl->regs[reg] = SHADER_BLENDTEX0; - } - - if (cc_features->used_blend[1]) { - int reg = reg_table_find_free(tbl, true); - assert(reg != -1); - tbl->regs[reg] = SHADER_BLENDTEX1; - } - - // find the highest used reg - for (int cnt = 127; cnt >= 0; cnt--) { - if (tbl->regs[cnt] != REG_TABLE_UNUSED) { - tbl->used = cnt + 1; - break; - } - } -} - -static uint8_t get_reg(struct RegTable* tbl, uint8_t c) { - // these are technically not regs but constants - if (c == SHADER_0) { - return ALU_SRC_0; - } - if (c == SHADER_1) { - return ALU_SRC_1; - } - - switch (c) { - case SHADER_TEXINFO0: - case SHADER_TEXEL0A: - c = SHADER_TEXEL0; - break; - case SHADER_TEXINFO1: - case SHADER_TEXEL1A: - c = SHADER_TEXEL1; - break; - default: - break; - } - - for (int i = 0; i < tbl->used; i++) { - if (tbl->regs[i] == c) { - return _R(i); - } - } - - assert(0 && "Failed to find reg!"); - return 0; -} - -#define ADD_INSTR(...) \ - uint64_t tmp[] = {__VA_ARGS__}; \ - memcpy(*alu_ptr, tmp, sizeof(tmp)); \ - *alu_ptr += sizeof(tmp) / sizeof(uint64_t) - -static void add_tex_clamp_S_T(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t tex) { - uint8_t texinfo_reg = get_reg(tbl, (tex == 0) ? SHADER_TEXINFO0 : SHADER_TEXINFO1); - uint8_t texcoord_reg = (tex == 0) ? _R1 : _R2; - - ADD_INSTR( - /* R127.xy = (float) texinfo.xy */ - ALU_INT_TO_FLT(_R127, _x, texinfo_reg, _x) SCL_210 - ALU_LAST, - - ALU_INT_TO_FLT(_R127, _y, texinfo_reg, _y) SCL_210 - ALU_LAST, - - /* R127.xy = 0.5f / texSize */ - ALU_RECIP_IEEE(__, _x, _R127, _x) SCL_210 - ALU_LAST, - - ALU_MUL_IEEE(_R127, _x, ALU_SRC_PS, _x, ALU_SRC_0_5, _x), - ALU_RECIP_IEEE(__, _y, _R127, _y) SCL_210 - ALU_LAST, - - ALU_MUL_IEEE(_R127, _y, ALU_SRC_PS, _y, ALU_SRC_0_5, _x) - ALU_LAST, - - /* texCoord.xy = clamp(texCoord.xy, R127.xy, texClamp.xy) */ - ALU_MAX(__, _x, texcoord_reg, _x, _R127, _x), - ALU_MAX(__, _y, texcoord_reg, _y, _R127, _y) - ALU_LAST, - - ALU_MIN(texcoord_reg, _x, ALU_SRC_PV, _x, texcoord_reg, _z), - ALU_MIN(texcoord_reg, _y, ALU_SRC_PV, _y, texcoord_reg, _w) - ALU_LAST, - ); -} - -static void add_tex_clamp_S(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t tex) { - uint8_t texinfo_reg = get_reg(tbl, (tex == 0) ? SHADER_TEXINFO0 : SHADER_TEXINFO1); - uint8_t texcoord_reg = (tex == 0) ? _R1 : _R2; - - ADD_INSTR( - /* R127.x = (float) texinfo.x */ - ALU_INT_TO_FLT(_R127, _x, texinfo_reg, _x) SCL_210 - ALU_LAST, - - /* R127.x = 0.5f / texSize */ - ALU_RECIP_IEEE(__, _x, _R127, _x) SCL_210 - ALU_LAST, - - ALU_MUL_IEEE(_R127, _x, ALU_SRC_PS, _x, ALU_SRC_0_5, _x) - ALU_LAST, - - /* texCoord.xy = clamp(texCoord.xy, R127.xy, texClamp.xy) */ - ALU_MAX(__, _x, texcoord_reg, _x, _R127, _x) - ALU_LAST, - - ALU_MIN(texcoord_reg, _x, ALU_SRC_PV, _x, texcoord_reg, _z) - ALU_LAST, - ); -} - -static void add_tex_clamp_T(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t tex) { - uint8_t texinfo_reg = get_reg(tbl, (tex == 0) ? SHADER_TEXINFO0 : SHADER_TEXINFO1); - uint8_t texcoord_reg = (tex == 0) ? _R1 : _R2; - - ADD_INSTR( - /* R127.y = (float) texinfo.y */ - ALU_INT_TO_FLT(_R127, _y, texinfo_reg, _y) SCL_210 - ALU_LAST, - - /* R127.y = 0.5f / texSize */ - ALU_RECIP_IEEE(__, _x, _R127, _y) SCL_210 - ALU_LAST, - - ALU_MUL_IEEE(_R127, _y, ALU_SRC_PS, _x, ALU_SRC_0_5, _x) - ALU_LAST, - - /* texCoord.xy = clamp(texCoord.xy, R127.xy, texClamp.xy) */ - ALU_MAX(__, _y, texcoord_reg, _y, _R127, _y) - ALU_LAST, - - ALU_MIN(texcoord_reg, _y, ALU_SRC_PV, _y, texcoord_reg, _w) - ALU_LAST, - ); -} - -static void add_mov(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t src, bool single) { - bool src_alpha = (src == SHADER_TEXEL0A) || (src == SHADER_TEXEL1A); - src = get_reg(tbl, src); - - /* texel = src */ - if (single) { - ADD_INSTR( - ALU_MOV(TEXEL_REG, _w, src, _w) - ALU_LAST, - ); - } else { - ADD_INSTR( - ALU_MOV(TEXEL_REG, _x, src, src_alpha ? _w :_x), - ALU_MOV(TEXEL_REG, _y, src, src_alpha ? _w :_y), - ALU_MOV(TEXEL_REG, _z, src, src_alpha ? _w :_z) - ALU_LAST, - ); - } -} - -static void add_mul(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t src0, uint8_t src1, bool single) { - bool src0_alpha = (src0 == SHADER_TEXEL0A) || (src0 == SHADER_TEXEL1A); - bool src1_alpha = (src1 == SHADER_TEXEL0A) || (src1 == SHADER_TEXEL1A); - src0 = get_reg(tbl, src0); - src1 = get_reg(tbl, src1); - - /* texel = src0 * src1 */ - if (single) { - ADD_INSTR( - ALU_MUL(TEXEL_REG, _w, src0, _w, src1, _w) - ALU_LAST, - ); - } else { - ADD_INSTR( - ALU_MUL(TEXEL_REG, _x, src0, src0_alpha ? _w : _x, src1, src1_alpha ? _w : _x), - ALU_MUL(TEXEL_REG, _y, src0, src0_alpha ? _w : _y, src1, src1_alpha ? _w : _y), - ALU_MUL(TEXEL_REG, _z, src0, src0_alpha ? _w : _z, src1, src1_alpha ? _w : _z) - ALU_LAST, - ); - } -} - -static void add_mix(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t src0, uint8_t src1, uint8_t src2, uint8_t src3, bool single) { - bool src0_alpha = (src0 == SHADER_TEXEL0A) || (src0 == SHADER_TEXEL1A); - bool src1_alpha = (src1 == SHADER_TEXEL0A) || (src1 == SHADER_TEXEL1A); - bool src2_alpha = (src2 == SHADER_TEXEL0A) || (src2 == SHADER_TEXEL1A); - bool src3_alpha = (src3 == SHADER_TEXEL0A) || (src3 == SHADER_TEXEL1A); - src0 = get_reg(tbl, src0); - src1 = get_reg(tbl, src1); - src2 = get_reg(tbl, src2); - src3 = get_reg(tbl, src3); - - /* texel = (src0 - src1) * src2 - src3 */ - if (single) { - ADD_INSTR( - ALU_ADD(__, _w, src0, _w, src1 _NEG, _w) - ALU_LAST, - - ALU_MULADD(TEXEL_REG, _w, ALU_SRC_PV, _w, src2, _w, src3, _w) - ALU_LAST, - ); - } else { - ADD_INSTR( - ALU_ADD(__, _x, src0, src0_alpha ? _w : _x, src1 _NEG, src1_alpha ? _w : _x), - ALU_ADD(__, _y, src0, src0_alpha ? _w : _y, src1 _NEG, src1_alpha ? _w : _y), - ALU_ADD(__, _z, src0, src0_alpha ? _w : _z, src1 _NEG, src1_alpha ? _w : _z) - ALU_LAST, - - ALU_MULADD(TEXEL_REG, _x, ALU_SRC_PV, _x, src2, src2_alpha ? _w : _x, src3, src3_alpha ? _w : _x), - ALU_MULADD(TEXEL_REG, _y, ALU_SRC_PV, _y, src2, src2_alpha ? _w : _y, src3, src3_alpha ? _w : _y), - ALU_MULADD(TEXEL_REG, _z, ALU_SRC_PV, _z, src2, src2_alpha ? _w : _z, src3, src3_alpha ? _w : _z) - ALU_LAST, - ); - } -} -#undef ADD_INSTR - -static void append_tex_clamp(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t tex, bool s, bool t) { - if (s && t) { - add_tex_clamp_S_T(tbl, alu_ptr, tex); - } else if (s) { - add_tex_clamp_S(tbl, alu_ptr, tex); - } else { - add_tex_clamp_T(tbl, alu_ptr, tex); - } -} - -static void append_formula(struct RegTable* tbl, uint64_t **alu_ptr, uint8_t c[2][4], bool do_single, bool do_multiply, bool do_mix, bool only_alpha) { - if (do_single) { - add_mov(tbl, alu_ptr, c[only_alpha][3], only_alpha); - } else if (do_multiply) { - add_mul(tbl, alu_ptr, c[only_alpha][0], c[only_alpha][2], only_alpha); - } else if (do_mix) { - add_mix(tbl, alu_ptr, c[only_alpha][0], c[only_alpha][1], c[only_alpha][2], c[only_alpha][1], only_alpha); - } else { - add_mix(tbl, alu_ptr, c[only_alpha][0], c[only_alpha][1], c[only_alpha][2], c[only_alpha][3], only_alpha); - } -} - -static const uint64_t noise_instructions[] = { - /* R127 = floor(gl_FragCoord.xy * window_params.x) */ - ALU_MUL(__, _x, FRAG_COORD_REG, _x, _C(0), _x), - ALU_MUL(__, _y, FRAG_COORD_REG, _y, _C(0), _x) - ALU_LAST, - - ALU_FLOOR(_R127, _x, ALU_SRC_PV, _x), - ALU_FLOOR(_R127, _y, ALU_SRC_PV, _y) - ALU_LAST, - - /* R127 = sin(vec3(R127.x, R127.y, window_params.y)) */ - ALU_MULADD(_R127, _x, _R127, _x, ALU_SRC_LITERAL, _x, ALU_SRC_0_5, _x), - ALU_MULADD(_R127, _y, _R127, _y, ALU_SRC_LITERAL, _x, ALU_SRC_0_5, _x), - ALU_MULADD(_R127, _z, _C(0), _y, ALU_SRC_LITERAL, _x, ALU_SRC_0_5, _x) - ALU_LAST, - ALU_LITERAL(0x3E22F983 /* 0.1591549367f (radians -> revolutions) */), - - ALU_FRACT(__, _x, _R127, _x), - ALU_FRACT(__, _y, _R127, _y), - ALU_FRACT(__, _z, _R127, _z) - ALU_LAST, - - ALU_MULADD(_R127, _x, ALU_SRC_PV, _x, ALU_SRC_LITERAL, _x, ALU_SRC_LITERAL, _y), - ALU_MULADD(_R127, _y, ALU_SRC_PV, _y, ALU_SRC_LITERAL, _x, ALU_SRC_LITERAL, _y), - ALU_MULADD(_R127, _z, ALU_SRC_PV, _z, ALU_SRC_LITERAL, _x, ALU_SRC_LITERAL, _y) - ALU_LAST, - ALU_LITERAL2(0x40C90FDB /* 6.283185482f (tau) */, 0xC0490FDB /* -3.141592741f (-pi) */), - - ALU_MUL(_R127, _x, ALU_SRC_PV, _x, ALU_SRC_LITERAL, _x), - ALU_MUL(_R127, _y, ALU_SRC_PV, _y, ALU_SRC_LITERAL, _x), - ALU_MUL(_R127, _z, ALU_SRC_PV, _z, ALU_SRC_LITERAL, _x) - ALU_LAST, - ALU_LITERAL(0x3E22F983 /* 0.1591549367f (radians -> revolutions) */), - - ALU_SIN(_R127, _x, _R127, _x) SCL_210 - ALU_LAST, - - ALU_SIN(_R127, _y, _R127, _y) SCL_210 - ALU_LAST, - - ALU_SIN(_R127, _z, _R127, _z) SCL_210 - ALU_LAST, - - /* R127.x = dot(R127.xyz, vec3(12.9898, 78.233, 37.719)); */ - ALU_DOT4(_R127, _x, _R127, _x, ALU_SRC_LITERAL, _x), - ALU_DOT4(__, _y, _R127, _y, ALU_SRC_LITERAL, _y), - ALU_DOT4(__, _z, _R127, _z, ALU_SRC_LITERAL, _z), - ALU_DOT4(__, _w, ALU_SRC_LITERAL, _w, ALU_SRC_0, _x) - ALU_LAST, - ALU_LITERAL4(0x414FD639 /* 12.9898f */, 0x429C774C /* 78.233f */, 0x4216E042 /* 37.719f */, 0x80000000 /* -0.0f */), - - /* R127.x = fract(sin(R127.x) * 143758.5453); */ - ALU_MULADD(_R127, _x, _R127, _x, ALU_SRC_LITERAL, _x, ALU_SRC_0_5, _x) - ALU_LAST, - ALU_LITERAL(0x3E22F983 /* 0.1591549367f (radians -> revolutions) */), - - ALU_FRACT(__, _x, _R127, _x) - ALU_LAST, - - ALU_MULADD(_R127, _x, ALU_SRC_PV, _x, ALU_SRC_LITERAL, _x, ALU_SRC_LITERAL, _y) - ALU_LAST, - ALU_LITERAL2(0x40C90FDB /* 6.283185482f (tau) */, 0xC0490FDB /* -3.141592741f (-pi) */), - - ALU_SIN(_R127, _x, _R127, _x) SCL_210 - ALU_LAST, - - ALU_MUL(__, _x, _R127, _x, ALU_SRC_LITERAL, _x) - ALU_LAST, - ALU_LITERAL(0x480C63A3 /* 143758.5453f */), - - ALU_FRACT(__, _x, ALU_SRC_PV, _x) - ALU_LAST, - - /* (PV + 1.0) / 2.0 */ - ALU_ADD(__, _x, ALU_SRC_PV, _x, ALU_SRC_1, _x) - ALU_LAST, - - /* place noise data into xyzw */ - ALU_MUL(FRAG_COORD_REG, _x, ALU_SRC_PV, _x, ALU_SRC_0_5, _x), - ALU_MUL(FRAG_COORD_REG, _y, ALU_SRC_PV, _x, ALU_SRC_0_5, _x), - ALU_MUL(FRAG_COORD_REG, _z, ALU_SRC_PV, _x, ALU_SRC_0_5, _x), - ALU_MUL(FRAG_COORD_REG, _w, ALU_SRC_PV, _x, ALU_SRC_0_5, _x) - ALU_LAST, -}; - -static GX2UniformVar uniformVars[] = { - { "window_params", GX2_SHADER_VAR_TYPE_FLOAT2, 1, 0, -1, }, -}; - -static GX2SamplerVar samplerVars[] = { - { "uTex0", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_TEXTURE + 0 }, - { "uTex1", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_TEXTURE + 1 }, - { "uTexMask0", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_MASK_TEXTURE + 0 }, - { "uTexMask1", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_MASK_TEXTURE + 1 }, - { "uTexBlend0", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_REPLACEMENT_TEXTURE + 0 }, - { "uTexBlend1", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, SHADER_FIRST_REPLACEMENT_TEXTURE + 1 }, -}; - -#define ADD_INSTR(...) \ - do { \ - uint64_t tmp[] = {__VA_ARGS__}; \ - memcpy(cur_buf, tmp, sizeof(tmp)); \ - cur_buf += sizeof(tmp) / sizeof(uint64_t); \ - } while (0) - -static int generatePixelShader(GX2PixelShader *psh, struct CCFeatures *cc_features) { - static const size_t max_program_buf_size = 512 * sizeof(uint64_t); - uint64_t *program_buf = memalign(GX2_SHADER_PROGRAM_ALIGNMENT, max_program_buf_size); - if (!program_buf) { - return -1; - } - - memset(program_buf, 0, max_program_buf_size); - - // start placing alus at offset 32 - static const uint32_t base_alu_offset = 32; - uint64_t *cur_buf = NULL; - - // check if we need to clamp - bool texclamp[2] = { false, false }; - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i]) { - if (cc_features->clamp[i][0] || cc_features->clamp[i][1]) { - texclamp[i] = true; - } - } - } - - // check if we should prepare randomness for noise - bool needs_noise = cc_features->opt_alpha && cc_features->opt_noise; - if (!needs_noise) { - for (int i = 0; i < (cc_features->opt_2cyc ? 2 : 1); i++) { - for (int j = 0; j < (cc_features->opt_alpha ? 2 : 1); j++) { - for (int k = 0; k < 4; k++) { - if (cc_features->c[i][j][k] == SHADER_NOISE) { - needs_noise = true; - break; - } - } - } - } - } - - // build the reg table - struct RegTable reg_table; - reg_table_build(®_table, cc_features, needs_noise); - - uint32_t texclamp_alu_offset = base_alu_offset; - uint32_t texclamp_alu_size = 0; - uint32_t texclamp_alu_cnt = 0; - - if (texclamp[0] || texclamp[1]) { - // texclamp alu - cur_buf = program_buf + texclamp_alu_offset; - - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i] && texclamp[i]) { - append_tex_clamp(®_table, &cur_buf, i, cc_features->clamp[i][0], cc_features->clamp[i][1]); - } - } - - texclamp_alu_size = (uintptr_t) cur_buf - ((uintptr_t) (program_buf + texclamp_alu_offset)); - texclamp_alu_cnt = texclamp_alu_size / sizeof(uint64_t); - } - - // main alu0 - uint32_t main_alu0_offset = texclamp_alu_offset + texclamp_alu_cnt; - cur_buf = program_buf + main_alu0_offset; - - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i] && cc_features->used_masks[i]) { - uint8_t dst_reg = get_reg(®_table, (i == 0) ? SHADER_TEXEL0 : SHADER_TEXEL1); - uint8_t mask_reg = get_reg(®_table, (i == 0) ? SHADER_MASKTEX0 : SHADER_MASKTEX1); - uint8_t blend_reg; - if (cc_features->used_blend[i]) { - blend_reg = get_reg(®_table, (i == 0) ? SHADER_BLENDTEX0 : SHADER_BLENDTEX1); - } else { - blend_reg = ALU_SRC_0; - } - - /* texVal%d = mix(texVal%d, blendVal%d, maskVal%d.a) */ - ADD_INSTR( - ALU_ADD(__, _x, blend_reg, _x, dst_reg _NEG, _x), - ALU_ADD(__, _y, blend_reg, _y, dst_reg _NEG, _y), - ALU_ADD(__, _z, blend_reg, _z, dst_reg _NEG, _z), - ALU_ADD(__, _w, blend_reg, _w, dst_reg _NEG, _w) - ALU_LAST, - - ALU_MULADD(dst_reg, _x, ALU_SRC_PV, _x, mask_reg, _w, dst_reg, _x), - ALU_MULADD(dst_reg, _y, ALU_SRC_PV, _y, mask_reg, _w, dst_reg, _y), - ALU_MULADD(dst_reg, _z, ALU_SRC_PV, _z, mask_reg, _w, dst_reg, _z), - ALU_MULADD(dst_reg, _w, ALU_SRC_PV, _w, mask_reg, _w, dst_reg, _w) - ALU_LAST, - ); - } - } - - // do noise calculation for SHADER_NOISE if necessary - if (needs_noise) { - memcpy(cur_buf, noise_instructions, sizeof(noise_instructions)); - cur_buf += sizeof(noise_instructions) / sizeof(uint64_t); - } - - for (int c = 0; c < (cc_features->opt_2cyc ? 2 : 1); c++) { - append_formula(®_table, &cur_buf, cc_features->c[c], cc_features->do_single[c][0], cc_features->do_multiply[c][0], cc_features->do_mix[c][0], false); - if (cc_features->opt_alpha) { - append_formula(®_table, &cur_buf, cc_features->c[c], cc_features->do_single[c][1], cc_features->do_multiply[c][1], cc_features->do_mix[c][1], true); - } - } - - if (cc_features->opt_fog) { - ADD_INSTR( - /* texel.rgb = mix(texel.rgb, vFog.rgb, vFog.a); */ - ALU_ADD(__, _x, FOG_REG, _x, _R1 _NEG, _x), - ALU_ADD(__, _y, FOG_REG, _y, _R1 _NEG, _y), - ALU_ADD(__, _z, FOG_REG, _z, _R1 _NEG, _z) - ALU_LAST, - - ALU_MULADD(TEXEL_REG, _x, ALU_SRC_PV, _x, FOG_REG, _w, TEXEL_REG, _x), - ALU_MULADD(TEXEL_REG, _y, ALU_SRC_PV, _y, FOG_REG, _w, TEXEL_REG, _y), - ALU_MULADD(TEXEL_REG, _z, ALU_SRC_PV, _z, FOG_REG, _w, TEXEL_REG, _z) - ALU_LAST, - ); - } - - if (cc_features->opt_texture_edge && cc_features->opt_alpha) { - ADD_INSTR( - /* if (texel.a > 0.19) texel.a = 1.0; else discard; */ - ALU_KILLGT(__, _x, ALU_SRC_LITERAL, _x, TEXEL_REG, _w), - ALU_MOV(TEXEL_REG, _w, ALU_SRC_1, _x) - ALU_LAST, - ALU_LITERAL(0x3e428f5c /*0.19f*/), - ); - } - - const uint32_t main_alu0_size = (uintptr_t) cur_buf - ((uintptr_t) (program_buf + main_alu0_offset)); - const uint32_t main_alu0_cnt = main_alu0_size / sizeof(uint64_t); - - // main alu1 - // place the following instructions into a new alu, in case the other alu uses KILL - const uint32_t main_alu1_offset = main_alu0_offset + main_alu0_cnt; - cur_buf = program_buf + main_alu1_offset; - - if (cc_features->opt_alpha && cc_features->opt_noise) { - ADD_INSTR( - /* we need to undo the stuff we did for SHADER_NOISE first */ - ALU_MUL(__, _x, FRAG_COORD_REG, _x, ALU_SRC_LITERAL, _x) - ALU_LAST, - ALU_LITERAL(0x40000000 /*2.0f*/), - - ALU_ADD(__, _x, ALU_SRC_PV, _x, ALU_SRC_1 _NEG, _x) - ALU_LAST, - - /* texel.a *= floor(clamp(random() + texel.a, 0.0, 1.0)); */ - ALU_ADD(__, _x, ALU_SRC_PV, _x, TEXEL_REG, _w) - ALU_LAST, - - ALU_MAX(__, _x, ALU_SRC_PV, _x, ALU_SRC_0, _x) - ALU_LAST, - - ALU_MIN(__, _x, ALU_SRC_PV, _x, ALU_SRC_1, _x) - ALU_LAST, - - ALU_FLOOR(__, _x, ALU_SRC_PV, _x) - ALU_LAST, - - ALU_MUL(TEXEL_REG, _w, TEXEL_REG, _w, ALU_SRC_PV, _x) - ALU_LAST, - ); - } - - if (cc_features->opt_grayscale) { - ADD_INSTR( - /* texel.r + texel.g + texel.b */ - ALU_ADD(__, _x, TEXEL_REG, _x, TEXEL_REG, _y) - ALU_LAST, - - ALU_ADD(__, _x, ALU_SRC_PV, _x, TEXEL_REG, _z) - ALU_LAST, - - /* PV.x / 3 */ - ALU_MUL_IEEE(__, _x, ALU_SRC_PV, _x, ALU_SRC_LITERAL, _x) - ALU_LAST, - ALU_LITERAL(0x3eaaaaab /*0.3333333433f*/), - - /* texel.rgb = mix(texel.rgb, vGrayscaleColor.rgb * intensity, vGrayscaleColor.a); */ - ALU_MULADD(_R127, _x, GRAYSCALE_REG, _x, ALU_SRC_PV, _x, _R1 _NEG, _x), - ALU_MULADD(_R127, _y, GRAYSCALE_REG, _y, ALU_SRC_PV, _x, _R1 _NEG, _y), - ALU_MULADD(_R127, _z, GRAYSCALE_REG, _z, ALU_SRC_PV, _x, _R1 _NEG, _z) - ALU_LAST, - - ALU_MULADD(TEXEL_REG, _x, ALU_SRC_PV, _x, GRAYSCALE_REG, _w, TEXEL_REG, _x), - ALU_MULADD(TEXEL_REG, _y, ALU_SRC_PV, _y, GRAYSCALE_REG, _w, TEXEL_REG, _y), - ALU_MULADD(TEXEL_REG, _z, ALU_SRC_PV, _z, GRAYSCALE_REG, _w, TEXEL_REG, _z) - ALU_LAST, - ); - } - - if (cc_features->opt_alpha) { - if (cc_features->opt_alpha_threshold) { - ADD_INSTR( - /* if (texel.a < 8.0 / 256.0) discard; */ - ALU_KILLGT(__, _x, ALU_SRC_LITERAL, _x, TEXEL_REG, _w) - ALU_LAST, - ALU_LITERAL(0x3d000000 /*0.03125f*/), - ); - } - - if (cc_features->opt_invisible) { - ADD_INSTR( - /* texel.a = 0.0; */ - ALU_MOV(TEXEL_REG, _w, ALU_SRC_0, _x) - ALU_LAST, - ); - } - } - - const uint32_t main_alu1_size = (uintptr_t) cur_buf - ((uintptr_t) (program_buf + main_alu1_offset)); - const uint32_t main_alu1_cnt = main_alu1_size / sizeof(uint64_t); - - // tex - uint32_t num_textures = 0; - uint32_t num_texinfo = texclamp[0] + texclamp[1]; - - uint32_t texinfo_offset = ROUNDUP(main_alu1_offset + main_alu1_cnt, 16); - uint32_t cur_tex_offset = texinfo_offset; - - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i]) { - if (texclamp[i]) { - uint8_t dst_reg = get_reg(®_table, (i == 0) ? SHADER_TEXINFO0 : SHADER_TEXINFO1); - int32_t loc = SHADER_FIRST_TEXTURE + i; - - uint64_t texinfo_buf[] = { - TEX_GET_TEXTURE_INFO(dst_reg, _x, _y, _m, _m, _R1, _0, _0, _0, _0, _t(loc), _s(loc)) - }; - - memcpy(program_buf + cur_tex_offset, texinfo_buf, sizeof(texinfo_buf)); - cur_tex_offset += sizeof(texinfo_buf) / sizeof(uint64_t); - } - } - } - - uint32_t texsample_offset = cur_tex_offset; - - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i]) { - uint8_t texcoord_reg = (i == 0) ? _R1 : _R2; - - // we need to sample these first or we override texcoords - if (cc_features->used_masks[i]) { - uint8_t dst_reg = get_reg(®_table, (i == 0) ? SHADER_MASKTEX0 : SHADER_MASKTEX1); - int32_t loc = SHADER_FIRST_MASK_TEXTURE + i; - - uint64_t tex_buf[] = { - TEX_SAMPLE(dst_reg, _x, _y, _z, _w, texcoord_reg, _x, _y, _0, _x, _t(loc), _s(loc)) - }; - - memcpy(program_buf + cur_tex_offset, tex_buf, sizeof(tex_buf)); - cur_tex_offset += sizeof(tex_buf) / sizeof(uint64_t); - - num_textures++; - } - - if (cc_features->used_blend[i]) { - uint8_t dst_reg = get_reg(®_table, (i == 0) ? SHADER_BLENDTEX0 : SHADER_BLENDTEX1); - int32_t loc = SHADER_FIRST_REPLACEMENT_TEXTURE + i; - - uint64_t tex_buf[] = { - TEX_SAMPLE(dst_reg, _x, _y, _z, _w, texcoord_reg, _x, _y, _0, _x, _t(loc), _s(loc)) - }; - - memcpy(program_buf + cur_tex_offset, tex_buf, sizeof(tex_buf)); - cur_tex_offset += sizeof(tex_buf) / sizeof(uint64_t); - - num_textures++; - } - - uint8_t dst_reg = get_reg(®_table, (i == 0) ? SHADER_TEXEL0 : SHADER_TEXEL1); - int32_t loc = SHADER_FIRST_TEXTURE + i; - - uint64_t tex_buf[] = { - TEX_SAMPLE(dst_reg, _x, _y, _z, _w, texcoord_reg, _x, _y, _0, _x, _t(loc), _s(loc)) - }; - - memcpy(program_buf + cur_tex_offset, tex_buf, sizeof(tex_buf)); - cur_tex_offset += sizeof(tex_buf) / sizeof(uint64_t); - - num_textures++; - } - } - - // make sure we didn't overflow the buffer - const uint32_t total_program_size = cur_tex_offset * sizeof(uint64_t); - assert(total_program_size <= max_program_buf_size); - - // cf - uint32_t cur_cf_offset = 0; - - // if we use texclamp place those alus first - if (texclamp[0] || texclamp[1]) { - program_buf[cur_cf_offset++] = TEX(texinfo_offset, num_texinfo); - program_buf[cur_cf_offset++] = ALU(texclamp_alu_offset, texclamp_alu_cnt); - } - - if (num_textures > 0) { - program_buf[cur_cf_offset++] = TEX(texsample_offset, num_textures) VALID_PIX; - } - - program_buf[cur_cf_offset++] = ALU(main_alu0_offset, main_alu0_cnt); - - if (main_alu1_cnt > 0) { - program_buf[cur_cf_offset++] = ALU(main_alu1_offset, main_alu1_cnt); - } - - if (cc_features->opt_alpha) { - program_buf[cur_cf_offset++] = EXP_DONE(PIX0, TEXEL_REG, _x, _y, _z, _w) END_OF_PROGRAM; - } else { - program_buf[cur_cf_offset++] = EXP_DONE(PIX0, TEXEL_REG, _x, _y, _z, _1) END_OF_PROGRAM; - } - - // regs - const uint32_t num_ps_inputs = 4 + cc_features->num_inputs; - - psh->regs.sq_pgm_resources_ps = reg_table.used; // num_gprs - psh->regs.sq_pgm_exports_ps = 2; // export_mode - psh->regs.spi_ps_in_control_0 = (num_ps_inputs + 1) // num_interp - | (1 << 26) // persp_gradient_ena - | (1 << 28) // baryc_sample_cntl - | (1 << 8); // position_ena - - psh->regs.num_spi_ps_input_cntl = num_ps_inputs + 1; - - // frag pos - psh->regs.spi_ps_input_cntls[0] = 0 | (1 << 8); - - // inputs - for (uint32_t i = 0; i < num_ps_inputs; i++) { - psh->regs.spi_ps_input_cntls[i + 1] = i | (1 << 8); - } - - psh->regs.cb_shader_mask = 0xf; // output0_enable - psh->regs.cb_shader_control = 1; // rt0_enable - psh->regs.db_shader_control = (1 << 4) // z_order - | (1 << 6); // kill_enable - - // program - psh->size = total_program_size; - psh->program = program_buf; - - psh->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; - - // uniform vars - psh->uniformVars = uniformVars; - psh->uniformVarCount = sizeof(uniformVars) / sizeof(GX2UniformVar); - - // samplers - psh->samplerVars = samplerVars; - psh->samplerVarCount = sizeof(samplerVars) / sizeof(GX2SamplerVar); - - return 0; -} - -static GX2AttribVar attribVars[] = { - { "aVtxPos", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 0 }, - { "aTexCoord0", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 1 }, - { "aTexCoord1", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 2 }, - { "aFog", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 3 }, - { "aGrayscaleColor", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 4 }, - { "aInput1", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 5 }, - { "aInput2", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 6 }, - { "aInput3", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 7 }, - { "aInput4", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 8 }, - { "aInput5", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 9 }, - { "aInput6", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 10 }, - { "aInput7", GX2_SHADER_VAR_TYPE_FLOAT4, 0, 11 }, -}; - -static int generateVertexShader(GX2VertexShader *vsh, struct CCFeatures *cc_features) { - static const size_t max_program_buf_size = 16 * sizeof(uint64_t); - uint64_t *program_buf = memalign(GX2_SHADER_PROGRAM_ALIGNMENT, max_program_buf_size); - if (!program_buf) { - return -1; - } - - const uint32_t num_vs_inputs = 5 + cc_features->num_inputs; - const uint32_t num_ps_inputs = 4 + cc_features->num_inputs; - - uint64_t *cur_buf = program_buf; - - // aVtxPos - ADD_INSTR( - CALL_FS NO_BARRIER, - EXP_DONE(POS0, _R1, _x, _y, _z, _w), - ); - - // params - for (uint32_t i = 0; i < num_ps_inputs - 1; i++) { - ADD_INSTR( - EXP(PARAM(i), _R(i + 2), _x, _y, _z, _w) NO_BARRIER, - ); - } - - // last param - ADD_INSTR( - (EXP_DONE(PARAM(num_ps_inputs - 1), _R(num_ps_inputs + 1), _x, _y, _z, _w) NO_BARRIER) - END_OF_PROGRAM, - ); - - const uint32_t program_size = (uintptr_t) cur_buf - ((uintptr_t) program_buf); - assert(program_size <= max_program_buf_size); - - // regs - vsh->regs.sq_pgm_resources_vs = (num_ps_inputs + 2) // num_gprs - | (1 << 8); // stack_size - - // num outputs minus 1 - vsh->regs.spi_vs_out_config = ((num_ps_inputs - 1) << 1); - - vsh->regs.num_spi_vs_out_id = (num_ps_inputs + 3) / 4; - memset(vsh->regs.spi_vs_out_id, 0xff, sizeof(vsh->regs.spi_vs_out_id)); - vsh->regs.spi_vs_out_id[0] = (0) | (1 << 8) | (2 << 16) | (3 << 24); - vsh->regs.spi_vs_out_id[1] = (4) | (5 << 8) | (6 << 16) | (7 << 24); - vsh->regs.spi_vs_out_id[2] = (8) | (9 << 8) | (10 << 16) | (11 << 24); - - vsh->regs.sq_vtx_semantic_clear = ~((1 << num_vs_inputs) - 1); - vsh->regs.num_sq_vtx_semantic = num_vs_inputs; - memset(vsh->regs.sq_vtx_semantic, 0xff, sizeof(vsh->regs.sq_vtx_semantic)); - // aVtxPos - vsh->regs.sq_vtx_semantic[0] = 0; - // aTexCoord0 - vsh->regs.sq_vtx_semantic[1] = 1; - // aTexCoord1 - vsh->regs.sq_vtx_semantic[2] = 2; - // aFog - vsh->regs.sq_vtx_semantic[3] = 3; - // aGrayscaleColor - vsh->regs.sq_vtx_semantic[4] = 4; - // aInput 1 - 7 - for (int i = 0; i < cc_features->num_inputs; i++) { - vsh->regs.sq_vtx_semantic[5 + i] = 5 + i; - } - - vsh->regs.vgt_vertex_reuse_block_cntl = 14; // vtx_reuse_depth - vsh->regs.vgt_hos_reuse_depth = 16; // reuse_depth - - // program - vsh->program = program_buf; - vsh->size = program_size; - - vsh->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; - - // attribs - vsh->attribVarCount = num_vs_inputs; - vsh->attribVars = attribVars; - - return 0; -} -#undef ADD_INSTR - -int gx2GenerateShaderGroup(struct ShaderGroup *group, struct CCFeatures *cc_features) { - memset(group, 0, sizeof(struct ShaderGroup)); - - // generate the pixel shader - if (generatePixelShader(&group->pixelShader, cc_features) != 0) { - gx2FreeShaderGroup(group); - return -1; - } - - // generate the vertex shader - if (generateVertexShader(&group->vertexShader, cc_features) != 0) { - gx2FreeShaderGroup(group); - return -1; - } - - uint32_t attribOffset = 0; - - // aVtxPos - group->attributes[group->numAttributes++] = - (GX2AttribStream) { 0, 0, attribOffset, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32, GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_x, _y, _z, _w), GX2_ENDIAN_SWAP_DEFAULT }; - attribOffset += 4 * sizeof(float); - - for (int i = 0; i < 2; i++) { - if (cc_features->used_textures[i]) { - // aTexCoordX - group->attributes[group->numAttributes++] = - (GX2AttribStream) { 1 + i, 0, attribOffset, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32, GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_x, _y, _z, _w), GX2_ENDIAN_SWAP_DEFAULT }; - attribOffset += 4 * sizeof(float); - } - } - - // aFog - if (cc_features->opt_fog) { - group->attributes[group->numAttributes++] = - (GX2AttribStream) { 3, 0, attribOffset, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32, GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_x, _y, _z, _w), GX2_ENDIAN_SWAP_DEFAULT }; - attribOffset += 4 * sizeof(float); - } - - // aGrayscaleColor - if (cc_features->opt_grayscale) { - group->attributes[group->numAttributes++] = - (GX2AttribStream) { 4, 0, attribOffset, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32, GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_x, _y, _z, _w), GX2_ENDIAN_SWAP_DEFAULT }; - attribOffset += 4 * sizeof(float); - } - - // aInput - for (int i = 0; i < cc_features->num_inputs; i++) { - group->attributes[group->numAttributes++] = - (GX2AttribStream) { 5 + i, 0, attribOffset, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32, GX2_ATTRIB_INDEX_PER_VERTEX, 0, GX2_COMP_SEL(_x, _y, _z, _w), GX2_ENDIAN_SWAP_DEFAULT }; - attribOffset += 4 * sizeof(float); - } - - group->stride = attribOffset; - - // init the fetch shader - group->fetchShader.size = GX2CalcFetchShaderSizeEx(group->numAttributes, GX2_FETCH_SHADER_TESSELLATION_NONE, GX2_TESSELLATION_MODE_DISCRETE); - group->fetchShader.program = memalign(GX2_SHADER_PROGRAM_ALIGNMENT, group->fetchShader.size); - if (!group->fetchShader.program) { - gx2FreeShaderGroup(group); - return -1; - } - - GX2InitFetchShaderEx(&group->fetchShader, group->fetchShader.program, group->numAttributes, group->attributes, GX2_FETCH_SHADER_TESSELLATION_NONE, GX2_TESSELLATION_MODE_DISCRETE); - - // invalidate all programs - GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, group->vertexShader.program, group->vertexShader.size); - GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, group->pixelShader.program, group->pixelShader.size); - GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, group->fetchShader.program, group->fetchShader.size); - - return 0; -} - -void gx2FreeShaderGroup(struct ShaderGroup *group) { - free(group->vertexShader.program); - free(group->pixelShader.program); - free(group->fetchShader.program); -} - -#endif diff --git a/src/graphic/Fast3D/gx2_shader_gen.h b/src/graphic/Fast3D/gx2_shader_gen.h deleted file mode 100644 index 47575cac2..000000000 --- a/src/graphic/Fast3D/gx2_shader_gen.h +++ /dev/null @@ -1,31 +0,0 @@ -/* gx2_shader_gen.h - Fast3D GX2 shader generator for libultraship - - Created in 2022 by GaryOderNichts -*/ -#pragma once - -#include "gfx_cc.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ShaderGroup { - GX2VertexShader vertexShader; - GX2PixelShader pixelShader; - GX2FetchShader fetchShader; - - uint32_t stride; - - uint32_t numAttributes; - GX2AttribStream attributes[13]; -}; - -int gx2GenerateShaderGroup(struct ShaderGroup* group, struct CCFeatures* cc_features); - -void gx2FreeShaderGroup(struct ShaderGroup* group); - -#ifdef __cplusplus -} -#endif diff --git a/src/graphic/Fast3D/gx2_shader_inl.h b/src/graphic/Fast3D/gx2_shader_inl.h deleted file mode 100644 index 91f63cbe1..000000000 --- a/src/graphic/Fast3D/gx2_shader_inl.h +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright (C) 2014-2016 - Ali Bouhlel - * Copyright (C) 2022 - GaryOderNichts - * - * Licensed as MIT. - */ - -#ifndef GX2_SHADER_INL_H -#define GX2_SHADER_INL_H - -#define to_QWORD(w0, w1) (((uint64_t)(w0) << 32ull) | (w1)) -#define to_LE(x) (__builtin_bswap32(x)) - -/* CF */ -#define CF_DWORD0(addr) to_LE(addr) - -#define CF_DWORD1(popCount, cfConst, cond, count, callCount, inst) \ - to_LE(popCount | (cfConst << 3) | (cond << 8) | (count << 10) | (callCount << 13) | (inst << 23) | (1 << 31)) - -#define CF_ALU_WORD0(addr, kcacheBank0, kcacheBank1, kcacheMode0) \ - to_LE(addr | (kcacheBank0 << 22) | (kcacheBank1 << 26) | (kcacheMode0 << 30)) -#define CF_ALU_WORD1(kcacheMode1, kcacheAddr0, kcacheAddr1, count, altConst, inst) \ - to_LE(kcacheMode1 | (kcacheAddr0 << 2) | (kcacheAddr1 << 10) | (count << 18) | (altConst << 25) | (inst << 26) | \ - (1 << 31)) - -#define CF_EXP_WORD0(dstReg_and_type, srcReg, srcRel, indexGpr, elemSize) \ - to_LE(dstReg_and_type | (srcReg << 15) | (srcRel << 22) | (indexGpr << 23) | (elemSize << 30)) - -#define CF_EXP_WORD1(srcSelX, srcSelY, srcSelZ, srcSelW, validPixelMode, inst) \ - to_LE(srcSelX | (srcSelY << 3) | (srcSelZ << 6) | (srcSelW << 9) | (validPixelMode << 22) | (inst << 23) | \ - (1 << 31)) - -#define CF_ALLOC_EXPORT_WORD0(arrayBase, type, dstReg, dstRel, indexGpr, elemSize) \ - to_LE(arrayBase | (type << 13) | (dstReg << 15) | (dstRel << 22) | (indexGpr << 23) | (elemSize << 30)) - -#define CF_ALLOC_EXPORT_WORD1_BUF(arraySize, writeMask, inst) \ - to_LE(arraySize | (writeMask << 12) | (inst << 23) | (1 << 31)) - -#define ALU_SRC_KCACHE0_BASE 0x80 -#define ALU_SRC_KCACHE1_BASE 0xA0 -#define CF_KCACHE_BANK_LOCK_1 0x1 -#define CB1 0x1 -#define CB2 0x2 -#define _0_15 CF_KCACHE_BANK_LOCK_1 - -#define KC0(x) (x + ALU_SRC_KCACHE0_BASE) -#define KC1(x) (x + ALU_SRC_KCACHE1_BASE) - -#define NO_BARRIER &(~to_QWORD(0, to_LE(1 << 31))) -#define END_OF_PROGRAM | to_QWORD(0, to_LE(1 << 21)) -#define VALID_PIX | to_QWORD(0, to_LE(1 << 22)) -#define WHOLE_QUAD_MODE | to_QWORD(0, to_LE(1 << 30)) -#define BURSTCNT(x) | to_QWORD(0, to_LE(x << 17)) -#define WRITE(x) (x >> 2) -#define ARRAY_SIZE(x) x -#define ELEM_SIZE(x) x -#define KCACHE0(bank, mode) | to_QWORD(CF_ALU_WORD0(0, bank, 0, mode), 0) -#define KCACHE1(bank, mode) | to_QWORD(CF_ALU_WORD0(0, 0, bank, 0), CF_ALU_WORD1(mode, 0, 0, 0, 0, 0)) - -#define DEACTIVATE 1 -#define UPDATE_EXEC_MASK(mode) | to_QWORD(0, to_LE(mode << 2)) -#define UPDATE_PRED | to_QWORD(0, to_LE(1ull << 3)) -#define CLAMP | to_QWORD(0, to_LE(1ull << 31)) -#define ALU_LAST | to_QWORD(to_LE(1ull << 31), 0) - -/* ALU */ - -#define ALU_WORD0(src0Sel, src0Rel, src0Chan, src0Neg, src1Sel, src1Rel, src1Chan, src1Neg, indexMode, predSel) \ - to_LE(src0Sel | ((src0Rel) << 9) | ((src0Chan) << 10) | ((src0Neg) << 12) | ((src1Sel) << 13) | \ - ((src1Rel) << 22) | ((src1Chan) << 23) | ((src1Neg) << 25) | ((indexMode) << 26) | ((predSel) << 29)) - -#define ALU_WORD1_OP2(src0Abs, src1Abs, updateExecuteMask, updatePred, writeMask, omod, inst, encoding, bankSwizzle, \ - dstGpr, dstRel, dstChan, clamp) \ - to_LE(src0Abs | (src1Abs << 1) | (updateExecuteMask << 2) | (updatePred << 3) | (writeMask << 4) | (omod << 5) | \ - (inst << 7) | (encoding << 15) | (bankSwizzle << 18) | ((dstGpr & 0x7F) << 21) | (dstRel << 28) | \ - ((dstChan & 0x3) << 29) | (clamp << 31)) - -#define ALU_WORD1_OP3(src2Sel, src2Rel, src2Chan, src2Neg, inst, bankSwizzle, dstGpr, dstRel, dstChan, clamp) \ - to_LE(src2Sel | (src2Rel << 9) | (src2Chan << 10) | (src2Neg << 12) | (inst << 13) | (bankSwizzle << 18) | \ - ((dstGpr & 0x7F) << 21) | (dstRel << 28) | ((dstChan & 0x3) << 29) | (clamp << 31)) - -/* TEX */ -#define TEX_WORD0(inst, bcFracMode, fetchWholeQuad, resourceID, srcReg, srcRel, altConst) \ - to_LE(inst | (bcFracMode << 5) | (fetchWholeQuad << 7) | (resourceID << 8) | (srcReg << 16) | (srcRel << 23) | \ - (altConst << 24)) - -#define TEX_WORD1(dstReg, dstRel, dstSelX, dstSelY, dstSelZ, dstSelW, lodBias, coordTypeX, coordTypeY, coordTypeZ, \ - coordTypeW) \ - to_LE(dstReg | (dstRel << 7) | (dstSelX << 9) | (dstSelY << 12) | (dstSelZ << 15) | (dstSelW << 18) | \ - (lodBias << 21) | (coordTypeX << 28) | (coordTypeY << 29) | (coordTypeZ << 30) | (coordTypeW << 31)) - -#define TEX_WORD2(offsetX, offsetY, offsetZ, samplerID, srcSelX, srcSelY, srcSelZ, srcSelW) \ - to_LE(offsetX | (offsetY << 5) | (offsetZ << 10) | (samplerID << 15) | (srcSelX << 20) | (srcSelY << 23) | \ - (srcSelZ << 26) | (srcSelW << 29)) - -#define VTX_WORD0(inst, type, buffer_id, srcReg, srcSelX, mega) \ - to_LE(inst | (type << 5) | (buffer_id << 8) | (srcReg << 16) | (srcSelX << 24) | (mega << 26)) - -#define VTX_WORD1(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW) \ - to_LE(dstReg | (dstSelX << 9) | (dstSelY << 12) | (dstSelZ << 15) | (dstSelW << 18) | (1 << 21)) - -#define VTX_WORD2(offset, ismega) to_LE(offset | (ismega << 19)) - -#define _x 0 -#define _y 1 -#define _z 2 -#define _w 3 -#define _0 4 -#define _1 5 -#define _m 7 /*mask*/ - -#define _xyzw 0b1111 -#define _xy__ 0b0011 - -#define GX2_COMP_SEL(c0, c1, c2, c3) (((c0) << 24) | ((c1) << 16) | ((c2) << 8) | (c3)) - -#define ALU_LITERAL(v) to_QWORD(to_LE(v), 0) -#define ALU_LITERAL2(v0, v1) to_QWORD(to_LE(v0), to_LE(v1)) -#define ALU_LITERAL3(v0, v1, v2) ALU_LITERAL2(v0, v1), ALU_LITERAL(v2) -#define ALU_LITERAL4(v0, v1, v2, v3) ALU_LITERAL2(v0, v1), ALU_LITERAL2(v2, v3) -#define ALU_LITERAL5(v0, v1, v2, v3, v5) ALU_LITERAL4(v0, v1, v2, v3), ALU_LITERAL(v4) - -/* SRCx_SEL special constants */ -#define ALU_SRC_1_DBL_L 0xF4 -#define ALU_SRC_1_DBL_M 0xF5 -#define ALU_SRC_0_5_DBL_L 0xF6 -#define ALU_SRC_0_5_DBL_M 0xF7 -#define ALU_SRC_0 0xF8 -#define ALU_SRC_1 0xF9 -#define ALU_SRC_1_INT 0xFA -#define ALU_SRC_M_1_INT 0xFB -#define ALU_SRC_0_5 0xFC -#define ALU_SRC_LITERAL 0xFD -#define ALU_SRC_PV 0xFE -#define ALU_SRC_PS 0xFF - -#define _NEG | (1 << 12) -#define _ABS | (1 << 13) - -#define ALU_OMOD_OFF 0x0 -#define ALU_OMOD_M2 0x1 -#define ALU_OMOD_M4 0x2 -#define ALU_OMOD_D2 0x3 - -#define ALU_VEC_012 0x0 -#define ALU_VEC_021 0x1 -#define ALU_VEC_120 0x2 -#define ALU_VEC_102 0x3 -#define ALU_VEC_201 0x4 -#define ALU_VEC_210 0x5 -#define VEC_012 | to_QWORD(0, to_LE(ALU_VEC_012 << 18)) -#define VEC_021 | to_QWORD(0, to_LE(ALU_VEC_021 << 18)) -#define VEC_120 | to_QWORD(0, to_LE(ALU_VEC_120 << 18)) -#define VEC_102 | to_QWORD(0, to_LE(ALU_VEC_102 << 18)) -#define VEC_201 | to_QWORD(0, to_LE(ALU_VEC_201 << 18)) -#define VEC_210 | to_QWORD(0, to_LE(ALU_VEC_210 << 18)) - -#define VALID_PIX | to_QWORD(0, to_LE(1 << 22)) - -#define ALU_SCL_210 0x0 -#define ALU_SCL_122 0x1 -#define ALU_SCL_212 0x2 -#define ALU_SCL_221 0x3 - -#define SCL_210 | to_QWORD(0, to_LE(ALU_SCL_210 << 18)) -#define SCL_122 | to_QWORD(0, to_LE(ALU_SCL_122 << 18)) -#define SCL_212 | to_QWORD(0, to_LE(ALU_SCL_212 << 18)) -#define SCL_221 | to_QWORD(0, to_LE(ALU_SCL_221 << 18)) - -#define FETCH_TYPE(x) x -#define MINI(x) ((x)-1) -#define MEGA(x) (MINI(x) | 0x80000000) -#define OFFSET(x) x - -#define VERTEX_DATA 0 -#define INSTANCE_DATA 1 -#define NO_INDEX_OFFSET 2 - -/* CF defines */ -#define CF_COND_ACTIVE 0x0 -#define CF_COND_FALSE 0x1 -#define CF_COND_BOOL 0x2 -#define CF_COND_NOT_BOOL 0x3 - -/* TEX defines */ -#define TEX_UNNORMALIZED 0x0 -#define TEX_NORMALIZED 0x1 - -/* instructions */ -/* CF */ -#define CF_INST_TEX 0x01 -#define CF_INST_VTX 0x02 -#define CF_INST_LOOP_END 0x05 -#define CF_INST_LOOP_START_DX10 0x06 -#define CF_INST_JUMP 0x0A -#define CF_INST_ELSE 0x0D -#define CF_INST_POP 0x0E -#define CF_INST_CALL_FS 0x13 -#define CF_INST_EMIT_VERTEX 0x15 -#define CF_INST_MEM_RING 0x26 - -#define CF_INST_ALU 0x08 -#define CF_INST_ALU_PUSH_BEFORE 0x09 -#define CF_INST_ALU_POP_AFTER 0x0A -#define CF_INST_ALU_POP2_AFTER 0x0B -#define CF_INST_ALU_BREAK 0x0E -#define CF_INST_ALU_ELSE_AFTER 0x0F -/* ALU */ -#define OP2_INST_ADD 0x0 -#define OP2_INST_MUL 0x1 -#define OP2_INST_MUL_IEEE 0x2 -#define OP2_INST_MIN 0x04 -#define OP2_INST_MAX 0x03 -#define OP2_INST_MAX_DX10 0x05 -#define OP2_INST_FRACT 0x10 -#define OP2_INST_SETGT 0x09 -#define OP2_INST_SETE_DX10 0x0C -#define OP2_INST_SETGT_DX10 0x0D -#define OP2_INST_SETGE_DX10 0x0E -#define OP2_INST_FLOOR 0x14 -#define OP2_INST_MOVA_INT 0x18 -#define OP2_INST_MOV 0x19 -#define OP2_INST_NOP 0x1A -#define OP2_INST_PRED_SETGT 0x21 -#define OP2_INST_KILLGT 0x2D -#define OP2_INST_AND_INT 0x30 -#define OP2_INST_OR_INT 0x31 -#define OP2_INST_NOT_INT 0x33 -#define OP2_INST_ADD_INT 0x34 -#define OP2_INST_SETE_INT 0x3A -#define OP2_INST_SETGT_INT 0x3B -#define OP2_INST_SETGE_INT 0x3C -#define OP2_INST_SETNE_INT 0x3D -#define OP2_INST_PRED_SETE_INT 0x42 -#define OP2_INST_PRED_SETGT_INT 0x43 -#define OP2_INST_PRED_SETGE_INT 0x44 -#define OP2_INST_PRED_SETNE_INT 0x45 -#define OP2_INST_KILLE_INT 0x46 -#define OP2_INST_KILLGT_INT 0x47 -#define OP2_INST_KILLGE_INT 0x48 -#define OP2_INST_KILLNE_INT 0x49 -#define OP2_INST_DOT4 0x50 -#define OP2_INST_DOT4_IEEE 0x51 -#define OP2_INST_EXP_IEEE 0x61 -#define OP2_INST_LOG_CLAMPED 0x62 -#define OP2_INST_RECIP_IEEE 0x66 -#define OP2_INST_RECIPSQRT_IEEE 0x69 -#define OP2_INST_SQRT_IEEE 0x6A -#define OP2_INST_FLT_TO_INT 0x6B -#define OP2_INST_INT_TO_FLT 0x6C -#define OP2_INST_SIN 0x6E -#define OP2_INST_COS 0x6F -#define OP2_INST_LSHR_INT 0x71 -#define OP2_INST_MULLO_INT 0x73 -#define OP2_INST_LSHL_INT 0x72 -#define OP2_INST_FLT_TO_UINT 0x79 - -#define OP3_INST_MULADD 0x10 -#define OP3_INST_MULADD_D2 0x13 -#define OP3_INST_CNDGT 0x19 -#define OP3_INST_CNDE_INT 0x1C -/* EXP */ -#define CF_INST_EXP 0x27 -#define CF_INST_EXP_DONE 0x28 - -/* TEX */ -#define TEX_INST_LD 0x3 -#define TEX_INST_GET_TEXTURE_INFO 0x4 -#define TEX_INST_GET_GRADIENTS_H 0x07 -#define TEX_INST_GET_GRADIENTS_V 0x08 -#define TEX_INST_SAMPLE 0x10 -/* VTX */ -#define VTX_INST_FETCH 0x0 - -/* EXPORT_TYPE */ -#define EXPORT_TYPE_PIXEL 0x0 -#define EXPORT_TYPE_POS 0x1 -#define EXPORT_TYPE_PARAM 0x2 - -#define EXPORT_ARRAY_BASE_POS(id) (0x3C + id) /* [0, 3] */ -#define EXPORT_ARRAY_BASE_PARAM(id) id /* [0, 31] */ -#define EXPORT_ARRAY_BASE_PIX(id) id - -/* exports */ -#define POS(id) EXPORT_ARRAY_BASE_POS(id) | (EXPORT_TYPE_POS << 13) -#define PARAM(id) EXPORT_ARRAY_BASE_PARAM(id) | (EXPORT_TYPE_PARAM << 13) -#define PIX(id) EXPORT_ARRAY_BASE_PIX(id) | (EXPORT_TYPE_PIXEL << 13) -#define POS0 POS(0) -#define PARAM0 PARAM(0) -#define PARAM1 PARAM(1) -#define PARAM2 PARAM(2) -#define PARAM3 PARAM(3) -#define PARAM4 PARAM(4) -#define PARAM5 PARAM(5) -#define PARAM6 PARAM(6) -#define PARAM7 PARAM(7) -#define PARAM8 PARAM(8) -#define PARAM9 PARAM(9) -#define PARAM10 PARAM(10) -#define PARAM11 PARAM(11) -#define PIX0 PIX(0) - -/* registers */ -#define __ (0x80) /* invalid regitser (write mask off) */ -#define _R(x) x -#define _R0 _R(0x0) -#define _R1 _R(0x1) -#define _R2 _R(0x2) -#define _R3 _R(0x3) -#define _R4 _R(0x4) -#define _R5 _R(0x5) -#define _R6 _R(0x6) -#define _R7 _R(0x7) -#define _R8 _R(0x8) -#define _R9 _R(0x9) -#define _R10 _R(0xA) -#define _R11 _R(0xB) -#define _R12 _R(0xC) -#define _R13 _R(0xD) -#define _R14 _R(0xE) -#define _R15 _R(0xF) -#define _R16 _R(0x10) -#define _R17 _R(0x11) -#define _R18 _R(0x12) -#define _R19 _R(0x13) -#define _R20 _R(0x14) -#define _R21 _R(0x15) -#define _R22 _R(0x16) -#define _R23 _R(0x17) -#define _R24 _R(0x18) -#define _R25 _R(0x19) -#define _R26 _R(0x1A) -#define _R27 _R(0x1B) -#define _R28 _R(0x1C) -#define _R29 _R(0x1D) -#define _R30 _R(0x1E) -#define _R31 _R(0x1F) - -#define _R120 _R(0x78) -#define _R121 _R(0x79) -#define _R122 _R(0x7A) -#define _R123 _R(0x7B) -#define _R124 _R(0x7C) -#define _R125 _R(0x7D) -#define _R126 _R(0x7E) -#define _R127 _R(0x7F) - -/* texture */ -#define _t(x) x -#define _t0 _t(0x0) -#define _t1 _t(0x1) - -/* sampler */ -#define _s(x) x -#define _s0 _s(0x0) -#define _s1 _s(0x1) - -#define _b(x) x - -/* const files */ -#define ALU_SRC_CONST_FILE_BASE 0x100 -#define _C(x) (ALU_SRC_CONST_FILE_BASE + (x)) - -#define CALL_FS to_QWORD(CF_DWORD0(0), CF_DWORD1(0, 0, 0, 0, 0, CF_INST_CALL_FS)) - -#define TEX(addr, cnt) to_QWORD(CF_DWORD0(addr), CF_DWORD1(0x0, 0x0, CF_COND_ACTIVE, (cnt - 1), 0x0, CF_INST_TEX)) -#define VTX(addr, cnt) to_QWORD(CF_DWORD0(addr), CF_DWORD1(0x0, 0x0, CF_COND_ACTIVE, (cnt - 1), 0x0, CF_INST_VTX)) -#define LOOP_END(addr) to_QWORD(CF_DWORD0(addr), CF_DWORD1(0x0, 0x0, CF_COND_ACTIVE, 0x0, 0x0, CF_INST_LOOP_END)) -#define LOOP_START_DX10(addr) \ - to_QWORD(CF_DWORD0(addr), CF_DWORD1(0x0, 0x0, CF_COND_ACTIVE, 0x0, 0x0, CF_INST_LOOP_START_DX10)) -#define JUMP(popCount, addr) to_QWORD(CF_DWORD0(addr), CF_DWORD1(popCount, 0x0, CF_COND_ACTIVE, 0x0, 0x0, CF_INST_JUMP)) -#define ELSE(popCount, addr) to_QWORD(CF_DWORD0(addr), CF_DWORD1(popCount, 0x0, CF_COND_ACTIVE, 0x0, 0x0, CF_INST_ELSE)) -#define POP(popCount, addr) to_QWORD(CF_DWORD0(addr), CF_DWORD1(popCount, 0x0, CF_COND_ACTIVE, 0x0, 0x0, CF_INST_POP)) - -#define ALU(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU)) -#define ALU_PUSH_BEFORE(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU_PUSH_BEFORE)) -#define ALU_POP_AFTER(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU_POP_AFTER)) -#define ALU_POP2_AFTER(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU_POP2_AFTER)) -#define ALU_BREAK(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU_BREAK)) -#define ALU_ELSE_AFTER(addr, cnt) \ - to_QWORD(CF_ALU_WORD0(addr, 0x0, 0x0, 0x0), CF_ALU_WORD1(0x0, 0x0, 0x0, (cnt - 1), 0x0, CF_INST_ALU_ELSE_AFTER)) - -#define EXP_DONE(dstReg_and_type, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW) \ - to_QWORD(CF_EXP_WORD0(dstReg_and_type, srcReg, 0x0, 0x0, 0x0), \ - CF_EXP_WORD1(srcSelX, srcSelY, srcSelZ, srcSelW, 0x0, CF_INST_EXP_DONE)) - -#define EXP(dstReg_and_type, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW) \ - to_QWORD(CF_EXP_WORD0(dstReg_and_type, srcReg, 0x0, 0x0, 0x0), \ - CF_EXP_WORD1(srcSelX, srcSelY, srcSelZ, srcSelW, 0x0, CF_INST_EXP)) - -#define MEM_RING(arrayBase, dstReg, writeMask, arraySize, elemSize) \ - to_QWORD(CF_ALLOC_EXPORT_WORD0(arrayBase, 0x00, dstReg, 0x00, 0x00, elemSize), \ - CF_ALLOC_EXPORT_WORD1_BUF(arraySize, writeMask, CF_INST_MEM_RING)) - -#define EMIT_VERTEX to_QWORD(0, CF_DWORD1(0, 0, 0, 0, 0, CF_INST_EMIT_VERTEX)) - -#define ALU_OP2(inst, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, omod) \ - to_QWORD(ALU_WORD0(((src0Sel) & ((1 << 13) - 1)), 0x0, src0Chan, 0x0, ((src1Sel) & ((1 << 13) - 1)), 0x0, \ - src1Chan, 0x0, 0x0, 0x0), \ - ALU_WORD1_OP2(((src0Sel) >> 13), ((src1Sel) >> 13), 0x0, 0x0, (((dstGpr & __) >> 7) ^ 0x1), omod, inst, \ - 0x0, 0x0, dstGpr, 0x0, dstChan, 0x0)) - -#define ALU_OP3(inst, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) \ - to_QWORD(ALU_WORD0(src0Sel, 0x0, src0Chan, 0x0, src1Sel, 0x0, src1Chan, 0x0, 0x0, 0x0), \ - ALU_WORD1_OP3(src2Sel, 0x0, src2Chan, 0x0, inst, 0x0, dstGpr, 0x0, dstChan, 0x0)) - -#define ALU_NOP(dstGpr, dstChan) \ - ALU_OP2(OP2_INST_NOP, dstGpr, dstChan, ALU_SRC_PV, dstChan, ALU_SRC_PV, dstChan, ALU_OMOD_OFF) - -#define ALU_ADD(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_ADD, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_ADD_x2(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_ADD, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_M2) - -#define ALU_ADD_D2(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_ADD, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_D2) - -#define ALU_MUL(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MUL_x2(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_M2) - -#define ALU_MUL_x4(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_M4) - -#define ALU_MUL_IEEE(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL_IEEE, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MUL_IEEE_x2(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL_IEEE, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_M2) - -#define ALU_MUL_IEEE_x4(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MUL_IEEE, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_M4) - -#define ALU_FRACT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_FRACT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_FLOOR(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_FLOOR, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_SQRT_IEEE(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_SQRT_IEEE, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_SQRT_IEEE_D2(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_SQRT_IEEE, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_D2) - -#define ALU_MOVA_INT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_MOVA_INT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_MOV(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_MOV, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_MOV_D2(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_MOV, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_D2) - -#define ALU_MOV_x2(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_MOV, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_M2) - -#define ALU_MOV_x4(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_MOV, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_M4) - -#define ALU_DOT4_IEEE(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_DOT4_IEEE, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_DOT4(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_DOT4, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_PRED_SETGT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_PRED_SETGT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_KILLGT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_KILLGT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETE_DX10(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETE_DX10, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETGT_DX10(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETGT_DX10, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETGE_DX10(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETGE_DX10, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETGT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETGT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_PRED_SETE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_PRED_SETE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_PRED_SETGT_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_PRED_SETGT_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_PRED_SETGE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_PRED_SETGE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_KILLGE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_KILLGE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETGT_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETGT_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETGE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETGE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_ADD_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_ADD_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_PRED_SETNE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_PRED_SETNE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MIN(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MIN, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MAX(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MAX, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MAX_DX10(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MAX_DX10, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_LSHR_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_LSHR_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_MULLO_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_MULLO_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_LSHL_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_LSHL_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_AND_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_AND_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_KILLE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_KILLE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_KILLGT_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_KILLGT_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_KILLNE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_KILLNE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_SETNE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_SETNE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_OR_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan) \ - ALU_OP2(OP2_INST_OR_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, ALU_OMOD_OFF) - -#define ALU_INT_TO_FLT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_INT_TO_FLT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_FLT_TO_UINT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_FLT_TO_UINT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_FLT_TO_INT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_FLT_TO_INT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_EXP_IEEE(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_EXP_IEEE, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_LOG_CLAMPED(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_LOG_CLAMPED, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_RECIP_IEEE(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_RECIP_IEEE, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_RECIPSQRT_IEEE(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_RECIPSQRT_IEEE, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_SIN(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_SIN, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_COS(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_COS, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_COS_D2(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_COS, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_D2) - -#define ALU_NOT_INT(dstGpr, dstChan, src0Sel, src0Chan) \ - ALU_OP2(OP2_INST_NOT_INT, dstGpr, dstChan, src0Sel, src0Chan, ALU_SRC_0, 0x0, ALU_OMOD_OFF) - -#define ALU_MULADD(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) \ - ALU_OP3(OP3_INST_MULADD, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) - -#define ALU_MULADD_D2(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) \ - ALU_OP3(OP3_INST_MULADD_D2, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) - -#define ALU_CNDGT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) \ - ALU_OP3(OP3_INST_CNDGT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) - -#define ALU_CNDE_INT(dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) \ - ALU_OP3(OP3_INST_CNDE_INT, dstGpr, dstChan, src0Sel, src0Chan, src1Sel, src1Chan, src2Sel, src2Chan) - -#define TEX_LD(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW, resourceID, \ - samplerID) \ - to_QWORD(TEX_WORD0(TEX_INST_LD, 0x0, 0x0, resourceID, srcReg, 0x0, 0x0), \ - TEX_WORD1(dstReg, 0x0, dstSelX, dstSelY, dstSelZ, dstSelW, 0x0, TEX_UNNORMALIZED, TEX_UNNORMALIZED, \ - TEX_UNNORMALIZED, TEX_UNNORMALIZED)), \ - to_QWORD(TEX_WORD2(0x0, 0x0, 0x0, samplerID, srcSelX, srcSelY, srcSelZ, srcSelW), 0x00000000) - -#define TEX_SAMPLE(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW, resourceID, \ - samplerID) \ - to_QWORD(TEX_WORD0(TEX_INST_SAMPLE, 0x0, 0x0, resourceID, srcReg, 0x0, 0x0), \ - TEX_WORD1(dstReg, 0x0, dstSelX, dstSelY, dstSelZ, dstSelW, 0x0, TEX_NORMALIZED, TEX_NORMALIZED, \ - TEX_NORMALIZED, TEX_NORMALIZED)), \ - to_QWORD(TEX_WORD2(0x0, 0x0, 0x0, samplerID, _x, _y, _0, _x), 0x00000000) - -#define TEX_GET_GRADIENTS_H(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW, \ - resourceID, samplerID) \ - to_QWORD(TEX_WORD0(TEX_INST_GET_GRADIENTS_H, 0x0, 0x0, resourceID, srcReg, 0x0, 0x0), \ - TEX_WORD1(dstReg, 0x0, dstSelX, dstSelY, dstSelZ, dstSelW, 0x0, TEX_NORMALIZED, TEX_NORMALIZED, \ - TEX_NORMALIZED, TEX_NORMALIZED)), \ - to_QWORD(TEX_WORD2(0x0, 0x0, 0x0, samplerID, _x, _y, _z, _x), 0x00000000) - -#define TEX_GET_GRADIENTS_V(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW, \ - resourceID, samplerID) \ - to_QWORD(TEX_WORD0(TEX_INST_GET_GRADIENTS_V, 0x0, 0x0, resourceID, srcReg, 0x0, 0x0), \ - TEX_WORD1(dstReg, 0x0, dstSelX, dstSelY, dstSelZ, dstSelW, 0x0, TEX_NORMALIZED, TEX_NORMALIZED, \ - TEX_NORMALIZED, TEX_NORMALIZED)), \ - to_QWORD(TEX_WORD2(0x0, 0x0, 0x0, samplerID, _x, _y, _z, _x), 0x00000000) - -#define TEX_GET_TEXTURE_INFO(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, srcSelY, srcSelZ, srcSelW, \ - resourceID, samplerID) \ - to_QWORD(TEX_WORD0(TEX_INST_GET_TEXTURE_INFO, 0x0, 0x0, resourceID, srcReg, 0x0, 0x0), \ - TEX_WORD1(dstReg, 0x0, dstSelX, dstSelY, dstSelZ, dstSelW, 0x0, TEX_NORMALIZED, TEX_NORMALIZED, \ - TEX_NORMALIZED, TEX_NORMALIZED)), \ - to_QWORD(TEX_WORD2(0x0, 0x0, 0x0, samplerID, srcSelX, srcSelY, srcSelZ, srcSelW), 0x00000000) - -#define VTX_FETCH(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW, srcReg, srcSelX, buffer_id, type, mega, offset) \ - to_QWORD(VTX_WORD0(VTX_INST_FETCH, type, buffer_id, srcReg, srcSelX, mega), \ - VTX_WORD1(dstReg, dstSelX, dstSelY, dstSelZ, dstSelW)), \ - to_QWORD(VTX_WORD2(offset, (mega >> 31)), 0x00000000) - -#define _x2(v) v, v -#define _x4(v) _x2(v), _x2(v) -#define _x8(v) _x4(v), _x4(v) -#define _x16(v) _x8(v), _x8(v) - -#define _x9(v) _x8(v), v -#define _x30(v) _x16(v), _x8(v), _x4(v), _x2(v) -#define _x31(v) _x30(v), v - -#endif /* GX2_SHADER_INL_H */ diff --git a/src/port/wiiu/WiiUImpl.cpp b/src/port/wiiu/WiiUImpl.cpp deleted file mode 100644 index a9c7753e9..000000000 --- a/src/port/wiiu/WiiUImpl.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#ifdef __WIIU__ -#include "WiiUImpl.h" - -#include -#include -#include - -#include -#include -#include - -#include "Context.h" - -namespace Ship { -namespace WiiU { - -static bool hasVpad = false; -static VPADReadError vpadError; -static VPADStatus vpadStatus; - -static bool hasKpad[4] = { false }; -static KPADError kpadError[4] = { KPAD_ERROR_OK }; -static KPADStatus kpadStatus[4]; -static uint8_t kpadExtensions[4]; - -static bool controllersInitialized = false; - -#ifdef _DEBUG -extern "C" { -void __wrap_abort() { - printf("Abort called.\n"); - // force a stack trace - *(uint32_t*)0xdeadc0de = 0xcafebabe; - while (1) - ; -} - -static ssize_t wiiu_log_write(struct _reent* r, void* fd, const char* ptr, size_t len) { - char buf[1024]; - snprintf(buf, sizeof(buf), "%*.*s", len, len, ptr); - OSReport(buf); - WHBLogWritef("%*.*s", len, len, ptr); - return len; -} - -static const devoptab_t dotab_stdout = { - .name = "stdout_whb", - .write_r = wiiu_log_write, -}; -}; -#endif - -void Init(const std::string& shortName) { -#ifdef _DEBUG - WHBLogUdpInit(); - WHBLogPrint("Hello World!"); - - devoptab_list[STD_OUT] = &dotab_stdout; - devoptab_list[STD_ERR] = &dotab_stdout; -#endif - - // make sure the required folders exist - mkdir("/vol/external01/wiiu/", 0755); - mkdir("/vol/external01/wiiu/apps/", 0755); - mkdir(("/vol/external01/wiiu/apps/" + shortName + "/").c_str(), 0755); - - chdir(("/vol/external01/wiiu/apps/" + shortName + "/").c_str()); - - KPADInit(); - WPADEnableURCC(true); -} - -void Exit() { - KPADShutdown(); - - WHBLogUdpDeinit(); -} - -void ThrowMissingOTR(const char* otrPath) { - // TODO handle this better in the future - OSFatal("Main OTR file not found!"); -} - -void ThrowInvalidOTR() { - OSFatal("Invalid OTR files! Try regenerating them!"); -} - -void Update() { - bool rescan = false; - - VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &vpadError); - if (vpadError == VPAD_READ_SUCCESS) { - if (!hasVpad) { - rescan = true; - } - - hasVpad = true; - } else if (vpadError != VPAD_READ_NO_SAMPLES) { - if (hasVpad) { - rescan = true; - } - - hasVpad = false; - } - - for (int i = 0; i < 4; i++) { - KPADReadEx((KPADChan)i, &kpadStatus[i], 1, &kpadError[i]); - if (kpadError[i] == KPAD_ERROR_OK && kpadStatus[i].extensionType != 255) { - if (!hasKpad[i]) { - rescan = true; - } - - if (kpadStatus[i].extensionType != kpadExtensions[i]) { - kpadExtensions[i] = kpadStatus[i].extensionType; - rescan = true; - } - - // set emulated stick button bits so all controllers behave like the gamepad does - switch (kpadStatus[i].extensionType) { - case WPAD_EXT_PRO_CONTROLLER: - if (kpadStatus[i].pro.leftStick.x > 0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_L_EMULATION_RIGHT; - } - if (kpadStatus[i].pro.leftStick.x < -0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_L_EMULATION_LEFT; - } - if (kpadStatus[i].pro.leftStick.y > 0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_L_EMULATION_UP; - } - if (kpadStatus[i].pro.leftStick.y < -0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_L_EMULATION_DOWN; - } - - if (kpadStatus[i].pro.rightStick.x > 0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_R_EMULATION_RIGHT; - } - if (kpadStatus[i].pro.rightStick.x < -0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_R_EMULATION_LEFT; - } - if (kpadStatus[i].pro.rightStick.y > 0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_R_EMULATION_UP; - } - if (kpadStatus[i].pro.rightStick.y < -0.7f) { - kpadStatus[i].pro.hold |= WPAD_PRO_STICK_R_EMULATION_DOWN; - } - break; - case WPAD_EXT_CLASSIC: - case WPAD_EXT_MPLUS_CLASSIC: - if (kpadStatus[i].classic.leftStick.x > 0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_L_EMULATION_RIGHT; - } - if (kpadStatus[i].classic.leftStick.x < -0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_L_EMULATION_LEFT; - } - if (kpadStatus[i].classic.leftStick.y < -0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_L_EMULATION_UP; - } - if (kpadStatus[i].classic.leftStick.y > 0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_L_EMULATION_DOWN; - } - - if (kpadStatus[i].classic.rightStick.x > 0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_R_EMULATION_RIGHT; - } - if (kpadStatus[i].classic.rightStick.x < -0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_R_EMULATION_LEFT; - } - if (kpadStatus[i].classic.rightStick.y > 0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_R_EMULATION_UP; - } - if (kpadStatus[i].classic.rightStick.y < -0.7f) { - kpadStatus[i].classic.hold |= WPAD_CLASSIC_STICK_R_EMULATION_DOWN; - } - break; - case WPAD_EXT_NUNCHUK: - case WPAD_EXT_MPLUS_NUNCHUK: - if (kpadStatus[i].nunchuck.stick.x < -0.7f) { - kpadStatus[i].nunchuck.hold |= WPAD_NUNCHUK_STICK_EMULATION_LEFT; - } - if (kpadStatus[i].nunchuck.stick.x > 0.7f) { - kpadStatus[i].nunchuck.hold |= WPAD_NUNCHUK_STICK_EMULATION_RIGHT; - } - if (kpadStatus[i].nunchuck.stick.y > 0.7f) { - kpadStatus[i].nunchuck.hold |= WPAD_NUNCHUK_STICK_EMULATION_UP; - } - if (kpadStatus[i].nunchuck.stick.y < -0.7f) { - kpadStatus[i].nunchuck.hold |= WPAD_NUNCHUK_STICK_EMULATION_DOWN; - } - break; - } - - hasKpad[i] = true; - } else if (kpadError[i] != KPAD_ERROR_NO_SAMPLES) { - if (hasKpad[i]) { - rescan = true; - } - - hasKpad[i] = false; - } - } - - // rescan devices if connection state changed - if (controllersInitialized && rescan) { - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->HandlePhysicalDevicesChanged(); - } -} - -void SetControllersInitialized() { - controllersInitialized = true; -} - -VPADStatus* GetVPADStatus(VPADReadError* error) { - *error = vpadError; - return hasVpad ? &vpadStatus : nullptr; -} - -KPADStatus* GetKPADStatus(WPADChan chan, KPADError* error) { - *error = kpadError[chan]; - return hasKpad[chan] ? &kpadStatus[chan] : nullptr; -} - -}; // namespace WiiU -}; // namespace Ship - -#endif diff --git a/src/port/wiiu/WiiUImpl.h b/src/port/wiiu/WiiUImpl.h deleted file mode 100644 index 86779fe09..000000000 --- a/src/port/wiiu/WiiUImpl.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace Ship { -namespace WiiU { - -void Init(const std::string& shortName); - -void Exit(); - -void ThrowMissingOTR(const char* otrPath); - -void ThrowInvalidOTR(); - -void Update(); - -VPADStatus* GetVPADStatus(VPADReadError* error); - -KPADStatus* GetKPADStatus(WPADChan chan, KPADError* error); - -void SetControllersInitialized(); - -}; // namespace WiiU -}; // namespace Ship diff --git a/src/public/libultra/os.cpp b/src/public/libultra/os.cpp index 43620a72d..6e7ebee22 100644 --- a/src/public/libultra/os.cpp +++ b/src/public/libultra/os.cpp @@ -13,7 +13,6 @@ uint8_t __osMaxControllers = MAXCONTROLLERS; int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* status) { *controllerBits = 0; -#ifndef __WIIU__ if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) { SPDLOG_ERROR("Failed to initialize SDL game controllers ({})", SDL_GetError()); exit(EXIT_FAILURE); @@ -27,7 +26,6 @@ int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* statu } else { SPDLOG_ERROR("Failed add SDL game controller mappings from \"{}\" ({})", controllerDb, SDL_GetError()); } -#endif #endif Ship::Context::GetInstance()->GetControlDeck()->Init(controllerBits); diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index c023a30ef..0ab670e4a 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -19,7 +19,7 @@ void ResourceManager::Init(const std::vector& otrFiles, const std:: mResourceLoader = std::make_shared(); mArchiveManager = std::make_shared(); GetArchiveManager()->Init(otrFiles, validHashes); -#if defined(__SWITCH__) || defined(__WIIU__) +#if defined(__SWITCH__) size_t threadCount = 1; #else // the extra `- 1` is because we reserve an extra thread for spdlog diff --git a/src/window/Window.cpp b/src/window/Window.cpp index cd74cb0d9..680c62222 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -8,8 +8,6 @@ #include "graphic/Fast3D/gfx_dxgi.h" #include "graphic/Fast3D/gfx_opengl.h" #include "graphic/Fast3D/gfx_metal.h" -#include "graphic/Fast3D/gfx_gx2.h" -#include "graphic/Fast3D/gfx_wiiu.h" #include "graphic/Fast3D/gfx_direct3d11.h" #include "graphic/Fast3D/gfx_direct3d12.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" @@ -19,8 +17,6 @@ #include "utils/AppleFolderManager.h" #elif defined(__SWITCH__) #include "port/switch/SwitchImpl.h" -#elif defined(__WIIU__) -#include "port/wiiu/WiiUImpl.h" #endif namespace Ship { @@ -86,20 +82,15 @@ void Window::Init() { mAvailableWindowBackends->push_back(WindowBackend::SDL_METAL); } #endif -#ifdef __WIIU__ - mAvailableWindowBackends->push_back(WindowBackend::GX2); -#else mAvailableWindowBackends->push_back(WindowBackend::SDL_OPENGL); -#endif InitWindowManager(); gfx_init(mWindowManagerApi, mRenderingApi, Ship::Context::GetInstance()->GetName().c_str(), mIsFullscreen, mWidth, mHeight, mPosX, mPosY); mWindowManagerApi->set_fullscreen_changed_callback(OnFullscreenChanged); -#ifndef __WIIU__ mWindowManagerApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); -#endif + SetTextureFilter((FilteringMode)CVarGetInteger("gTextureFilter", FILTER_THREE_POINT)); } @@ -144,7 +135,6 @@ void Window::MainLoop(void (*mainFunction)(void)) { mWindowManagerApi->main_loop(mainFunction); } -#ifndef __WIIU__ bool Window::KeyUp(int32_t scancode) { if (scancode == Context::GetInstance()->GetConfig()->GetInt("Shortcuts.Fullscreen", KbScancode::LUS_KB_F11)) { Context::GetInstance()->GetWindow()->ToggleFullscreen(); @@ -167,7 +157,6 @@ void Window::AllKeysUp(void) { Context::GetInstance()->GetControlDeck()->ProcessKeyboardEvent(KbEventType::LUS_KB_EVENT_ALL_KEYS_UP, KbScancode::LUS_KB_UNKNOWN); } -#endif void Window::OnFullscreenChanged(bool isNowFullscreen) { std::shared_ptr wnd = Context::GetInstance()->GetWindow(); @@ -242,12 +231,6 @@ void Window::InitWindowManager() { mRenderingApi = &gfx_metal_api; mWindowManagerApi = &gfx_sdl; break; -#endif -#ifdef __WIIU__ - case WindowBackend::GX2: - mRenderingApi = &gfx_gx2_api; - mWindowManagerApi = &gfx_wiiu; - break; #endif default: SPDLOG_ERROR("Could not load the correct rendering backend"); diff --git a/src/window/Window.h b/src/window/Window.h index 0ead1b912..22fbbd370 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -57,11 +57,9 @@ class Window { void SaveWindowSizeToConfig(std::shared_ptr conf); private: -#ifndef __WIIU__ static bool KeyDown(int32_t scancode); static bool KeyUp(int32_t scancode); static void AllKeysUp(void); -#endif static void OnFullscreenChanged(bool isNowFullscreen); std::shared_ptr mGui; diff --git a/src/window/gui/ConsoleWindow.cpp b/src/window/gui/ConsoleWindow.cpp index 2f1ef7f15..ec74adc69 100644 --- a/src/window/gui/ConsoleWindow.cpp +++ b/src/window/gui/ConsoleWindow.cpp @@ -423,11 +423,7 @@ void ConsoleWindow::DrawElement() { constexpr ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; -#ifdef __WIIU__ - ImGui::PushItemWidth(-53.0f * 2.0f); -#else ImGui::PushItemWidth(-53.0f); -#endif if (ImGui::InputTextWithHint("##CMDInput", ">", mInputBuffer, gMaxBufferSize, flags, &ConsoleWindow::CallbackStub, this)) { inputFocus = true; @@ -450,11 +446,8 @@ void ConsoleWindow::DrawElement() { } ImGui::SameLine(); -#ifdef __WIIU__ - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 50 * 2.0f); -#else ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 50); -#endif + if (ImGui::Button("Submit") && !inputFocus && mInputBuffer[0] != '\0' && mInputBuffer[0] != ' ') { Dispatch(std::string(mInputBuffer)); memset(mInputBuffer, 0, gMaxBufferSize); diff --git a/src/window/gui/GameOverlay.cpp b/src/window/gui/GameOverlay.cpp index 5fd0685d7..c98463ffb 100644 --- a/src/window/gui/GameOverlay.cpp +++ b/src/window/gui/GameOverlay.cpp @@ -215,7 +215,7 @@ void GameOverlay::Draw() { const float duration = overlay.duration / overlay.fadeTime; const ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, duration); -#if defined(__WIIU__) || defined(__ANDROID__) +#ifdef __ANDROID__ const float textWidth = GetStringWidth(overlay.Value.c_str()) * 2.0f; const float textOffset = 40.0f * 2.0f; #else diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 7276e6ac8..b611ba27e 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -19,16 +19,6 @@ #include "window/gui/GfxDebuggerWindow.h" -#ifdef __WIIU__ -#include // GX2SetViewport / GX2SetScissor - -#include -#include - -#include "graphic/Fast3D/gfx_wiiu.h" -#include "graphic/Fast3D/gfx_gx2.h" -#endif - #ifdef __APPLE__ #include #include @@ -124,16 +114,6 @@ void Gui::Init(GuiWindowInitData windowImpl) { mImGuiIo->FontGlobalScale = 2.0f; #endif -#ifdef __WIIU__ - // Scale everything by 2 for the Wii U - ImGui::GetStyle().ScaleAllSizes(2.0f); - mImGuiIo->FontGlobalScale = 2.0f; - - // Setup display sizes - mImGuiIo->DisplaySize.x = mImpl.Gx2.Width; - mImGuiIo->DisplaySize.y = mImpl.Gx2.Height; -#endif - auto imguiIniPath = Ship::Context::GetPathRelativeToAppDirectory("imgui.ini"); auto imguiLogPath = Ship::Context::GetPathRelativeToAppDirectory("imgui_log.txt"); mImGuiIo->IniFilename = strcpy(new char[imguiIniPath.length() + 1], imguiIniPath.c_str()); @@ -175,17 +155,11 @@ void Gui::Init(GuiWindowInitData windowImpl) { void Gui::ImGuiWMInit() { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - ImGui_ImplWiiU_Init(); - break; -#else case WindowBackend::SDL_OPENGL: SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); ImGui_ImplSDL2_InitForOpenGL(static_cast(mImpl.Opengl.Window), mImpl.Opengl.Context); break; -#endif #if __APPLE__ case WindowBackend::SDL_METAL: SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "1"); @@ -205,12 +179,6 @@ void Gui::ImGuiWMInit() { void Gui::ImGuiBackendInit() { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - ImGui_ImplGX2_Init(); - break; -#endif - #ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: #ifdef __APPLE__ @@ -282,11 +250,6 @@ void Gui::Update(WindowEvent event) { } switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - if (!ImGui_ImplWiiU_ProcessInput((ImGui_ImplWiiU_ControllerInput*)event.Gx2.Input)) {} - break; -#else case WindowBackend::SDL_OPENGL: case WindowBackend::SDL_METAL: ImGui_ImplSDL2_ProcessEvent(static_cast(event.Sdl.Event)); @@ -296,7 +259,6 @@ void Gui::Update(WindowEvent event) { Ship::Mobile::ImGuiProcessEvent(mImGuiIo->WantTextInput); #endif break; -#endif #if defined(ENABLE_DX11) || defined(ENABLE_DX12) case WindowBackend::DX11: ImGui_ImplWin32_WndProcHandler(static_cast(event.Win32.Handle), event.Win32.Msg, event.Win32.Param1, @@ -458,13 +420,6 @@ void Gui::DrawMenu() { void Gui::ImGuiBackendNewFrame() { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - mImGuiIo->DeltaTime = (float)frametime / 1000.0f / 1000.0f; - ImGui_ImplGX2_NewFrame(); - break; -#endif - #ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: ImGui_ImplOpenGL3_NewFrame(); @@ -489,15 +444,10 @@ void Gui::ImGuiBackendNewFrame() { void Gui::ImGuiWMNewFrame() { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - break; -#else case WindowBackend::SDL_OPENGL: case WindowBackend::SDL_METAL: ImGui_ImplSDL2_NewFrame(); break; -#endif #if defined(ENABLE_DX11) || defined(ENABLE_DX12) case WindowBackend::DX11: ImGui_ImplWin32_NewFrame(); @@ -685,11 +635,6 @@ ImTextureID Gui::GetTextureById(int32_t id) { return gfx_metal_get_texture_by_id(id); } #endif -#ifdef __WIIU__ - if (Context::GetInstance()->GetWindow()->GetWindowBackend() == WindowBackend::GX2) { - return gfx_gx2_texture_for_imgui(id); - } -#endif return reinterpret_cast(id); } @@ -714,16 +659,6 @@ ImVec2 Gui::GetTextureSize(const std::string& name) { void Gui::ImGuiRenderDrawData(ImDrawData* data) { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { -#ifdef __WIIU__ - case WindowBackend::GX2: - ImGui_ImplGX2_RenderDrawData(data); - - // Reset viewport and scissor for drawing the keyboard - GX2SetViewport(0.0f, 0.0f, mImGuiIo->DisplaySize.x, mImGuiIo->DisplaySize.y, 0.0f, 1.0f); - GX2SetScissor(0, 0, mImGuiIo->DisplaySize.x, mImGuiIo->DisplaySize.y); - ImGui_ImplWiiU_DrawKeyboardOverlay(); - break; -#endif #ifdef ENABLE_OPENGL case WindowBackend::SDL_OPENGL: diff --git a/src/window/gui/InputEditorWindow.cpp b/src/window/gui/InputEditorWindow.cpp index 53e28d4aa..4b3e95e62 100644 --- a/src/window/gui/InputEditorWindow.cpp +++ b/src/window/gui/InputEditorWindow.cpp @@ -4,9 +4,7 @@ #include #include "public/bridge/consolevariablebridge.h" -#ifndef __WIIU__ #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" -#endif namespace Ship { @@ -270,7 +268,6 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER ImGui::PopStyleVar(); ImGui::SameLine(0, 0); -#ifndef __WIIU__ auto sdlAxisDirectionToButtonMapping = std::dynamic_pointer_cast(mapping); auto indexMapping = Context::GetInstance() ->GetControlDeck() @@ -335,7 +332,6 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER ImGui::PopStyleVar(); ImGui::SameLine(0, 0); } -#endif ImGui::PushStyleColor(ImGuiCol_Button, buttonColor); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor); @@ -1228,127 +1224,6 @@ void InputEditorWindow::DrawPortTab(uint8_t portIndex) { } } -#ifdef __WIIU__ -void InputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) { - ImGui::SameLine(); - ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(1.0f, 0.5f)); - auto popupId = StringHelper::Sprintf("setDefaultsPopup##%d", portIndex); - if (ImGui::Button(StringHelper::Sprintf("Set defaults...##%d", portIndex).c_str())) { - ImGui::OpenPopup(popupId.c_str()); - } - ImGui::PopStyleVar(); - - if (ImGui::BeginPopup(popupId.c_str())) { - std::map> indexMappings; - for (auto [lusIndex, mapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::static_pointer_cast(mapping); - if (wiiuIndexMapping == nullptr) { - continue; - } - - indexMappings[lusIndex] = { wiiuIndexMapping->GetWiiUControllerName(), - wiiuIndexMapping->IsWiiUGamepad() ? INT32_MAX - : wiiuIndexMapping->GetDeviceChannel() }; - } - - bool shouldClose = false; - for (auto [lusIndex, info] : indexMappings) { - auto [name, wiiuChannel] = info; - bool isGamepad = wiiuChannel == INT32_MAX; - - auto buttonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button); - auto buttonHoveredColor = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); - GetButtonColorsForShipDeviceIndex(lusIndex, buttonColor, buttonHoveredColor); - ImGui::PushStyleColor(ImGuiCol_Button, buttonColor); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor); - - auto fancyName = StringHelper::Sprintf( - "%s%s", name.c_str(), isGamepad ? "" : StringHelper::Sprintf(" (%d)", wiiuChannel).c_str()); - if (ImGui::Button(StringHelper::Sprintf("%s %s", ICON_FA_GAMEPAD, fancyName.c_str()).c_str())) { - ImGui::OpenPopup(StringHelper::Sprintf("Set Defaults for %s", name.c_str()).c_str()); - } - ImGui::PopStyleColor(); - ImGui::PopStyleColor(); - if (ImGui::BeginPopupModal(StringHelper::Sprintf("Set Defaults for %s", name.c_str()).c_str(), NULL, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::Text("This will clear all existing mappings for\n%s on port %d.\n\nContinue?", fancyName.c_str(), - portIndex + 1); - if (ImGui::Button("Cancel")) { - shouldClose = true; - ImGui::CloseCurrentPopup(); - } - if (ImGui::Button("Set defaults")) { - Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->ClearAllMappingsForDevice( - lusIndex); - Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings( - lusIndex); - shouldClose = true; - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } - } - - if (ImGui::Button("Cancel") || shouldClose) { - ImGui::CloseCurrentPopup(); - } - - ImGui::EndPopup(); - } -} - -void InputEditorWindow::DrawDevicesTab() { - if (ImGui::BeginTabItem("Devices")) { - std::map> indexMappings; - for (auto [lusIndex, mapping] : Context::GetInstance() - ->GetControlDeck() - ->GetDeviceIndexMappingManager() - ->GetAllDeviceIndexMappingsFromConfig()) { - auto wiiuIndexMapping = std::static_pointer_cast(mapping); - if (wiiuIndexMapping == nullptr) { - continue; - } - - indexMappings[lusIndex] = { wiiuIndexMapping->GetWiiUControllerName(), -1 }; - } - - for (auto [lusIndex, mapping] : - Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) { - auto wiiuIndexMapping = std::static_pointer_cast(mapping); - if (wiiuIndexMapping == nullptr) { - continue; - } - - indexMappings[lusIndex] = { wiiuIndexMapping->GetWiiUControllerName(), - wiiuIndexMapping->IsWiiUGamepad() ? INT32_MAX - : wiiuIndexMapping->GetDeviceChannel() }; - } - - for (auto [lusIndex, info] : indexMappings) { - auto [name, wiiuChannel] = info; - bool connected = wiiuChannel != -1; - bool isGamepad = wiiuChannel == INT32_MAX; - - auto buttonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button); - auto buttonHoveredColor = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); - GetButtonColorsForShipDeviceIndex(lusIndex, buttonColor, buttonHoveredColor); - ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - ImGui::PushStyleColor(ImGuiCol_Button, buttonColor); - ImGui::Button(StringHelper::Sprintf("%s %s%s", connected ? ICON_FA_GAMEPAD : ICON_FA_CHAIN_BROKEN, - name.c_str(), - !connected ? " (Disconnected)" - : isGamepad ? "" - : StringHelper::Sprintf(" (%d)", wiiuChannel).c_str()) - .c_str()); - ImGui::PopStyleColor(); - ImGui::PopItemFlag(); - } - - ImGui::EndTabItem(); - } -} -#else void InputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) { ImGui::SameLine(); ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(1.0f, 0.5f)); @@ -1459,7 +1334,6 @@ void InputEditorWindow::DrawDevicesTab() { ImGui::EndTabItem(); } } -#endif void InputEditorWindow::DrawElement() { ImGui::Begin("Controller Configuration", &mIsVisible); diff --git a/src/window/gui/StatsWindow.cpp b/src/window/gui/StatsWindow.cpp index 0d5b3eeb4..b318484fc 100644 --- a/src/window/gui/StatsWindow.cpp +++ b/src/window/gui/StatsWindow.cpp @@ -28,8 +28,6 @@ void StatsWindow::DrawElement() { ImGui::Text("Platform: macOS"); #elif defined(__SWITCH__) ImGui::Text("Platform: Nintendo Switch"); -#elif defined(__WIIU__) - ImGui::Text("Platform: Nintendo Wii U"); #elif defined(__linux__) ImGui::Text("Platform: Linux"); #else