Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GHOST_XrAction.h « intern « ghost « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e2224fe3ff873abcaacb63e510820e0f3e0c19d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup GHOST
 */

/* NOTE: Requires OpenXR headers to be included before this one for OpenXR types
 * (XrSpace, XrPath, etc.). */

#pragma once

#include <map>
#include <memory>
#include <string>

#include "GHOST_Util.h"

/* -------------------------------------------------------------------- */

class GHOST_XrActionSpace {
 public:
  GHOST_XrActionSpace() = delete; /* Default constructor for map storage. */
  GHOST_XrActionSpace(XrSession session,
                      XrAction action,
                      const char *action_name,
                      const char *profile_path,
                      XrPath subaction_path,
                      const char *subaction_path_str,
                      const GHOST_XrPose &pose);
  ~GHOST_XrActionSpace();

  XrSpace getSpace() const;

 private:
  XrSpace m_space = XR_NULL_HANDLE;
};

/* -------------------------------------------------------------------- */

typedef struct GHOST_XrSubactionData {
  XrPath subaction_path = XR_NULL_PATH;
  float float_threshold;
  int16_t axis_flag;
  std::unique_ptr<GHOST_XrActionSpace> space = nullptr;
} GHOST_XrSubactionData;

/* -------------------------------------------------------------------- */

class GHOST_XrActionProfile {
 public:
  GHOST_XrActionProfile() = delete; /* Default constructor for map storage. */
  GHOST_XrActionProfile(XrInstance instance,
                        XrSession session,
                        XrAction action,
                        GHOST_XrActionType type,
                        const GHOST_XrActionProfileInfo &info);
  ~GHOST_XrActionProfile() = default;

  XrPath getProfile() const;
  const GHOST_XrSubactionData *getSubaction(XrPath subaction_path) const;
  void getBindings(XrAction action,
                   std::map<XrPath, std::vector<XrActionSuggestedBinding>> &r_bindings) const;

 private:
  XrPath m_profile = XR_NULL_PATH;

  /** Sub-action data identified by user `subaction` path. */
  std::map<std::string, GHOST_XrSubactionData> m_subaction_data;
  /** Bindings identified by interaction (user `subaction` + component) path. */
  std::map<std::string, XrPath> m_bindings;
};

/* -------------------------------------------------------------------- */

class GHOST_XrAction {
 public:
  GHOST_XrAction() = delete; /* Default constructor for map storage. */
  GHOST_XrAction(XrInstance instance, XrActionSet action_set, const GHOST_XrActionInfo &info);
  ~GHOST_XrAction();

  bool createBinding(XrInstance instance,
                     XrSession session,
                     const GHOST_XrActionProfileInfo &info);
  void destroyBinding(const char *profile_path);

  void updateState(XrSession session,
                   const char *action_name,
                   XrSpace reference_space,
                   const XrTime &predicted_display_time);
  void applyHapticFeedback(XrSession session,
                           const char *action_name,
                           const char *subaction_path,
                           const int64_t &duration,
                           const float &frequency,
                           const float &amplitude);
  void stopHapticFeedback(XrSession session, const char *action_name, const char *subaction_path);

  void *getCustomdata();
  void getBindings(std::map<XrPath, std::vector<XrActionSuggestedBinding>> &r_bindings) const;

 private:
  using SubactionIndexMap = std::map<std::string, uint32_t>;

  XrAction m_action = XR_NULL_HANDLE;
  GHOST_XrActionType m_type;
  SubactionIndexMap m_subaction_indices;
  std::vector<XrPath> m_subaction_paths;
  /** States for each subaction path. */
  void *m_states;
  /** Input thresholds/regions for each subaction path. */
  float *m_float_thresholds;
  int16_t *m_axis_flags;

  std::unique_ptr<GHOST_C_CustomDataWrapper> m_custom_data_ = nullptr; /* wmXrAction */

  /** Profiles identified by interaction profile path. */
  std::map<std::string, GHOST_XrActionProfile> m_profiles;
};

/* -------------------------------------------------------------------- */

class GHOST_XrActionSet {
 public:
  GHOST_XrActionSet() = delete; /* Default constructor for map storage. */
  GHOST_XrActionSet(XrInstance instance, const GHOST_XrActionSetInfo &info);
  ~GHOST_XrActionSet();

  bool createAction(XrInstance instance, const GHOST_XrActionInfo &info);
  void destroyAction(const char *action_name);
  GHOST_XrAction *findAction(const char *action_name);

  void updateStates(XrSession session,
                    XrSpace reference_space,
                    const XrTime &predicted_display_time);

  XrActionSet getActionSet() const;
  void *getCustomdata();
  uint32_t getActionCount() const;
  void getActionCustomdataArray(void **r_customdata_array);
  void getBindings(std::map<XrPath, std::vector<XrActionSuggestedBinding>> &r_bindings) const;

 private:
  XrActionSet m_action_set = XR_NULL_HANDLE;

  std::unique_ptr<GHOST_C_CustomDataWrapper> m_custom_data_ = nullptr; /* wmXrActionSet */

  std::map<std::string, GHOST_XrAction> m_actions;
};

/* -------------------------------------------------------------------- */