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