Vixen
02b45cc4
csharp
public sealed class FoliageCollision

Which instances are near enough to something to be worth a physics body.

Read the guide page for this →

Remarks

[docs/plan/31 § D10]: a foliage type declares a collision shape and an activation radius, and instances within that radius of a physics-relevant entity get a body. Ten thousand static bodies is not a scene, it is a broadphase problem.

⚠ This is a visible behavioural difference and it is stated rather than hidden: a projectile fired at a tree four hundred metres away passes through it. The alternative is a broadphase that degrades for the whole game, and the mitigation available to a project that needs it is to raise ActivationRadius for that type.

⚠ What comes out is a difference, not a set. The caller pools bodies, and a set would make it diff two collections of ten thousand addresses every frame to find the four that changed. Update hands back exactly the four.

Grass never collides: a derived type is never asked, because its instances do not exist between one frame and the next.

Fields and properties (4)

  • public IReadOnlySet<FoliageAddress> Active

    Every instance that currently has a body.

  • public IReadOnlyList<FoliageAddress> Activated

    What gained one on the last Update.

  • public IReadOnlyList<FoliageAddress> Deactivated

    And what lost one.

  • public int Count

    How many bodies are wanted right now.

Methods (4)

  • public int Update(FoliageVolume volume, IReadOnlyList<Vector3> sources)

    Works out which instances should have a body, and says what changed.

  • public void Clear()

    Drops every body, which is what leaving a level does.

  • public bool Forget(FoliageAddress address)

    Forgets an address without reporting it, for an instance that no longer exists.

  • public int ForgetCell(int type, FoliageCellKey cell)

    Forgets every body in a cell, for a cell an edit rewrote.

Used by (1)

  • FoliageCollisionTestsVixen.Foliage.Tests