mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
Updates the SDL library to the latest standard bugfix release
This commit is contained in:
parent
cb766f2878
commit
083d2175ea
1280 changed files with 343926 additions and 179615 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -31,51 +31,73 @@
|
|||
#define BUTTON_SIZE 50
|
||||
#define AXIS_SIZE 50
|
||||
|
||||
#define BUTTON_SIZE 50
|
||||
#define AXIS_SIZE 50
|
||||
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{431, 132}, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{342, 132}, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{389, 101}, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{174, 132}, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{232, 128}, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{289, 132}, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{75, 154}, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{305, 230}, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{77, 40}, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{396, 36}, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{154, 188}, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{154, 249}, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{116, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{186, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{232, 174}, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{132, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{330, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{132, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{330, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{0, 0}, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
static const struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} button_positions[] = {
|
||||
{ 387, 167 }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{ 431, 132 }, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{ 342, 132 }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{ 389, 101 }, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{ 174, 132 }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 232, 128 }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132 }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154 }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230 }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40 }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36 }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188 }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249 }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{ 186, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{ 232, 174 }, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{ 132, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{ 330, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{ 132, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{ 330, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{ 0, 0 }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(button_positions, SDL_arraysize(button_positions) == SDL_CONTROLLER_BUTTON_MAX);
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{74, 153, 270.0}, /* LEFTX */
|
||||
{74, 153, 0.0}, /* LEFTY */
|
||||
{306, 231, 270.0}, /* RIGHTX */
|
||||
{306, 231, 0.0}, /* RIGHTY */
|
||||
{91, -20, 0.0}, /* TRIGGERLEFT */
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
static const struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
double angle;
|
||||
} axis_positions[] = {
|
||||
{ 74, 153, 270.0 }, /* LEFTX */
|
||||
{ 74, 153, 0.0 }, /* LEFTY */
|
||||
{ 306, 231, 270.0 }, /* RIGHTX */
|
||||
{ 306, 231, 0.0 }, /* RIGHTY */
|
||||
{ 91, -20, 0.0 }, /* TRIGGERLEFT */
|
||||
{ 375, -20, 0.0 }, /* TRIGGERRIGHT */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(axis_positions, SDL_arraysize(axis_positions) == SDL_CONTROLLER_AXIS_MAX);
|
||||
|
||||
/* This is indexed by SDL_JoystickPowerLevel + 1. */
|
||||
static const char *power_level_strings[] = {
|
||||
"unknown", /* SDL_JOYSTICK_POWER_UNKNOWN */
|
||||
"empty", /* SDL_JOYSTICK_POWER_EMPTY */
|
||||
"low", /* SDL_JOYSTICK_POWER_LOW */
|
||||
"medium", /* SDL_JOYSTICK_POWER_MEDIUM */
|
||||
"full", /* SDL_JOYSTICK_POWER_FULL */
|
||||
"wired", /* SDL_JOYSTICK_POWER_WIRED */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(power_level_strings, SDL_arraysize(power_level_strings) == SDL_JOYSTICK_POWER_MAX + 1);
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *screen = NULL;
|
||||
static SDL_bool retval = SDL_FALSE;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
static SDL_bool set_LED = SDL_FALSE;
|
||||
static int trigger_effect = 0;
|
||||
static SDL_Texture *background_front, *background_back, *button, *axis;
|
||||
static SDL_Texture *background_front, *background_back, *button_texture, *axis_texture;
|
||||
static SDL_GameController *gamecontroller;
|
||||
static SDL_GameController **gamecontrollers;
|
||||
static int num_controllers = 0;
|
||||
|
|
@ -87,7 +109,7 @@ static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_IN
|
|||
|
||||
static void UpdateWindowTitle()
|
||||
{
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -95,14 +117,17 @@ static void UpdateWindowTitle()
|
|||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *serial = SDL_GameControllerGetSerial(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
|
||||
const size_t titlelen = SDL_strlen(basetitle) + (name ? SDL_strlen(name) : 0) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
|
||||
retval = SDL_FALSE;
|
||||
done = SDL_FALSE;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
SDL_strlcpy(title, basetitle, titlelen);
|
||||
if (name) {
|
||||
SDL_strlcat(title, name, titlelen);
|
||||
}
|
||||
if (serial) {
|
||||
SDL_strlcat(title, " (", titlelen);
|
||||
SDL_strlcat(title, serial, titlelen);
|
||||
|
|
@ -116,6 +141,26 @@ static void UpdateWindowTitle()
|
|||
}
|
||||
}
|
||||
|
||||
static const char *GetSensorName(SDL_SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SDL_SENSOR_ACCEL:
|
||||
return "accelerometer";
|
||||
case SDL_SENSOR_GYRO:
|
||||
return "gyro";
|
||||
case SDL_SENSOR_ACCEL_L:
|
||||
return "accelerometer (L)";
|
||||
case SDL_SENSOR_GYRO_L:
|
||||
return "gyro (L)";
|
||||
case SDL_SENSOR_ACCEL_R:
|
||||
return "accelerometer (R)";
|
||||
case SDL_SENSOR_GYRO_R:
|
||||
return "gyro (R)";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static int FindController(SDL_JoystickID controller_id)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -133,6 +178,16 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
SDL_JoystickID controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
SDL_GameController *controller;
|
||||
SDL_GameController **controllers;
|
||||
Uint16 firmware_version;
|
||||
SDL_SensorType sensors[] = {
|
||||
SDL_SENSOR_ACCEL,
|
||||
SDL_SENSOR_GYRO,
|
||||
SDL_SENSOR_ACCEL_L,
|
||||
SDL_SENSOR_GYRO_L,
|
||||
SDL_SENSOR_ACCEL_R,
|
||||
SDL_SENSOR_GYRO_R
|
||||
};
|
||||
unsigned int i;
|
||||
|
||||
controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
if (controller_id < 0) {
|
||||
|
|
@ -146,13 +201,13 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
}
|
||||
|
||||
controller = SDL_GameControllerOpen(device_index);
|
||||
if (!controller) {
|
||||
if (controller == NULL) {
|
||||
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers));
|
||||
if (!controllers) {
|
||||
if (controllers == NULL) {
|
||||
SDL_GameControllerClose(controller);
|
||||
return;
|
||||
}
|
||||
|
|
@ -168,18 +223,22 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
SDL_Log("Opened game controller %s%s%s\n", name, path ? ", " : "", path ? path : "");
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
|
||||
firmware_version = SDL_GameControllerGetFirmwareVersion(gamecontroller);
|
||||
if (firmware_version) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling accelerometer at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_ACCEL));
|
||||
SDL_Log("Firmware version: 0x%x (%d)\n", firmware_version, firmware_version);
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_GYRO)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling gyro at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_GYRO));
|
||||
for (i = 0; i < SDL_arraysize(sensors); ++i) {
|
||||
SDL_SensorType sensor = sensors[i];
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, sensor)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling %s at %.2f Hz\n", GetSensorName(sensor), SDL_GameControllerGetSensorDataRate(gamecontroller, sensor));
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, sensor, SDL_TRUE);
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasRumble(gamecontroller)) {
|
||||
|
|
@ -219,7 +278,7 @@ static void DelController(SDL_JoystickID controller)
|
|||
|
||||
--num_controllers;
|
||||
if (i < num_controllers) {
|
||||
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i+1], (num_controllers - i) * sizeof(*gamecontrollers));
|
||||
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i + 1], (num_controllers - i) * sizeof(*gamecontrollers));
|
||||
}
|
||||
|
||||
if (num_controllers > 0) {
|
||||
|
|
@ -246,35 +305,34 @@ static Uint16 ConvertAxisToRumble(Sint16 axisval)
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucLedFlags; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucLedFlags; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
} DS5EffectsState_t;
|
||||
|
||||
static void CyclePS5TriggerEffect()
|
||||
{
|
||||
DS5EffectsState_t state;
|
||||
|
||||
Uint8 effects[3][11] =
|
||||
{
|
||||
Uint8 effects[3][11] = {
|
||||
/* Clear trigger effect */
|
||||
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
/* Constant resistance across entire trigger pull */
|
||||
|
|
@ -355,7 +413,7 @@ static void OpenVirtualController()
|
|||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
} else {
|
||||
virtual_joystick = SDL_JoystickOpen(virtual_index);
|
||||
if (!virtual_joystick) {
|
||||
if (virtual_joystick == NULL) {
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -365,7 +423,7 @@ static void CloseVirtualController()
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = SDL_NumJoysticks(); i--; ) {
|
||||
for (i = SDL_NumJoysticks(); i--;) {
|
||||
if (SDL_JoystickIsVirtual(i)) {
|
||||
SDL_JoystickDetachVirtual(i);
|
||||
}
|
||||
|
|
@ -460,7 +518,7 @@ static void VirtualControllerMouseMotion(int x, int y)
|
|||
valueY = (Sint16)(distanceY * -SDL_JOYSTICK_AXIS_MIN);
|
||||
}
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, valueY);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, valueY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -497,14 +555,13 @@ static void VirtualControllerMouseUp(int x, int y)
|
|||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
|
||||
} else {
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, 0);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, 0);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, 0);
|
||||
}
|
||||
virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
void loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
|
@ -517,40 +574,38 @@ loop(void *arg)
|
|||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
SDL_Log("Game controller device %d added.\n", (int) SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
SDL_Log("Game controller device %d added.\n", (int)SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
AddController(event.cdevice.which, SDL_TRUE);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
SDL_Log("Game controller device %d removed.\n", (int) event.cdevice.which);
|
||||
SDL_Log("Game controller device %d removed.\n", (int)event.cdevice.which);
|
||||
DelController(event.cdevice.which);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERTOUCHPADDOWN:
|
||||
case SDL_CONTROLLERTOUCHPADMOTION:
|
||||
case SDL_CONTROLLERTOUCHPADUP:
|
||||
SDL_Log("Controller %d touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.which,
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" :
|
||||
(event.type == SDL_CONTROLLERTOUCHPADUP ? "released at" :
|
||||
"moved to")),
|
||||
event.ctouchpad.x,
|
||||
event.ctouchpad.y,
|
||||
event.ctouchpad.pressure);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " touchpad %" SDL_PRIs32 " finger %" SDL_PRIs32 " %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.which,
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" : (event.type == SDL_CONTROLLERTOUCHPADUP ? "released at" : "moved to")),
|
||||
event.ctouchpad.x,
|
||||
event.ctouchpad.y,
|
||||
event.ctouchpad.pressure);
|
||||
break;
|
||||
|
||||
#define VERBOSE_SENSORS
|
||||
#ifdef VERBOSE_SENSORS
|
||||
case SDL_CONTROLLERSENSORUPDATE:
|
||||
SDL_Log("Controller %d sensor %s: %.2f, %.2f, %.2f\n",
|
||||
event.csensor.which,
|
||||
event.csensor.sensor == SDL_SENSOR_ACCEL ? "accelerometer" :
|
||||
event.csensor.sensor == SDL_SENSOR_GYRO ? "gyro" : "unknown",
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2]);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " sensor %s: %.2f, %.2f, %.2f (%" SDL_PRIu64 ")\n",
|
||||
event.csensor.which,
|
||||
GetSensorName((SDL_SensorType)event.csensor.sensor),
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2],
|
||||
event.csensor.timestamp_us);
|
||||
break;
|
||||
#endif /* VERBOSE_SENSORS */
|
||||
|
||||
|
|
@ -560,7 +615,7 @@ loop(void *arg)
|
|||
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
|
||||
SetController(event.caxis.which);
|
||||
}
|
||||
SDL_Log("Controller %d axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
break;
|
||||
#endif /* VERBOSE_AXES */
|
||||
|
||||
|
|
@ -569,7 +624,7 @@ loop(void *arg)
|
|||
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
SetController(event.cbutton.which);
|
||||
}
|
||||
SDL_Log("Controller %d button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
|
||||
/* Cycle PS5 trigger effects when the microphone button is pressed */
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
|
||||
|
|
@ -579,6 +634,10 @@ loop(void *arg)
|
|||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYBATTERYUPDATED:
|
||||
SDL_Log("Controller %" SDL_PRIs32 " battery state changed to %s\n", event.jbattery.which, power_level_strings[event.jbattery.level + 1]);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (virtual_joystick) {
|
||||
VirtualControllerMouseDown(event.button.x, event.button.y);
|
||||
|
|
@ -644,14 +703,14 @@ loop(void *arg)
|
|||
dst.y = button_positions[i].y;
|
||||
dst.w = BUTTON_SIZE;
|
||||
dst.h = BUTTON_SIZE;
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, button_texture, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showing_front) {
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const double angle = axis_positions[i].angle;
|
||||
|
|
@ -660,7 +719,7 @@ loop(void *arg)
|
|||
dst.y = axis_positions[i].y;
|
||||
dst.w = AXIS_SIZE;
|
||||
dst.h = AXIS_SIZE;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, axis_texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
} else if (value > deadzone) {
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_Rect dst;
|
||||
|
|
@ -668,7 +727,7 @@ loop(void *arg)
|
|||
dst.y = axis_positions[i].y;
|
||||
dst.w = AXIS_SIZE;
|
||||
dst.h = AXIS_SIZE;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, axis_texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -685,14 +744,14 @@ loop(void *arg)
|
|||
Uint8 r, g, b;
|
||||
|
||||
if (x < 0) {
|
||||
r = (Uint8)(((int)(~x) * 255) / 32767);
|
||||
r = (Uint8)(((~x) * 255) / 32767);
|
||||
b = 0;
|
||||
} else {
|
||||
r = 0;
|
||||
b = (Uint8)(((int)(x) * 255) / 32767);
|
||||
b = (Uint8)(((int)(x)*255) / 32767);
|
||||
}
|
||||
if (y > 0) {
|
||||
g = (Uint8)(((int)(y) * 255) / 32767);
|
||||
g = (Uint8)(((int)(y)*255) / 32767);
|
||||
} else {
|
||||
g = 0;
|
||||
}
|
||||
|
|
@ -732,8 +791,7 @@ loop(void *arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int controller_count = 0;
|
||||
|
|
@ -741,9 +799,9 @@ main(int argc, char *argv[])
|
|||
char guid[64];
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ROG_CHAKRAM, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
SDL_SetHint(SDL_HINT_LINUX_JOYSTICK_DEADZONES, "1");
|
||||
|
|
@ -752,7 +810,7 @@ main(int argc, char *argv[])
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -779,7 +837,7 @@ main(int argc, char *argv[])
|
|||
const char *description;
|
||||
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
|
||||
guid, sizeof (guid));
|
||||
guid, sizeof(guid));
|
||||
|
||||
if (SDL_IsGameController(i)) {
|
||||
controller_count++;
|
||||
|
|
@ -792,6 +850,11 @@ main(int argc, char *argv[])
|
|||
case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
|
||||
description = "Google Stadia Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT:
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT:
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
|
||||
description = "Nintendo Switch Joy-Con";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
description = "Nintendo Switch Pro Controller";
|
||||
break;
|
||||
|
|
@ -824,8 +887,8 @@ main(int argc, char *argv[])
|
|||
description = "Joystick";
|
||||
}
|
||||
SDL_Log("%s %d: %s%s%s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
|
||||
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());
|
||||
|
||||
|
|
@ -854,16 +917,16 @@ main(int argc, char *argv[])
|
|||
|
||||
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE, NULL, NULL);
|
||||
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE, NULL, NULL);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
|
||||
button_texture = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
|
||||
axis_texture = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
|
||||
|
||||
if (!background_front || !background_back || !button || !axis) {
|
||||
if (background_front == NULL || background_back == NULL || button_texture == NULL || axis_texture == NULL) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return 2;
|
||||
}
|
||||
SDL_SetTextureColorMod(button, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(button_texture, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis_texture, 10, 255, 21);
|
||||
|
||||
/* !!! FIXME: */
|
||||
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue