Ensure transient octrees bypass the NavCache
This commit is contained in:
parent
a17180f5b0
commit
72ec70f275
2 changed files with 66 additions and 65 deletions
|
@ -43,8 +43,8 @@ namespace flightgear
|
|||
namespace Octree
|
||||
{
|
||||
|
||||
std::unique_ptr<Node> global_spatialOctree;
|
||||
std::unique_ptr<Node> global_transientOctree;
|
||||
static std::unique_ptr<Node> global_spatialOctree;
|
||||
static std::unique_ptr<Node> global_transientOctree;
|
||||
|
||||
double RADIUS_EARTH_M = 7000 * 1000.0; // 7000km is plenty
|
||||
|
||||
|
@ -98,9 +98,11 @@ Node *Node::findNodeForBox(const SGBoxd&) const
|
|||
return const_cast<Node*>(this);
|
||||
}
|
||||
|
||||
Leaf::Leaf(const SGBoxd& aBox, int64_t aIdent, bool persistent) : Node(aBox, aIdent, persistent),
|
||||
childrenLoaded(false)
|
||||
Leaf::Leaf(const SGBoxd& aBox, int64_t aIdent, bool persistent) : Node(aBox, aIdent, persistent)
|
||||
{
|
||||
if (!persistent) {
|
||||
_childrenLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Leaf::visit(const SGVec3d& aPos, double aCutoff,
|
||||
|
@ -152,7 +154,7 @@ void Leaf::insertChild(FGPositioned::Type ty, PositionedID id)
|
|||
|
||||
void Leaf::loadChildren()
|
||||
{
|
||||
if (childrenLoaded) {
|
||||
if (_childrenLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -162,15 +164,17 @@ void Leaf::loadChildren()
|
|||
children.insert(children.end(), tp);
|
||||
} // of leaf members iteration
|
||||
|
||||
childrenLoaded = true;
|
||||
_childrenLoaded = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Branch::Branch(const SGBoxd& aBox, int64_t aIdent, bool persistent) : Node(aBox, aIdent, persistent),
|
||||
childrenLoaded(false)
|
||||
Branch::Branch(const SGBoxd& aBox, int64_t aIdent, bool persistent) : Node(aBox, aIdent, persistent)
|
||||
{
|
||||
memset(children, 0, sizeof(Node*) * 8);
|
||||
_children.fill(nullptr);
|
||||
if (!_persistent) {
|
||||
_childrenLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Branch::visit(const SGVec3d& aPos, double aCutoff,
|
||||
|
@ -179,16 +183,16 @@ void Branch::visit(const SGVec3d& aPos, double aCutoff,
|
|||
{
|
||||
loadChildren();
|
||||
for (unsigned int i=0; i<8; ++i) {
|
||||
if (!children[i]) {
|
||||
if (!_children[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double d = children[i]->distToNearest(aPos);
|
||||
double d = _children[i]->distToNearest(aPos);
|
||||
if (d > aCutoff) {
|
||||
continue; // exceeded cutoff
|
||||
}
|
||||
|
||||
aQ.push(Ordered<Node*>(children[i], d));
|
||||
aQ.push(Ordered<Node*>(_children[i], d));
|
||||
} // of child iteration
|
||||
}
|
||||
|
||||
|
@ -200,16 +204,16 @@ void Branch::visitForLines(const SGVec3d& aPos, double aCutoff,
|
|||
Node::visitForLines(aPos, aCutoff, aLines, aQ);
|
||||
|
||||
for (unsigned int i=0; i<8; ++i) {
|
||||
if (!children[i]) {
|
||||
if (!_children[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double d = children[i]->distToNearest(aPos);
|
||||
double d = _children[i]->distToNearest(aPos);
|
||||
if (d > aCutoff) {
|
||||
continue; // exceeded cutoff
|
||||
}
|
||||
|
||||
aQ.push_back(children[i]);
|
||||
aQ.push_back(_children[i]);
|
||||
} // of child iteration
|
||||
}
|
||||
|
||||
|
@ -266,7 +270,7 @@ Node* Branch::childForPos(const SGVec3d& aCart) const
|
|||
|
||||
Node* Branch::childAtIndex(int childIndex) const
|
||||
{
|
||||
Node* child = children[childIndex];
|
||||
Node* child = _children[childIndex];
|
||||
if (!child) { // lazy building of children
|
||||
SGBoxd cb(boxForChild(childIndex));
|
||||
double d2 = dot(cb.getSize(), cb.getSize());
|
||||
|
@ -285,28 +289,24 @@ Node* Branch::childAtIndex(int childIndex) const
|
|||
child = new Branch(cb, childIdent, _persistent);
|
||||
}
|
||||
|
||||
children[childIndex] = child;
|
||||
_children[childIndex] = child;
|
||||
|
||||
if (_persistent && childrenLoaded) {
|
||||
if (_persistent && _childrenLoaded) {
|
||||
// childrenLoad is done, so we're defining a new node - add it to the
|
||||
// cache too.
|
||||
NavDataCache::instance()->defineOctreeNode(const_cast<Branch*>(this), child);
|
||||
}
|
||||
}
|
||||
|
||||
return children[childIndex];
|
||||
return _children[childIndex];
|
||||
}
|
||||
|
||||
void Branch::loadChildren() const
|
||||
{
|
||||
if (childrenLoaded) {
|
||||
if (_childrenLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_persistent) {
|
||||
childrenLoaded = true;
|
||||
}
|
||||
|
||||
int childrenMask = NavDataCache::instance()->getOctreeBranchChildren(guid());
|
||||
for (int i=0; i<8; ++i) {
|
||||
if ((1 << i) & childrenMask) {
|
||||
|
@ -316,14 +316,14 @@ void Branch::loadChildren() const
|
|||
|
||||
// set this after creating the child nodes, so the cache update logic
|
||||
// in childAtIndex knows any future created children need to be added.
|
||||
childrenLoaded = true;
|
||||
_childrenLoaded = true;
|
||||
}
|
||||
|
||||
int Branch::childMask() const
|
||||
{
|
||||
int result = 0;
|
||||
for (int i=0; i<8; ++i) {
|
||||
if (children[i]) {
|
||||
if (_children[i]) {
|
||||
result |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@
|
|||
#define FG_POSITIONED_OCTREE_HXX
|
||||
|
||||
// std
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
// SimGear
|
||||
#include <simgear/math/SGGeometry.hxx>
|
||||
|
@ -194,7 +195,7 @@ namespace Octree
|
|||
void insertChild(FGPositioned::Type ty, PositionedID id);
|
||||
|
||||
private:
|
||||
bool childrenLoaded;
|
||||
bool _childrenLoaded = false;
|
||||
|
||||
typedef std::multimap<FGPositioned::Type, PositionedID> ChildMap;
|
||||
ChildMap children;
|
||||
|
@ -241,8 +242,8 @@ namespace Octree
|
|||
|
||||
void loadChildren() const;
|
||||
|
||||
mutable Node* children[8];
|
||||
mutable bool childrenLoaded;
|
||||
mutable std::array<Node*, 8> _children;
|
||||
mutable bool _childrenLoaded = false;
|
||||
};
|
||||
|
||||
bool findNearestN(const SGVec3d& aPos, unsigned int aN, double aCutoffM, FGPositioned::Filter* aFilter, FGPositionedList& aResults, int aCutoffMsec);
|
||||
|
|
Loading…
Reference in a new issue