Private
Public Access
1
0

try to further decrease allocations

This commit is contained in:
2026-03-22 03:54:48 +01:00
parent e9e4fec229
commit e16ae3f30c
8 changed files with 69 additions and 28 deletions

View File

@@ -40,6 +40,8 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
private double hangingDurationHours = 5.0;
private double migrationPhaseDurationHours = 5.0;
private Vec3d windVec = new(1, 0, 0);
public int ActiveBeesCount => activeBees.Count;
public int ActiveHoveringCount => activeBees.Count(b => b.Role == BeeRole.Hovering);
public int ActiveTravelingCount => activeBees.Count(b => b.Role == BeeRole.Traveling);
@@ -77,9 +79,15 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
var updateFrequency = 20;
if (api.Side == EnumAppSide.Server)
updateFrequency *= server_tick_frequency_decrease;
Blockentity.RegisterGameTickListener(UpdateWindSpeed, 10000);
Blockentity.RegisterGameTickListener(OnTick, updateFrequency);
}
private void UpdateWindSpeed(float dt)
{
windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
}
private void BuildHoverSurfaceMap()
{
shapeElements = ComputeShapeElements();
@@ -316,7 +324,6 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB
ReadSwarmAttributesFromBlockEntity();
var windVec = Api.World.BlockAccessor.GetWindSpeedAt(Blockentity.Pos);
var windSpeed = (float)Math.Min(windVec.Length(), 1.0);
for (int i = activeBees.Count - 1; i >= 0; i--)

View File

@@ -37,6 +37,9 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
private float temperature;
private bool initialized;
private ClimateCondition? climate;
private Vec3d? windVec;
private readonly List<StructVec3i> flowerPositions = [];
private readonly List<StructVec3i> cropPositions = [];
private readonly List<Vector3> relativePlantPositions = [];
@@ -83,6 +86,13 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
if (api.Side == EnumAppSide.Server)
updateFrequency *= SERVER_TICK_FREQUENCY_DECREASE;
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()
@@ -230,11 +240,12 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
{
if (dt > 10f)
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 climate = Api.World.BlockAccessor.GetClimateAt(Blockentity.Pos, EnumGetClimateMode.NowValues);
rainfall = climate?.Rainfall ?? 0f;
temperature = climate?.Temperature ?? 20f;
@@ -391,7 +402,15 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti
InitialScanProgress = initialScanProgress;
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 relY = pos.Y - Blockentity.Pos.Y + 0.5f;