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

@ -21,11 +21,42 @@ namespace GrassCutter
Grabbable _g;
bool _wasInGrass;
public bool Loaded { get; set; }
/// <summary>Server: the belt this item is locked onto (null when loose).</summary>
public Conveyor Belt { get; set; }
/// <summary>Server: the belt this item is locked onto (null when loose). On a belt it is on the Riding layer.</summary>
public Conveyor Belt
{
get => _belt;
set
{
bool was = !ReferenceEquals(_belt, null), now = !ReferenceEquals(value, null);
_belt = value;
if (was != now) Ride(now);
}
}
Conveyor _belt;
Transform[] _parts;
void Ride(bool riding)
{
if (_parts == null) _parts = GetComponentsInChildren<Transform>(true);
int layer = riding ? Layers.Riding : Layers.Prop;
foreach (var t in _parts)
if (t && (t.gameObject.layer == Layers.Prop || t.gameObject.layer == Layers.Riding)) t.gameObject.layer = layer;
}
public Grabbable Grab => _g ? _g : (_g = GetComponent<Grabbable>());
void Awake() { _g = GetComponent<Grabbable>(); }
void Awake()
{
_g = GetComponent<Grabbable>();
// what it looks like, for CargoTick to draw it with all the others
Look = GetComponentInChildren<MeshRenderer>(true);
var mf = Look ? Look.GetComponent<MeshFilter>() : null;
LookMesh = mf ? mf.sharedMesh : null;
LookMats = Look ? Look.sharedMaterials : null;
}
public MeshRenderer Look { get; private set; }
public Mesh LookMesh { get; private set; }
public Material[] LookMats { get; private set; }
/// <summary>Server: unlock from the belt and become a loose physics body again.</summary>
public void ServerLeaveBelt(Vector3 velocity)
@ -70,6 +101,7 @@ namespace GrassCutter
/// FixedUpdate messages cost more than the work in them.</summary>
internal void Step()
{
if (_belt) return;
if (!IsSpawned) return;
var rb = _g.Body;
// riding a belt or lying still: nothing below needs looking at (most of a big farm's bundles, every step)