From 2d2dc9e520711ab7af7702775998bd031c4a5e3e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 21 Oct 2020 01:56:27 -0400 Subject: [PATCH] libnx support fixes --- CMakeLists.txt | 1 - Runtime/CBasicsPC.cpp | 4 +++ Runtime/CMakeLists.txt | 10 ++++++- Runtime/CStateManager.cpp | 2 ++ Runtime/Input/CFinalInput.cpp | 46 ++++++++++++++++++++++++++++++ Runtime/Input/CFinalInput.hpp | 4 +++ Runtime/Input/CInputGenerator.cpp | 12 ++++++++ Runtime/Input/CLibnxController.hpp | 18 ++++++++++++ Runtime/Input/CMakeLists.txt | 1 + Runtime/MP1/MP1.cpp | 10 +++++++ Runtime/MP1/MP1.hpp | 2 ++ 11 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 Runtime/Input/CLibnxController.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5c09447..79a94369e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,7 +325,6 @@ add_subdirectory(assetnameparser) add_compile_definitions(URDE_ZIP_INPUT_STREAM=1) # Enable CZipInputStream now that zlib header is known add_subdirectory(DataSpec) add_subdirectory(kabufuda) -add_subdirectory(Editor) add_subdirectory(jbus) set(JBUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jbus/include) diff --git a/Runtime/CBasicsPC.cpp b/Runtime/CBasicsPC.cpp index 2f6d95345..9fa4649d6 100644 --- a/Runtime/CBasicsPC.cpp +++ b/Runtime/CBasicsPC.cpp @@ -64,7 +64,11 @@ static struct tm* localtime_r(const time_t& time, struct tm& timeSt, long& gmtOf auto ret = ::localtime_r(&time, &timeSt); if (!ret) return nullptr; +#ifdef __SWITCH__ + gmtOff = 0; +#else gmtOff = ret->tm_gmtoff; +#endif return ret; #else struct tm _gmSt; diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 9c0d10dc2..f7ba5b480 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -137,7 +137,10 @@ endfunction() set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) set(RUNTIME_LIBRARIES RetroDataSpec AssetNameMapNull NESEmulator - libjpeg-turbo jbus kabufuda discord-rpc logvisor) + libjpeg-turbo jbus kabufuda logvisor) +if(NOT GEKKO AND NOT NX) + list(APPEND RUNTIME_LIBRARIES discord-rpc) +endif() add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A}) add_runtime_common_library(RuntimeCommonB ${RUNTIME_SOURCES_B}) @@ -149,3 +152,8 @@ target_hsh(RuntimeCommonB) add_executable(urde CMain.hpp CMain.cpp) target_link_libraries(urde PUBLIC RuntimeCommon) + +if(NX) + add_nro_target(urde) + add_nso_target(urde) +endif() diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index d37afdc8d..88b4684b8 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -2073,7 +2073,9 @@ void CStateManager::UpdateGraphicsTiming(float dt) { } void CStateManager::Update(float dt) { +#ifndef __SWITCH__ MP1::CMain::UpdateDiscordPresence(GetWorld()->IGetStringTableAssetId()); +#endif CElementGen::SetGlobalSeed(x8d8_updateFrameIdx); CParticleElectric::SetGlobalSeed(x8d8_updateFrameIdx); diff --git a/Runtime/Input/CFinalInput.cpp b/Runtime/Input/CFinalInput.cpp index d863e4ab7..5c85666d2 100644 --- a/Runtime/Input/CFinalInput.cpp +++ b/Runtime/Input/CFinalInput.cpp @@ -96,6 +96,52 @@ CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& } } +#ifdef __SWITCH__ +CFinalInput::CFinalInput(int cIdx, float dt, const CLibnxControllerData& data, const CFinalInput& prevInput) +: x0_dt(dt) +, x4_controllerIdx(cIdx) +, x8_anaLeftX(zeus::clamp(-1.0f, float(data.lStick.dx) / JOYSTICK_MAX, 1.0f)) +, xc_anaLeftY(zeus::clamp(-1.0f, float(data.lStick.dy) / JOYSTICK_MAX, 1.0f)) +, x10_anaRightX(zeus::clamp(-1.0f, float(data.rStick.dx) / JOYSTICK_MAX, 1.0f)) +, x14_anaRightY(zeus::clamp(-1.0f, float(data.rStick.dy) / JOYSTICK_MAX, 1.0f)) +, x18_anaLeftTrigger((data.keysDown & KEY_ZL) ? 1.f : 0.f) +, x1c_anaRightTrigger((data.keysDown & KEY_ZR) ? 1.f : 0.f) +, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight()) +, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft()) +, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp()) +, x21_enableAnaLeftNegYP(DLADown() && !prevInput.DLADown()) +, x22_enableAnaRightXP(DRARight() && !prevInput.DRARight()) +, x22_enableAnaRightNegXP(DRALeft() && !prevInput.DRALeft()) +, x23_enableAnaRightYP(DRAUp() && !prevInput.DRAUp()) +, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown()) +, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger()) +, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger()) +, x2c_b24_A(data.keysDown & KEY_A) +, x2c_b25_B(data.keysDown & KEY_B) +, x2c_b26_X(data.keysDown & KEY_Y) +, x2c_b27_Y(data.keysDown & KEY_X) +, x2c_b28_Z(data.keysDown & KEY_R) +, x2c_b29_L(data.keysDown & KEY_ZL) +, x2c_b30_R(data.keysDown & KEY_ZR) +, x2c_b31_DPUp(data.keysDown & KEY_DUP) +, x2d_b24_DPRight(data.keysDown & KEY_DRIGHT) +, x2d_b25_DPDown(data.keysDown & KEY_DDOWN) +, x2d_b26_DPLeft(data.keysDown & KEY_DLEFT) +, x2d_b27_Start(data.keysDown & KEY_PLUS) +, x2d_b28_PA(DA() && !prevInput.DA()) +, x2d_b29_PB(DB() && !prevInput.DB()) +, x2d_b30_PX(DX() && !prevInput.DX()) +, x2d_b31_PY(DY() && !prevInput.DY()) +, x2e_b24_PZ(DZ() && !prevInput.DZ()) +, x2e_b25_PL(DL() && !prevInput.DL()) +, x2e_b26_PR(DR() && !prevInput.DR()) +, x2e_b27_PDPUp(DDPUp() && !prevInput.DDPUp()) +, x2e_b28_PDPRight(DDPRight() && !prevInput.DDPRight()) +, x2e_b29_PDPDown(DDPDown() && !prevInput.DDPDown()) +, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft()) +, x2e_b31_PStart(DStart() && !prevInput.DStart()) {} +#endif + CFinalInput& CFinalInput::operator|=(const CFinalInput& other) { if (std::fabs(other.x8_anaLeftX) > std::fabs(x8_anaLeftX)) x8_anaLeftX = other.x8_anaLeftX; diff --git a/Runtime/Input/CFinalInput.hpp b/Runtime/Input/CFinalInput.hpp index 45a8abee5..c640ed086 100644 --- a/Runtime/Input/CFinalInput.hpp +++ b/Runtime/Input/CFinalInput.hpp @@ -4,6 +4,7 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Input/CKeyboardMouseController.hpp" +#include "Runtime/Input/CLibnxController.hpp" #include "boo2/inputdev/DolphinSmashAdapter.hpp" @@ -75,6 +76,9 @@ struct CFinalInput { CFinalInput(int cIdx, float dt, const boo2::DolphinControllerState& data, const CFinalInput& prevInput, float leftDiv, float rightDiv); CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& data, const CFinalInput& prevInput); +#ifdef __SWITCH__ + CFinalInput(int cIdx, float dt, const CLibnxControllerData& data, const CFinalInput& prevInput); +#endif CFinalInput& operator|=(const CFinalInput& other); diff --git a/Runtime/Input/CInputGenerator.cpp b/Runtime/Input/CInputGenerator.cpp index 52cab0777..4ebc1c8d2 100644 --- a/Runtime/Input/CInputGenerator.cpp +++ b/Runtime/Input/CInputGenerator.cpp @@ -11,6 +11,18 @@ void CInputGenerator::Update(float dt, CArchitectureQueue& queue) { return; } +#ifdef __SWITCH__ + { + CLibnxControllerData data; + data.keysDown = hidKeysDown(CONTROLLER_P1_AUTO) | hidKeysHeld(CONTROLLER_P1_AUTO); + hidJoystickRead(&data.lStick, CONTROLLER_P1_AUTO, JOYSTICK_LEFT); + hidJoystickRead(&data.rStick, CONTROLLER_P1_AUTO, JOYSTICK_RIGHT); + CFinalInput input(0, dt, data, m_lastUpdate); + queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, input)); + return; + } +#endif + /* Keyboard/Mouse first */ CFinalInput kbInput = getFinalInput(0, dt); bool kbUsed = false; diff --git a/Runtime/Input/CLibnxController.hpp b/Runtime/Input/CLibnxController.hpp new file mode 100644 index 000000000..2a0e3c7d3 --- /dev/null +++ b/Runtime/Input/CLibnxController.hpp @@ -0,0 +1,18 @@ +#pragma once + +#ifdef __SWITCH__ + +#include +#include "boo2/boo2.hpp" + +namespace urde { + +struct CLibnxControllerData { + u64 keysDown; + JoystickPosition lStick; + JoystickPosition rStick; +}; + +} // namespace urde + +#endif diff --git a/Runtime/Input/CMakeLists.txt b/Runtime/Input/CMakeLists.txt index 260c262e8..d21fe0fbb 100644 --- a/Runtime/Input/CMakeLists.txt +++ b/Runtime/Input/CMakeLists.txt @@ -1,6 +1,7 @@ set(INPUT_SOURCES IController.hpp CKeyboardMouseController.hpp + CLibnxController.hpp ControlMapper.hpp ControlMapper.cpp CInputGenerator.hpp CInputGenerator.cpp CFinalInput.hpp CFinalInput.cpp diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 1c8c660df..4cf293b30 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -45,7 +45,9 @@ #include #include +#ifndef __SWITCH__ #include +#endif namespace urde::MP1 { namespace { @@ -614,6 +616,7 @@ static std::string DiscordWorldName; static u32 DiscordItemPercent = 0xffffffff; static std::string DiscordState; +#ifndef __SWITCH__ void CMain::InitializeDiscord() { DiscordStartTime = std::time(nullptr); DiscordEventHandlers handlers = {}; @@ -673,10 +676,13 @@ void CMain::HandleDiscordDisconnected(int errorCode, const char* message) { void CMain::HandleDiscordErrored(int errorCode, const char* message) { DiscordLog.report(logvisor::Error, FMT_STRING("Discord Error: {}"), message); } +#endif void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo2::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) { +#ifndef __SWITCH__ InitializeDiscord(); +#endif m_cvarMgr = cvarMgr; m_cvarCommons = std::make_unique(*m_cvarMgr); #if 0 @@ -878,7 +884,9 @@ bool CMain::Proc() { x160_24_finished = true; } +#ifndef __SWITCH__ Discord_RunCallbacks(); +#endif return x160_24_finished; } @@ -936,7 +944,9 @@ void CMain::Shutdown() { CFluidPlaneManager::RippleMapTex.reset(); CBooModel::Shutdown(); CGraphics::ShutdownBoo(); +#ifndef __SWITCH__ ShutdownDiscord(); +#endif } #if 0 diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 9853bcd30..1389b5eb6 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -257,11 +257,13 @@ private: CCameraFilterPass m_alphaPass; void InitializeSubsystems(); +#ifndef __SWITCH__ static void InitializeDiscord(); static void ShutdownDiscord(); static void HandleDiscordReady(const DiscordUser* request); static void HandleDiscordDisconnected(int errorCode, const char* message); static void HandleDiscordErrored(int errorCode, const char* message); +#endif public: CMain(IFactory* resFactory, CSimplePool* resStore, hsh::surface surface);