try to decrease allocations
This commit is contained in:
@@ -81,26 +81,33 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
}
|
||||
|
||||
public (
|
||||
IEnumerable<BlockPos> Flowers,
|
||||
IEnumerable<BlockPos> Crops,
|
||||
float InitialScanProgress,
|
||||
float RescanProgress
|
||||
) GetPlantsNearPosition(BlockPos hivePos, int radius)
|
||||
) GetPlantsNearPosition(BlockPos hivePos, int radius, List<StructVec3i> flowerPositionsBuffer, List<StructVec3i> cropPositionsBuffer)
|
||||
{
|
||||
flowerPositionsBuffer.Clear();
|
||||
cropPositionsBuffer.Clear();
|
||||
|
||||
var key = StructVec3i.FromBlockPos(hivePos);
|
||||
|
||||
var flowers = flowerPositions
|
||||
.Where(p => Overlaps.IsWithinSphericalRadius(hivePos, p, radius))
|
||||
.Select(p => new BlockPos(p.X, p.Y, p.Z, hivePos.dimension));
|
||||
foreach (var flowerPos in flowerPositions)
|
||||
{
|
||||
if (!Overlaps.IsWithinSphericalRadius(hivePos, flowerPos, radius))
|
||||
continue;
|
||||
flowerPositionsBuffer.Add(flowerPos);
|
||||
}
|
||||
|
||||
var crops = cropPositions
|
||||
.Where(p => Overlaps.IsWithinSphericalRadius(hivePos, p, radius))
|
||||
.Select(p => new BlockPos(p.X, p.Y, p.Z, hivePos.dimension));
|
||||
foreach (var cropPos in cropPositions)
|
||||
{
|
||||
if (!Overlaps.IsWithinSphericalRadius(hivePos, cropPos, radius))
|
||||
continue;
|
||||
cropPositionsBuffer.Add(cropPos);
|
||||
}
|
||||
|
||||
float initialProgress = 1.0f;
|
||||
float rescanProgress = 0.0f;
|
||||
if (!beehives.TryGetValue(key, out var cursor))
|
||||
return (flowers, crops, initialProgress, rescanProgress);
|
||||
return (initialProgress, rescanProgress);
|
||||
|
||||
var table = offsetTables[cursor.Radius];
|
||||
if (table.Count > 0)
|
||||
@@ -109,13 +116,24 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
rescanProgress = cursor.GetRescanProgress(offsetTables);
|
||||
}
|
||||
|
||||
return (flowers, crops, initialProgress, rescanProgress);
|
||||
return (initialProgress, rescanProgress);
|
||||
}
|
||||
|
||||
public (int FlowerCount, int CropCount, float InitialScanProgress, float RescanProgress) GetPlantCountsNearPosition(BlockPos hivePos, int radius)
|
||||
{
|
||||
int flowers = flowerPositions.Count(p => Overlaps.IsWithinSphericalRadius(hivePos, p, radius));
|
||||
int crops = cropPositions.Count(p => Overlaps.IsWithinSphericalRadius(hivePos, p, radius));
|
||||
int flowers = 0;
|
||||
foreach (var flowerPos in flowerPositions)
|
||||
{
|
||||
if (Overlaps.IsWithinSphericalRadius(hivePos, flowerPos, radius))
|
||||
flowers++;
|
||||
}
|
||||
|
||||
int crops = 0;
|
||||
foreach (var cropPos in cropPositions)
|
||||
{
|
||||
if (Overlaps.IsWithinSphericalRadius(hivePos, cropPos, radius))
|
||||
crops++;
|
||||
}
|
||||
|
||||
float initialProgress = 0.0f;
|
||||
float rescanProgress = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user