Overte C++ Documentation
MovingEntitiesOperator.h
1 //
2 // MovingEntitiesOperator.h
3 // libraries/entities/src
4 //
5 // Created by Brad Hefta-Gaub on 8/11/2014.
6 // Copyright 2014 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_MovingEntitiesOperator_h
13 #define hifi_MovingEntitiesOperator_h
14 
15 #include <QSet>
16 
17 #include "EntityItem.h"
18 
19 class EntityToMoveDetails {
20 public:
21  EntityItemPointer entity;
22  AACube oldCube; // meters
23  AACube newCube; // meters
24  AABox newCubeClamped; // meters
25  EntityTreeElementPointer oldContainingElement;
26  AACube oldContainingElementCube; // meters
27  bool oldFound;
28  bool newFound;
29 };
30 
31 inline uint qHash(const EntityToMoveDetails& a, uint seed) {
32  return qHash(a.entity->getEntityItemID(), seed);
33 }
34 
35 inline bool operator==(const EntityToMoveDetails& a, const EntityToMoveDetails& b) {
36  return a.entity->getEntityItemID() == b.entity->getEntityItemID();
37 }
38 
39 class MovingEntitiesOperator : public RecurseOctreeOperator {
40 public:
41  MovingEntitiesOperator();
42  ~MovingEntitiesOperator();
43 
44  void addEntityToMoveList(EntityItemPointer entity, const AACube& newCube);
45  virtual bool preRecursion(const OctreeElementPointer& element) override;
46  virtual bool postRecursion(const OctreeElementPointer& element) override;
47  virtual OctreeElementPointer possiblyCreateChildAt(const OctreeElementPointer& element, int childIndex) override;
48  bool hasMovingEntities() const { return _entitiesToMove.size() > 0; }
49  void reset();
50 private:
51  bool shouldRecurseSubTree(const OctreeElementPointer& element);
52 
53  QSet<EntityToMoveDetails> _entitiesToMove;
54  int _foundOldCount { 0 };
55  int _foundNewCount { 0 };
56  int _lookingCount { 0 };
57  bool _wantDebug { false };
58 };
59 
60 #endif // hifi_MovingEntitiesOperator_h
derive from this class to use the Octree::recurseTreeWithOperator() method
Definition: Octree.h:43