Overte C++ Documentation
SafeLanding.h
1 //
2 // SafeLanding.h
3 // interface/src/octree
4 //
5 // Created by Simon Walton.
6 // Copyright 2018 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 // Controller for logic to wait for local collision bodies before enabling physics.
13 
14 #ifndef hifi_SafeLanding_h
15 #define hifi_SafeLanding_h
16 
17 #include <QtCore/QObject>
18 #include <QtCore/QSharedPointer>
19 
20 #include <set>
21 
22 #include "EntityItem.h"
23 #include "EntityDynamicInterface.h"
24 
25 #include "EntityTreeRenderer.h"
26 
27 class EntityTreeRenderer;
28 class EntityItemID;
29 
30 class SafeLanding : public QObject {
31 public:
32  static constexpr OCTREE_PACKET_SEQUENCE MAX_SEQUENCE = std::numeric_limits<OCTREE_PACKET_SEQUENCE>::max();
33  static constexpr OCTREE_PACKET_SEQUENCE INVALID_SEQUENCE = MAX_SEQUENCE; // not technically invalid, but close enough
34 
35  void startTracking(QSharedPointer<EntityTreeRenderer> entityTreeRenderer);
36  void updateTracking();
37  void stopTracking();
38  void reset();
39  bool isTracking() const { return _trackingEntities; }
40  bool trackingIsComplete() const;
41 
42  void finishSequence(OCTREE_PACKET_SEQUENCE first, OCTREE_PACKET_SEQUENCE last); // 'last' exclusive.
43  void addToSequence(OCTREE_PACKET_SEQUENCE sequenceNumber);
44  float loadingProgressPercentage();
45 
46 private slots:
47  void addTrackedEntity(const EntityItemID& entityID);
48  void deleteTrackedEntity(const EntityItemID& entityID);
49 
50 private:
51  bool isEntityPhysicsReady(const EntityItemPointer& entity);
52  void debugDumpSequenceIDs() const;
53 
54  std::mutex _lock;
55  using Locker = std::lock_guard<std::mutex>;
56  bool _trackingEntities { false };
57  QSharedPointer<EntityTreeRenderer> _entityTreeRenderer;
58  using EntityMap = std::map<EntityItemID, EntityItemPointer>;
59  EntityMap _trackedEntities;
60 
61  OCTREE_PACKET_SEQUENCE _sequenceStart { INVALID_SEQUENCE };
62  OCTREE_PACKET_SEQUENCE _sequenceEnd { INVALID_SEQUENCE };
63  int32_t _maxTrackedEntityCount { 0 };
64  int32_t _trackedEntityStabilityCount { 0 };
65 
66  quint64 _startTime { 0 };
67 
68  struct SequenceLessThan {
69  bool operator()(const OCTREE_PACKET_SEQUENCE& a, const OCTREE_PACKET_SEQUENCE& b) const;
70  };
71 
72  using SequenceSet = std::set<OCTREE_PACKET_SEQUENCE, SequenceLessThan>;
73  SequenceSet _sequenceNumbers;
74 
75  static CalculateEntityLoadingPriority entityLoadingOperatorElevateCollidables;
76  CalculateEntityLoadingPriority _prevEntityLoadingPriorityOperator { nullptr };
77 };
78 
79 #endif // hifi_SafeLanding_h
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28