try to further decrease allocations
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"total": 602351,
|
"total": 605357,
|
||||||
"sessions": [
|
"sessions": [
|
||||||
{
|
{
|
||||||
"begin": "2026-01-09T17:26:02+01:00",
|
"begin": "2026-01-09T17:26:02+01:00",
|
||||||
@@ -1360,6 +1360,11 @@
|
|||||||
"begin": "2026-03-21T01:43:25+01:00",
|
"begin": "2026-03-21T01:43:25+01:00",
|
||||||
"end": "2026-03-21T04:23:47+01:00",
|
"end": "2026-03-21T04:23:47+01:00",
|
||||||
"duration": 9621
|
"duration": 9621
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"begin": "2026-03-22T03:01:07+01:00",
|
||||||
|
"end": "2026-03-22T03:51:14+01:00",
|
||||||
|
"duration": 3006
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -57,12 +57,13 @@ public class BlockEntityBehaviorBeehiveYieldMultiplier(BlockEntity blockEntity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly BlockPos _onServerTickBlockPos = new(0);
|
||||||
private void OnServerTick(float dt)
|
private void OnServerTick(float dt)
|
||||||
{
|
{
|
||||||
if (Blockentity.Block is not BlockFarmland)
|
if (Blockentity.Block is not BlockFarmland)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockPos cropPos = Blockentity.Pos.UpCopy();
|
BlockPos cropPos = _onServerTickBlockPos.Set(Blockentity.Pos.X, Blockentity.Pos.Y + 1, Blockentity.Pos.Z);
|
||||||
if (Api.World.BlockAccessor.GetBlock(cropPos) is not BlockCrop crop)
|
if (Api.World.BlockAccessor.GetBlock(cropPos) is not BlockCrop crop)
|
||||||
{
|
{
|
||||||
ClearTracking();
|
ClearTracking();
|
||||||
|
|||||||
@@ -354,9 +354,12 @@ public class BlockEntityBeeSwarm : BlockEntity
|
|||||||
return targetHive.AddBeePopulationFromSwarm(amount);
|
return targetHive.AddBeePopulationFromSwarm(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly List<SwarmTargetCandidate> _findEligibleTargetsList = [];
|
||||||
|
private readonly BlockPos _findEligibleTargetsBlockPos = new(0);
|
||||||
private List<SwarmTargetCandidate> FindEligibleTargets()
|
private List<SwarmTargetCandidate> FindEligibleTargets()
|
||||||
{
|
{
|
||||||
var candidates = new List<SwarmTargetCandidate>();
|
var candidates = _findEligibleTargetsList;
|
||||||
|
candidates.Clear();
|
||||||
var cfg = Config.Instance;
|
var cfg = Config.Instance;
|
||||||
var radius = Math.Max(1, cfg.BeehiveRadius);
|
var radius = Math.Max(1, cfg.BeehiveRadius);
|
||||||
|
|
||||||
@@ -365,7 +368,7 @@ public class BlockEntityBeeSwarm : BlockEntity
|
|||||||
{
|
{
|
||||||
foreach (var pos in modSystem.BeehiveRegistry.BeehivePositions)
|
foreach (var pos in modSystem.BeehiveRegistry.BeehivePositions)
|
||||||
{
|
{
|
||||||
var targetPos = new BlockPos(pos.X, pos.Y, pos.Z);
|
var targetPos = _findEligibleTargetsBlockPos.Set(pos.X, pos.Y, pos.Z);
|
||||||
if (targetPos.Equals(OriginHivePos) || targetPos.Equals(Pos))
|
if (targetPos.Equals(OriginHivePos) || targetPos.Equals(Pos))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public class BlockEntityReusableBeehive : BlockEntityContainer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
double hoursPerDay = Api.World.Calendar.HoursPerDay;
|
double hoursPerDay = Api.World.Calendar.HoursPerDay;
|
||||||
double daysElapsed = hoursElapsed / hoursPerDay;
|
double daysElapsed;
|
||||||
|
|
||||||
var maxDaysSkip = 0.3;
|
var maxDaysSkip = 0.3;
|
||||||
var maxHoursSkip = maxDaysSkip * hoursPerDay;
|
var maxHoursSkip = maxDaysSkip * hoursPerDay;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ namespace OrekiWoofsBees.Common;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||||
{
|
{
|
||||||
|
private readonly static BlockPos staticBlockPos = new(0);
|
||||||
|
|
||||||
private const int default_blocks_per_tick = 20;
|
private const int default_blocks_per_tick = 20;
|
||||||
private const int tick_interval_ms = 20;
|
private const int tick_interval_ms = 20;
|
||||||
|
|
||||||
@@ -231,21 +233,20 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
|||||||
|
|
||||||
cursor.Advance();
|
cursor.Advance();
|
||||||
|
|
||||||
var block = accessor.GetBlock(blockPos);
|
var block = accessor.GetBlock(staticBlockPos.Set(blockPos.X, blockPos.Y, blockPos.Z));
|
||||||
var structPos = new StructVec3i(blockPos.X, blockPos.Y, blockPos.Z);
|
|
||||||
|
|
||||||
if (block == null || block.BlockId == 0)
|
if (block == null || block.BlockId == 0)
|
||||||
{
|
{
|
||||||
// block is air or unloaded - remove from caches if present
|
// block is air or unloaded - remove from caches if present
|
||||||
flowerPositions.Remove(structPos);
|
flowerPositions.Remove(blockPos);
|
||||||
cropPositions.Remove(structPos);
|
cropPositions.Remove(blockPos);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this is soil with soil below - mark as soil floor
|
// check if this is soil with soil below - mark as soil floor
|
||||||
if (block is BlockSoil)
|
if (block is BlockSoil)
|
||||||
{
|
{
|
||||||
var blockBelow = accessor.GetBlock(blockPos.DownCopy());
|
var blockBelow = accessor.GetBlockRaw(blockPos.X, blockPos.Y - 1, blockPos.Z);
|
||||||
if (blockBelow is BlockSoil)
|
if (blockBelow is BlockSoil)
|
||||||
{
|
{
|
||||||
// found soil floor - record it
|
// found soil floor - record it
|
||||||
@@ -263,18 +264,18 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
|||||||
|
|
||||||
if (PlantRecognitionUtilities.IsCrop(block))
|
if (PlantRecognitionUtilities.IsCrop(block))
|
||||||
{
|
{
|
||||||
cropPositions.Add(structPos);
|
cropPositions.Add(blockPos);
|
||||||
flowerPositions.Remove(structPos);
|
flowerPositions.Remove(blockPos);
|
||||||
}
|
}
|
||||||
else if (PlantRecognitionUtilities.IsFlower(block, accessor, blockPos))
|
else if (PlantRecognitionUtilities.IsFlower(block, accessor, blockPos))
|
||||||
{
|
{
|
||||||
flowerPositions.Add(structPos);
|
flowerPositions.Add(blockPos);
|
||||||
cropPositions.Remove(structPos);
|
cropPositions.Remove(blockPos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
flowerPositions.Remove(structPos);
|
flowerPositions.Remove(blockPos);
|
||||||
cropPositions.Remove(structPos);
|
cropPositions.Remove(blockPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +291,7 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
|||||||
/// 2. pick the closest horizontal space vertically
|
/// 2. pick the closest horizontal space vertically
|
||||||
/// 3. check the next closest block to the beehive in this horizontal space
|
/// 3. check the next closest block to the beehive in this horizontal space
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private (BeehiveScanCursor Cursor, BlockPos BlockPos)? GetNextBlockToCheck()
|
private (BeehiveScanCursor Cursor, StructVec3i BlockPos)? GetNextBlockToCheck()
|
||||||
{
|
{
|
||||||
if (beehives.Count == 0)
|
if (beehives.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
@@ -327,9 +328,9 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var beehivesList = beehives.Values.ToList();
|
var beehivesList = beehives.Values;
|
||||||
lastScannedBeehiveIndex = (lastScannedBeehiveIndex + 1) % beehivesList.Count;
|
lastScannedBeehiveIndex = (lastScannedBeehiveIndex + 1) % beehivesList.Count;
|
||||||
bestCursor = beehivesList[lastScannedBeehiveIndex];
|
bestCursor = beehivesList.ElementAt(lastScannedBeehiveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestCursor == null)
|
if (bestCursor == null)
|
||||||
@@ -350,15 +351,14 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
|||||||
|
|
||||||
private int currentIndex = 0;
|
private int currentIndex = 0;
|
||||||
|
|
||||||
public BlockPos GetCurrentBlockPos(Dictionary<int, ScanOffsetTable> tables)
|
public StructVec3i GetCurrentBlockPos(Dictionary<int, ScanOffsetTable> tables)
|
||||||
{
|
{
|
||||||
var table = tables[Radius];
|
var table = tables[Radius];
|
||||||
var (X, Y, Z) = table.GetOffset(currentIndex);
|
var (X, Y, Z) = table.GetOffset(currentIndex);
|
||||||
return new BlockPos(
|
return new(
|
||||||
HivePos.X + X,
|
HivePos.X + X,
|
||||||
HivePos.Y + Y,
|
HivePos.Y + Y,
|
||||||
HivePos.Z + Z,
|
HivePos.Z + Z
|
||||||
HivePos.dimension
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ namespace OrekiWoofsBees.Common;
|
|||||||
|
|
||||||
public static class PlantRecognitionUtilities
|
public static class PlantRecognitionUtilities
|
||||||
{
|
{
|
||||||
|
private static readonly BlockPos blockPos = new(0);
|
||||||
|
|
||||||
public static bool IsCrop(Block block)
|
public static bool IsCrop(Block block)
|
||||||
{
|
{
|
||||||
return block is BlockCrop;
|
return block is BlockCrop;
|
||||||
@@ -38,8 +40,12 @@ public static class PlantRecognitionUtilities
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsFlower(Block block, IBlockAccessor accessor, StructVec3i pos) => IsFlower(block, accessor, blockPos.Set(pos.X, pos.Y, pos.Z));
|
||||||
|
|
||||||
public static bool IsPlant(Block block, IBlockAccessor accessor, BlockPos pos)
|
public static bool IsPlant(Block block, IBlockAccessor accessor, BlockPos pos)
|
||||||
{
|
{
|
||||||
return IsCrop(block) || IsFlower(block, accessor, pos);
|
return IsCrop(block) || IsFlower(block, accessor, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsPlant(Block block, IBlockAccessor accessor, StructVec3i pos) => IsPlant(block, accessor, blockPos.Set(pos.X, pos.Y, pos.Z));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
|
|||||||
private double hangingDurationHours = 5.0;
|
private double hangingDurationHours = 5.0;
|
||||||
private double migrationPhaseDurationHours = 5.0;
|
private double migrationPhaseDurationHours = 5.0;
|
||||||
|
|
||||||
|
private Vec3d windVec = new(1, 0, 0);
|
||||||
|
|
||||||
public int ActiveBeesCount => activeBees.Count;
|
public int ActiveBeesCount => activeBees.Count;
|
||||||
public int ActiveHoveringCount => activeBees.Count(b => b.Role == BeeRole.Hovering);
|
public int ActiveHoveringCount => activeBees.Count(b => b.Role == BeeRole.Hovering);
|
||||||
public int ActiveTravelingCount => activeBees.Count(b => b.Role == BeeRole.Traveling);
|
public int ActiveTravelingCount => activeBees.Count(b => b.Role == BeeRole.Traveling);
|
||||||
@@ -77,9 +79,15 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
|
|||||||
var updateFrequency = 20;
|
var updateFrequency = 20;
|
||||||
if (api.Side == EnumAppSide.Server)
|
if (api.Side == EnumAppSide.Server)
|
||||||
updateFrequency *= server_tick_frequency_decrease;
|
updateFrequency *= server_tick_frequency_decrease;
|
||||||
|
Blockentity.RegisterGameTickListener(UpdateWindSpeed, 10000);
|
||||||
Blockentity.RegisterGameTickListener(OnTick, updateFrequency);
|
Blockentity.RegisterGameTickListener(OnTick, updateFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateWindSpeed(float dt)
|
||||||
|
{
|
||||||
|
windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
|
||||||
|
}
|
||||||
|
|
||||||
private void BuildHoverSurfaceMap()
|
private void BuildHoverSurfaceMap()
|
||||||
{
|
{
|
||||||
shapeElements = ComputeShapeElements();
|
shapeElements = ComputeShapeElements();
|
||||||
@@ -316,7 +324,6 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
|
|||||||
|
|
||||||
ReadSwarmAttributesFromBlockEntity();
|
ReadSwarmAttributesFromBlockEntity();
|
||||||
|
|
||||||
var windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
|
|
||||||
var windSpeed = (float)Math.Min(windVec.Length(), 1.0);
|
var windSpeed = (float)Math.Min(windVec.Length(), 1.0);
|
||||||
|
|
||||||
for (int i = activeBees.Count - 1; i >= 0; i--)
|
for (int i = activeBees.Count - 1; i >= 0; i--)
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
|
|||||||
private float temperature;
|
private float temperature;
|
||||||
private bool initialized;
|
private bool initialized;
|
||||||
|
|
||||||
|
private ClimateCondition? climate;
|
||||||
|
private Vec3d? windVec;
|
||||||
|
|
||||||
private readonly List<StructVec3i> flowerPositions = [];
|
private readonly List<StructVec3i> flowerPositions = [];
|
||||||
private readonly List<StructVec3i> cropPositions = [];
|
private readonly List<StructVec3i> cropPositions = [];
|
||||||
private readonly List<Vector3> relativePlantPositions = [];
|
private readonly List<Vector3> relativePlantPositions = [];
|
||||||
@@ -83,6 +86,13 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
|
|||||||
if (api.Side == EnumAppSide.Server)
|
if (api.Side == EnumAppSide.Server)
|
||||||
updateFrequency *= SERVER_TICK_FREQUENCY_DECREASE;
|
updateFrequency *= SERVER_TICK_FREQUENCY_DECREASE;
|
||||||
Blockentity.RegisterGameTickListener(OnParticleTick, updateFrequency);
|
Blockentity.RegisterGameTickListener(OnParticleTick, updateFrequency);
|
||||||
|
Blockentity.RegisterGameTickListener(UpdateClimateInfo, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateClimateInfo(float dt)
|
||||||
|
{
|
||||||
|
windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
|
||||||
|
climate = Api.World.BlockAccessor.GetClimateAt(Blockentity.Pos, EnumGetClimateMode.NowValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetRadiusFromBlockEntity()
|
private int GetRadiusFromBlockEntity()
|
||||||
@@ -230,11 +240,12 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
|
|||||||
{
|
{
|
||||||
if (dt > 10f)
|
if (dt > 10f)
|
||||||
return;
|
return;
|
||||||
dt = Math.Min(0.5f, dt);
|
|
||||||
|
|
||||||
var windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
|
if (climate is null || windVec is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dt = Math.Min(0.5f, dt);
|
||||||
var windSpeed = (float)Math.Min(windVec.Length(), 1.0);
|
var windSpeed = (float)Math.Min(windVec.Length(), 1.0);
|
||||||
var climate = Api.World.BlockAccessor.GetClimateAt(Blockentity.Pos, EnumGetClimateMode.NowValues);
|
|
||||||
rainfall = climate?.Rainfall ?? 0f;
|
rainfall = climate?.Rainfall ?? 0f;
|
||||||
temperature = climate?.Temperature ?? 20f;
|
temperature = climate?.Temperature ?? 20f;
|
||||||
|
|
||||||
@@ -391,7 +402,15 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
|
|||||||
InitialScanProgress = initialScanProgress;
|
InitialScanProgress = initialScanProgress;
|
||||||
RescanProgress = rescanProgress;
|
RescanProgress = rescanProgress;
|
||||||
|
|
||||||
foreach (var pos in flowerPositions.Concat(cropPositions))
|
foreach (var pos in flowerPositions)
|
||||||
|
{
|
||||||
|
float relX = pos.X - Blockentity.Pos.X + 0.5f;
|
||||||
|
float relY = pos.Y - Blockentity.Pos.Y + 0.5f;
|
||||||
|
float relZ = pos.Z - Blockentity.Pos.Z + 0.5f;
|
||||||
|
relativePlantPositions.Add(new Vector3(relX, relY, relZ));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var pos in cropPositions)
|
||||||
{
|
{
|
||||||
float relX = pos.X - Blockentity.Pos.X + 0.5f;
|
float relX = pos.X - Blockentity.Pos.X + 0.5f;
|
||||||
float relY = pos.Y - Blockentity.Pos.Y + 0.5f;
|
float relY = pos.Y - Blockentity.Pos.Y + 0.5f;
|
||||||
|
|||||||
Reference in New Issue
Block a user