joypad_apple.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**************************************************************************/
  2. /* joypad_apple.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/input/input.h"
  32. #include "core/input/input_enums.h"
  33. #define Key _QKey
  34. #import <GameController/GameController.h>
  35. #undef Key
  36. @class GCController;
  37. class RumbleContext;
  38. struct GameController {
  39. int joy_id;
  40. GCController *controller;
  41. RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
  42. NSInteger ff_effect_timestamp = 0;
  43. bool force_feedback = false;
  44. bool double_nintendo_joycon_layout = false;
  45. bool single_nintendo_joycon_layout = false;
  46. uint32_t axis_changed_mask = 0;
  47. static_assert(static_cast<uint32_t>(JoyAxis::MAX) < 32, "JoyAxis::MAX must be less than 32");
  48. double axis_value[(int)JoyAxis::MAX];
  49. GameController(int p_joy_id, GCController *p_controller);
  50. ~GameController();
  51. };
  52. class JoypadApple {
  53. private:
  54. id<NSObject> connect_observer = nil;
  55. id<NSObject> disconnect_observer = nil;
  56. HashMap<int, GameController *> joypads;
  57. HashMap<GCController *, int> controller_to_joy_id;
  58. GCControllerPlayerIndex get_free_player_index();
  59. void add_joypad(GCController *p_controller);
  60. void remove_joypad(GCController *p_controller);
  61. public:
  62. JoypadApple();
  63. ~JoypadApple();
  64. void joypad_vibration_start(GameController &p_joypad, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));
  65. void joypad_vibration_stop(GameController &p_joypad, uint64_t p_timestamp) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));
  66. void process_joypads();
  67. };