Controller.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef CONTROLLER_H
  2. #define CONTROLLER_H
  3. #include "utils/Array.h"
  4. enum Button {
  5. A, B, X, Y, L, R, SELECT, START, LEFT, RIGHT, UP, DOWN
  6. };
  7. struct Controller final {
  8. Controller();
  9. void tick();
  10. uint getButtonAmount() const;
  11. const char* getName(uint button) const;
  12. uint getDownTime(uint button) const;
  13. bool isDown(uint button) const;
  14. bool wasReleased(uint button) const;
  15. private:
  16. bool findController();
  17. void reset();
  18. void increment(uint button, const u8* mapping, uint index);
  19. void increment(uint button, bool notReleased);
  20. struct ButtonState final {
  21. ButtonState();
  22. uint downTime;
  23. bool justReleased;
  24. };
  25. Array<ButtonState, 12> buttons;
  26. uint activeController;
  27. };
  28. #endif
  29. /*#ifndef KEYS_H
  30. #define KEYS_H
  31. #include <iostream>
  32. #include <array>
  33. #include "common/utils/Types.h"
  34. class Keys final {
  35. public:
  36. class Key final {
  37. public:
  38. friend class Keys;
  39. bool isDown() const;
  40. bool isReleased() const;
  41. u32 getDownTime() const;
  42. private:
  43. Key();
  44. Key(const Key&) = delete;
  45. Key(Key&&) = delete;
  46. Key& operator=(const Key&) = delete;
  47. Key& operator=(Key&&) = delete;
  48. int glfwKey;
  49. bool down;
  50. bool shouldRelease;
  51. u32 downTime;
  52. };
  53. private:
  54. Key keys[15];
  55. public:
  56. Keys();
  57. const Key& left;
  58. const Key& right;
  59. const Key& up;
  60. const Key& down;
  61. const Key& jump;
  62. const Key& sneak;
  63. const Key& camLeft;
  64. const Key& camRight;
  65. const Key& camUp;
  66. const Key& camDown;
  67. const Key& test;
  68. const Key& test2;
  69. const Key& test3;
  70. const Key& test4;
  71. const Key& test5;
  72. void release(int key);
  73. void press(int key);
  74. void tick();
  75. private:
  76. Keys(const Keys&) = delete;
  77. Keys& operator=(const Keys&) = delete;
  78. Keys(Key&&) = delete;
  79. Keys& operator=(Keys&&) = delete;
  80. };
  81. std::ostream& operator<<(std::ostream& os, const Keys::Key& k);
  82. #endif*/