Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/apple/joypad_apple.h
9973 views
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
31
#pragma once
32
33
#include "core/input/input.h"
34
#include "core/input/input_enums.h"
35
36
#define Key _QKey
37
#import <GameController/GameController.h>
38
#undef Key
39
40
@class GCController;
41
class RumbleContext;
42
43
struct GameController {
44
int joy_id;
45
GCController *controller;
46
RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
47
NSInteger ff_effect_timestamp = 0;
48
bool force_feedback = false;
49
bool double_nintendo_joycon_layout = false;
50
bool single_nintendo_joycon_layout = false;
51
52
uint32_t axis_changed_mask = 0;
53
static_assert(static_cast<uint32_t>(JoyAxis::MAX) < 32, "JoyAxis::MAX must be less than 32");
54
double axis_value[(int)JoyAxis::MAX];
55
56
GameController(int p_joy_id, GCController *p_controller);
57
~GameController();
58
};
59
60
class JoypadApple {
61
private:
62
id<NSObject> connect_observer = nil;
63
id<NSObject> disconnect_observer = nil;
64
HashMap<int, GameController *> joypads;
65
HashMap<GCController *, int> controller_to_joy_id;
66
67
GCControllerPlayerIndex get_free_player_index();
68
69
void add_joypad(GCController *p_controller);
70
void remove_joypad(GCController *p_controller);
71
72
public:
73
JoypadApple();
74
~JoypadApple();
75
76
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));
77
void joypad_vibration_stop(GameController &p_joypad, uint64_t p_timestamp) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));
78
79
void process_joypads();
80
};
81
82