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:
@ -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;
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -339,7 +339,7 @@ namespace GrassCutter
|
||||
foreach (var c in Cargo.All)
|
||||
if (c && c.IsSpawned && !c.Grab.Consumed && d.cargo.Count < MaxSavedBundles)
|
||||
d.cargo.Add(new CargoSave { kind = (int)c.kind, kg = c.Kg.Value, at = c.transform.position });
|
||||
SaveSlots.Write(JsonUtility.ToJson(d), MowMap.Serialize());
|
||||
SaveSlots.Write(() => JsonUtility.ToJson(d), MowMap.SerializeLater());
|
||||
}
|
||||
|
||||
void Load()
|
||||
|
||||
Reference in New Issue
Block a user