Debian Codegraph @

3rdparty/osgXR/src/InteractionProfile.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-only
2 // Copyright (C) 2021 James Hogan <[email protected]>
3
4 #include "Action.h"
5 #include "InteractionProfile.h"
6
7 #include "OpenXR/InteractionProfile.h"
8 #include "OpenXR/Path.h"
9 #include "OpenXR/Session.h"
10
11 #include <osgXR/Manager>
12
13 #include "XRState.h"
14
15 using namespace osgXR;
16
17 // Internal API
18
19 InteractionProfile::Private::Private(InteractionProfile *pub,
20 XRState *state,
21 const std::string &vendor,
22 const std::string &type) :
23 _pub(pub),
24 _state(state),
25 _vendor(vendor),
26 _type(type),
27 _updated(true)
28 {
29 state->addInteractionProfile(this);
30 }
31
32 InteractionProfile::Private::~Private()
33 {
34 XRState *state = _state.get();
35 if (state)
36 state->removeInteractionProfile(this);
37 }
38
39 void InteractionProfile::Private::suggestBinding(Action *action,
40 const std::string &binding)
41 {
42 _bindings.push_back({action, binding});
43 _updated = true;
44 }
45
46 bool InteractionProfile::Private::setup(OpenXR::Instance *instance)
47 {
48 // Recreate every time, as actions may have been altered and recreated
49 _profile = new OpenXR::InteractionProfile(instance, _vendor.c_str(),
50 _type.c_str());
51
52 for (Binding &binding: _bindings)
53 {
54 // ensure action is set up
55 OpenXR::Action *action = Action::Private::get(binding.action)->setup(instance);
56 if (action)
57 _profile->addBinding(action, binding.binding);
58 }
59
60 bool ret = _profile->suggestBindings();
61 if (ret)
62 _updated = false;
63 return ret;
64 }
65
66 void InteractionProfile::Private::cleanupInstance()
67 {
68 _profile = nullptr;
69 }
70
71 OpenXR::Path InteractionProfile::Private::getPath() const
72 {
73 if (_profile.valid())
74 return _profile->getPath();
75 else
76 return OpenXR::Path();
77 }
78
79 // Public API
80
81 InteractionProfile::InteractionProfile(Manager *manager,
82 const std::string &vendor,
83 const std::string &type) :
84 _private(new Private(this, manager->_getXrState(), vendor, type))
85 {
86 }
87
88 InteractionProfile::~InteractionProfile()
89 {
90 }
91
92 const std::string &InteractionProfile::getVendor() const
93 {
94 return _private->getVendor();
95 }
96
97 const std::string &InteractionProfile::getType() const
98 {
99 return _private->getType();
100 }
101
102 void InteractionProfile::suggestBinding(Action *action,
103 const std::string &binding)
104 {
105 _private->suggestBinding(action, binding);
106 }