Fast-path 0-amplitude haptics
This commit is contained in:
@@ -132,11 +132,11 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
self->fence = self->device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled});
|
||||
|
||||
// Look up the XrActions for haptics
|
||||
self->haptics_actions[0].first = application::get_action("/user/hand/left/output/haptic").first;
|
||||
self->haptics_actions[0].second = application::string_to_path("/user/hand/left");
|
||||
self->haptics_actions[0].action = application::get_action("/user/hand/left/output/haptic").first;
|
||||
self->haptics_actions[0].path = application::string_to_path("/user/hand/left");
|
||||
|
||||
self->haptics_actions[1].first = application::get_action("/user/hand/right/output/haptic").first;
|
||||
self->haptics_actions[1].second = application::string_to_path("/user/hand/right");
|
||||
self->haptics_actions[1].action = application::get_action("/user/hand/right/output/haptic").first;
|
||||
self->haptics_actions[1].path = application::string_to_path("/user/hand/right");
|
||||
|
||||
// Look up the XrActions for input
|
||||
for (const auto & [action, action_type, name]: application::inputs())
|
||||
|
||||
@@ -94,7 +94,13 @@ private:
|
||||
vk::raii::Fence fence = nullptr;
|
||||
vk::raii::CommandBuffer command_buffer = nullptr;
|
||||
|
||||
std::array<std::pair<XrAction, XrPath>, 2> haptics_actions;
|
||||
struct haptics_action
|
||||
{
|
||||
XrAction action;
|
||||
XrPath path;
|
||||
std::atomic<float> amplitude;
|
||||
};
|
||||
std::array<haptics_action, 2> haptics_actions;
|
||||
std::vector<std::tuple<device_id, XrAction, XrActionType>> input_actions;
|
||||
|
||||
state state_ = state::initializing;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user