Skip to content

Commit

Permalink
Various fixes for OpenXR action map meta data and editing
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Nov 25, 2022
1 parent 7580565 commit 96bbdf7
Show file tree
Hide file tree
Showing 29 changed files with 1,420 additions and 1,020 deletions.
6 changes: 6 additions & 0 deletions modules/openxr/action_map/openxr_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ String OpenXRAction::get_name_with_set() const {

void OpenXRAction::set_localized_name(const String p_localized_name) {
localized_name = p_localized_name;
emit_changed();
}

String OpenXRAction::get_localized_name() const {
Expand All @@ -83,6 +84,7 @@ String OpenXRAction::get_localized_name() const {

void OpenXRAction::set_action_type(const OpenXRAction::ActionType p_action_type) {
action_type = p_action_type;
emit_changed();
}

OpenXRAction::ActionType OpenXRAction::get_action_type() const {
Expand All @@ -91,6 +93,7 @@ OpenXRAction::ActionType OpenXRAction::get_action_type() const {

void OpenXRAction::set_toplevel_paths(const PackedStringArray p_toplevel_paths) {
toplevel_paths = p_toplevel_paths;
emit_changed();
}

PackedStringArray OpenXRAction::get_toplevel_paths() const {
Expand All @@ -100,15 +103,18 @@ PackedStringArray OpenXRAction::get_toplevel_paths() const {
void OpenXRAction::add_toplevel_path(const String p_toplevel_path) {
if (!toplevel_paths.has(p_toplevel_path)) {
toplevel_paths.push_back(p_toplevel_path);
emit_changed();
}
}

void OpenXRAction::rem_toplevel_path(const String p_toplevel_path) {
if (toplevel_paths.has(p_toplevel_path)) {
toplevel_paths.erase(p_toplevel_path);
emit_changed();
}
}

void OpenXRAction::parse_toplevel_paths(const String p_toplevel_paths) {
toplevel_paths = p_toplevel_paths.split(",", false);
emit_changed();
}
34 changes: 21 additions & 13 deletions modules/openxr/action_map/openxr_action_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ void OpenXRActionMap::add_action_set(Ref<OpenXRActionSet> p_action_set) {

if (action_sets.find(p_action_set) == -1) {
action_sets.push_back(p_action_set);
emit_changed();
}
}

void OpenXRActionMap::remove_action_set(Ref<OpenXRActionSet> p_action_set) {
int idx = action_sets.find(p_action_set);
if (idx != -1) {
action_sets.remove_at(idx);
emit_changed();
}
}

Expand Down Expand Up @@ -146,13 +148,15 @@ void OpenXRActionMap::add_interaction_profile(Ref<OpenXRInteractionProfile> p_in

if (interaction_profiles.find(p_interaction_profile) == -1) {
interaction_profiles.push_back(p_interaction_profile);
emit_changed();
}
}

void OpenXRActionMap::remove_interaction_profile(Ref<OpenXRInteractionProfile> p_interaction_profile) {
int idx = interaction_profiles.find(p_interaction_profile);
if (idx != -1) {
interaction_profiles.remove_at(idx);
emit_changed();
}
}

Expand Down Expand Up @@ -489,30 +493,34 @@ Ref<OpenXRAction> OpenXRActionMap::get_action(const String p_path) const {
return Ref<OpenXRAction>();
}

void OpenXRActionMap::remove_action(const String p_path) {
void OpenXRActionMap::remove_action(const String p_path, bool p_remove_interaction_profiles) {
Ref<OpenXRAction> action = get_action(p_path);
if (action.is_valid()) {
for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];

if (p_remove_interaction_profiles) {
// Remove any bindings for this action
interaction_profile->remove_binding_for_action(action);
} else {
ERR_FAIL_COND(interaction_profile->has_binding_for_action(action));
}
}

OpenXRActionSet *action_set = action->get_action_set();
if (action_set != nullptr) {
// Remove the action from this action set
action_set->remove_action(action);
}

for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> interaction_profile = interaction_profiles[i];

// Remove any bindings for this action
interaction_profile->remove_binding_for_action(action);
}
}
}

PackedStringArray OpenXRActionMap::get_top_level_paths(Ref<OpenXRAction> p_action) {
PackedStringArray OpenXRActionMap::get_top_level_paths(const Ref<OpenXRAction> p_action) {
PackedStringArray arr;

for (int i = 0; i < interaction_profiles.size(); i++) {
Ref<OpenXRInteractionProfile> ip = interaction_profiles[i];
const OpenXRDefs::InteractionProfile *profile = OpenXRDefs::get_profile(ip->get_interaction_profile_path());
const OpenXRInteractionProfileMetaData::InteractionProfile *profile = OpenXRInteractionProfileMetaData::get_singleton()->get_profile(ip->get_interaction_profile_path());

if (profile != nullptr) {
for (int j = 0; j < ip->get_binding_count(); j++) {
Expand All @@ -521,9 +529,9 @@ PackedStringArray OpenXRActionMap::get_top_level_paths(Ref<OpenXRAction> p_actio
PackedStringArray paths = binding->get_paths();

for (int k = 0; k < paths.size(); k++) {
const OpenXRDefs::IOPath *io_path = profile->get_io_path(paths[k]);
const OpenXRInteractionProfileMetaData::IOPath *io_path = profile->get_io_path(paths[k]);
if (io_path != nullptr) {
String top_path = String(io_path->top_level_path->openxr_path);
String top_path = io_path->top_level_path;

if (!arr.has(top_path)) {
arr.push_back(top_path);
Expand All @@ -535,7 +543,7 @@ PackedStringArray OpenXRActionMap::get_top_level_paths(Ref<OpenXRAction> p_actio
}
}

print_line("Toplevel paths for", p_action->get_name_with_set(), "are", arr);
// print_line("Toplevel paths for", p_action->get_name_with_set(), "are", arr);

return arr;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/openxr/action_map/openxr_action_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class OpenXRActionMap : public Resource {

// Helper functions for editor
Ref<OpenXRAction> get_action(const String p_path) const; // Retrieve an action using <action name>/<action> as our parameter
void remove_action(const String p_path); // Remove action from action set, also removes it from interaction profiles
PackedStringArray get_top_level_paths(Ref<OpenXRAction> p_action); // Determines the top level paths based on where an action is bound in interaction profiles
void remove_action(const String p_path, bool p_remove_interaction_profiles = false); // Remove action from action set, also removes it from interaction profiles
PackedStringArray get_top_level_paths(const Ref<OpenXRAction> p_action); // Determines the top level paths based on where an action is bound in interaction profiles

// TODO add validation to display in the interface that checks if we have action sets with the same name or if we have interaction profiles for the same path

Expand Down
10 changes: 10 additions & 0 deletions modules/openxr/action_map/openxr_action_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Ref<OpenXRActionSet> OpenXRActionSet::new_action_set(const char *p_name, const c

void OpenXRActionSet::set_localized_name(const String p_localized_name) {
localized_name = p_localized_name;
emit_changed();
}

String OpenXRActionSet::get_localized_name() const {
Expand All @@ -70,6 +71,7 @@ String OpenXRActionSet::get_localized_name() const {

void OpenXRActionSet::set_priority(const int p_priority) {
priority = p_priority;
emit_changed();
}

int OpenXRActionSet::get_priority() const {
Expand All @@ -82,11 +84,16 @@ int OpenXRActionSet::get_action_count() const {

void OpenXRActionSet::clear_actions() {
// Actions held within our action set should be released and destroyed but just in case they are still used some where else
if (actions.size() == 0) {
return;
}

for (int i = 0; i < actions.size(); i++) {
Ref<OpenXRAction> action = actions[i];
action->action_set = nullptr;
}
actions.clear();
emit_changed();
}

void OpenXRActionSet::set_actions(Array p_actions) {
Expand Down Expand Up @@ -125,6 +132,7 @@ void OpenXRActionSet::add_action(Ref<OpenXRAction> p_action) {

p_action->action_set = this;
actions.push_back(p_action);
emit_changed();
}
}

Expand All @@ -135,6 +143,8 @@ void OpenXRActionSet::remove_action(Ref<OpenXRAction> p_action) {

ERR_FAIL_COND_MSG(p_action->action_set != this, "Removing action that belongs to this action set but had incorrect action set pointer."); // this should never happen!
p_action->action_set = nullptr;

emit_changed();
}
}

Expand Down
Loading

0 comments on commit 96bbdf7

Please sign in to comment.