Fix Sky Mower tumbling and the hitches on a big farm

- Mowbot keeps its heading apart from the drawn pose: a flyer's lean and sway
  were fed back each frame and rolled it over.
- Drone pads looked through every loose bundle, testing every belt end, for
  each idle drone every frame (43 ms on a 1500-bundle farm): distance first,
  and a 1.5 s pause after finding nothing.
- Saves are written, laid out and compressed off the main thread; backups go
  in the same queue (an autosave froze the game ~50 ms every 30 s).
- Robots tick on staggered frames.
- -demoperf N profiles save slot N; -demobots logs the Sky Mower's tilt.

On the player's save: frames over 25 ms went from 144 to 0 in 40 s, worst
frame 74 ms -> 22 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-09 19:04:36 +06:00
parent 27d075103b
commit 80271aea72
9 changed files with 251 additions and 37 deletions

View File

@ -44,6 +44,7 @@ namespace GrassCutter
int Count => Mathf.Min(Most, 2 + (Piece ? Piece.Tier.Value : 0));
float Fly => Speed * Mathf.Sqrt(Piece ? Piece.TierMul : 1f);
float Reach => Range + RangePerTier * (Piece ? Piece.Tier.Value : 0);
readonly float[] _idleUntil = new float[Most];
float _shipAt;
double Now => NetworkManager ? NetworkManager.ServerTime.Time : Time.timeAsDouble;
@ -231,6 +232,8 @@ namespace GrassCutter
int out_ = 0;
for (int k = 0; k < Most; k++) if (Trip(k).Value.w >= 0f) out_++;
if (Silo.Value + (out_ + 1) * GameDefs.BundleKg > Room) return;
// found nothing a moment ago: there are often a thousand bundles on a big farm, don't look through them every frame
if (Time.time < _idleUntil[i]) return;
Cargo best = null;
float bestD = Reach * Reach;
var here = transform.position;
@ -240,13 +243,16 @@ namespace GrassCutter
var g = c.Grab;
if (!g || g.IsHeld || g.Consumed || !g.Body || g.Body.isKinematic || g.Body.linearVelocity.sqrMagnitude > 0.25f) continue;
float d = (c.transform.position - here).sqrMagnitude;
// out of reach or no nearer than the best so far: the cheap test first, the belt ends only for the few left
if (d >= bestD) continue;
// right by the pad: just put out of the hatch, or about to be
if (d < 3f * 3f) continue;
// dropped off the free end of a belt: that's where someone wants it, and it may be this pad's own
if (AtBeltEnd(c.transform.position)) continue;
if (d < bestD) { bestD = d; best = c; }
bestD = d;
best = c;
}
if (!best) return;
if (!best) { _idleUntil[i] = Time.time + 1.5f; return; }
s_claimed.Add(best);
_for[i] = best;
_holding[i] = false;