mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 00:51:32 -08:00
The self-assignment in the haptics handler left the stored amplitude at its initial value of 0, so the "skip redundant calls" guard was true for every amplitude-0 packet and haptic_stop() was never called. Rumbles could not be cancelled early and kept playing for their whole duration. Store the newly applied amplitude so the guard only skips stops when nothing was playing.
94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
/*
|
|
* WiVRn VR streaming
|
|
* Copyright (C) 2022 Guillaume Meunier <[email protected]>
|
|
* Copyright (C) 2022 Patrick Nicolas <[email protected]>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "application.h"
|
|
#include "stream.h"
|
|
#include <spdlog/spdlog.h>
|
|
|
|
void scenes::stream::read_actions()
|
|
{
|
|
from_headset::inputs inputs;
|
|
|
|
if (not is_gui_interactable())
|
|
{
|
|
for (const auto & [id, action, action_type]: input_actions)
|
|
{
|
|
switch (action_type)
|
|
{
|
|
case XR_ACTION_TYPE_BOOLEAN_INPUT: {
|
|
auto value = application::read_action_bool(action);
|
|
if (value)
|
|
inputs.values.push_back({id, (float)value->second, value->first});
|
|
}
|
|
break;
|
|
|
|
case XR_ACTION_TYPE_FLOAT_INPUT: {
|
|
auto value = application::read_action_float(action);
|
|
if (value)
|
|
inputs.values.push_back({id, value->second, value->first});
|
|
}
|
|
break;
|
|
|
|
case XR_ACTION_TYPE_VECTOR2F_INPUT: {
|
|
auto value = application::read_action_vec2(action);
|
|
if (value)
|
|
{
|
|
inputs.values.push_back({id, value->second.x, value->first});
|
|
inputs.values.push_back({(device_id)((int)id + 1), value->second.y, value->first});
|
|
}
|
|
}
|
|
break;
|
|
|
|
case XR_ACTION_TYPE_POSE_INPUT:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
network_session->send_stream(std::move(inputs));
|
|
}
|
|
catch (std::exception & e)
|
|
{
|
|
spdlog::warn("Exception while sending inputs packet: {}", e.what());
|
|
}
|
|
}
|
|
|
|
void scenes::stream::operator()(to_headset::haptics && haptics)
|
|
{
|
|
auto range = haptics_actions.equal_range(haptics.id);
|
|
for (auto it = range.first; it != range.second; ++it)
|
|
{
|
|
XrAction action = it->second.action;
|
|
float old = it->second.amplitude;
|
|
it->second.amplitude = haptics.amplitude;
|
|
// Some runtimes may be slow to process actions
|
|
// Skip it if not necessary
|
|
if (old == 0 and haptics.amplitude == 0)
|
|
continue;
|
|
|
|
if (haptics.amplitude > 0)
|
|
application::haptic_start(action, XR_NULL_PATH, haptics.duration.count(), haptics.frequency, std::min(1.0f, haptics.amplitude));
|
|
else
|
|
application::haptic_stop(action, XR_NULL_PATH);
|
|
}
|
|
}
|