mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 12:40:10 +02:00
hooking up the input playback
This commit is contained in:
parent
4bf3fa56f8
commit
c298886896
7 changed files with 144 additions and 13 deletions
BIN
libraries/controllers/src/controllers/.#Input.h
Normal file
BIN
libraries/controllers/src/controllers/.#Input.h
Normal file
Binary file not shown.
|
@ -8,11 +8,74 @@
|
|||
|
||||
#include "InputRecorder.h"
|
||||
|
||||
InputRecorder::InputRecorder() {}
|
||||
namespace controller {
|
||||
|
||||
InputRecorder::InputRecorder() {}
|
||||
|
||||
InputRecorder::~InputRecorder() {}
|
||||
InputRecorder::~InputRecorder() {}
|
||||
|
||||
InputRecorder& InputRecorder::getInstance() {
|
||||
static InputRecorder inputRecorder;
|
||||
return inputRecorder;
|
||||
InputRecorder& InputRecorder::getInstance() {
|
||||
static InputRecorder inputRecorder;
|
||||
return inputRecorder;
|
||||
}
|
||||
|
||||
void InputRecorder::startRecording() {
|
||||
_recording = true;
|
||||
_framesRecorded = 0;
|
||||
_poseStateList.clear();
|
||||
_actionStateList.clear();
|
||||
qDebug() << "-------------> input recording starting <---------------";
|
||||
}
|
||||
|
||||
void InputRecorder::stopRecording() {
|
||||
_recording = false;
|
||||
qDebug() << "--------------> input recording stopping <-----------------";
|
||||
}
|
||||
|
||||
void InputRecorder::startPlayback() {
|
||||
_playback = true;
|
||||
_recording = false;
|
||||
qDebug() << "-----------------> starting playback <---------------";
|
||||
}
|
||||
|
||||
void InputRecorder::stopPlayback() {
|
||||
_playback = false;
|
||||
_recording = false;
|
||||
}
|
||||
|
||||
void InputRecorder::setActionState(controller::Action action, float value) {
|
||||
if (_recording) {
|
||||
qDebug() << "-----------------> setiing action state <---------------";
|
||||
_actionStateList[_framesRecorded][toInt(action)] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void InputRecorder::setActionState(controller::Action action, const controller::Pose pose) {
|
||||
if (_recording) {
|
||||
qDebug() << "-----------------> setiing Pose state <---------------";
|
||||
_poseStateList[_framesRecorded][toInt(action)] = pose;
|
||||
}
|
||||
}
|
||||
|
||||
float InputRecorder::getActionState(controller::Action action) {
|
||||
return _actionStateList[_playCount][toInt(action)];
|
||||
}
|
||||
|
||||
controller::Pose InputRecorder::getPoseState(controller::Action action) {
|
||||
return _poseStateList[_playCount][toInt(action)];
|
||||
}
|
||||
|
||||
void InputRecorder::frameTick() {
|
||||
if (_recording) {
|
||||
_framesRecorded++;
|
||||
}
|
||||
|
||||
if (_playback) {
|
||||
if (_playCount < _framesRecorded) {
|
||||
_playCount++;
|
||||
} else {
|
||||
_playCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,44 @@
|
|||
|
||||
#ifndef hifi_InputRecorder_h
|
||||
#define hifi_InputRecorder_h
|
||||
class InputRecorder {
|
||||
public:
|
||||
InputRecorder();
|
||||
~InputRecorder();
|
||||
|
||||
InputRecorder& getInstance();
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
#include "Pose.h"
|
||||
#include "Actions.h"
|
||||
|
||||
namespace controller {
|
||||
class InputRecorder {
|
||||
public:
|
||||
using PoseStates = std::vector<Pose>;
|
||||
using ActionStates = std::vector<float>;
|
||||
|
||||
};
|
||||
InputRecorder();
|
||||
~InputRecorder();
|
||||
|
||||
static InputRecorder& getInstance();
|
||||
void startRecording();
|
||||
void startPlayback();
|
||||
void stopPlayback();
|
||||
void stopRecording();
|
||||
bool isRecording() { return _recording; }
|
||||
bool isPlayingback() { return _playback; }
|
||||
void setActionState(controller::Action action, float value);
|
||||
void setActionState(controller::Action action, const controller::Pose pose);
|
||||
float getActionState(controller::Action action);
|
||||
controller::Pose getPoseState(controller::Action action);
|
||||
void frameTick();
|
||||
private:
|
||||
bool _recording { false };
|
||||
bool _playback { false };
|
||||
std::vector<PoseStates> _poseStateList;
|
||||
std::vector<ActionStates> _actionStateList;
|
||||
|
||||
int _framesRecorded { 0 };
|
||||
int _playCount { 0 };
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "impl/MappingBuilderProxy.h"
|
||||
#include "Logging.h"
|
||||
#include "InputDevice.h"
|
||||
#include "InputRecorder.h"
|
||||
|
||||
|
||||
static QRegularExpression SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" };
|
||||
|
@ -154,6 +155,26 @@ namespace controller {
|
|||
return DependencyManager::get<UserInputMapper>()->triggerHapticPulse(strength, SHORT_HAPTIC_DURATION_MS, hand);
|
||||
}
|
||||
|
||||
void ScriptingInterface::startInputRecording() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.startRecording();
|
||||
}
|
||||
|
||||
void ScriptingInterface::stopInputRecording() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.stopRecording();
|
||||
}
|
||||
|
||||
void ScriptingInterface::startInputPlayback() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.startPlayback();
|
||||
}
|
||||
|
||||
void ScriptingInterface::stopInputPlayback() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.stopPlayback();
|
||||
}
|
||||
|
||||
bool ScriptingInterface::triggerHapticPulseOnDevice(unsigned int device, float strength, float duration, controller::Hand hand) const {
|
||||
return DependencyManager::get<UserInputMapper>()->triggerHapticPulseOnDevice(device, strength, duration, hand);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,10 @@ namespace controller {
|
|||
Q_INVOKABLE const QVariantMap& getHardware() { return _hardware; }
|
||||
Q_INVOKABLE const QVariantMap& getActions() { return _actions; }
|
||||
Q_INVOKABLE const QVariantMap& getStandard() { return _standard; }
|
||||
Q_INVOKABLE void startInputRecording();
|
||||
Q_INVOKABLE void stopInputRecording();
|
||||
Q_INVOKABLE void startInputPlayback();
|
||||
Q_INVOKABLE void stopInputPlayback();
|
||||
|
||||
bool isMouseCaptured() const { return _mouseCaptured; }
|
||||
bool isTouchCaptured() const { return _touchCaptured; }
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "StandardController.h"
|
||||
#include "StateController.h"
|
||||
|
||||
#include "InputRecorder.h"
|
||||
#include "Logging.h"
|
||||
|
||||
#include "impl/conditionals/AndConditional.h"
|
||||
|
@ -243,7 +243,7 @@ void fixBisectedAxis(float& full, float& negative, float& positive) {
|
|||
|
||||
void UserInputMapper::update(float deltaTime) {
|
||||
Locker locker(_lock);
|
||||
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
static uint64_t updateCount = 0;
|
||||
++updateCount;
|
||||
|
||||
|
@ -298,6 +298,7 @@ void UserInputMapper::update(float deltaTime) {
|
|||
emit inputEvent(input.id, value);
|
||||
}
|
||||
}
|
||||
inputRecorder.frameTick();
|
||||
}
|
||||
|
||||
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
||||
|
@ -571,6 +572,7 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
|||
}
|
||||
}
|
||||
// no filters yet for pose
|
||||
qDebug() << "--------------> applying destination <----------------";
|
||||
destination->apply(value, source);
|
||||
} else {
|
||||
// Fetch the value, may have been overriden by previous loopback routes
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <DependencyManager.h>
|
||||
|
||||
#include "../../UserInputMapper.h"
|
||||
#include "../../InputRecorder.h"
|
||||
|
||||
using namespace controller;
|
||||
|
||||
|
@ -20,10 +21,20 @@ void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
|||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue);
|
||||
}
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentValue);
|
||||
}
|
||||
|
||||
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
||||
_currentPose = value;
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentPose);
|
||||
qDebug << "<--------------- destination";
|
||||
if (inputRecorder.isPlayingback()) {
|
||||
qDebug() << "-------------> playing back <--------------";
|
||||
_currentPose = inputRecorder.getPoseState(Action(_input.getChannel()));
|
||||
}
|
||||
|
||||
if (!_currentPose.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue