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  class AvatarEntityDataHash {
77  public:
78  AvatarEntityDataHash(uint32_t h) : hash(h) {};
79  uint32_t hash { 0 };
80  bool success { false };
81  };
82 
83  using MapOfAvatarEntityDataHashes = QMap<QUuid, AvatarEntityDataHash>;
84  MapOfAvatarEntityDataHashes _avatarEntityDataHashes;
85 
86  std::vector<QUuid> _attachedAvatarEntities;
87  QUuid _otherAvatarOrbMeshPlaceholderID;
88  AvatarMotionState* _motionState { nullptr };
89  std::vector<DetailedMotionState*> _detailedMotionStates;
90  int32_t _spaceIndex { -1 };
91  uint8_t _workloadRegion { workload::Region::INVALID };
92  BodyLOD _bodyLOD { BodyLOD::Sphere };
93  bool _needsDetailedRebuild { false };
94 };
95 
96 using OtherAvatarPointer = std::shared_ptr<OtherAvatar>;
97 using AvatarPointer = std::shared_ptr<Avatar>;
98 
99 #endif // hifi_OtherAvatar_h