3 #include "../Dialogs/InformationDialog.h" 4 #include "../MathUtilities.h" 26 sprintf_s(msg, 199,
"Failed to Poll and failed to Acquire device: %s (%x)", config->
friendlyName.c_str(), hr);
32 if (FAILED(hr = config->
g_pJoystick->GetDeviceState(
sizeof DIJOYSTATE, js)))
34 sprintf_s(msg, 199,
"joystick::GetOrPoll failed to GetDeviceState DIJOYSTICK: %s (%x)", config->
friendlyName.c_str(), hr);
37 sprintf_s(msg, 199,
"It appears a game controller was unplugged or stolen by another application: %s", config->
friendlyName.c_str());
38 MessageBoxA(DXUTGetHWND(), msg,
"Lost Joystick Connection", MB_ICONWARNING | MB_OK);
46 case 0: *value = js->lX;
break;
47 case 1: *value = js->lY;
break;
48 case 2: *value = js->lZ;
break;
49 case 3: *value = js->lRx;
break;
50 case 4: *value = js->lRy;
break;
51 case 5: *value = js->lRz;
break;
52 case 6: *value = js->rglSlider[0];
break;
53 case 7: *value = js->rglSlider[1];
break;
54 default: *value = 0;
break;
57 if (abs(*value) > 2000)
59 sprintf_s(msg, 199,
"Value was out-of-range for game controller: %i", *value);
70 *value = (*value + 500) * 2;
116 if (abs(value) > 400)
130 if (abs(value) > 400)
140 if (abs(value) > 400)
158 else if (labs(value) > 400)
161 if (js.rgdwPOV[0] == 0 || js.rgdwPOV[0] == 31500 || js.rgdwPOV[0] == 4500)
163 else if (js.rgdwPOV[0] == 18000 || js.rgdwPOV[0] == 13500 || js.rgdwPOV[0] == 22500)
166 if (js.rgdwPOV[0] == 9000 || js.rgdwPOV[0] == 4500 || js.rgdwPOV[0] == 13500)
168 else if (js.rgdwPOV[0] == 27000 || js.rgdwPOV[0] == 22500 || js.rgdwPOV[0] == 31500)
194 else if (labs(value) > 400)
214 viewscreen->
yawInput =
static_cast<float>(value)*0.001f * fabsf(static_cast<float>(value)*0.001f);
222 viewscreen->
yawInput =
static_cast<float>(value)*0.001f * fabsf(static_cast<float>(value)*0.001f);
229 static unsigned char oldButton4 = 0, oldButton5 = 0;
230 if (oldButton4 != js.rgbButtons[4] && js.rgbButtons[4])
232 if (oldButton5 != js.rgbButtons[5] && js.rgbButtons[5])
234 oldButton4 = js.rgbButtons[4];
235 oldButton5 = js.rgbButtons[5];
358 logger->
Log(
"joystick::EnumDevices Starting...");
361 logger->
Log(
"joystick::EnumDevices() failed!", Logger::Level::Warn);
365 logger->
Log(
"joystick::EnumDevices Done!");
377 sprintf_s(msg, 199,
"joystick::InitializeDevice Releasing %s", control.c_str());
386 for (
size_t device = 0; device <
deviceList.size(); device++)
388 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
389 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
390 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
391 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
392 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
393 control ==
"Look Lateral")
398 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
399 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
400 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
401 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
402 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
403 control ==
"Look Vertical")
408 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
409 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
410 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
411 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
412 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
418 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
419 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
420 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
421 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
422 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
428 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
429 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
430 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
431 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
432 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
433 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
434 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
435 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
436 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
437 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
438 control ==
"Pitch" && priority > 1)
444 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
445 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
446 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
447 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
448 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
449 control ==
"Pitch" && priority > 9)
455 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
456 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
457 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
458 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
459 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
460 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
461 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
462 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
463 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
464 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
465 control ==
"Roll" && priority > 1)
471 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
472 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
473 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
474 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
475 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
476 control ==
"Roll" && priority > 9)
482 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
483 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
484 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
485 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
486 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
487 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
488 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
489 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
490 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
491 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
492 control ==
"Yaw" && priority > 1)
498 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Throttle") == 0 ||
499 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Throttle") == 0) &&
500 control ==
"Left Thrust" && priority > 1)
506 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
507 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0) &&
508 control ==
"Left Thrust" && priority > 2)
514 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
515 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
516 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
517 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
518 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
519 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
520 control ==
"Left Thrust" && priority > 2)
526 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
527 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
528 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
529 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
530 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
531 control ==
"Left Thrust" && priority > 9)
535 config->
split =
true;
538 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Throttle") == 0 ||
539 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Throttle") == 0) &&
540 control ==
"Right Thrust" && priority > 1)
546 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
547 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0) &&
548 control ==
"Right Thrust" && priority > 2)
554 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
555 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
556 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
557 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
558 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
559 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
560 control ==
"Right Thrust" && priority > 2)
566 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
567 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
568 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
569 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
570 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
571 control ==
"Right Thrust" && priority > 9)
575 config->
split =
true;
578 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
579 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
580 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
581 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
582 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
583 control ==
"Left Toe Brake" && priority > 9)
587 config->
split =
true;
591 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
592 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
593 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
594 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
595 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
596 control ==
"Right Toe Brake" && priority > 9)
600 config->
split =
true;
604 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 && control ==
"Steering" && priority > 1)
610 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
611 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
612 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
613 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
614 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
615 control ==
"Steering" && priority > 9)
621 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 && control ==
"Gas" && priority > 1)
625 config->
split =
true;
628 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
629 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
630 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
631 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
632 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
633 control ==
"Gas" && priority > 9)
637 config->
split =
true;
640 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 && control ==
"Brake" && priority > 1)
644 config->
split =
true;
648 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
649 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
650 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
651 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
652 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
653 control ==
"Brake" && priority > 9)
657 config->
split =
true;
689 sprintf_s(msg, 199,
"Could not find the game controller assigned to: %s", control.c_str());
692 MessageBoxA(DXUTGetHWND(), msg,
"Initialize Game Controller", MB_ICONWARNING | MB_OK);
704 logger->
Log(
"joystick::InitializeDevice Calling SetDataFormat...");
705 if (FAILED(hr = config->
g_pJoystick->SetDataFormat(&c_dfDIJoystick)))
707 logger->
Log(
"joystick::InitializeDevice SetDataFormat() failed!", Logger::Level::Warn);
710 logger->
Log(
"joystick::InitializeDevice Done with SetDataFormat!");
715 logger->
Log(
"joystick::InitializeDevice Calling SetCooperativeLevel...");
716 if (FAILED(hr = config->
g_pJoystick->SetCooperativeLevel(
hDlg, DISCL_EXCLUSIVE | DISCL_BACKGROUND)))
718 logger->
Log(
"joystick::InitializeDevice SetCooperativeLevel() failed!", Logger::Level::Warn);
721 logger->
Log(
"joystick::InitializeDevice Done with SetCooperativeLevel!");
724 logger->
Log(
"joystick::InitializeDevice Calling EnumObjects for axes...");
731 logger->
Log(
"joystick::InitializeDevice EnumObjects() failed!", Logger::Level::Warn);
734 logger->
Log(
"joystick::InitializeDevice Done with EnumObjects!");
872 if (pdidoi->dwType & DIDFT_AXIS)
875 diprg.diph.dwSize =
sizeof(DIPROPRANGE);
876 diprg.diph.dwHeaderSize =
sizeof(DIPROPHEADER);
877 diprg.diph.dwHow = DIPH_BYID;
878 diprg.diph.dwObj = pdidoi->dwType;
886 if (FAILED(hr = wrapper->
config->
g_pJoystick->SetProperty(DIPROP_RANGE, &diprg.diph)))
889 sprintf_s(msg, 199,
"Failed to SetProperty of DIPROP_RANGE on %S: %i", pdidoi->tszName, hr);
890 wrapper->
logger->
Log(msg, Logger::Level::Error);
892 MessageBoxA(
nullptr, msg,
"Could not EnumAxesCallback", MB_ICONERROR | MB_OK);
896 return DIENUM_CONTINUE;
906 instance->
logger->
Log(
"viewscreen->g_pDI is nullptr!", Logger::Level::Error);
907 return DIENUM_CONTINUE;
912 instance->
logger->
Log(
"pInst is nullptr!", Logger::Level::Error);
913 return DIENUM_CONTINUE;
919 LPDIRECTINPUTDEVICE8 pDevice;
920 if (FAILED(instance->
viewscreen->
g_pDI->CreateDevice(pInst->guidInstance, &pDevice, NULL)))
925 instance->
logger->
Log(
"This one failed, continue enumerating...");
926 return DIENUM_CONTINUE;
929 catch (
const std::exception& e)
931 instance->
logger->
Log(const_cast<char *>(e.what()), Logger::Level::Error);
935 sprintf_s(msg, 999,
"Found a good device, adding to list: %S", pInst->tszInstanceName);
940 return DIENUM_CONTINUE;
InputConfig inputConfigLeftToeBrake
void Initialize(HWND prmHWND)
std::vector< DIDEVICEINSTANCE > deviceList
HRESULT Poll(InputConfig *config, long *value, DIJOYSTATE *js) const
void InitializeDevice(InputConfig *config, std::string control)
InformationDialog * informationDialog
void AutopilotDisconnect() const
s_network_objects playerships[MAX_SCAN]
void Update(float fElapsedTime) const
InputConfig inputConfigGas
InputConfig inputConfigRoll
InputConfig inputConfigLookVertical
void ToggleFullScreen(bool goFullScreen)
joystick(Viewscreen *ptr)
InputConfig inputConfigThrustLeft
InputConfig inputConfigThrustRight
float DesiredClosingSpeed
const GUID MYGUID_DEFAULT
InputConfig inputConfigPitchTrim
float Clamp(float val, float min, float max)
InputConfig inputConfigPitch
InputConfig inputConfigBrake
static BOOL CALLBACK EnumDevicesCallback(const DIDEVICEINSTANCE *pInst, VOID *pContext)
void Log(const char *msg, Level level=Info, int errorCode=0)
InputConfig inputConfigRightToeBrake
InputConfig inputConfigWalkVertical
InputConfig inputConfigWalkLateral
InputConfig inputConfigYaw
void AddToCallStack(const char *msg)
static BOOL CALLBACK EnumAxesCallback(const DIDEVICEOBJECTINSTANCE *pdidoi, VOID *pContext)
void GearDownShift() const
InputConfig inputConfigSteer
InputConfig inputConfigLookLateral
float EngineThrustLever[MAX_ENGINES]