From 6f3afd9cd892f23cf2b6f29a118462615f5c1988 Mon Sep 17 00:00:00 2001 From: OrekiWoof Date: Tue, 17 Mar 2026 10:56:33 +0100 Subject: [PATCH] fix GeneratePathForCurrentState exception, add catchup perf logging --- .../RoamingBees/Behaviors/BlockEntityBehaviorBeeSwarm.cs | 9 +++++++-- .../Behaviors/BlockEntityBehaviorRoamingBees.cs | 8 +++++++- RoamingBees/RoamingBees/modinfo.json | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorBeeSwarm.cs b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorBeeSwarm.cs index df24587..e8e41ef 100644 --- a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorBeeSwarm.cs +++ b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorBeeSwarm.cs @@ -286,11 +286,16 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB activeBees.Add(bee); if (catchup) { - var totalDelta = Api.World.Calendar.ElapsedSeconds - packet.TimeElapsedSeconds; + var totalDelta = Math.Abs(Api.World.Calendar.ElapsedSeconds - packet.TimeElapsedSeconds); if (modSystem?.Mod.Info.Version.Contains("dev") == true) modSystem.Mod.Logger.Notification($"HandleBeeParticleSpawn catchup totalDelta: {totalDelta}s"); + + var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < totalDelta / 0.1f; i++) bee.Step(0.1f, 0.1f); // todo + stopwatch.Stop(); + if (stopwatch.Elapsed.TotalSeconds > 0.02) + modSystem?.Mod?.Logger.Warning($"{nameof(BlockEntityBehaviorBeeSwarm)} {nameof(HandleBeeParticleSpawn)} catchup took {stopwatch.Elapsed.TotalSeconds:F2}s"); } } @@ -508,7 +513,7 @@ public class BlockEntityBehaviorBeeSwarm(BlockEntity blockEntity) : BlockEntityB case SwarmState.BuildingSwarm: { var path = GenerateBuildingSwarmPath(blockAccessor, cfg); - var start = path is not null ? path[0].Position : hiddenAnchor; + var start = path is not null && path.Length > 0 ? path[0].Position : hiddenAnchor; return (path, BeeRole.Traveling, start, hiddenAnchor); } case SwarmState.HangingOut: diff --git a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs index fbb6bff..16acb6d 100644 --- a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs +++ b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs @@ -4,6 +4,7 @@ using RoamingBees.Particles.Catchup; using RoamingBees.Utilities; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Numerics; using Vintagestory.API.Client; @@ -153,11 +154,16 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti activeBees.Add(bee); if (catchup) { - var totalDelta = Api.World.Calendar.ElapsedSeconds - packet.TimeElapsedSeconds; + var totalDelta = Math.Abs(Api.World.Calendar.ElapsedSeconds - packet.TimeElapsedSeconds); if (modSystem?.Mod.Info.Version.Contains("dev") == true) modSystem.Mod.Logger.Notification($"HandleBeeParticleSpawn catchup totalDelta: {totalDelta}s"); + + var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < totalDelta / 0.1f; i++) bee.Step(0.1f, 0.1f); // todo + stopwatch.Stop(); + if (stopwatch.Elapsed.TotalSeconds > 0.02) + modSystem?.Mod?.Logger.Warning($"{nameof(BlockEntityBehaviorRoamingBees)} {nameof(HandleBeeParticleSpawn)} catchup took {stopwatch.Elapsed.TotalSeconds:F2}s"); } } diff --git a/RoamingBees/RoamingBees/modinfo.json b/RoamingBees/RoamingBees/modinfo.json index c6c2bf8..4bd08ed 100644 --- a/RoamingBees/RoamingBees/modinfo.json +++ b/RoamingBees/RoamingBees/modinfo.json @@ -7,7 +7,7 @@ "OrekiWoof" ], "description": "Cute immersive roaming bees. Now on vanilla skeps and other mods' hives.", - "version": "2.0.0-dev.5", + "version": "2.0.0-dev.6", "dependencies": { "game": "1.21.0" }