Skip to content

Commit 7305be6

Browse files
committed
make now static sdl effect direction a template
1 parent 79681dd commit 7305be6

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

rpcs3/Emu/Io/LogitechG27.cpp

+18-22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
LOG_CHANNEL(logitech_g27_log, "LOGIG27");
2121

22+
// ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
23+
static const SDL_HapticDirection STEERING_DIRECTION = {
24+
.type = SDL_HAPTIC_STEERING_AXIS,
25+
.dir = {0, 0, 0}
26+
};
27+
2228
usb_device_logitech_g27::usb_device_logitech_g27(u32 controller_index, const std::array<u8, 7>& location)
2329
: usb_device_emulated(location), m_controller_index(controller_index)
2430
{
@@ -36,11 +42,7 @@ usb_device_logitech_g27::usb_device_logitech_g27(u32 controller_index, const std
3642
m_default_spring_effect.type = SDL_HAPTIC_SPRING;
3743

3844
// ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
39-
m_default_spring_effect.condition.direction = SDL_HapticDirection
40-
{
41-
.type = SDL_HAPTIC_STEERING_AXIS,
42-
.dir = {0, 0, 0}
43-
};
45+
m_default_spring_effect.condition.direction = STEERING_DIRECTION;
4446
m_default_spring_effect.condition.length = SDL_HAPTIC_INFINITY;
4547
for (int i = 0; i < 1 /*3*/; i++)
4648
{
@@ -790,12 +792,6 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
790792
// logitech_g27_log.error("%02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
791793
// printf("%02x %02x %02x %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
792794

793-
// ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
794-
SDL_HapticDirection direction = {
795-
.type = SDL_HAPTIC_STEERING_AXIS,
796-
.dir = {0, 0, 0}
797-
};
798-
799795
// TODO maybe force clipping from cfg
800796

801797
// Process effects
@@ -908,7 +904,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
908904
{
909905
// Constant force
910906
new_effect.type = SDL_HAPTIC_CONSTANT;
911-
new_effect.constant.direction = direction;
907+
new_effect.constant.direction = STEERING_DIRECTION;
912908
new_effect.constant.length = SDL_HAPTIC_INFINITY;
913909
new_effect.constant.level = logitech_g27_force_to_level(buf[2 + i], m_reverse_effects);
914910
break;
@@ -918,7 +914,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
918914
{
919915
// Spring/High resolution spring
920916
new_effect.type = SDL_HAPTIC_SPRING;
921-
new_effect.condition.direction = direction;
917+
new_effect.condition.direction = STEERING_DIRECTION;
922918
new_effect.condition.length = SDL_HAPTIC_INFINITY;
923919
const u8 s1 = buf[5] & 1;
924920
const u8 s2 = (buf[5] >> 4) & 1;
@@ -969,7 +965,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
969965
{
970966
// Damper/High resolution damper
971967
new_effect.type = SDL_HAPTIC_DAMPER;
972-
new_effect.condition.direction = direction;
968+
new_effect.condition.direction = STEERING_DIRECTION;
973969
new_effect.condition.length = SDL_HAPTIC_INFINITY;
974970
const u8 s1 = buf[3] & 1;
975971
const u8 s2 = buf[5] & 1;
@@ -1009,7 +1005,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
10091005
{
10101006
// Friction
10111007
new_effect.type = SDL_HAPTIC_FRICTION;
1012-
new_effect.condition.direction = direction;
1008+
new_effect.condition.direction = STEERING_DIRECTION;
10131009
new_effect.condition.length = SDL_HAPTIC_INFINITY;
10141010
const u8 k1 = buf[2];
10151011
const u8 k2 = buf[3];
@@ -1036,7 +1032,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
10361032
{
10371033
// Auto center spring/High resolution auto center spring
10381034
new_effect.type = SDL_HAPTIC_SPRING;
1039-
new_effect.condition.direction = direction;
1035+
new_effect.condition.direction = STEERING_DIRECTION;
10401036
new_effect.condition.length = SDL_HAPTIC_INFINITY;
10411037
const u16 saturation = logitech_g27_clip_to_saturation(buf[4]);
10421038
const u16 deadband = 2 * 0xFFFF / 255;
@@ -1082,7 +1078,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
10821078
else
10831079
new_effect.type = m_reverse_effects ? SDL_HAPTIC_SAWTOOTHUP : SDL_HAPTIC_SAWTOOTHDOWN;
10841080
new_effect.type = buf[1] == 0x04 ? SDL_HAPTIC_SAWTOOTHUP : SDL_HAPTIC_SAWTOOTHDOWN;
1085-
new_effect.periodic.direction = direction;
1081+
new_effect.periodic.direction = STEERING_DIRECTION;
10861082
new_effect.periodic.length = SDL_HAPTIC_INFINITY;
10871083
const u8 l1 = buf[2];
10881084
const u8 l2 = buf[3];
@@ -1106,7 +1102,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
11061102
{
11071103
// Trapezoid, convert to SDL_HAPTIC_SQUARE or SDL_HAPTIC_TRIANGLE
11081104
// TODO full accuracy will need some kind of rendering thread, cannot be represented with a single effect
1109-
new_effect.periodic.direction = direction;
1105+
new_effect.periodic.direction = STEERING_DIRECTION;
11101106
new_effect.periodic.length = SDL_HAPTIC_INFINITY;
11111107
const u8 l1 = buf[2];
11121108
const u8 l2 = buf[3];
@@ -1135,7 +1131,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
11351131
// Rectangle, convert to SDL_HAPTIC_SQUARE
11361132
// TODO full accuracy will need some kind of rendering thread, cannot be represented with a single effect
11371133
new_effect.type = SDL_HAPTIC_SQUARE;
1138-
new_effect.periodic.direction = direction;
1134+
new_effect.periodic.direction = STEERING_DIRECTION;
11391135
new_effect.periodic.length = SDL_HAPTIC_INFINITY;
11401136
const u8 l1 = buf[2];
11411137
const u8 l2 = buf[3];
@@ -1178,7 +1174,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
11781174
const u8 d = i == 0 ? d1 : d2;
11791175
const u8 l = i == 0 ? l1 : l2;
11801176
new_effect.constant.length = SDL_HAPTIC_INFINITY;
1181-
new_effect.constant.direction = direction;
1177+
new_effect.constant.direction = STEERING_DIRECTION;
11821178
if (s == 0 || t == 0)
11831179
{
11841180
// gran turismo 6 does this, gives a variable force with no step so it just behaves as constant force
@@ -1204,7 +1200,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
12041200
{
12051201

12061202
new_effect.type = SDL_HAPTIC_RAMP;
1207-
new_effect.ramp.direction = direction;
1203+
new_effect.ramp.direction = STEERING_DIRECTION;
12081204
const s16 l1_converted = logitech_g27_force_to_level(l1, m_reverse_effects);
12091205
const s16 l2_converted = logitech_g27_force_to_level(l2, m_reverse_effects);
12101206
new_effect.ramp.start = d1 ? l1_converted : l2_converted;
@@ -1221,7 +1217,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
12211217
{
12221218
// Square
12231219
new_effect.type = SDL_HAPTIC_SQUARE;
1224-
new_effect.periodic.direction = direction;
1220+
new_effect.periodic.direction = STEERING_DIRECTION;
12251221
const u8 a = buf[2];
12261222
const u8 tl = buf[3];
12271223
const u8 th = buf[4];

0 commit comments

Comments
 (0)