Frame time on a big farm, round two: riding layer, instanced bundles

- Bundles on a belt move to a Riding layer that ignores the belts and the
  static world: every belt's catch trigger called OnTriggerStay (with a
  GetComponent) for each bundle riding it, every physics step.
- Bundles draw as instanced batches from CargoTick (their own renderers off,
  one in someone's hands draws itself), not as 2000 renderers to cull, sort
  and draw in the view and every shadow cascade.
- The main camera skips front-to-back sorting: the GPU has time to spare.
- BeltNet.Belted and DronePad.Belted are cached until the build changes;
  splitters on the host look only at their own items.

On the player's Mommy save, 2560x1440: base 14-15 ms -> 7.7 ms (~130 fps),
meadow 11.5-12 ms -> 6.8-7.5 ms (~135-145 fps).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-09 20:35:35 +06:00
parent 57d0f4d31a
commit bbf73a6b96
12 changed files with 184 additions and 16 deletions

View File

@ -163,6 +163,9 @@ namespace GrassCutter
/// <summary>One physics step, from <see cref="CargoTick"/>.</summary>
internal void Step()
{
// riding a belt (most bundles on a big farm): nothing to do, and the managed test is the cheap one
if (!_cargoLooked) { _cargo = GetComponent<Cargo>(); _cargoLooked = true; }
if (_cargo && _cargo.Belt) return;
if (!IsSpawned || !IsOwner || !Body || Body.isKinematic) return;
// at rest it sleeps: our own gravity, pushed every step, would keep it awake for ever, and a big farm has
// hundreds of bundles lying about. A knock, a grab or a belt wakes it again.
@ -207,6 +210,10 @@ namespace GrassCutter
public const int ViewModel = 11;
public const int LocalPlayer = 12;
public const int Build = 13;
/// <summary>Cargo riding a belt: the belts' catch triggers (and the static world) don't see it, everything else does.</summary>
public const int Riding = 14;
/// <summary>Loose cargo and cargo on a belt, for the casts that look for either.</summary>
public const int CargoMask = (1 << Prop) | (1 << Riding);
public static void SetupCollisions()
{
@ -216,9 +223,14 @@ namespace GrassCutter
Physics.IgnoreLayerCollision(Wrap, Vehicle);
Physics.IgnoreLayerCollision(ViewModel, Default);
for (int i = 0; i < 32; i++) Physics.IgnoreLayerCollision(ViewModel, i);
// a bundle on a belt is kinematic: against the belts and the static world it only ever made trigger calls,
// one per bundle per belt per physics step (two thousand on a big farm), all of them for nothing
Physics.IgnoreLayerCollision(Riding, Build);
Physics.IgnoreLayerCollision(Riding, Default);
Physics.IgnoreLayerCollision(Riding, Riding);
}
/// <summary>Things the player's interaction ray can hit.</summary>
public static readonly int InteractMask = (1 << Default) | (1 << Wrap) | (1 << Prop) | (1 << Vehicle) | (1 << Player) | (1 << Build);
public static readonly int InteractMask = (1 << Default) | (1 << Wrap) | (1 << Prop) | (1 << Riding) | (1 << Vehicle) | (1 << Player) | (1 << Build);
}
}