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

@ -105,6 +105,8 @@ namespace GrassCutter
if (IsServer) Seat(Planet.Up(transform.position));
_shown = _from = _to = At.Value;
_bobPhase = Random.value * 6.28f;
// each bot thinks on a frame of its own: two dozen robots planning their rows at once was a hitch
_clock = Random.value * Tick;
At.OnValueChanged += Heard;
_engine = Sfx.Loop(Def.hover > 0f ? "drone_loop" : "robot_mower_loop", Body, 0f);
}
@ -197,10 +199,15 @@ namespace GrassCutter
_shown = Vector3.Lerp(_from, _to, _leg);
// the nose, where the cutter is, goes first
float nose = NoseOnBack ? -1f : 1f;
if (flat.sqrMagnitude < 0.01f) flat = Vector3.ProjectOnPlane(body.forward * nose, up);
// the heading is kept apart from the body: a flyer's lean and sway go on top of it when it is drawn, and must
// never be fed back in, or they pile up frame after frame and it rolls over
if (!_headed) { _heading = body.rotation; _headed = true; }
if (flat.sqrMagnitude < 0.01f) flat = Vector3.ProjectOnPlane(_heading * Vector3.forward * nose, up);
if (flat.sqrMagnitude < 1e-4f) return;
var was = body.rotation;
var was = _heading;
var turn = Quaternion.Slerp(was, Quaternion.LookRotation(flat * nose, up), 1f - Mathf.Exp(-6f * Time.deltaTime));
_heading = turn;
var pose = turn;
// it glides: no shake, no bob, the moving parts do the living
bool going = _leg < 1f && (_to - _from).sqrMagnitude > 1e-4f;
// a flyer hangs over the grass, bobbing a little, and leans into the way it goes
@ -208,9 +215,10 @@ namespace GrassCutter
if (Def.hover > 0f)
{
at += up * (Def.hover + Mathf.Sin(Time.time * 1.9f + _bobPhase) * 0.15f);
turn *= Quaternion.Euler((going ? 8f : 0f) * -nose, 0f, Mathf.Sin(Time.time * 1.3f + _bobPhase) * 2f);
_lean = Mathf.MoveTowards(_lean, going ? 6f : 0f, Time.deltaTime * 12f);
pose = turn * Quaternion.Euler(_lean * -nose, 0f, Mathf.Sin(Time.time * 1.3f + _bobPhase) * 1.5f);
}
body.SetPositionAndRotation(at, turn);
body.SetPositionAndRotation(at, pose);
Animate(body, Vector3.SignedAngle(was * Vector3.forward, turn * Vector3.forward, up) / Mathf.Max(1e-3f, Time.deltaTime), going);
}
@ -226,7 +234,9 @@ namespace GrassCutter
float _roll, _level;
bool _parts;
float _spun, _nextBlink = 2f, _blinkAt = -1f, _swayX, _swayV, _wasGoing, _go;
float _bobPhase;
float _bobPhase, _lean;
Quaternion _heading;
bool _headed;
void Animate(Transform body, float turnRate, bool going)
{