prelim work for sensors and other outputs
This commit is contained in:
parent
f770b5c8f5
commit
ca9abfc9f8
7 changed files with 140 additions and 4 deletions
|
|
@ -29,6 +29,7 @@ typedef enum
|
|||
ev_console,
|
||||
ev_mouse,
|
||||
ev_joystick,
|
||||
ev_sensor,
|
||||
} evtype_t;
|
||||
|
||||
// Event structure.
|
||||
|
|
|
|||
|
|
@ -471,6 +471,20 @@ static keyname_t keynames[] =
|
|||
{KEY_AXIS1+7, "R-STICK DOWN"},
|
||||
{KEY_AXIS1+8, "L TRIGGER"},
|
||||
{KEY_AXIS1+9, "R TRIGGER"},
|
||||
|
||||
{KEY_ACCELEROMETER1+0, "TILT -X"},
|
||||
{KEY_ACCELEROMETER1+1, "TILT +X"},
|
||||
{KEY_ACCELEROMETER1+2, "TILT -Y"},
|
||||
{KEY_ACCELEROMETER1+3, "TILT +Y"},
|
||||
{KEY_ACCELEROMETER1+4, "TILT -Z"},
|
||||
{KEY_ACCELEROMETER1+5, "TILT +Z"},
|
||||
|
||||
{KEY_GYROSCOPE1+0, "ROTATE -X"},
|
||||
{KEY_GYROSCOPE1+1, "ROTATE +X"},
|
||||
{KEY_GYROSCOPE1+2, "ROTATE -Y"},
|
||||
{KEY_GYROSCOPE1+3, "ROTATE +Y"},
|
||||
{KEY_GYROSCOPE1+4, "ROTATE -Z"},
|
||||
{KEY_GYROSCOPE1+5, "ROTATE +Z"},
|
||||
};
|
||||
|
||||
static const char *gamecontrolname[num_gamecontrols] =
|
||||
|
|
|
|||
|
|
@ -32,10 +32,11 @@ extern "C" {
|
|||
#define JOYBUTTONS 26 // 26 buttons, to match SDL_GameControllerButton
|
||||
#define JOY_DPAD_UP 11
|
||||
|
||||
#define JOYANALOGS 4 // 4 analog stick axes (2 sticks * 2 axes)
|
||||
#define JOYTRIGGERS 2 // 2 trigger axes, positive only
|
||||
#define JOYAXISES (JOYANALOGS + JOYTRIGGERS)
|
||||
#define JOYAXISKEYS ((2 * JOYANALOGS) + JOYTRIGGERS)
|
||||
#define JOYANALOGS 4 // 4 analog stick axes (2 sticks * 2 axes)
|
||||
#define JOYTRIGGERS 2 // 2 trigger axes, positive only
|
||||
#define JOYIMUAXISES 6 // 3 accelerometer, 3 gyroscope axes (x, y, z)
|
||||
#define JOYAXISES (JOYANALOGS + JOYTRIGGERS + JOYIMUAXISES)
|
||||
#define JOYAXISKEYS ((2 * JOYANALOGS) + JOYTRIGGERS + (2 * JOYIMUAXISES))
|
||||
|
||||
#define MAXINPUTMAPPING 4
|
||||
|
||||
|
|
@ -47,6 +48,8 @@ typedef enum
|
|||
KEY_JOY1 = NUMKEYS,
|
||||
KEY_HAT1 = KEY_JOY1 + JOY_DPAD_UP,
|
||||
KEY_AXIS1 = KEY_JOY1 + JOYBUTTONS,
|
||||
KEY_ACCELEROMETER1 = KEY_AXIS1 + JOYANALOGS + JOYTRIGGERS,
|
||||
KEY_GYROSCOPE1 = KEY_ACCELEROMETER1 + 6,
|
||||
JOYINPUTEND = KEY_AXIS1 + JOYAXISKEYS,
|
||||
|
||||
KEY_MOUSE1 = JOYINPUTEND,
|
||||
|
|
|
|||
|
|
@ -108,7 +108,12 @@ const char *I_GetControllerName(INT32 joyid);
|
|||
INT32 I_GetControllerSlotfromID(INT32 id);
|
||||
|
||||
boolean I_ControllerSupportsRumble(INT32 playernum);
|
||||
boolean I_ControllerSupportsIndicatorMono(INT32 playernum);
|
||||
boolean I_ControllerSupportsIndicatorColor(INT32 playernum);
|
||||
boolean I_ControllerSupportsIndicatorPlayer(INT32 playernum);
|
||||
|
||||
boolean I_ControllerSupportsSensorAccelerometer(INT32 playernum);
|
||||
boolean I_ControllerSupportsSensorGyro(INT32 playernum);
|
||||
|
||||
void I_ControllerRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration);
|
||||
void I_SetControllerIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 blue);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,12 @@ static void I_ControllerReset(controllerinfo_t *controller)
|
|||
controller->id = -1;
|
||||
//controller->name = NULL;
|
||||
controller->hasrumble = false;
|
||||
controller->hasmonoled = false;
|
||||
controller->hasrgbled = false;
|
||||
controller->hasplayerled = false;
|
||||
controller->hasaccelerometer = false;
|
||||
controller->hasgyro = false;
|
||||
controller->flipbuttons = false;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -218,6 +223,12 @@ void I_InitController(UINT8 playernum)
|
|||
SDL_PropertiesID controllerproperties = SDL_GetGamepadProperties(newcontroller);
|
||||
controller->hasrumble = SDL_GetBooleanProperty(controllerproperties, SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, false);
|
||||
controller->hasrgbled = SDL_GetBooleanProperty(controllerproperties, SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN, false);
|
||||
controller->hasmonoled = SDL_GetBooleanProperty(controllerproperties, SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN, false) && (!controller->hasrgbled);
|
||||
controller->hasplayerled = SDL_GetBooleanProperty(controllerproperties, SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN, false);
|
||||
|
||||
controller->hasaccelerometer = SDL_GamepadHasSensor(newcontroller, SDL_SENSOR_ACCEL);
|
||||
controller->hasgyro = SDL_GamepadHasSensor(newcontroller, SDL_SENSOR_GYRO);
|
||||
|
||||
controller->flipbuttons = SDL_GetGamepadButtonLabel(newcontroller, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B;
|
||||
}
|
||||
|
||||
|
|
@ -378,11 +389,31 @@ boolean I_ControllerSupportsRumble(INT32 playernum)
|
|||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasrumble);
|
||||
}
|
||||
|
||||
boolean I_ControllerSupportsIndicatorMono(INT32 playernum)
|
||||
{
|
||||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasmonoled);
|
||||
}
|
||||
|
||||
boolean I_ControllerSupportsIndicatorColor(INT32 playernum)
|
||||
{
|
||||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasrgbled);
|
||||
}
|
||||
|
||||
boolean I_ControllerSupportsIndicatorPlayer(INT32 playernum)
|
||||
{
|
||||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasplayerled);
|
||||
}
|
||||
|
||||
boolean I_ControllerSupportsSensorAccelerometer(INT32 playernum)
|
||||
{
|
||||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasaccelerometer);
|
||||
}
|
||||
|
||||
boolean I_ControllerSupportsSensorGyro(INT32 playernum)
|
||||
{
|
||||
return (controllerInfo[playernum].dev && controllerInfo[playernum].hasgyro);
|
||||
}
|
||||
|
||||
void I_ControllerRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration)
|
||||
{
|
||||
SDL_Gamepad *controller = controllerInfo[playernum].dev;
|
||||
|
|
@ -407,4 +438,28 @@ void I_SetControllerIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT
|
|||
SDL_SetGamepadLED(controller, red, green, blue);
|
||||
}
|
||||
|
||||
void I_SetControllerIndicatorMonochrome(INT32 playernum, UINT8 brightness)
|
||||
{
|
||||
SDL_Gamepad *controller = controllerInfo[playernum].dev;
|
||||
|
||||
if (controller == NULL || !I_ControllerSupportsIndicatorMono(playernum))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_SetGamepadLED(controller, brightness, 0, 0);
|
||||
}
|
||||
|
||||
void I_SetControllerPlayerNumber(INT32 playernum, INT32 number)
|
||||
{
|
||||
SDL_Gamepad *controller = controllerInfo[playernum].dev;
|
||||
|
||||
if (controller == NULL || !I_ControllerSupportsIndicatorPlayer(playernum))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_SetGamepadPlayerIndex(controller, number);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -937,6 +937,50 @@ static void Impl_HandleControllerButtonEvent(SDL_GamepadButtonEvent evt, Uint32
|
|||
}
|
||||
}
|
||||
|
||||
static void Impl_HandleControllerSensorEvent(SDL_GamepadSensorEvent evt)
|
||||
{
|
||||
event_t event;
|
||||
|
||||
event.type = ev_sensor;
|
||||
|
||||
event.device = 1 + evt.which;
|
||||
|
||||
event.data1 = event.data2 = event.data3 = INT32_MAX;
|
||||
|
||||
if (event.device == INT32_MAX)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt.sensor)
|
||||
{
|
||||
// data[0]: x acceleration in m/s
|
||||
// data[1]: y acceleration in m/s
|
||||
// data[2]: z acceleration in m/s
|
||||
case SDL_SENSOR_ACCEL:
|
||||
event.data1 = FLOAT_TO_FIXED(evt.data[0]);
|
||||
event.data2 = FLOAT_TO_FIXED(evt.data[1]);
|
||||
event.data3 = FLOAT_TO_FIXED(evt.data[2]);
|
||||
break;
|
||||
|
||||
// data[0]: delta pitch in rad/s
|
||||
// data[1]: delta yaw in rad/s
|
||||
// data[2]: delta roll in rad/s
|
||||
case SDL_SENSOR_GYRO:
|
||||
#define RAD2DEG 57.295779513f
|
||||
event.data1 = FixedAngle(FLOAT_TO_FIXED(RAD2DEG * evt.data[0]));
|
||||
event.data2 = FixedAngle(FLOAT_TO_FIXED(RAD2DEG * evt.data[1]));
|
||||
event.data3 = FixedAngle(FLOAT_TO_FIXED(RAD2DEG * evt.data[2]));
|
||||
#undef RAD2DEG
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
|
||||
static void Impl_HandleControllerAddEvent(SDL_Event evt)
|
||||
{
|
||||
UINT8 i;
|
||||
|
|
@ -1027,6 +1071,9 @@ void I_GetEvent(void)
|
|||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
Impl_HandleControllerButtonEvent(evt.gbutton, evt.type);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE:
|
||||
Impl_HandleControllerSensorEvent(evt.gsensor);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_ADDED:
|
||||
Impl_HandleControllerAddEvent(evt);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -52,10 +52,21 @@ typedef struct SDLJoyInfo_s
|
|||
//const char *name;
|
||||
/// scale of axises
|
||||
INT32 scale;
|
||||
|
||||
// Rumble Support
|
||||
boolean hasrumble;
|
||||
// Mono LED Support
|
||||
boolean hasmonoled;
|
||||
// RGB LED Support
|
||||
boolean hasrgbled;
|
||||
// Player LED Support
|
||||
boolean hasplayerled;
|
||||
|
||||
// Accelerometer Support
|
||||
boolean hasaccelerometer;
|
||||
// Gyroscope Support
|
||||
boolean hasgyro;
|
||||
|
||||
// you can pry my nintendo button layout out of my cold dead hands, SDL3
|
||||
boolean flipbuttons;
|
||||
} controllerinfo_t;
|
||||
|
|
|
|||
Loading…
Reference in a new issue