Skip to content

Commit

Permalink
Merge pull request #80198 from Faolan-Rad/XRos_Optimize
Browse files Browse the repository at this point in the history
Optimized the XRTracker by reusing XRPose objects to minimize garbage collection overhead in C#
  • Loading branch information
akien-mga committed Aug 3, 2023
2 parents f9d960c + 7d8a9d2 commit 789b392
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions servers/xr/xr_positional_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,20 @@ void XRPositionalTracker::invalidate_pose(const StringName &p_action_name) {
void XRPositionalTracker::set_pose(const StringName &p_action_name, const Transform3D &p_transform, const Vector3 &p_linear_velocity, const Vector3 &p_angular_velocity, const XRPose::TrackingConfidence p_tracking_confidence) {
Ref<XRPose> new_pose;

new_pose.instantiate();
if (poses.has(p_action_name)) {
new_pose = poses[p_action_name];
} else {
new_pose.instantiate();
poses[p_action_name] = new_pose;
}

new_pose->set_name(p_action_name);
new_pose->set_has_tracking_data(true);
new_pose->set_transform(p_transform);
new_pose->set_linear_velocity(p_linear_velocity);
new_pose->set_angular_velocity(p_angular_velocity);
new_pose->set_tracking_confidence(p_tracking_confidence);

poses[p_action_name] = new_pose;
emit_signal(SNAME("pose_changed"), new_pose);

// TODO discuss whether we also want to create and emit an InputEventXRPose event
Expand Down

0 comments on commit 789b392

Please sign in to comment.