From f207abdd98ae6afa27ff033a962f5757762c7aef Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 21 Aug 2014 15:24:19 -0700 Subject: [PATCH] Move Player over to AvatarData for ACs to use --- interface/src/avatar/MyAvatar.cpp | 77 ---------------- interface/src/avatar/MyAvatar.h | 9 -- libraries/avatars/src/AvatarData.cpp | 88 +++++++++++++++++++ libraries/avatars/src/AvatarData.h | 11 +++ .../avatars}/src/Recorder.cpp | 10 ++- .../avatars}/src/Recorder.h | 2 +- 6 files changed, 108 insertions(+), 89 deletions(-) rename {interface => libraries/avatars}/src/Recorder.cpp (98%) rename {interface => libraries/avatars}/src/Recorder.h (99%) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ed764d7536..2202eafc00 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -575,58 +575,6 @@ void MyAvatar::saveRecording(QString filename) { } } -bool MyAvatar::isPlaying() { - if (!_player) { - return false; - } - if (QThread::currentThread() != thread()) { - bool result; - QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(bool, result)); - return result; - } - return _player && _player->isPlaying(); -} - -qint64 MyAvatar::playerElapsed() { - if (!_player) { - return 0; - } - if (QThread::currentThread() != thread()) { - qint64 result; - QMetaObject::invokeMethod(this, "playerElapsed", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(qint64, result)); - return result; - } - return _player->elapsed(); -} - -qint64 MyAvatar::playerLength() { - if (!_player) { - return 0; - } - if (QThread::currentThread() != thread()) { - qint64 result; - QMetaObject::invokeMethod(this, "playerLength", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(qint64, result)); - return result; - } - return _player->getRecording()->getLength(); -} - -void MyAvatar::loadRecording(QString filename) { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection, - Q_ARG(QString, filename)); - return; - } - if (!_player) { - _player = PlayerPointer(new Player(this)); - } - - _player->loadFromFile(filename); -} - void MyAvatar::loadLastRecording() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection); @@ -643,31 +591,6 @@ void MyAvatar::loadLastRecording() { _player->loadRecording(_recorder->getRecording()); } -void MyAvatar::startPlaying() { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection); - return; - } - if (!_player) { - _player = PlayerPointer(new Player(this)); - } - - _player->startPlaying(); -} - -void MyAvatar::stopPlaying() { - if (!_player) { - return; - } - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection); - return; - } - if (_player) { - _player->stopPlaying(); - } -} - void MyAvatar::setLocalGravity(glm::vec3 gravity) { _motionBehaviors |= AVATAR_MOTION_OBEY_LOCAL_GRAVITY; // Environmental and Local gravities are incompatible. Since Local is being set here diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 37daab3fa8..0ba2706e7d 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -174,15 +174,7 @@ public slots: void startRecording(); void stopRecording(); void saveRecording(QString filename); - - bool isPlaying(); - qint64 playerElapsed(); - qint64 playerLength(); - void loadRecording(QString filename); void loadLastRecording(); - void startPlaying(); - void stopPlaying(); - signals: void transformChanged(); @@ -222,7 +214,6 @@ private: PhysicsSimulation _physicsSimulation; RecorderPointer _recorder; - PlayerPointer _player; // private methods float computeDistanceToFloor(const glm::vec3& startPoint); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0e7d3228f9..0ec008d0cd 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -585,6 +585,94 @@ bool AvatarData::hasReferential() { return _referential != NULL; } +bool AvatarData::isPlaying() { + if (!_player) { + return false; + } + if (QThread::currentThread() != thread()) { + bool result; + QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, result)); + return result; + } + return _player && _player->isPlaying(); +} + +qint64 AvatarData::playerElapsed() { + if (!_player) { + return 0; + } + if (QThread::currentThread() != thread()) { + qint64 result; + QMetaObject::invokeMethod(this, "playerElapsed", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(qint64, result)); + return result; + } + return _player->elapsed(); +} + +qint64 AvatarData::playerLength() { + if (!_player) { + return 0; + } + if (QThread::currentThread() != thread()) { + qint64 result; + QMetaObject::invokeMethod(this, "playerLength", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(qint64, result)); + return result; + } + return _player->getRecording()->getLength(); +} + +void AvatarData::loadRecording(QString filename) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection, + Q_ARG(QString, filename)); + return; + } + if (!_player) { + _player = PlayerPointer(new Player(this)); + } + + _player->loadFromFile(filename); +} + +void AvatarData::startPlaying() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection); + return; + } + if (!_player) { + _player = PlayerPointer(new Player(this)); + } + + _player->startPlaying(); +} + +void AvatarData::play() { + if (isPlaying()) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "play", Qt::BlockingQueuedConnection); + return; + } + + _player->play(); + } +} + +void AvatarData::stopPlaying() { + if (!_player) { + return; + } + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection); + return; + } + if (_player) { + _player->stopPlaying(); + } +} + void AvatarData::changeReferential(Referential *ref) { delete _referential; _referential = ref; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index fa884c0229..12fe3adb6e 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -49,6 +49,7 @@ typedef unsigned long long quint64; #include +#include "Recorder.h" #include "Referential.h" #include "HeadData.h" #include "HandData.h" @@ -298,6 +299,14 @@ public slots: void setSessionUUID(const QUuid& sessionUUID) { _sessionUUID = sessionUUID; } bool hasReferential(); + bool isPlaying(); + qint64 playerElapsed(); + qint64 playerLength(); + void loadRecording(QString filename); + void startPlaying(); + void play(); + void stopPlaying(); + protected: QUuid _sessionUUID; glm::vec3 _position; @@ -351,6 +360,8 @@ protected: QWeakPointer _owningAvatarMixer; QElapsedTimer _lastUpdateTimer; + PlayerPointer _player; + /// Loads the joint indices, names from the FST file (if any) virtual void updateJointMappings(); void changeReferential(Referential* ref); diff --git a/interface/src/Recorder.cpp b/libraries/avatars/src/Recorder.cpp similarity index 98% rename from interface/src/Recorder.cpp rename to libraries/avatars/src/Recorder.cpp index fb5c92c849..09dea9fe22 100644 --- a/interface/src/Recorder.cpp +++ b/libraries/avatars/src/Recorder.cpp @@ -15,6 +15,7 @@ #include #include +#include "AvatarData.h" #include "Recorder.h" void RecordingFrame::setBlendshapeCoefficients(QVector blendshapeCoefficients) { @@ -281,7 +282,9 @@ void Player::play() { _avatar->setTargetScale(_recording->getFrame(_currentFrame).getScale()); _avatar->setJointRotations(_recording->getFrame(_currentFrame).getJointRotations()); HeadData* head = const_cast(_avatar->getHeadData()); - head->setBlendshapeCoefficients(_recording->getFrame(_currentFrame).getBlendshapeCoefficients()); + if (head) { + head->setBlendshapeCoefficients(_recording->getFrame(_currentFrame).getBlendshapeCoefficients()); + } } else { _avatar->setPosition(_recording->getFrame(0).getTranslation() + _recording->getFrame(_currentFrame).getTranslation()); @@ -291,7 +294,10 @@ void Player::play() { _recording->getFrame(_currentFrame).getScale()); _avatar->setJointRotations(_recording->getFrame(_currentFrame).getJointRotations()); HeadData* head = const_cast(_avatar->getHeadData()); - head->setBlendshapeCoefficients(_recording->getFrame(_currentFrame).getBlendshapeCoefficients()); + if (head) { + + head->setBlendshapeCoefficients(_recording->getFrame(_currentFrame).getBlendshapeCoefficients()); + } } _options.setPosition(_avatar->getPosition()); diff --git a/interface/src/Recorder.h b/libraries/avatars/src/Recorder.h similarity index 99% rename from interface/src/Recorder.h rename to libraries/avatars/src/Recorder.h index 2670d78365..770027a21d 100644 --- a/interface/src/Recorder.h +++ b/libraries/avatars/src/Recorder.h @@ -23,10 +23,10 @@ #include #include -#include #include #include +class AvatarData; class Recorder; class Recording; class Player;