// // AvatarManager.h // interface/src/avatar // // Created by Stephen Birarda on 1/23/2014. // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_AvatarManager_h #define hifi_AvatarManager_h #include #include #include #include #include #include #include #include #include "Avatar.h" #include "AvatarMotionState.h" class MyAvatar; class AudioInjector; class AvatarManager : public AvatarHashMap { Q_OBJECT SINGLETON_DEPENDENCY public: /// Registers the script types associated with the avatar manager. static void registerMetaTypes(QScriptEngine* engine); virtual ~AvatarManager(); void init(); std::shared_ptr getMyAvatar() { return _myAvatar; } AvatarSharedPointer getAvatarBySessionID(const QUuid& sessionID) const override; int getFullySimulatedAvatars() const { return _fullySimulatedAvatars; } int getPartiallySimulatedAvatars() const { return _partiallySimulatedAvatars; } float getAvatarSimulationTime() const { return _avatarSimulationTime; } void updateMyAvatar(float deltaTime); void updateOtherAvatars(float deltaTime); void postUpdate(float deltaTime); void clearOtherAvatars(); void clearAllAvatars(); bool shouldShowReceiveStats() const { return _shouldShowReceiveStats; } class LocalLight { public: glm::vec3 color; glm::vec3 direction; }; Q_INVOKABLE void setLocalLights(const QVector& localLights); Q_INVOKABLE QVector getLocalLights() const; void getObjectsToRemoveFromPhysics(VectorOfMotionStates& motionStates); void getObjectsToAddToPhysics(VectorOfMotionStates& motionStates); void getObjectsToChange(VectorOfMotionStates& motionStates); void handleOutgoingChanges(const VectorOfMotionStates& motionStates); void handleCollisionEvents(const CollisionEvents& collisionEvents); Q_INVOKABLE float getAvatarDataRate(const QUuid& sessionID, const QString& rateName = QString("")) const; Q_INVOKABLE float getAvatarUpdateRate(const QUuid& sessionID, const QString& rateName = QString("")) const; Q_INVOKABLE float getAvatarSimulationRate(const QUuid& sessionID, const QString& rateName = QString("")) const; Q_INVOKABLE RayToAvatarIntersectionResult findRayIntersection(const PickRay& ray, const QScriptValue& avatarIdsToInclude = QScriptValue(), const QScriptValue& avatarIdsToDiscard = QScriptValue()); // TODO: remove this HACK once we settle on optimal default sort coefficients Q_INVOKABLE float getAvatarSortCoefficient(const QString& name); Q_INVOKABLE void setAvatarSortCoefficient(const QString& name, const QScriptValue& value); float getMyAvatarSendRate() const { return _myAvatarSendRate.rate(); } public slots: void setShouldShowReceiveStats(bool shouldShowReceiveStats) { _shouldShowReceiveStats = shouldShowReceiveStats; } void updateAvatarRenderStatus(bool shouldRenderAvatars); private slots: virtual void removeAvatar(const QUuid& sessionUUID, KillAvatarReason removalReason = KillAvatarReason::NoReason) override; private: explicit AvatarManager(QObject* parent = 0); explicit AvatarManager(const AvatarManager& other); void simulateAvatarFades(float deltaTime); // virtual overrides virtual AvatarSharedPointer newSharedAvatar() override; virtual AvatarSharedPointer addAvatar(const QUuid& sessionUUID, const QWeakPointer& mixerWeakPointer) override; virtual void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason) override; QVector _avatarFades; std::shared_ptr _myAvatar; quint64 _lastSendAvatarDataTime = 0; // Controls MyAvatar send data rate. QVector _localLights; bool _shouldShowReceiveStats = false; std::list> _collisionInjectors; SetOfAvatarMotionStates _motionStatesThatMightUpdate; SetOfMotionStates _motionStatesToAddToPhysics; VectorOfMotionStates _motionStatesToRemoveFromPhysics; RateCounter<> _myAvatarSendRate; int _fullySimulatedAvatars { 0 }; int _partiallySimulatedAvatars { 0 }; float _avatarSimulationTime { 0.0f }; // TODO: remove this HACK once we settle on optimal sort coefficients // These coefficients exposed for fine tuning the sort priority for transfering new _jointData to the render pipeline. float _avatarSortCoefficientSize { 0.5f }; float _avatarSortCoefficientCenter { 0.25 }; float _avatarSortCoefficientAge { 1.0f }; }; Q_DECLARE_METATYPE(AvatarManager::LocalLight) Q_DECLARE_METATYPE(QVector) #endif // hifi_AvatarManager_h