Initial commit: Final state of the master project
This commit is contained in:
51
Research/scene/Octree/BaseTree.cpp
Normal file
51
Research/scene/Octree/BaseTree.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include "BaseTree.h"
|
||||
|
||||
std::vector<BaseTree*> BaseTree::mTreePool = std::vector<BaseTree*>();
|
||||
|
||||
BaseTree::BaseTree()
|
||||
{
|
||||
mTreeIndex = AssignRootIndex();
|
||||
}
|
||||
BaseTree::~BaseTree()
|
||||
{
|
||||
mTreePool[mTreeIndex] = NULL;
|
||||
}
|
||||
|
||||
// Returns the number of bytes per pointer for each level as a vector
|
||||
std::vector<unsigned8> BaseTree::GetAdditionalBytesPerPointer() const
|
||||
{
|
||||
std::vector<unsigned8> res(GetMaxLevel() + 1);
|
||||
for (unsigned8 level = 0; level <= GetMaxLevel(); level++)
|
||||
res[level] = GetAdditionalBytesPerPointer(level);
|
||||
return res;
|
||||
}
|
||||
// Returns the number of bytes per node for each level as a vector.
|
||||
std::vector<unsigned8> BaseTree::GetAdditionalBytesPerNode() const
|
||||
{
|
||||
std::vector<unsigned8> res(GetMaxLevel() + 1);
|
||||
for (unsigned8 level = 0; level <= GetMaxLevel(); level++)
|
||||
res[level] = GetAdditionalBytesPerNode(level);
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned16 BaseTree::AssignRootIndex()
|
||||
{
|
||||
if (!mTreePool.empty())
|
||||
{
|
||||
// Try and find an empty spot in the RootPool:
|
||||
for (size_t i = 0; i < mTreePool.size(); i++)
|
||||
{
|
||||
if (mTreePool[i] == NULL)
|
||||
{
|
||||
mTreePool[i] = this;
|
||||
return (unsigned16)i;
|
||||
}
|
||||
if (mTreePool[i] == this) return (unsigned16)i; // Already assigned
|
||||
}
|
||||
}
|
||||
// If no empty spot was found, increase the size of the root
|
||||
mTreePool.push_back(this);
|
||||
assert(mTreePool.size() < BitHelper::Exp2(16));
|
||||
return (unsigned16)(mTreePool.size() - 1);
|
||||
}
|
||||
Reference in New Issue
Block a user