Joypad.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /******************************************************************************
  2. Use 'Joypads' container to access Joypads input.
  3. /******************************************************************************/
  4. struct Joypad // Joypad Input
  5. {
  6. Vec2 dir , // direction
  7. dir_a [2], // analog direction
  8. dir_an [2]; // normalized analog direction
  9. Flt trigger[2]; // trigger
  10. Bool b (Int x)C {return InRange(x, _button) ? ButtonOn(_button[x]) : false;} // if button 'x' is on
  11. Bool bp(Int x)C {return InRange(x, _button) ? ButtonPd(_button[x]) : false;} // if button 'x' pushed in this frame
  12. Bool br(Int x)C {return InRange(x, _button) ? ButtonRs(_button[x]) : false;} // if button 'x' released in this frame
  13. Bool bd(Int x)C {return InRange(x, _button) ? ButtonDb(_button[x]) : false;} // if button 'x' double clicked
  14. Bool supportsVibrations()C; // if supports force feedback vibrations
  15. UInt id( )C {return _id ;} // get unique id of this joypad
  16. C Str& name( )C {return _name;} // get joypad name
  17. Str buttonName(Int x)C; // get button name, buttonName(0) -> "Joypad1", buttonName(1) -> "Joypad2", ..
  18. Joypad& vibration(C Vec2 &force); // set force feedback vibrations, (-1,-1)..(1,1), length of vector specifies intensity (value of (0,0) disables vibrations)
  19. #if EE_PRIVATE
  20. // manage
  21. void acquire(Bool on);
  22. void update (C Byte *on, Int elms);
  23. void update ();
  24. void clear ();
  25. void zero ();
  26. void push (Byte b);
  27. void release(Byte b);
  28. Int index ()C;
  29. #endif
  30. #if !EE_PRIVATE
  31. private:
  32. #endif
  33. Byte _button[32], _vibration_axes, _xinput1, _offset_x, _offset_y, _connected;
  34. Flt _last_t[32];
  35. UInt _id;
  36. Str _name;
  37. #if EE_PRIVATE
  38. #if WINDOWS_OLD
  39. IDirectInputDevice8 *_did;
  40. IDirectInputEffect *_effect;
  41. #else
  42. Ptr _did, _effect;
  43. #endif
  44. #else
  45. Ptr _did, _effect;
  46. #endif
  47. static CChar *_button_name[32];
  48. ~Joypad();
  49. Joypad();
  50. NO_COPY_CONSTRUCTOR(Joypad);
  51. };
  52. extern MemtN<Joypad, 4> Joypads;
  53. /******************************************************************************/
  54. Joypad* FindJoypad(UInt id); // find joypad in 'Joypads' container according to its 'id', null on fail
  55. #if EE_PRIVATE
  56. void ListJoypads();
  57. void InitJoypads();
  58. void ShutJoypads();
  59. #endif
  60. /******************************************************************************/