Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

106 строки
2.3 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #if defined _XBOX
  14. # include <xtl.h>
  15. # include <xbdm.h>
  16. #endif
  17. #include "core.h"
  18. #include "xboxinput.h"
  19. namespace lol
  20. {
  21. /*
  22. * Xbox Input implementation class
  23. */
  24. class XboxInputData
  25. {
  26. friend class XboxInput;
  27. private:
  28. #if defined _XBOX
  29. Array<int, Stick *> m_joysticks;
  30. #endif
  31. };
  32. /*
  33. * Public XboxInput class
  34. */
  35. XboxInput::XboxInput()
  36. : m_data(new XboxInputData())
  37. {
  38. #if defined _XBOX
  39. for (int i = 0; i < XUSER_MAX_COUNT; i++)
  40. {
  41. XINPUT_STATE state;
  42. if (XInputGetState(i, &state) != ERROR_SUCCESS)
  43. continue;
  44. Stick *stick = Input::CreateStick();
  45. stick->SetAxisCount(4);
  46. stick->SetButtonCount(16);
  47. m_data->m_joysticks.Push(i, stick);
  48. }
  49. #endif
  50. m_gamegroup = GAMEGROUP_BEFORE;
  51. }
  52. XboxInput::~XboxInput()
  53. {
  54. #if defined _XBOX
  55. /* Unregister all the joysticks we added */
  56. while (m_data->m_joysticks.Count())
  57. {
  58. Input::DestroyStick(m_data->m_joysticks[0].m2);
  59. m_data->m_joysticks.Remove(0);
  60. }
  61. #endif
  62. delete m_data;
  63. }
  64. void XboxInput::TickGame(float seconds)
  65. {
  66. Entity::TickGame(seconds);
  67. }
  68. void XboxInput::TickDraw(float seconds, Scene &scene)
  69. {
  70. Entity::TickDraw(seconds, scene);
  71. #if defined _XBOX
  72. for (int i = 0; i < m_data->m_joysticks.Count(); i++)
  73. {
  74. XINPUT_STATE state;
  75. if (XInputGetState(m_data->m_joysticks[i].m1, &state) != ERROR_SUCCESS)
  76. continue;
  77. m_data->m_joysticks[i].m2->SetAxis(0, (float)state.Gamepad.sThumbLX / 32768.f);
  78. m_data->m_joysticks[i].m2->SetAxis(1, -(float)state.Gamepad.sThumbLY / 32768.f);
  79. m_data->m_joysticks[i].m2->SetAxis(2, (float)state.Gamepad.sThumbRX / 32768.f);
  80. m_data->m_joysticks[i].m2->SetAxis(3, -(float)state.Gamepad.sThumbRY / 32768.f);
  81. for (int b = 0; b < 16; b++)
  82. m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
  83. }
  84. #endif
  85. }
  86. } /* namespace lol */