Overte C++ Documentation
OctreeSendThread.h
1 //
2 // OctreeSendThread.h
3 // assignment-client/src/octree
4 //
5 // Created by Brad Hefta-Gaub on 8/21/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Threaded or non-threaded object for sending octree data packets to a client
9 //
10 // Distributed under the Apache License, Version 2.0.
11 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
12 //
13 
14 #ifndef hifi_OctreeSendThread_h
15 #define hifi_OctreeSendThread_h
16 
17 #include <atomic>
18 
19 #include <GenericThread.h>
20 #include <Node.h>
21 #include <OctreePacketData.h>
22 #include "OctreeQueryNode.h"
23 
24 class OctreeQueryNode;
25 class OctreeServer;
26 
27 using AtomicUIntStat = std::atomic<uintmax_t>;
28 
31  Q_OBJECT
32 public:
33  OctreeSendThread(OctreeServer* myServer, const SharedNodePointer& node);
34  virtual ~OctreeSendThread();
35 
36  void setIsShuttingDown();
37  bool isShuttingDown() { return _isShuttingDown; }
38 
39  QUuid getNodeUuid() const { return _nodeUuid; }
40 
41  static AtomicUIntStat _totalBytes;
42  static AtomicUIntStat _totalWastedBytes;
43  static AtomicUIntStat _totalPackets;
44 
45  static AtomicUIntStat _totalSpecialBytes;
46  static AtomicUIntStat _totalSpecialPackets;
47 
48  static AtomicUIntStat _usleepTime;
49  static AtomicUIntStat _usleepCalls;
50 
51 protected:
53  virtual bool process() override;
54 
55  virtual bool traverseTreeAndSendContents(SharedNodePointer node, OctreeQueryNode* nodeData,
56  bool viewFrustumChanged, bool isFullScene);
57  virtual bool traverseTreeAndBuildNextPacketPayload(EncodeBitstreamParams& params, const QJsonObject& jsonFilters) = 0;
58 
59  OctreePacketData _packetData;
60  QWeakPointer<Node> _node;
61  OctreeServer* _myServer { nullptr };
62  QUuid _nodeUuid;
63 
64 private:
66  virtual void preDistributionProcessing() = 0;
67  int handlePacketSend(SharedNodePointer node, OctreeQueryNode* nodeData, bool dontSuppressDuplicate = false);
68  int packetDistributor(SharedNodePointer node, OctreeQueryNode* nodeData, bool viewFrustumChanged);
69 
70  virtual bool hasSomethingToSend(OctreeQueryNode* nodeData) = 0;
71  virtual bool shouldStartNewTraversal(OctreeQueryNode* nodeData, bool viewFrustumChanged) = 0;
72 
73  int _truePacketsSent { 0 }; // available for debug stats
74  int _trueBytesSent { 0 }; // available for debug stats
75  int _packetsSentThisInterval { 0 }; // used for bandwidth throttle condition
76  bool _isShuttingDown { false };
77 };
78 
79 #endif // hifi_OctreeSendThread_h
Definition: GenericThread.h:23
Handles packing of the data portion of PacketType_OCTREE_DATA messages.
Definition: OctreePacketData.h:93
Threaded processor for sending octree packets to a single client.
Definition: OctreeSendThread.h:30
virtual bool process() override
Implements generic processing behavior for this thread.
Definition: OctreeSendThread.cpp:69
Handles assignments of type OctreeServer - sending octrees to various clients.
Definition: OctreeServer.h:38