Skip to content

Commit

Permalink
Overload GameControllerManager::rumble to make it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
n0toose committed Jan 24, 2024
1 parent d7e327d commit fb6976f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/control/game_controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ GameControllerManager::on_controller_added(int joystick_index)
m_parent->push_user();

m_game_controllers[game_controller] = id;
// this->rumble(game_controller);

if (GameSession::current() && !GameSession::current()->get_savegame().is_title_screen() && id != 0)
{
Expand Down Expand Up @@ -325,6 +326,12 @@ GameControllerManager::has_corresponding_game_controller(int player_id) const

int
GameControllerManager::rumble(SDL_GameController* controller) const
{
return SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 100);
}

int
GameControllerManager::rumble(SDL_GameController* controller, uint16_t low_frequency_rumble, uint16_t high_frequency_rumble, uint32_t duration_ms) const
{
#if SDL_VERSION_ATLEAST(2, 0, 9)
if (g_config->multiplayer_buzz_controllers)
Expand All @@ -333,8 +340,7 @@ GameControllerManager::rumble(SDL_GameController* controller) const
if (SDL_GameControllerHasRumble(controller))
{
#endif
// TODO: Rumble intensity setting (like volume).
SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 300);
SDL_GameControllerRumble(controller, low_frequency_rumble, high_frequency_rumble, duration_ms);
#if SDL_VERSION_ATLEAST(2, 0, 18)
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/control/game_controller_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef HEADER_SUPERTUX_CONTROL_GAME_CONTROLLER_MANAGER_HPP
#define HEADER_SUPERTUX_CONTROL_GAME_CONTROLLER_MANAGER_HPP

#include "control/controller.hpp"

#include <stdint.h>
#include <array>
#include <vector>
#include <unordered_map>

#include "control/controller.hpp"

class InputManager;
struct SDL_ControllerAxisEvent;
struct SDL_ControllerButtonEvent;
Expand Down Expand Up @@ -51,6 +52,7 @@ class GameControllerManager final

/** @returns 0 if success, 1 if controller doesn't support rumbling, 2 if game doesn't support rumbling */
int rumble(SDL_GameController* controller) const;
int rumble(SDL_GameController* controller, uint16_t low_frequency_rumble, uint16_t high_frequency_rumble, uint32_t duration_ms) const;

void bind_controller(SDL_GameController* controller, int player_id);

Expand Down

0 comments on commit fb6976f

Please sign in to comment.