Rumble cvar and fixes (#184)

* Rumble indefinitely until turned off

* Add rumble cvar

* Register CVar

* Check if controller can rumble to insert rumble pak

* Reduce verbosity of checks

* Remove extraneous const_cast

* Once again remove extraneous const_cast

* Add per-controller settings

* Add nice spacing

* Only display controller entry if pad connected

* Const some stuff
This commit is contained in:
Sirius902 2022-04-26 16:50:24 -07:00 committed by GitHub
commit eea5135d62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 274 additions and 150 deletions

View file

@ -25,6 +25,7 @@ void BootCommands_Init()
CVar_RegisterS32("gDebugEnabled", 0);
CVar_RegisterS32("gPauseLiveLink", 0);
CVar_RegisterS32("gMinimalUI", 0);
CVar_RegisterS32("gRumbleEnabled", 0);
CVar_RegisterS32("gUniformLR", 1);
CVar_RegisterS32("gNewDrops", 0);
CVar_RegisterS32("gVisualAgony", 0);

View file

@ -337,11 +337,11 @@ static bool SetCVarHandler(const std::vector<std::string>& args) {
int vType = CheckVarType(args[2]);
if (vType == VARTYPE_STRING)
CVar_SetString((char*)args[1].c_str(), (char*)args[2].c_str());
CVar_SetString(args[1].c_str(), (char*)args[2].c_str());
else if (vType == VARTYPE_FLOAT)
CVar_SetFloat((char*)args[1].c_str(), std::stof(args[2]));
CVar_SetFloat(args[1].c_str(), std::stof(args[2]));
else
CVar_SetS32((char*)args[1].c_str(), std::stoi(args[2]));
CVar_SetS32(args[1].c_str(), std::stoi(args[2]));
DebugConsole_SaveCVars();
@ -354,7 +354,7 @@ static bool GetCVarHandler(const std::vector<std::string>& args) {
if (args.size() < 2)
return CMD_FAILED;
CVar* cvar = CVar_GetVar((char*) args[1].c_str());
CVar* cvar = CVar_GetVar(args[1].c_str());
if (cvar != nullptr)
{
@ -446,4 +446,4 @@ void DebugConsole_SaveCVars()
}
File::WriteAllText("cvars.cfg", output);
}
}

View file

@ -3,6 +3,7 @@
#include <locale>
#include <codecvt>
#include "GlobalCtx2.h"
#include "GameSettings.h"
#include "ResourceMgr.h"
#include "DisplayList.h"
#include "PlayerAnimation.h"
@ -885,3 +886,13 @@ extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) {
OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Play(buf, len);
}
}
extern "C" int Controller_ShouldRumble(size_t i) {
for (const auto& controller : Ship::Window::Controllers.at(i)) {
if (controller->CanRumble() && Game::Settings.controller.extra[i].rumble_strength > 0.001f) {
return 1;
}
}
return 0;
}

View file

@ -64,4 +64,5 @@ int AudioPlayer_Buffered(void);
int AudioPlayer_GetDesiredBuffered(void);
void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i);
#endif

View file

@ -102,7 +102,7 @@ void osCreateViManager(OSPri pri)
s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel)
{
return 0;
}
u32 osAiGetLength(void)
@ -2099,4 +2099,4 @@ u8 gSequenceFontTable[0x1C0] = {
0x01, 0x12, 0x01, 0x24, 0x01, 0x18, 0x01, 0x19, 0x01, 0x13, 0x01, 0x20, 0x01, 0x1B, 0x01, 0x1C, 0x01, 0x1D, 0x01,
0x03, 0x01, 0x1F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x09, 0x01, 0x21, 0x01, 0x22, 0x01, 0x21, 0x01, 0x09, 0x01, 0x20,
0x01, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
};

View file

@ -269,7 +269,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y);
}
controllerCallback.rumble = padMgr->rumbleEnable[0] > 0 ? 1 : 0;
controllerCallback.rumble = CVar_GetS32("gRumbleEnabled", 0) && (padMgr->rumbleEnable[0] > 0);
if (HealthMeter_IsCritical()) {
controllerCallback.ledColor = 0;
@ -303,6 +303,11 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) {
}
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
osContGetReadData(padMgr->pads);
for (i = 0; i < __osMaxControllers; i++) {
padMgr->padStatus[i].status = CVar_GetS32("gRumbleEnabled", 0) && Controller_ShouldRumble(i);
}
if (padMgr->preNMIShutdown) {
memset(padMgr->pads, 0, sizeof(padMgr->pads));
}