summaryrefslogtreecommitdiff
path: root/src/heretic/g_game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/heretic/g_game.c')
-rw-r--r--src/heretic/g_game.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index e9302e83..20858cb7 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -185,7 +185,7 @@ int turnheld; // for accelerative turning
int lookheld;
-boolean mousearray[4];
+boolean mousearray[MAX_MOUSE_BUTTONS + 1];
boolean *mousebuttons = &mousearray[1];
// allow [-1]
int mousex, mousey; // mouse values are used once
@@ -681,7 +681,51 @@ static void SetJoyButtons(unsigned int buttons_mask)
for (i=0; i<MAX_JOY_BUTTONS; ++i)
{
- joybuttons[i] = (buttons_mask & (1 << i)) != 0;
+ int button_on = (buttons_mask & (1 << i)) != 0;
+
+ // Detect button press:
+
+ if (!joybuttons[i] && button_on)
+ {
+ // Weapon cycling:
+
+ if (i == joybprevweapon)
+ {
+ next_weapon = -1;
+ }
+ else if (i == joybnextweapon)
+ {
+ next_weapon = 1;
+ }
+ }
+
+ joybuttons[i] = button_on;
+ }
+}
+
+static void SetMouseButtons(unsigned int buttons_mask)
+{
+ int i;
+
+ for (i=0; i<MAX_MOUSE_BUTTONS; ++i)
+ {
+ unsigned int button_on = (buttons_mask & (1 << i)) != 0;
+
+ // Detect button press:
+
+ if (!mousebuttons[i] && button_on)
+ {
+ if (i == mousebprevweapon)
+ {
+ next_weapon = -1;
+ }
+ else if (i == mousebnextweapon)
+ {
+ next_weapon = 1;
+ }
+ }
+
+ mousebuttons[i] = button_on;
}
}
@@ -826,9 +870,7 @@ boolean G_Responder(event_t * ev)
return (false); // always let key up events filter down
case ev_mouse:
- mousebuttons[0] = ev->data1 & 1;
- mousebuttons[1] = ev->data1 & 2;
- mousebuttons[2] = ev->data1 & 4;
+ SetMouseButtons(ev->data1);
mousex = ev->data2 * (mouseSensitivity + 5) / 10;
mousey = ev->data3 * (mouseSensitivity + 5) / 10;
return (true); // eat events