aboutsummaryrefslogtreecommitdiff
path: root/src/rumble.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rumble.c')
-rw-r--r--src/rumble.c50
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