Skip to content

Commit 4873d7c

Browse files
LIJI32Lior Halphon
authored andcommitted
Make it possible to adjust the maximum rumble strength
1 parent 8de2d12 commit 4873d7c

File tree

11 files changed

+95
-22
lines changed

11 files changed

+95
-22
lines changed

Cocoa/GBApp.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ - (void) applicationDidFinishLaunching:(NSNotification *)notification
108108

109109
@"GBColorPalette": @1,
110110
@"GBTurboCap": @0,
111+
@"GBRumbleStrength" : @1,
111112

112113
// Default themes
113114
@"GBThemes": @{

Cocoa/GBView.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ -(void)keyUp:(NSEvent *)theEvent
558558

559559
- (void)setRumble:(double)amp
560560
{
561+
double strength = [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBRumbleStrength"];
562+
if (strength != 1) {
563+
amp = pow(amp, strength) * strength;
564+
}
561565
[lastController setRumbleAmplitude:amp];
562566
}
563567

Cocoa/Preferences.xib

Lines changed: 41 additions & 21 deletions
Large diffs are not rendered by default.

SDL/configuration.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ configuration_t configuration =
5151
.cgb_revision = GB_MODEL_CGB_E - GB_MODEL_CGB_0,
5252
.dmg_palette = 1, // Replacing the old default (0) as of 0.15.2
5353
.agb_revision = GB_MODEL_AGB_A,
54+
.rumble_strength = 8,
5455
};

SDL/configuration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ typedef struct {
165165
/* v1.0.2 */
166166
int8_t vsync_mode;
167167
uint8_t turbo_cap;
168+
169+
/* v1.0.3 */
170+
uint8_t rumble_strength;
168171
};
169172
} configuration_t;
170173

SDL/font.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern const uint8_t font_max;
1515
#define ELLIPSIS_STRING "\x87"
1616
#define MOJIBAKE_STRING "\x88"
1717
#define SLIDER_STRING "\x89\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8F\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8B"
18+
#define TICKLESS_SLIDER_STRING "\x89\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8A\x8B"
1819
#define SELECTED_SLIDER_STRING "\x8C\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8D\x8E"
1920
#define COPYRIGHT_STRING "\x90"
2021
#define CHECKBOX_OFF_STRING "\x93"

SDL/gui.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,12 +2144,36 @@ static const char *current_hotkey(unsigned index)
21442144
}) [configuration.hotkey_actions[index - 2]];
21452145
}
21462146

2147+
static void increase_rumble_strength(unsigned index)
2148+
{
2149+
if (configuration.rumble_strength < 8) {
2150+
configuration.rumble_strength++;
2151+
}
2152+
}
2153+
2154+
static void decrease_rumble_strength(unsigned index)
2155+
{
2156+
if (configuration.rumble_strength > 1) {
2157+
configuration.rumble_strength--;
2158+
}
2159+
}
2160+
2161+
const char *current_rumble_strength(unsigned index)
2162+
{
2163+
static char ret[22];
2164+
strcpy(ret, TICKLESS_SLIDER_STRING);
2165+
unsigned pos = ((configuration.rumble_strength - 1) * (strlen(TICKLESS_SLIDER_STRING) - 1) + 3) / 7;
2166+
ret[pos] = SELECTED_SLIDER_STRING[pos];
2167+
return ret;
2168+
}
2169+
21472170
static const struct menu_item joypad_menu[] = {
21482171
{"Joypad:", cycle_joypads, current_joypad_name, cycle_joypads_backwards},
21492172
{"Configure layout", detect_joypad_layout},
21502173
{"Hotkey 1 Action:", cycle_hotkey, current_hotkey, cycle_hotkey_backwards},
21512174
{"Hotkey 2 Action:", cycle_hotkey, current_hotkey, cycle_hotkey_backwards},
21522175
{"Rumble Mode:", cycle_rumble_mode, current_rumble_mode, cycle_rumble_mode_backwards},
2176+
{"Rumble Strength:", increase_rumble_strength, current_rumble_strength, decrease_rumble_strength},
21532177
{"Analog Stick Behavior:", toggle_use_faux_analog_inputs, current_faux_analog_inputs, toggle_use_faux_analog_inputs},
21542178
{"Enable Control:", toggle_allow_background_controllers, current_background_control_mode, toggle_allow_background_controllers},
21552179
{"Back", enter_controls_menu},

SDL/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ static void vblank(GB_gameboy_t *gb, GB_vblank_type_t type)
715715

716716
static void rumble(GB_gameboy_t *gb, double amp)
717717
{
718+
if (configuration.rumble_strength != 8) {
719+
double strength = configuration.rumble_strength / 8.0;
720+
amp = pow(amp, strength) * strength;
721+
}
718722
SDL_HapticRumblePlay(haptic, amp, 250);
719723
}
720724

@@ -1441,13 +1445,17 @@ int main(int argc, char **argv)
14411445
configuration.cgb_revision %= GB_MODEL_CGB_E - GB_MODEL_CGB_0 + 1;
14421446
configuration.audio_driver[15] = 0;
14431447
configuration.dmg_palette_name[24] = 0;
1444-
// Fix broken defaults, should keys 12-31 should be unmapped by default
1448+
// Fix broken defaults, keys 12-31 should be unmapped by default
14451449
if (configuration.joypad_configuration[31] == 0) {
14461450
memset(configuration.joypad_configuration + 12 , -1, 32 - 12);
14471451
}
14481452
if ((configuration.agb_revision & ~GB_MODEL_GBP_BIT) != GB_MODEL_AGB_A) {
14491453
configuration.agb_revision = GB_MODEL_AGB_A;
14501454
}
1455+
1456+
if (configuration.rumble_strength > 8 || configuration.rumble_strength == 0) {
1457+
configuration.rumble_strength = 8;
1458+
}
14511459
}
14521460

14531461
if (configuration.model >= MODEL_MAX) {

iOS/GBSettingsViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ + (UIImage *)settingsImageNamed:(NSString *)name
369369
@{@"type": typeRadio, @"pref": @"GBRumbleMode", @"title": @"Always", @"value": @(GB_RUMBLE_ALL_GAMES),},
370370
],
371371
},
372+
@{
373+
@"header": @"Rumble Strength",
374+
@"items": @[
375+
@{@"type": typeSlider, @"pref": @"GBRumbleStrength", @"min": @0.125, @"max": @1, @"minImage": @"waveform.weak", @"maxImage": @"waveform"}
376+
],
377+
},
372378
@{
373379
@"items": @[
374380
@{@"type": typeCheck, @"pref": @"GBControllersHideInterface", @"title": @"Hide UI While Using a Controller"},

iOS/GBViewController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static uint8_t cameraGetPixel(GB_gameboy_t *gb, uint8_t x, uint8_t y)
225225
static void rumbleCallback(GB_gameboy_t *gb, double amp)
226226
{
227227
GBViewController *self = (__bridge GBViewController *)GB_get_user_data(gb);
228+
double strength = [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBRumbleStrength"];
229+
if (strength != 1) {
230+
amp = pow(amp, strength) * strength;
231+
}
228232
[self rumbleChanged:amp];
229233
}
230234

0 commit comments

Comments
 (0)