Overte C++ Documentation
OctreeQueryNode.h
1 //
2 // OctreeQueryNode.h
3 // libraries/octree/src
4 //
5 // Created by Brad Hefta-Gaub on 12/4/13.
6 // Copyright 2013 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 #ifndef hifi_OctreeQueryNode_h
13 #define hifi_OctreeQueryNode_h
14 
15 #include <iostream>
16 
17 #include <qqueue.h>
18 
19 #include "OctreeConstants.h"
20 #include "OctreeElementBag.h"
21 #include "OctreePacketData.h"
22 #include "OctreeQuery.h"
23 #include "OctreeSceneStats.h"
24 #include "SentPacketHistory.h"
25 
26 class OctreeSendThread;
27 class OctreeServer;
28 
29 class OctreeQueryNode : public OctreeQuery {
30  Q_OBJECT
31 public:
32  OctreeQueryNode() = default;
33  virtual ~OctreeQueryNode() = default;
34 
35  void init(); // called after creation to set up some virtual items
36  virtual PacketType getMyPacketType() const = 0;
37 
38  void resetOctreePacket(); // resets octree packet to after "V" header
39 
40  void writeToPacket(const unsigned char* buffer, unsigned int bytes); // writes to end of packet
41 
42  NLPacket& getPacket() const { return *_octreePacket; }
43  bool isPacketWaiting() const { return _octreePacketWaiting; }
44 
45  bool packetIsDuplicate() const;
46  bool shouldSuppressDuplicatePacket();
47 
48  unsigned int getAvailable() const { return _octreePacket->bytesAvailableForWrite(); }
49 
50  OctreeElementExtraEncodeData extraEncodeData;
51 
52  const ConicalViewFrustums& getCurrentViews() const { return _currentConicalViews; }
53 
54  // These are not classic setters because they are calculating and maintaining state
55  // which is set asynchronously through the network receive
56  bool updateCurrentViewFrustum();
57 
58  bool getViewSent() const { return _viewSent; }
59  void setViewSent(bool viewSent);
60 
61  bool getViewFrustumChanging() const { return _viewFrustumChanging; }
62  bool getViewFrustumJustStoppedChanging() const { return _viewFrustumJustStoppedChanging; }
63 
64  bool hasLodChanged() const { return _lodChanged; }
65 
66  OctreeSceneStats stats;
67 
68  unsigned int getlastOctreePacketLength() const { return _lastOctreePacketLength; }
69  int getDuplicatePacketCount() const { return _duplicatePacketCount; }
70 
71  void nodeKilled();
72  bool isShuttingDown() const { return _isShuttingDown; }
73 
74  void octreePacketSent() { packetSent(*_octreePacket); }
75  void packetSent(const NLPacket& packet);
76 
77  OCTREE_PACKET_SEQUENCE getSequenceNumber() const { return _sequenceNumber; }
78 
79  void parseNackPacket(ReceivedMessage& message);
80  bool hasNextNackedPacket() const;
81  const NLPacket* getNextNackedPacket();
82 
83  // call only from OctreeSendThread for the given node
84  bool haveJSONParametersChanged();
85 
86  bool shouldForceFullScene() const { return _shouldForceFullScene; }
87  void setShouldForceFullScene(bool shouldForceFullScene) { _shouldForceFullScene = shouldForceFullScene; }
88 
89 private:
90  bool _viewSent { false };
91  std::unique_ptr<NLPacket> _octreePacket;
92  bool _octreePacketWaiting;
93 
94  unsigned int _lastOctreePacketLength { 0 };
95  int _duplicatePacketCount { 0 };
96  quint64 _firstSuppressedPacket { usecTimestampNow() };
97 
98  ConicalViewFrustums _currentConicalViews;
99  bool _viewFrustumChanging { false };
100  bool _viewFrustumJustStoppedChanging { true };
101 
102  // watch for LOD changes
103  int _lastClientBoundaryLevelAdjust { 0 };
104  float _lastClientOctreeSizeScale { DEFAULT_OCTREE_SIZE_SCALE };
105  bool _lodChanged { false };
106  bool _lodInitialized { false };
107 
108  OCTREE_PACKET_SEQUENCE _sequenceNumber { 0 };
109 
110  PacketType _myPacketType { PacketType::Unknown };
111  bool _isShuttingDown { false };
112 
113  SentPacketHistory _sentPacketHistory;
114  QQueue<OCTREE_PACKET_SEQUENCE> _nackedSequenceNumbers;
115 
116  std::array<char, udt::MAX_PACKET_SIZE> _lastOctreePayload;
117 
118  QJsonObject _lastCheckJSONParameters;
119 
120  bool _shouldForceFullScene { false };
121 };
122 
123 #endif // hifi_OctreeQueryNode_h
Collects statistics for calculating and sending a scene from a octree server to an interface client.
Definition: OctreeSceneStats.h:31
Threaded processor for sending octree packets to a single client.
Definition: OctreeSendThread.h:30
Handles assignments of type OctreeServer - sending octrees to various clients.
Definition: OctreeServer.h:38