From 1fc23b2f4f9c46a4cc3bb86c61726b2b9b5a65c3 Mon Sep 17 00:00:00 2001 From: skyjake Date: Wed, 11 Feb 2004 10:37:38 +0000 Subject: [PATCH] Different axis types: pointer, stick --- doomsday/Src/con_bind.c | 15 ++++++++++++++- doomsday/Src/dd_input.c | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/doomsday/Src/con_bind.c b/doomsday/Src/con_bind.c index f7a15d7baa..f10c66d1ea 100644 --- a/doomsday/Src/con_bind.c +++ b/doomsday/Src/con_bind.c @@ -178,13 +178,26 @@ void B_UpdateAxisControls(void) for(i = 0, ab = axisBinds; i < numAxisBinds; i++, ab++) { axis = &ab->device->axes[ab->axis]; + // Invert the axis position, if requested. if(ab->invert) pos = -axis->position; else pos = axis->position; + // Update the control state. - P_ControlSetAxis(P_LocalToConsole(ab->localPlayer), ab->control, pos); + switch(ab->device->axes[ab->axis].type) + { + case IDAT_STICK: // joysticks, gamepads + P_ControlSetAxis(P_LocalToConsole(ab->localPlayer), + ab->control, pos); + break; + + case IDAT_POINTER: // mouse + P_ControlAxisDelta(P_LocalToConsole(ab->localPlayer), + ab->control, pos); + break; + } } } diff --git a/doomsday/Src/dd_input.c b/doomsday/Src/dd_input.c index 671b2224ae..31e9d7ce82 100644 --- a/doomsday/Src/dd_input.c +++ b/doomsday/Src/dd_input.c @@ -198,6 +198,8 @@ inputdevaxis_t *I_DeviceNewAxis(inputdev_t *dev, const char *name) memset(axis, 0, sizeof(*axis)); strcpy(axis->name, name); + axis->type = IDAT_STICK; + // Set reasonable defaults. The user's settings will be restored // later. axis->scale = 1/10.0f; @@ -229,8 +231,8 @@ void I_InitInputDevices(void) // The wheel is translated to keys, so there is no need to // create an axis for it. - I_DeviceNewAxis(dev, "x"); - I_DeviceNewAxis(dev, "y"); + I_DeviceNewAxis(dev, "x")->type = IDAT_POINTER; + I_DeviceNewAxis(dev, "y")->type = IDAT_POINTER; if(I_MousePresent()) dev->flags = ID_ACTIVE; @@ -350,15 +352,18 @@ void I_UpdateAxis(inputdev_t *dev, int axis, float pos) // Apply scaling, deadzone and clamping. pos *= a->scale; - if(fabs(pos) <= a->deadZone) + if(a->type == IDAT_STICK) // Pointer axes are exempt. { - a->position = 0; - return; + if(fabs(pos) <= a->deadZone) + { + a->position = 0; + return; + } + pos += a->deadZone * (pos > 0? -1 : 1); // Remove the dead zone. + pos *= 1.0f/(1.0f - a->deadZone); // Normalize. + if(pos < -1.0f) pos = -1.0f; + if(pos > 1.0f) pos = 1.0f; } - pos += a->deadZone * (pos > 0? -1 : 1); // Remove the dead zone. - pos *= 1.0f/(1.0f - a->deadZone); // Normalize. - if(pos < -1.0f) pos = -1.0f; - if(pos > 1.0f) pos = 1.0f; if(a->flags & IDA_INVERT) {