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:
@ -434,7 +434,7 @@ namespace GrassCutter
|
||||
}
|
||||
// nothing there: drop it off the end, but only onto a free spot (one item waits there at a time)
|
||||
var land = WorldOnPath(L, s.route, 0f) + dir * 0.45f;
|
||||
int n = Physics.OverlapSphereNonAlloc(land, 0.3f, s_hits, 1 << Layers.Prop, QueryTriggerInteraction.Ignore);
|
||||
int n = Physics.OverlapSphereNonAlloc(land, 0.3f, s_hits, Layers.CargoMask, QueryTriggerInteraction.Ignore);
|
||||
for (int k = 0; k < n; k++)
|
||||
{
|
||||
var other = s_hits[k].GetComponentInParent<Cargo>();
|
||||
@ -510,7 +510,7 @@ namespace GrassCutter
|
||||
port = index;
|
||||
if (belt && !belt.HasRoom) return false;
|
||||
}
|
||||
else if (Physics.OverlapSphereNonAlloc(way.at + way.dir * 0.5f, 0.45f, s_hits, 1 << Layers.Prop, QueryTriggerInteraction.Ignore) > 0) return false;
|
||||
else if (Physics.OverlapSphereNonAlloc(way.at + way.dir * 0.5f, 0.45f, s_hits, Layers.CargoMask, QueryTriggerInteraction.Ignore) > 0) return false;
|
||||
var made = Spawner.Instance.SpawnCargo(kind, way.at + way.dir * 0.2f + from.transform.up * 0.35f, from.transform.rotation, way.dir * 1.6f);
|
||||
if (!made) return false;
|
||||
if (belt) belt.ServerAcceptPort(made, port);
|
||||
@ -544,9 +544,21 @@ namespace GrassCutter
|
||||
static readonly List<Port> s_belted = new List<Port>();
|
||||
|
||||
/// <summary>Does a belt leave any of this piece's hatches?</summary>
|
||||
static readonly Dictionary<BuildPiece, (int ver, bool on)> s_beltedAt = new Dictionary<BuildPiece, (int, bool)>();
|
||||
|
||||
public static bool Belted(BuildPiece piece)
|
||||
{
|
||||
if (!piece) return false;
|
||||
// asked every frame by every pad and dock: the answer only changes when the build does
|
||||
if (s_beltedAt.TryGetValue(piece, out var had) && had.ver == BuildPiece.Version) return had.on;
|
||||
bool on = Look(piece);
|
||||
if (s_beltedAt.Count > 512) s_beltedAt.Clear();
|
||||
s_beltedAt[piece] = (BuildPiece.Version, on);
|
||||
return on;
|
||||
}
|
||||
|
||||
static bool Look(BuildPiece piece)
|
||||
{
|
||||
s_belted.Clear();
|
||||
piece.Ports(s_belted);
|
||||
foreach (var p in s_belted)
|
||||
|
||||
Reference in New Issue
Block a user