mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-10 10:34:56 +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 <shared/QtHelpers.h>
|
||||
#include <GLMHelpers.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) {
|
||||
_globalPosition = getWorldPosition();
|
||||
|
@ -63,8 +67,6 @@ void ScriptableAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
|||
_animSkeleton.reset();
|
||||
|
||||
AvatarData::setSkeletonModelURL(skeletonModelURL);
|
||||
|
||||
_clientTraitsHandler.markTraitChanged(AvatarTraits::SkeletonModelURL);
|
||||
}
|
||||
|
||||
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 <AnimSkeleton.h>
|
||||
#include <AvatarData.h>
|
||||
#include <ClientTraitsHandler.h>
|
||||
#include <ScriptEngine.h>
|
||||
|
||||
/**jsdoc
|
||||
|
@ -125,6 +124,8 @@ class ScriptableAvatar : public AvatarData, public Dependency {
|
|||
Q_OBJECT
|
||||
public:
|
||||
|
||||
ScriptableAvatar();
|
||||
|
||||
/**jsdoc
|
||||
* @function Avatar.startAnimation
|
||||
* @param {string} url
|
||||
|
@ -165,8 +166,6 @@ private:
|
|||
QStringList _maskedJoints;
|
||||
AnimationPointer _bind; // a sleazy way to get the skeleton, given the various library/cmake dependencies
|
||||
std::shared_ptr<AnimSkeleton> _animSkeleton;
|
||||
|
||||
ClientTraitsHandler _clientTraitsHandler { this };
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptableAvatar_h
|
||||
|
|
|
@ -119,9 +119,9 @@ MyAvatar::MyAvatar(QThread* thread) :
|
|||
_goToOrientation(),
|
||||
_prevShouldDrawHead(true),
|
||||
_audioListenerMode(FROM_HEAD),
|
||||
_hmdAtRestDetector(glm::vec3(0), glm::quat()),
|
||||
_clientTraitsHandler(this)
|
||||
_hmdAtRestDetector(glm::vec3(0), glm::quat())
|
||||
{
|
||||
_clientTraitsHandler = std::unique_ptr<ClientTraitsHandler>(new ClientTraitsHandler(this));
|
||||
|
||||
// give the pointer to our head to inherited _headData variable from AvatarData
|
||||
_headData = new MyHead(this);
|
||||
|
@ -514,7 +514,7 @@ void MyAvatar::update(float deltaTime) {
|
|||
sendIdentityPacket();
|
||||
}
|
||||
|
||||
_clientTraitsHandler.sendChangedTraitsToMixer();
|
||||
_clientTraitsHandler->sendChangedTraitsToMixer();
|
||||
|
||||
simulate(deltaTime);
|
||||
|
||||
|
@ -1702,10 +1702,6 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
|||
|
||||
saveAvatarUrl();
|
||||
emit skeletonChanged();
|
||||
|
||||
if (previousSkeletonModelURL != _skeletonModelURL) {
|
||||
_clientTraitsHandler.markTraitChanged(AvatarTraits::SkeletonModelURL);
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition) {
|
||||
|
|
|
@ -1334,7 +1334,6 @@ public slots:
|
|||
*/
|
||||
void setAnimGraphUrl(const QUrl& url); // thread-safe
|
||||
|
||||
|
||||
/**jsdoc
|
||||
* @function MyAvatar.getPositionForAudio
|
||||
* @returns {Vec3}
|
||||
|
@ -1347,7 +1346,6 @@ public slots:
|
|||
*/
|
||||
glm::quat getOrientationForAudio();
|
||||
|
||||
|
||||
/**jsdoc
|
||||
* @function MyAvatar.setModelScale
|
||||
* @param {number} scale
|
||||
|
@ -1776,8 +1774,6 @@ private:
|
|||
|
||||
bool _haveReceivedHeightLimitsFromDomain { false };
|
||||
int _disableHandTouchCount { 0 };
|
||||
|
||||
ClientTraitsHandler _clientTraitsHandler;
|
||||
};
|
||||
|
||||
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
#include "AvatarLogging.h"
|
||||
#include "AvatarTraits.h"
|
||||
#include "ClientTraitsHandler.h"
|
||||
|
||||
//#define WANT_DEBUG
|
||||
|
||||
|
@ -1897,6 +1898,10 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
|||
|
||||
updateJointMappings();
|
||||
|
||||
if (_clientTraitsHandler) {
|
||||
_clientTraitsHandler->markTraitChanged(AvatarTraits::SkeletonModelURL);
|
||||
}
|
||||
|
||||
emit skeletonModelURLChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -372,6 +372,8 @@ public:
|
|||
bool operator<(const AvatarPriority& other) const { return priority < other.priority; }
|
||||
};
|
||||
|
||||
class ClientTraitsHandler;
|
||||
|
||||
class AvatarData : public QObject, public SpatiallyNestable {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -924,6 +926,7 @@ public:
|
|||
* @param {string} entityData
|
||||
*/
|
||||
Q_INVOKABLE void updateAvatarEntity(const QUuid& entityID, const QByteArray& entityData);
|
||||
|
||||
/**jsdoc
|
||||
* @function MyAvatar.clearAvatarEntity
|
||||
* @param {Uuid} entityID
|
||||
|
@ -1435,6 +1438,9 @@ protected:
|
|||
bool _hasProcessedFirstIdentity { false };
|
||||
float _density;
|
||||
|
||||
// null unless MyAvatar or ScriptableAvatar sending traits data to mixer
|
||||
std::unique_ptr<ClientTraitsHandler> _clientTraitsHandler;
|
||||
|
||||
template <typename T, typename F>
|
||||
T readLockWithNamedJointIndex(const QString& name, const T& defaultValue, F f) const {
|
||||
int index = getFauxJointIndex(name);
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#ifndef hifi_AvatarTraits_h
|
||||
#define hifi_AvatarTraits_h
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace AvatarTraits {
|
||||
|
@ -23,7 +23,28 @@ namespace AvatarTraits {
|
|||
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 };
|
||||
|
||||
using TraitVersion = uint32_t;
|
||||
|
@ -35,6 +56,6 @@ namespace AvatarTraits {
|
|||
using TraitWireSize = uint16_t;
|
||||
|
||||
using SimpleTraitVersions = std::vector<TraitVersion>;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarTraits_h
|
||||
|
|
|
@ -63,7 +63,7 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() {
|
|||
auto changedTraitsCopy { _changedTraits };
|
||||
_changedTraits.clear();
|
||||
|
||||
if (_performInitialSend || changedTraitsCopy.count(AvatarTraits::SkeletonModelURL)) {
|
||||
if (_performInitialSend || changedTraitsCopy.contains(AvatarTraits::SkeletonModelURL)) {
|
||||
traitsPacketList->startSegment();
|
||||
_owningAvatar->packTrait(AvatarTraits::SkeletonModelURL, *traitsPacketList);
|
||||
traitsPacketList->endSegment();
|
||||
|
|
|
@ -26,10 +26,10 @@ public:
|
|||
|
||||
void sendChangedTraitsToMixer();
|
||||
|
||||
bool hasChangedTraits() { return _changedTraits.size(); }
|
||||
bool hasChangedTraits() { return _changedTraits.hasAny(); }
|
||||
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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue