Initial commit: Final state of the master project
This commit is contained in:
52
Research/scene/Octree/ChildMask.h
Normal file
52
Research/scene/Octree/ChildMask.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "../../core/Defines.h"
|
||||
#include "../../core/BitHelper.h"
|
||||
|
||||
struct ChildBits
|
||||
{
|
||||
unsigned8 c0 : 1, c1 : 1, c2 : 1, c3 : 1, c4 : 1, c5 : 1, c6 : 1, c7 : 1;
|
||||
};
|
||||
union ChildMask
|
||||
{
|
||||
ChildBits children;
|
||||
unsigned8 mask;
|
||||
|
||||
ChildMask() : ChildMask(0) {}
|
||||
ChildMask(unsigned8 mask) { this->mask = mask; }
|
||||
|
||||
inline bool Get(ChildIndex index) const {
|
||||
return BitHelper::GetLS(mask, index);
|
||||
//switch (index)
|
||||
//{
|
||||
//case 0: return children.c0;
|
||||
//case 1: return children.c1;
|
||||
//case 2: return children.c2;
|
||||
//case 3: return children.c3;
|
||||
//case 4: return children.c4;
|
||||
//case 5: return children.c5;
|
||||
//case 6: return children.c6;
|
||||
//case 7: return children.c7;
|
||||
//}
|
||||
//return false;
|
||||
}
|
||||
|
||||
inline void Set(ChildIndex index, bool value)
|
||||
{
|
||||
BitHelper::SetLS(mask, index, value);
|
||||
//switch (index)
|
||||
//{
|
||||
//case 0: children.c0 = value; break;
|
||||
//case 1: children.c1 = value; break;
|
||||
//case 2: children.c2 = value; break;
|
||||
//case 3: children.c3 = value; break;
|
||||
//case 4: children.c4 = value; break;
|
||||
//case 5: children.c5 = value; break;
|
||||
//case 6: children.c6 = value; break;
|
||||
//case 7: children.c7 = value; break;
|
||||
//}
|
||||
}
|
||||
|
||||
// Use bit-tricks to count the number of set bits before a certain positions
|
||||
inline unsigned8 GetSetBefore(ChildIndex pos) const { return BitHelper::GetHSSetBefore(mask, pos); }
|
||||
inline unsigned8 GetSet() const { return BitHelper::GetSet(mask); }
|
||||
};
|
||||
Reference in New Issue
Block a user