Frame time on a big farm: batched grass, sleeping bundles, no light probes
Measured in a real 2560x1440 window on the player's Mommy save (RTX 4090): the GPU took ~5 ms, the main thread the rest. - Grass: a fully mown sector draws only its floor (one draw, not up to six); untouched and fully mown sectors share a mow map look, so the fur pile draws them all in one instanced call per pile (GC_SECTOR_BUFFER, sector frames from a structured buffer). Grass draws 1112 -> 337 at the base, 876 -> 439 in the meadow. - Bundles: loose ones sleep when they come to rest (our gravity kept ~600 bodies awake), ones on belts skip the ground checks, and all of them are stepped from one CargoTick instead of two Unity messages each. - Belts leave a jammed line alone and only look every few steps whether it can move; splitters test distance before transforming every bundle. - Light probes off on everything (the planet has none) and the GPU Resident Drawer off: both cost CPU per moving renderer for nothing. - -demogpu N -onscreen measures frame time with one feature off at a time. Base view 17-19 ms -> 14-15 ms, meadow 14-16 ms -> 11.5-12 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -46,6 +46,9 @@ namespace GrassCutter
|
||||
public float blend;
|
||||
/// <summary>Has it settled which way it's going?</summary>
|
||||
public bool set;
|
||||
/// <summary>Where it was last put, and for how many steps it hasn't moved: a jammed line is left alone.</summary>
|
||||
public float placedD = -1f;
|
||||
public int still;
|
||||
}
|
||||
|
||||
struct Link
|
||||
@ -307,6 +310,7 @@ namespace GrassCutter
|
||||
int i = 0;
|
||||
while (i < Items.Count && Items[i].d > d) i++;
|
||||
Items.Insert(i, s);
|
||||
_idle = 0;
|
||||
}
|
||||
|
||||
/// <summary>Server: take an item off this belt (a player grabbed it, it got despawned).</summary>
|
||||
@ -334,7 +338,10 @@ namespace GrassCutter
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (!Server || !Piece || !Piece.IsSpawned || Items.Count == 0) return;
|
||||
float dt = Time.fixedDeltaTime;
|
||||
// a line that hasn't moved for a while only looks again every few steps whether the front can go on
|
||||
if (_idle > 40 && ++_idleSkip % 6 != 0) return;
|
||||
bool moved = false;
|
||||
float dt = Time.fixedDeltaTime * (_idle > 40 ? 6f : 1f);
|
||||
float step = Speed * dt;
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
@ -347,16 +354,25 @@ namespace GrassCutter
|
||||
}
|
||||
float L = Length(s.route);
|
||||
float limit = Room(i, ref L);
|
||||
if (s.d < limit) s.d = Mathf.Min(s.d + step, limit);
|
||||
if (s.d < limit - 1e-5f) { s.d = Mathf.Min(s.d + step, limit); moved = true; }
|
||||
if ((i == 0 || RouteCount > 1) && s.d >= L - 1e-4f && HandOff(s))
|
||||
{
|
||||
Items.RemoveAt(i--);
|
||||
moved = true;
|
||||
continue;
|
||||
}
|
||||
// stuck behind the one ahead: once it has come square and settled there is nothing to move
|
||||
if (s.blend >= 1f && Mathf.Abs(s.d - s.placedD) < 1e-5f) { if (++s.still > 40) continue; }
|
||||
else s.still = 0;
|
||||
Place(s, dt);
|
||||
s.placedD = s.d;
|
||||
if (s.blend < 1f) moved = true;
|
||||
}
|
||||
_idle = moved ? 0 : _idle + 1;
|
||||
}
|
||||
|
||||
int _idle, _idleSkip;
|
||||
|
||||
/// <summary>How far an item can go: to the turn until it has chosen, then the end of its route, and never into the one ahead.</summary>
|
||||
float Room(int i, ref float L)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user