修改水
This commit is contained in:
@@ -23,9 +23,7 @@ namespace Obi
|
||||
public unsafe struct NativeMultilevelGrid<T> : IDisposable where T : unmanaged, IEquatable<T>
|
||||
{
|
||||
|
||||
public const float minSize = 0.01f; // minimum cell size is 1 centimeter, enough for very small particles.
|
||||
public const int minLevel = -6; // grid level for minSize.
|
||||
public const int maxLevel = 17;
|
||||
public const float minSize = 0.01f;
|
||||
|
||||
/**
|
||||
* A cell in the multilevel grid. Coords are 4-dimensional, the 4th component is the grid level.
|
||||
@@ -60,7 +58,7 @@ namespace Obi
|
||||
{
|
||||
get
|
||||
{
|
||||
return contents.ElementAt(index);
|
||||
return UnsafeUtility.ReadArrayElement<K>(contents.Ptr, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +69,11 @@ namespace Obi
|
||||
|
||||
public bool Remove(K entity)
|
||||
{
|
||||
int index = contents.IndexOf(entity);
|
||||
//int index = contents.IndexOf(entity);
|
||||
int index = -1;
|
||||
for (int i = 0; i < contents.Length; ++i)
|
||||
if (contents[i].Equals(entity)) { index = i; break; }
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
contents.RemoveAtSwapBack(index);
|
||||
@@ -86,15 +88,15 @@ namespace Obi
|
||||
}
|
||||
}
|
||||
|
||||
public NativeParallelHashMap<int4, int> grid;
|
||||
public NativeHashMap<int4, int> grid;
|
||||
public NativeList<Cell<T>> usedCells;
|
||||
public NativeParallelHashMap<int, int> populatedLevels;
|
||||
public NativeHashMap<int, int> populatedLevels;
|
||||
|
||||
public NativeMultilevelGrid(int capacity, Allocator label)
|
||||
{
|
||||
grid = new NativeParallelHashMap<int4, int>(capacity, label);
|
||||
grid = new NativeHashMap<int4, int>(capacity, label);
|
||||
usedCells = new NativeList<Cell<T>>(label);
|
||||
populatedLevels = new NativeParallelHashMap<int, int>(10, label);
|
||||
populatedLevels = new NativeHashMap<int, int>(10, label);
|
||||
}
|
||||
|
||||
public int CellCount
|
||||
@@ -170,16 +172,14 @@ namespace Obi
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GridLevelForSize(float size)
|
||||
{
|
||||
// the magic number is 1/log(2), used because log_a(x) = log_b(x) / log_b(a)
|
||||
// level is clamped between MIN_LEVEL and MAX_LEVEL, then remapped to (0, MAX_LEVEL - MIN_LEVEL)
|
||||
// this allows us to avoid InterlockedMax issues on GPU, since it doesn't work on negative numbers on some APIs.
|
||||
return math.clamp((int)math.ceil(math.log(size) * 1.44269504089f), minLevel, maxLevel) - minLevel;
|
||||
// the magic number is 1/log(2)
|
||||
return (int)math.ceil(math.log(math.max(size,minSize)) * 1.44269504089f);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CellSizeOfLevel(int level)
|
||||
{
|
||||
return math.exp2(level + minLevel);
|
||||
return math.exp2(level);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +187,7 @@ namespace Obi
|
||||
*/
|
||||
public static int4 GetParentCellCoords(int4 cellCoords, int level)
|
||||
{
|
||||
float decimation = math.exp2(level - cellCoords[3]);
|
||||
float decimation = CellSizeOfLevel(level - cellCoords[3]);
|
||||
int4 cell = (int4)math.floor((float4)cellCoords / decimation);
|
||||
cell[3] = level;
|
||||
return cell;
|
||||
|
||||
Reference in New Issue
Block a user