Moves the entities with a NavAgent component over the navmeshes of the level.
Every loaded navmesh which has agents gets a Detour crowd, which steers its agents along their paths and around each other. An agent joins the crowd of the navmesh baked for its agent kind as soon as that navmesh is loaded, a target set before that is walked to once it has joined.
Each frame the crowd is stepped and the entity is moved:
- with a Game::Velocity component, the velocity is set and whatever moves the entity by it does, like a physics character controller. The crowd follows the entity, so collisions are respected
- without one, the position is set to the position on the navmesh
A crowd is made for the agents of its kind there are, with room to spare. When more join than fit, it is made again for all of them, and its agents join again keeping their targets.
The crowds step in jobs, off the game thread. The update starts in OnFrame, joining agents, following their entities and handing out paths, and dispatches a job for every crowd. It finishes in OnEndFrame, before the physics frame, waiting for the jobs and moving the entities. In between the crowds belong to the jobs: a target set meanwhile is put on the navmesh right away and handed to the crowd with the next update, and anything which changes or frees a crowd waits for the jobs first.
A crowd keeps pointers into its navmesh, it is rebuilt when the navmesh is reloaded, and its agents join again, keeping their targets.
- Copyright
- (C) 2026 Individual contributors, see AUTHORS file
|
| | AgentManager () |
| | constructor
|
| | ~AgentManager () |
| | destructor
|
| void | OnActivate () override |
| | listen for navmesh reloads
|
| void | OnDeactivate () override |
| | free every crowd
|
| void | OnFrame () override |
| | start the update of the agents of the default world, the crowds step in jobs
|
| void | OnEndFrame () override |
| | finish the update, wait for the crowds and move the entities
|
| void | OnCleanup (Game::World *world) override |
| | free the crowds of a world which is cleaned up
|
| | RefCounted () |
| | constructor
|
| int | GetRefCount () const |
| | get the current refcount
|
| void | AddRef () |
| | increment refcount by one
|
| void | Release () |
| | decrement refcount and destroy object if refcount is zero
|
| bool | IsInstanceOf (const Rtti &rtti) const |
| | return true if this object is instance of given class
|
| bool | IsInstanceOf (const Util::String &className) const |
| | return true if this object is instance of given class by string
|
| bool | IsInstanceOf (const Util::FourCC &classFourCC) const |
| | return true if this object is instance of given class by fourcc
|
| bool | IsA (const Rtti &rtti) const |
| | return true if this object is instance of given class, or a derived class
|
| bool | IsA (const Util::String &rttiName) const |
| | return true if this object is instance of given class, or a derived class, by string
|
| bool | IsA (const Util::FourCC &rttiFourCC) const |
| | return true if this object is instance of given class, or a derived class, by fourcc
|
| const Util::String & | GetClassName () const |
| | get the class name
|
| Util::FourCC | GetClassFourCC () const |
| | get the class FourCC code
|
|
| static void | InitAgent (Game::World *world, Game::Entity entity, NavAgent *component) |
| | register the agent of a NavAgent component
|
| static void | DecayAgent (Game::World *world, Game::Entity entity, NavAgent *component) |
| | remove the agent of a NavAgent component
|
| static void | UpdateAgents (Game::World *world, float dt) |
| | join agents to crowds, step the crowds by dt and move the entities.
|
| static void | StartUpdate (Game::World *world, float dt) |
| | join agents to crowds, follow the entities, hand out paths, and start the crowds stepping by dt in jobs
|
| static void | FinishUpdate (Game::World *world) |
| | wait for the crowds of the update started last, and move the entities
|
| static void | WaitForCrowds () |
| | wait until no crowd steps in a job, before a crowd or its navmesh is changed or freed
|
| static void | DumpRefCountingLeaks () |
| | dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
|