Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rumble cvar and fixes #184

Merged
merged 15 commits into from
Apr 26, 2022
1 change: 1 addition & 0 deletions libultraship/libultraship/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Ship {
void Read(OSContPad* pad);
virtual void ReadFromSource() = 0;
virtual void WriteToSource(ControllerCallback* controller) = 0;
virtual bool CanRumble() const = 0;
bool isRumbling;

void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode);
Expand Down
4 changes: 4 additions & 0 deletions libultraship/libultraship/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ namespace Game {
Settings.controller.rumble_strength = Ship::stof(Conf[ControllerSection]["rumble_strength"]);
CVar_SetFloat("gRumbleStrength", Settings.controller.rumble_strength);

Settings.controller.rumble_enabled = Ship::stof(Conf[ControllerSection]["rumble_enabled"]);
CVar_SetS32("gRumbleEnabled", Settings.controller.rumble_enabled);

Settings.controller.input_scale = Ship::stof(Conf[ControllerSection]["input_scale"]);
CVar_SetFloat("gInputScale", Settings.controller.input_scale);

Expand Down Expand Up @@ -160,6 +163,7 @@ namespace Game {
// Controllers
Conf[ControllerSection]["gyro_sensitivity"] = std::to_string(Settings.controller.gyro_sensitivity);
Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength);
Conf[ControllerSection]["rumble_enabled"] = std::to_string(Settings.controller.rumble_enabled);
Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale);
Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled);
Conf[ControllerSection]["dpad_pause_name"] = std::to_string(Settings.controller.dpad_pause_name);
Expand Down
1 change: 1 addition & 0 deletions libultraship/libultraship/GameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct SoHConfigType {
struct {
float gyro_sensitivity = 1.0f;
float rumble_strength = 1.0f;
bool rumble_enabled = true;
float input_scale = 1.0f;
float gyroDriftX = 0.0f;
float gyroDriftY = 0.0f;
Expand Down
1 change: 1 addition & 0 deletions libultraship/libultraship/KeyboardController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Ship {

void ReadFromSource();
void WriteToSource(ControllerCallback* controller);
bool CanRumble() const { return false; }

bool PressButton(int32_t dwScancode);
bool ReleaseButton(int32_t dwScancode);
Expand Down
7 changes: 6 additions & 1 deletion libultraship/libultraship/SDLController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ namespace Ship {
}

bool SDLController::Close() {
if (SDL_GameControllerHasRumble(Cont)) {
SDL_GameControllerRumble(Cont, 0, 0, 0);
}
if (Cont != nullptr) {
SDL_GameControllerClose(Cont);
}
Expand Down Expand Up @@ -331,7 +334,9 @@ namespace Ship {
{
if (SDL_GameControllerHasRumble(Cont)) {
if (controller->rumble > 0) {
SDL_GameControllerRumble(Cont, 0xFFFF * Game::Settings.controller.rumble_strength, 0xFFFF * Game::Settings.controller.rumble_strength, 1);
SDL_GameControllerRumble(Cont, 0xFFFF * Game::Settings.controller.rumble_strength, 0xFFFF * Game::Settings.controller.rumble_strength, 0);
} else {
SDL_GameControllerRumble(Cont, 0, 0, 0);
}
}

Expand Down
1 change: 1 addition & 0 deletions libultraship/libultraship/SDLController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Ship {

void ReadFromSource();
void WriteToSource(ControllerCallback* controller);
bool CanRumble() const { return SDL_GameControllerHasRumble(Cont); }

std::string GetGuid() { return guid; };

Expand Down
5 changes: 5 additions & 0 deletions libultraship/libultraship/SohImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ namespace SohImGui {

ImGui::Separator();

if (ImGui::Checkbox("Rumble Enabled", &Game::Settings.controller.rumble_enabled)) {
CVar_SetS32("gRumbleEnabled", Game::Settings.controller.rumble_enabled);
needs_save = true;
}

ImGui::Text("Rumble Strength: %d %%", static_cast<int>(100 * Game::Settings.controller.rumble_strength));
if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.rumble_strength, 0.0f, 1.0f, "")) {
needs_save = true;
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/bootcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void BootCommands_Init()
CVar_RegisterS32("gDebugEnabled", 0);
CVar_RegisterS32("gPauseLiveLink", 0);
CVar_RegisterS32("gMinimalUI", 0);
CVar_RegisterS32("gRumbleEnabled", 0);
}

//void BootCommands_ParseBootArgs(char* str)
Expand Down
10 changes: 10 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,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_CanRumble(void) {
for (const auto& controller : Ship::Window::Controllers.at(0)) {
if (controller->CanRumble()) {
return 1;
}
}

return 0;
}
1 change: 1 addition & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_CanRumble(void);
#endif
4 changes: 2 additions & 2 deletions soh/soh/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void osCreateViManager(OSPri pri)

s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel)
{

return 0;
}

u32 osAiGetLength(void)
Expand Down Expand Up @@ -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,
};
};
5 changes: 4 additions & 1 deletion soh/src/code/padmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -303,6 +303,9 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) {
}
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
osContGetReadData(padMgr->pads);

padMgr->padStatus[0].status = CVar_GetS32("gRumbleEnabled", 0) && Controller_CanRumble();

Sirius902 marked this conversation as resolved.
Show resolved Hide resolved
if (padMgr->preNMIShutdown) {
memset(padMgr->pads, 0, sizeof(padMgr->pads));
}
Expand Down