mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 18:04:12 +02:00
make client traits handler a unique ptr in AvatarData
This commit is contained in:
parent
a0df68f32f
commit
ea7c0e923a
9 changed files with 49 additions and 24 deletions
|
@ -16,9 +16,13 @@
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
#include <shared/QtHelpers.h>
|
#include <shared/QtHelpers.h>
|
||||||
#include <GLMHelpers.h>
|
|
||||||
#include <AnimUtil.h>
|
#include <AnimUtil.h>
|
||||||
|
#include <ClientTraitsHandler.h>
|
||||||
|
#include <GLMHelpers.h>
|
||||||
|
|
||||||
|
ScriptableAvatar::ScriptableAvatar() {
|
||||||
|
_clientTraitsHandler = std::unique_ptr<ClientTraitsHandler>(new ClientTraitsHandler(this));
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray ScriptableAvatar::toByteArrayStateful(AvatarDataDetail dataDetail, bool dropFaceTracking) {
|
QByteArray ScriptableAvatar::toByteArrayStateful(AvatarDataDetail dataDetail, bool dropFaceTracking) {
|
||||||
_globalPosition = getWorldPosition();
|
_globalPosition = getWorldPosition();
|
||||||
|
@ -63,8 +67,6 @@ void ScriptableAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||||
_animSkeleton.reset();
|
_animSkeleton.reset();
|
||||||
|
|
||||||
AvatarData::setSkeletonModelURL(skeletonModelURL);
|
AvatarData::setSkeletonModelURL(skeletonModelURL);
|
||||||
|
|
||||||
_clientTraitsHandler.markTraitChanged(AvatarTraits::SkeletonModelURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static AnimPose composeAnimPose(const FBXJoint& fbxJoint, const glm::quat rotation, const glm::vec3 translation) {
|
static AnimPose composeAnimPose(const FBXJoint& fbxJoint, const glm::quat rotation, const glm::vec3 translation) {
|
||||||
|
@ -141,5 +143,5 @@ void ScriptableAvatar::update(float deltatime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_clientTraitsHandler.sendChangedTraitsToMixer();
|
_clientTraitsHandler->sendChangedTraitsToMixer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <AnimationCache.h>
|
#include <AnimationCache.h>
|
||||||
#include <AnimSkeleton.h>
|
#include <AnimSkeleton.h>
|
||||||
#include <AvatarData.h>
|
#include <AvatarData.h>
|
||||||
#include <ClientTraitsHandler.h>
|
|
||||||
#include <ScriptEngine.h>
|
#include <ScriptEngine.h>
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
@ -125,6 +124,8 @@ class ScriptableAvatar : public AvatarData, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ScriptableAvatar();
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function Avatar.startAnimation
|
* @function Avatar.startAnimation
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
|
@ -165,8 +166,6 @@ private:
|
||||||
QStringList _maskedJoints;
|
QStringList _maskedJoints;
|
||||||
AnimationPointer _bind; // a sleazy way to get the skeleton, given the various library/cmake dependencies
|
AnimationPointer _bind; // a sleazy way to get the skeleton, given the various library/cmake dependencies
|
||||||
std::shared_ptr<AnimSkeleton> _animSkeleton;
|
std::shared_ptr<AnimSkeleton> _animSkeleton;
|
||||||
|
|
||||||
ClientTraitsHandler _clientTraitsHandler { this };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ScriptableAvatar_h
|
#endif // hifi_ScriptableAvatar_h
|
||||||
|
|
|
@ -119,9 +119,9 @@ MyAvatar::MyAvatar(QThread* thread) :
|
||||||
_goToOrientation(),
|
_goToOrientation(),
|
||||||
_prevShouldDrawHead(true),
|
_prevShouldDrawHead(true),
|
||||||
_audioListenerMode(FROM_HEAD),
|
_audioListenerMode(FROM_HEAD),
|
||||||
_hmdAtRestDetector(glm::vec3(0), glm::quat()),
|
_hmdAtRestDetector(glm::vec3(0), glm::quat())
|
||||||
_clientTraitsHandler(this)
|
|
||||||
{
|
{
|
||||||
|
_clientTraitsHandler = std::unique_ptr<ClientTraitsHandler>(new ClientTraitsHandler(this));
|
||||||
|
|
||||||
// give the pointer to our head to inherited _headData variable from AvatarData
|
// give the pointer to our head to inherited _headData variable from AvatarData
|
||||||
_headData = new MyHead(this);
|
_headData = new MyHead(this);
|
||||||
|
@ -514,7 +514,7 @@ void MyAvatar::update(float deltaTime) {
|
||||||
sendIdentityPacket();
|
sendIdentityPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
_clientTraitsHandler.sendChangedTraitsToMixer();
|
_clientTraitsHandler->sendChangedTraitsToMixer();
|
||||||
|
|
||||||
simulate(deltaTime);
|
simulate(deltaTime);
|
||||||
|
|
||||||
|
@ -1702,10 +1702,6 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||||
|
|
||||||
saveAvatarUrl();
|
saveAvatarUrl();
|
||||||
emit skeletonChanged();
|
emit skeletonChanged();
|
||||||
|
|
||||||
if (previousSkeletonModelURL != _skeletonModelURL) {
|
|
||||||
_clientTraitsHandler.markTraitChanged(AvatarTraits::SkeletonModelURL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition) {
|
void MyAvatar::removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition) {
|
||||||
|
|
|
@ -1334,7 +1334,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void setAnimGraphUrl(const QUrl& url); // thread-safe
|
void setAnimGraphUrl(const QUrl& url); // thread-safe
|
||||||
|
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function MyAvatar.getPositionForAudio
|
* @function MyAvatar.getPositionForAudio
|
||||||
* @returns {Vec3}
|
* @returns {Vec3}
|
||||||
|
@ -1347,7 +1346,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
glm::quat getOrientationForAudio();
|
glm::quat getOrientationForAudio();
|
||||||
|
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function MyAvatar.setModelScale
|
* @function MyAvatar.setModelScale
|
||||||
* @param {number} scale
|
* @param {number} scale
|
||||||
|
@ -1776,8 +1774,6 @@ private:
|
||||||
|
|
||||||
bool _haveReceivedHeightLimitsFromDomain { false };
|
bool _haveReceivedHeightLimitsFromDomain { false };
|
||||||
int _disableHandTouchCount { 0 };
|
int _disableHandTouchCount { 0 };
|
||||||
|
|
||||||
ClientTraitsHandler _clientTraitsHandler;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
#include "AvatarLogging.h"
|
#include "AvatarLogging.h"
|
||||||
#include "AvatarTraits.h"
|
#include "AvatarTraits.h"
|
||||||
|
#include "ClientTraitsHandler.h"
|
||||||
|
|
||||||
//#define WANT_DEBUG
|
//#define WANT_DEBUG
|
||||||
|
|
||||||
|
@ -1897,6 +1898,10 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||||
|
|
||||||
updateJointMappings();
|
updateJointMappings();
|
||||||
|
|
||||||
|
if (_clientTraitsHandler) {
|
||||||
|
_clientTraitsHandler->markTraitChanged(AvatarTraits::SkeletonModelURL);
|
||||||
|
}
|
||||||
|
|
||||||
emit skeletonModelURLChanged();
|
emit skeletonModelURLChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -372,6 +372,8 @@ public:
|
||||||
bool operator<(const AvatarPriority& other) const { return priority < other.priority; }
|
bool operator<(const AvatarPriority& other) const { return priority < other.priority; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ClientTraitsHandler;
|
||||||
|
|
||||||
class AvatarData : public QObject, public SpatiallyNestable {
|
class AvatarData : public QObject, public SpatiallyNestable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -924,6 +926,7 @@ public:
|
||||||
* @param {string} entityData
|
* @param {string} entityData
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void updateAvatarEntity(const QUuid& entityID, const QByteArray& entityData);
|
Q_INVOKABLE void updateAvatarEntity(const QUuid& entityID, const QByteArray& entityData);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function MyAvatar.clearAvatarEntity
|
* @function MyAvatar.clearAvatarEntity
|
||||||
* @param {Uuid} entityID
|
* @param {Uuid} entityID
|
||||||
|
@ -1435,6 +1438,9 @@ protected:
|
||||||
bool _hasProcessedFirstIdentity { false };
|
bool _hasProcessedFirstIdentity { false };
|
||||||
float _density;
|
float _density;
|
||||||
|
|
||||||
|
// null unless MyAvatar or ScriptableAvatar sending traits data to mixer
|
||||||
|
std::unique_ptr<ClientTraitsHandler> _clientTraitsHandler;
|
||||||
|
|
||||||
template <typename T, typename F>
|
template <typename T, typename F>
|
||||||
T readLockWithNamedJointIndex(const QString& name, const T& defaultValue, F f) const {
|
T readLockWithNamedJointIndex(const QString& name, const T& defaultValue, F f) const {
|
||||||
int index = getFauxJointIndex(name);
|
int index = getFauxJointIndex(name);
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
#ifndef hifi_AvatarTraits_h
|
#ifndef hifi_AvatarTraits_h
|
||||||
#define hifi_AvatarTraits_h
|
#define hifi_AvatarTraits_h
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <set>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace AvatarTraits {
|
namespace AvatarTraits {
|
||||||
|
@ -23,7 +23,28 @@ namespace AvatarTraits {
|
||||||
TotalTraitTypes
|
TotalTraitTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
using TraitTypeSet = std::set<TraitType>;
|
class TraitTypeSet {
|
||||||
|
public:
|
||||||
|
TraitTypeSet() {};
|
||||||
|
|
||||||
|
TraitTypeSet(std::initializer_list<TraitType> types) {
|
||||||
|
for (auto type : types) {
|
||||||
|
_types[type] = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool contains(TraitType type) const { return _types[type]; }
|
||||||
|
|
||||||
|
bool hasAny() const { return std::find(_types.begin(), _types.end(), true) != _types.end(); }
|
||||||
|
int size() const { return std::count(_types.begin(), _types.end(), true); }
|
||||||
|
|
||||||
|
void insert(TraitType type) { _types[type] = true; }
|
||||||
|
void erase(TraitType type) { _types[type] = false; }
|
||||||
|
void clear() { std::fill(_types.begin(), _types.end(), false); }
|
||||||
|
private:
|
||||||
|
std::vector<bool> _types = { AvatarTraits::TotalTraitTypes, false };
|
||||||
|
};
|
||||||
|
|
||||||
const TraitTypeSet SimpleTraitTypes = { SkeletonModelURL };
|
const TraitTypeSet SimpleTraitTypes = { SkeletonModelURL };
|
||||||
|
|
||||||
using TraitVersion = uint32_t;
|
using TraitVersion = uint32_t;
|
||||||
|
@ -35,6 +56,6 @@ namespace AvatarTraits {
|
||||||
using TraitWireSize = uint16_t;
|
using TraitWireSize = uint16_t;
|
||||||
|
|
||||||
using SimpleTraitVersions = std::vector<TraitVersion>;
|
using SimpleTraitVersions = std::vector<TraitVersion>;
|
||||||
}
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarTraits_h
|
#endif // hifi_AvatarTraits_h
|
||||||
|
|
|
@ -63,7 +63,7 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() {
|
||||||
auto changedTraitsCopy { _changedTraits };
|
auto changedTraitsCopy { _changedTraits };
|
||||||
_changedTraits.clear();
|
_changedTraits.clear();
|
||||||
|
|
||||||
if (_performInitialSend || changedTraitsCopy.count(AvatarTraits::SkeletonModelURL)) {
|
if (_performInitialSend || changedTraitsCopy.contains(AvatarTraits::SkeletonModelURL)) {
|
||||||
traitsPacketList->startSegment();
|
traitsPacketList->startSegment();
|
||||||
_owningAvatar->packTrait(AvatarTraits::SkeletonModelURL, *traitsPacketList);
|
_owningAvatar->packTrait(AvatarTraits::SkeletonModelURL, *traitsPacketList);
|
||||||
traitsPacketList->endSegment();
|
traitsPacketList->endSegment();
|
||||||
|
|
|
@ -26,10 +26,10 @@ public:
|
||||||
|
|
||||||
void sendChangedTraitsToMixer();
|
void sendChangedTraitsToMixer();
|
||||||
|
|
||||||
bool hasChangedTraits() { return _changedTraits.size(); }
|
bool hasChangedTraits() { return _changedTraits.hasAny(); }
|
||||||
void markTraitChanged(AvatarTraits::TraitType changedTrait) { _changedTraits.insert(changedTrait); }
|
void markTraitChanged(AvatarTraits::TraitType changedTrait) { _changedTraits.insert(changedTrait); }
|
||||||
|
|
||||||
bool hasTraitChanged(AvatarTraits::TraitType checkTrait) { return _changedTraits.count(checkTrait) > 0; }
|
bool hasTraitChanged(AvatarTraits::TraitType checkTrait) { return _changedTraits.contains(checkTrait) > 0; }
|
||||||
|
|
||||||
void resetForNewMixer();
|
void resetForNewMixer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue