Skip to content

Commit

Permalink
engine: platform: add improved Platform_Vibrate2 function, that allow…
Browse files Browse the repository at this point in the history
…s to control vibration strength
  • Loading branch information
a1batross committed Feb 1, 2025
1 parent 694c630 commit 1b44d77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion engine/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ static inline void Sys_RestoreCrashHandler( void )
==============================================================================
*/
void Platform_Vibrate( float life, char flags );
void Platform_Vibrate( float life, char flags ); // left for compatibility
void Platform_Vibrate2( float time, int low_freq, int high_freq, uint flags );

/*
==============================================================================
Expand Down
31 changes: 21 additions & 10 deletions engine/platform/sdl/joy_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,37 @@ void SDLash_HandleGameControllerEvent( SDL_Event *ev )
}
}

/*
=============
Platform_Vibrate
=============
*/
void Platform_Vibrate( float time, char flags )
void Platform_Vibrate2( float time, int val1, int val2, uint flags )
{
#if SDL_VERSION_ATLEAST( 2, 0, 9 )
SDL_GameController *gc = g_current_gamepad;
Uint32 ms;

if( g_current_gamepad_id < 0 || !gc )
return;

// a1ba: time is in milliseconds but might be not enough
// to spin up rumble
SDL_GameControllerRumble( gc, 0xFFFF, 0xFFFF, (int)floor( time ));
if( val1 < 0 )
val1 = COM_RandomLong( 0x7FFF, 0xFFFF );

if( val2 < 0 )
val2 = COM_RandomLong( 0x7FFF, 0xFFFF );

ms = (Uint32)ceil( time );
SDL_GameControllerRumble( gc, val1, val2, ms );
#endif // SDL_VERSION_ATLEAST( 2, 0, 9 )
}

/*
=============
Platform_Vibrate
=============
*/
void Platform_Vibrate( float time, char flags )
{
Platform_Vibrate2( time, -1, -1, flags );
}

/*
=============
Platform_JoyInit
Expand Down

0 comments on commit 1b44d77

Please sign in to comment.