diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-25 17:29:32 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-25 17:29:32 -0300 |
| commit | 6f4930e920b3f368d0fcb9acfd2824095b101681 (patch) | |
| tree | b6154c99c4fd67c7d3e6b94295bd182f2ac0fdfa /src/rumble.c | |
| parent | 776d0e8262e8206819f5475d08ff10caa855cca5 (diff) | |
Controller and Rumble stuff.
Diffstat (limited to 'src/rumble.c')
| -rw-r--r-- | src/rumble.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/rumble.c b/src/rumble.c new file mode 100644 index 0000000..2313d68 --- /dev/null +++ b/src/rumble.c @@ -0,0 +1,50 @@ +/* +I made this a separate source file because Raylib has some quirks +regarding Windows compilation. And I also suppose because it has +some state of its own. +*/ + +#include "controller.h" + +// Windows stuff starts // +typedef struct _XINPUT_VIBRATION { + unsigned wLeftMotorSpeed; + unsigned wRightMotorSpeed; +} XINPUT_VIBRATION; +unsigned int XInputSetState(unsigned int dwUserIndex, XINPUT_VIBRATION *pVibration); +// Windows stuff ends // + +static fx32 timer = 0; + +void set_rumble(f32 duration, f32 strength) +{ + XINPUT_VIBRATION state = {}; + state.wLeftMotorSpeed = (unsigned)(strength * 65535.0f); + state.wRightMotorSpeed = (unsigned)(strength * 65535.0f); + + if (XInputSetState(0, &state) == 0){ + timer = FIXED_POINT_ONE * duration; + } +} + +void poll_rumble(f32 dt) +{ + if(timer <= 0) + return; + + fx32 delta = FIXED_POINT_ONE * dt; + + timer -= delta; + if(timer <= 0){ + stop_rumble(); + } +} + +void stop_rumble(void) +{ + timer = 0; + + XINPUT_VIBRATION state = {}; + state.wLeftMotorSpeed = 0; + state.wRightMotorSpeed = 0; +}
\ No newline at end of file |
