libnx support fixes

This commit is contained in:
Luke Street 2020-10-21 01:56:27 -04:00
parent ddf17bd8b7
commit 2d2dc9e520
11 changed files with 108 additions and 2 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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()

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -0,0 +1,18 @@
#pragma once
#ifdef __SWITCH__
#include <array>
#include "boo2/boo2.hpp"
namespace urde {
struct CLibnxControllerData {
u64 keysDown;
JoystickPosition lStick;
JoystickPosition rStick;
};
} // namespace urde
#endif

View File

@ -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

View File

@ -45,7 +45,9 @@
#include <DataSpec/DNAMP1/SFX/Weapons.h>
#include <DataSpec/DNAMP1/SFX/ZZZ.h>
#ifndef __SWITCH__
#include <discord_rpc.h>
#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<hecl::CVarCommons>(*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

View File

@ -257,11 +257,13 @@ private:
CCameraFilterPass<CColoredQuadFilter> 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);