Overte C++ Documentation
OtherAvatar.h
1 //
2 // Created by amantly 2018.06.26
3 // Copyright 2018 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #ifndef hifi_OtherAvatar_h
10 #define hifi_OtherAvatar_h
11 
12 #include <memory>
13 #include <vector>
14 #include <optional>
15 
16 #include <avatars-renderer/Avatar.h>
17 #include <workload/Space.h>
18 
19 #include "InterfaceLogging.h"
20 
21 class AvatarManager;
22 class AvatarMotionState;
23 class DetailedMotionState;
24 
25 class OtherAvatar : public Avatar {
26 public:
27  explicit OtherAvatar(QThread* thread);
28  virtual ~OtherAvatar();
29 
30  enum BodyLOD {
31  Sphere = 0,
32  MultiSphereLow, // No finger joints
33  MultiSphereHigh // All joints
34  };
35 
36  virtual void instantiableAvatar() override { };
37  virtual void createOrb() override;
38  virtual void indicateLoadingStatus(LoadingStatus loadingStatus) override;
39  void updateOrbPosition();
40  void removeOrb();
41 
42  void setSpaceIndex(int32_t index);
43  int32_t getSpaceIndex() const { return _spaceIndex; }
44  void updateSpaceProxy(workload::Transaction& transaction) const;
45 
46  int parseDataFromBuffer(const QByteArray& buffer) override;
47 
48  bool isInPhysicsSimulation() const;
49  void rebuildCollisionShape() override;
50 
51  void setWorkloadRegion(uint8_t region);
52  uint8_t getWorkloadRegion() { return _workloadRegion; }
53  bool shouldBeInPhysicsSimulation() const;
54  bool needsPhysicsUpdate() const;
55 
56  const btCollisionShape* createCollisionShape(int32_t jointIndex, bool& isBound, std::vector<int32_t>& boundJoints);
57  std::vector<DetailedMotionState*>& getDetailedMotionStates() { return _detailedMotionStates; }
58  void forgetDetailedMotionStates();
59  BodyLOD getBodyLOD() { return _bodyLOD; }
60  void computeShapeLOD();
61 
62  void updateCollisionGroup(bool myAvatarCollide);
63  bool getCollideWithOtherAvatars() const { return _collideWithOtherAvatars; }
64 
65  void setCollisionWithOtherAvatarsFlags() override;
66 
67  void simulate(float deltaTime, bool inView) override;
68  void interpolateJoints();
69  void debugJointData() const;
70  friend AvatarManager;
71 
72 protected:
73  void handleChangedAvatarEntityData();
74  void updateAttachedAvatarEntities();
75  void onAddAttachedAvatarEntity(const QUuid& id);
76  void onRemoveAttachedAvatarEntity(const QUuid& id);
77 
78  void onIdentityRecieved() override;
79 
80  class AvatarEntityDataHash {
81  public:
82  AvatarEntityDataHash(uint32_t h) : hash(h) {};
83  uint32_t hash { 0 };
84  bool success { false };
85  };
86 
87  using MapOfAvatarEntityDataHashes = QMap<QUuid, AvatarEntityDataHash>;
88  MapOfAvatarEntityDataHashes _avatarEntityDataHashes;
89 
90  std::vector<QUuid> _attachedAvatarEntities;
91  QUuid _otherAvatarOrbMeshPlaceholderID;
92  AvatarMotionState* _motionState { nullptr };
93  std::vector<DetailedMotionState*> _detailedMotionStates;
94  int32_t _spaceIndex { -1 };
95  uint8_t _workloadRegion { workload::Region::INVALID };
96  BodyLOD _bodyLOD { BodyLOD::Sphere };
97  bool _needsDetailedRebuild { false };
98 
100  std::vector<std::vector<std::pair<quint64, JointData>>> _jointHistory;
101  std::optional<glm::vec3> _lerpServerPosition {};
102 
103 private:
104  // When determining _hasCheckedForAvatarEntities for OtherAvatars, we can set it to true in
105  // handleChangedAvatarEntityData if we have avatar entities. But we never receive explicit
106  // confirmation from the avatar mixer if we don't have any. So instead, we wait to receive
107  // a few identity packets, and assume that if we haven't gotten any avatar entities by then,
108  // that we're safe to say there aren't any.
109  uint8_t _avatarEntityIdentityCountdown { 2 };
110 };
111 
112 using OtherAvatarPointer = std::shared_ptr<OtherAvatar>;
113 using AvatarPointer = std::shared_ptr<Avatar>;
114 
115 #endif // hifi_OtherAvatar_h