From ef103b6548bcae03ea43531c1ef44818da8a471e Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Thu, 23 May 2013 16:24:44 +0100
Subject: [PATCH] [Fix] Prevent acceleration from sticking sometimes.

---
 src/input.c | 21 ++++++++++++++++++++-
 src/input.h |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/input.c b/src/input.c
index 6c301e7..158fb80 100644
--- a/src/input.c
+++ b/src/input.c
@@ -113,6 +113,20 @@ void input_setKeybind(char* keybind, KeybindType type, int key, int reverse) {
   WARN("Unable to set keybind '%s', That command does not exist.", keybind);
 }
 
+// Get the value of a keybind.
+int input_getKeybind(char* keybind, KeybindType* type, int* reverse) {
+  int i;
+  for(i = 0; strcmp(keybindNames[i], "end"); i++)
+    if(strcmp(keybind, input_keybinds[i]->name)==0) {
+      if(type != NULL) (*type) = input_keybinds[i]->type;
+      if(reverse != NULL) (*reverse) = input_keybinds[i]->reverse;
+      return input_keybinds[i]->key;
+    }
+
+  WARN("Unable to get keybinding '%s', that command doesn't exist", keybind);
+  return -1;
+}
+
 // == Run input method. ================================================
 // keynum : Index of the input_keybinds keybind.
 // value  : Value of keypress (defined above).
@@ -131,7 +145,12 @@ static void input_key(int keynum, double value, int abs) {
   // Accelerating.
   if(INGAME() && KEY("accel")) {
     if(abs)player_acc = value;
-    else player_acc += value;
+    else {
+      // Prevent it from getting stuck.
+      if(value == KEY_PRESS) player_acc = 1.;
+      else if(value == KEY_RELEASE) player_acc = 0.;
+    }
+
     // Double tap accel = afterburn!
     t = SDL_GetTicks();
     if((value == KEY_PRESS) && (t-input_accelLast <= input_afterburnSensibility)) {
diff --git a/src/input.h b/src/input.h
index 6cacf69..9147766 100644
--- a/src/input.h
+++ b/src/input.h
@@ -12,6 +12,7 @@ typedef enum {
 // Set input.
 void input_setDefault(void);
 void input_setKeybind(char* keybind, KeybindType type, int key, int reverse);
+int  input_getKeybind(char* keybind, KeybindType* type, int* reverse);
 
 // Handle the events.
 void input_handle(SDL_Event* event);