Fast-path 0-amplitude haptics

This commit is contained in:
Patrick Nicolas
2024-04-05 15:21:12 +02:00
parent 40043d1e45
commit fd6b9f539a
3 changed files with 21 additions and 13 deletions
+10 -8
View File
@@ -70,19 +70,21 @@ void scenes::stream::read_actions()
void scenes::stream::operator()(to_headset::haptics && haptics)
{
XrAction action;
size_t i;
if (haptics.id == device_id::LEFT_CONTROLLER_HAPTIC)
{
action = haptics_actions[0].first;
}
i = 0;
else if (haptics.id == device_id::RIGHT_CONTROLLER_HAPTIC)
{
action = haptics_actions[1].first;
}
i = 1;
else
return;
XrAction action = haptics_actions[i].action;
float old = haptics_actions[i].amplitude.exchange(haptics.amplitude);
// Some runtimes may be slow to process actions
// Skip it if not necessary
if (old == 0 and haptics.amplitude == 0)
return;
if (haptics.amplitude > 0)
application::haptic_start(action, XR_NULL_PATH, haptics.duration.count(), haptics.frequency, std::min(1.0f, haptics.amplitude));
else