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