4 #include "IMortonKeyBasedEventProvider.h"
13 template <
typename TEvent,
int MortonKeyDepth>
14 class MortonKeyEventProxy :
public ICallback1<const Streaming::MortonKey>,
public IMortonKeyBasedEventProvider<TEvent>
17 using EventType = TEvent;
18 static constexpr
int Depth = MortonKeyDepth;
20 virtual TEvent& GetEventForMortonKey(Streaming::MortonKey mortonKey)
override
22 return m_quadTree[mortonKey];
25 virtual void operator()(
const Streaming::MortonKey& mortonKey)
const override
27 m_quadTree(mortonKey);
30 virtual int GetPreferredDepth()
const override
32 return MortonKeyDepth;
38 struct QuadTreeNode :
public TEvent1<TEvent>
40 QuadTreeNode(QuadTreeNode* parent)
44 QuadTreeNode() =
delete;
46 virtual void RemoveChild(
int quadrant) = 0;
51 struct QuadTreeRegularNode :
public QuadTreeNode
53 QuadTreeRegularNode(Streaming::MortonKey nodeKey, QuadTreeNode* parent)
54 : QuadTreeNode(parent)
56 , children({
nullptr,
nullptr,
nullptr,
nullptr})
58 QuadTreeRegularNode() =
delete;
60 Streaming::MortonKey nodeKey;
61 std::array<std::unique_ptr<QuadTreeRegularNode>, 4> children;
65 if (this->m_callbacks.empty())
67 for (
const auto& child : children)
74 this->parent->RemoveChild(nodeKey.Element(nodeKey.Depth() - 1));
78 void Unregister(
typename TEvent1<TEvent>::CallbackType& callback)
override
80 TEvent1<TEvent>::Unregister(callback);
84 void RemoveChild(
int quadrant)
override
86 children[quadrant] =
nullptr;
90 TEvent& operator[] (
const Streaming::MortonKey& mortonKey)
92 if (nodeKey == mortonKey || nodeKey.Depth() == Depth)
98 int childIndex = mortonKey.Element(nodeKey.Depth());
99 auto& child = children[childIndex];
103 child.reset(Eegeo_NEW(QuadTreeRegularNode)(nodeKey.Push(childIndex),
this));
105 return (*child)[mortonKey];
109 void operator()(
const Streaming::MortonKey& mortonKey)
const
111 this->Raise(mortonKey);
112 if (mortonKey.Depth() > nodeKey.Depth())
114 const auto& child = children[mortonKey.Element(nodeKey.Depth())];
122 for (
const auto& child : children)
133 struct QuadTreeRootNode :
public QuadTreeNode
136 : QuadTreeNode(nullptr)
137 , children({
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr})
139 std::array<std::unique_ptr<QuadTreeRegularNode>, 6> children;
141 void RemoveChild(
int face)
override
143 children[face] =
nullptr;
146 TEvent& operator[] (
const Streaming::MortonKey& mortonKey)
154 auto& child = children[mortonKey.Face()];
158 child.reset(Eegeo_NEW(QuadTreeRegularNode)(Streaming::MortonKey(mortonKey.Face()),
this));
160 return (*child)[mortonKey];
164 void operator()(
const Streaming::MortonKey& mortonKey)
const
166 this->Raise(mortonKey);
167 auto& child = children[mortonKey.Face()];
175 QuadTreeRootNode m_quadTree;