ref: 5a35c4381b1559e5d12709f9692de4984f9c64e6
parent: a658822289e10e37363fc60153492738fb43095a
author: svdijk <[email protected]>
date: Mon Dec 23 09:45:20 EST 2013
heretic, hexen: Fix mouse (and joystick) weapon cycling. Implement this the same way it is implemented for doom and strife.
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -185,7 +185,7 @@
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,10 +681,54 @@
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 @@
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
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -152,7 +152,7 @@
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
@@ -671,7 +671,60 @@
}
}
+static void SetJoyButtons(unsigned int buttons_mask)
+{
+ int i;
+ for (i=0; i<MAX_JOY_BUTTONS; ++i)
+ {
+ 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;
+ }
+}
+
/*
===============================================================================
=
@@ -814,18 +867,13 @@
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
case ev_joystick:
- joybuttons[0] = ev->data1 & 1;
- joybuttons[1] = ev->data1 & 2;
- joybuttons[2] = ev->data1 & 4;
- joybuttons[3] = ev->data1 & 8;
+ SetJoyButtons(ev->data1);
joyxmove = ev->data2;
joyymove = ev->data3;
return (true); // eat events