Add timestamps for inputs
This commit is contained in:
@@ -761,7 +761,7 @@ void application::poll_actions()
|
||||
instance_->xr_session.sync_actions(instance_->xr_actionset);
|
||||
}
|
||||
|
||||
bool application::read_action(XrAction action, bool & value)
|
||||
bool application::read_action(XrAction action, bool & value, XrTime& last_change_time)
|
||||
{
|
||||
if (!is_focused())
|
||||
return false;
|
||||
@@ -778,10 +778,11 @@ bool application::read_action(XrAction action, bool & value)
|
||||
return false;
|
||||
|
||||
value = state.currentState;
|
||||
last_change_time = state.lastChangeTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool application::read_action(XrAction action, float & value)
|
||||
bool application::read_action(XrAction action, float & value, XrTime& last_change_time)
|
||||
{
|
||||
if (!is_focused())
|
||||
return false;
|
||||
@@ -798,10 +799,11 @@ bool application::read_action(XrAction action, float & value)
|
||||
return false;
|
||||
|
||||
value = state.currentState;
|
||||
last_change_time = state.lastChangeTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool application::read_action(XrAction action, XrVector2f & value)
|
||||
bool application::read_action(XrAction action, XrVector2f & value, XrTime& last_change_time)
|
||||
{
|
||||
if (!is_focused())
|
||||
return false;
|
||||
@@ -818,6 +820,7 @@ bool application::read_action(XrAction action, XrVector2f & value)
|
||||
return false;
|
||||
|
||||
value = state.currentState;
|
||||
last_change_time = state.lastChangeTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,9 +300,9 @@ public:
|
||||
};
|
||||
|
||||
static void poll_actions();
|
||||
static bool read_action(XrAction action, float & value);
|
||||
static bool read_action(XrAction action, bool & value);
|
||||
static bool read_action(XrAction action, XrVector2f & value);
|
||||
static bool read_action(XrAction action, float & value, XrTime& last_change_time);
|
||||
static bool read_action(XrAction action, bool & value, XrTime& last_change_time);
|
||||
static bool read_action(XrAction action, XrVector2f & value, XrTime& last_change_time);
|
||||
static void haptic_start(XrAction action, XrPath subpath, int64_t duration, float frequency, float amplitude);
|
||||
static void haptic_stop(XrAction action, XrPath subpath);
|
||||
|
||||
|
||||
@@ -28,26 +28,27 @@ void scenes::stream::read_actions()
|
||||
{
|
||||
switch (action_type)
|
||||
{
|
||||
XrTime last_change_time;
|
||||
case XR_ACTION_TYPE_BOOLEAN_INPUT: {
|
||||
bool value;
|
||||
if (application::read_action(action, value))
|
||||
inputs.values.push_back({id, (float)value});
|
||||
if (application::read_action(action, value, last_change_time))
|
||||
inputs.values.push_back({id, (float)value, (uint64_t)last_change_time});
|
||||
}
|
||||
break;
|
||||
|
||||
case XR_ACTION_TYPE_FLOAT_INPUT: {
|
||||
float value;
|
||||
if (application::read_action(action, value))
|
||||
inputs.values.push_back({id, value});
|
||||
if (application::read_action(action, value, last_change_time))
|
||||
inputs.values.push_back({id, value, (uint64_t)last_change_time});
|
||||
}
|
||||
break;
|
||||
|
||||
case XR_ACTION_TYPE_VECTOR2F_INPUT: {
|
||||
XrVector2f value;
|
||||
if (application::read_action(action, value))
|
||||
if (application::read_action(action, value, last_change_time))
|
||||
{
|
||||
inputs.values.push_back({id, value.x});
|
||||
inputs.values.push_back({(device_id)((int)id + 1), value.y});
|
||||
inputs.values.push_back({id, value.x, (uint64_t)last_change_time});
|
||||
inputs.values.push_back({(device_id)((int)id + 1), value.y, (uint64_t)last_change_time});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -151,6 +151,7 @@ struct inputs
|
||||
{
|
||||
device_id id;
|
||||
float value;
|
||||
uint64_t last_change_time;
|
||||
};
|
||||
std::vector<input_value> values;
|
||||
};
|
||||
|
||||
@@ -209,7 +209,6 @@ wivrn_controller::wivrn_controller(int hand_id,
|
||||
{
|
||||
case 0:
|
||||
device_type = XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER;
|
||||
SET_INPUT(MENU_CLICK);
|
||||
|
||||
// Print name.
|
||||
strcpy(str, "WiVRn HMD left hand controller");
|
||||
@@ -240,16 +239,16 @@ void wivrn_controller::update_inputs()
|
||||
inputs_array = inputs_staging;
|
||||
}
|
||||
|
||||
void wivrn_controller::set_inputs(const from_headset::inputs & inputs)
|
||||
void wivrn_controller::set_inputs(const from_headset::inputs & inputs, const clock_offset& clock_offset)
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
for (const auto & input: inputs.values)
|
||||
{
|
||||
set_inputs(input.id, input.value);
|
||||
set_inputs(input.id, input.value, clock_offset.from_headset(input.last_change_time));
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_controller::set_inputs(device_id input_id, float value)
|
||||
void wivrn_controller::set_inputs(device_id input_id, float value, uint64_t last_change_time)
|
||||
{
|
||||
const struct wivrn_to_wivrn_controller_input * bindings;
|
||||
size_t bindings_count;
|
||||
@@ -276,6 +275,7 @@ void wivrn_controller::set_inputs(device_id input_id, float value)
|
||||
|
||||
if (binding)
|
||||
{
|
||||
inputs_staging[binding->input_id].timestamp = last_change_time;
|
||||
switch (binding->input_type)
|
||||
{
|
||||
case wivrn_input_type::BOOL:
|
||||
|
||||
@@ -54,11 +54,11 @@ public:
|
||||
|
||||
void set_output(xrt_output_name name, const xrt_output_value * value);
|
||||
|
||||
void set_inputs(const from_headset::inputs &);
|
||||
void set_inputs(const from_headset::inputs &, const clock_offset &);
|
||||
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
|
||||
private:
|
||||
void
|
||||
set_inputs(device_id input_id, float value);
|
||||
set_inputs(device_id input_id, float value, uint64_t last_change_time);
|
||||
};
|
||||
|
||||
@@ -160,8 +160,9 @@ void wivrn_session::operator()(from_headset::tracking && tracking)
|
||||
|
||||
void wivrn_session::operator()(from_headset::inputs && inputs)
|
||||
{
|
||||
left_hand->set_inputs(inputs);
|
||||
right_hand->set_inputs(inputs);
|
||||
auto offset = get_offset();
|
||||
left_hand->set_inputs(inputs, offset);
|
||||
right_hand->set_inputs(inputs, offset);
|
||||
}
|
||||
|
||||
template <typename Rep, typename Period>
|
||||
|
||||
Reference in New Issue
Block a user