Nebula
Loading...
Searching...
No Matches
NavigationFeature::AgentManager Class Reference

#include <agentmanager.h>

Detailed Description

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.

Inherits Game::Manager.

Classes

struct  CrowdRecord
struct  AgentRecord

Public Member Functions

 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
Public Member Functions inherited from Core::RefCounted
 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 Public Member Functions

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 Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)

Private Member Functions

 __DeclareClass (AgentManager) __DeclareSingleton(AgentManager)

Private Attributes

Util::Array< AgentRecord * > agents
Util::Array< CrowdRecord * > crowds
Util::Array< dtCrowd * > stepping
 the crowds the jobs step, signalled when the last is done
Threading::Event steppingDone
bool crowdsStepping = false
Game::World * startedWorld = nullptr
 the update which was started and not finished, and how far it steps
float startedDt = 0.0f

Friends

struct AgentAccess

Additional Inherited Members

Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)

Constructor & Destructor Documentation

◆ AgentManager()

NavigationFeature::AgentManager::AgentManager ( )

constructor

◆ ~AgentManager()

NavigationFeature::AgentManager::~AgentManager ( )

destructor

Member Function Documentation

◆ __DeclareClass()

NavigationFeature::AgentManager::__DeclareClass ( AgentManager )
private

◆ DecayAgent()

void NavigationFeature::AgentManager::DecayAgent ( Game::World * world,
Game::Entity entity,
NavAgent * component )
static

remove the agent of a NavAgent component

◆ FinishUpdate()

void NavigationFeature::AgentManager::FinishUpdate ( Game::World * world)
static

wait for the crowds of the update started last, and move the entities

◆ InitAgent()

void NavigationFeature::AgentManager::InitAgent ( Game::World * world,
Game::Entity entity,
NavAgent * component )
static

register the agent of a NavAgent component

◆ OnActivate()

void NavigationFeature::AgentManager::OnActivate ( )
overridevirtual

listen for navmesh reloads

Reimplemented from Game::Manager.

◆ OnCleanup()

void NavigationFeature::AgentManager::OnCleanup ( Game::World * world)
overridevirtual

free the crowds of a world which is cleaned up

Removing the entities of a world doesn't decay their components.

Reimplemented from Game::Manager.

◆ OnDeactivate()

void NavigationFeature::AgentManager::OnDeactivate ( )
overridevirtual

free every crowd

Reimplemented from Game::Manager.

◆ OnEndFrame()

void NavigationFeature::AgentManager::OnEndFrame ( )
overridevirtual

finish the update, wait for the crowds and move the entities

Before the physics frame of the world, which moves the characters by the velocities set here.

Reimplemented from Game::Manager.

◆ OnFrame()

void NavigationFeature::AgentManager::OnFrame ( )
overridevirtual

start the update of the agents of the default world, the crowds step in jobs

Reimplemented from Game::Manager.

◆ StartUpdate()

void NavigationFeature::AgentManager::StartUpdate ( Game::World * world,
float dt )
static

join agents to crowds, follow the entities, hand out paths, and start the crowds stepping by dt in jobs

◆ UpdateAgents()

void NavigationFeature::AgentManager::UpdateAgents ( Game::World * world,
float dt )
static

join agents to crowds, step the crowds by dt and move the entities.

A dt of 0 joins and requests without moving. Starts and finishes the update in one go

◆ WaitForCrowds()

void NavigationFeature::AgentManager::WaitForCrowds ( )
static

wait until no crowd steps in a job, before a crowd or its navmesh is changed or freed

◆ AgentAccess

friend struct AgentAccess
friend

Member Data Documentation

◆ agents

Util::Array<AgentRecord*> NavigationFeature::AgentManager::agents
private

◆ crowds

Util::Array<CrowdRecord*> NavigationFeature::AgentManager::crowds
private

◆ crowdsStepping

bool NavigationFeature::AgentManager::crowdsStepping = false
private

◆ startedDt

float NavigationFeature::AgentManager::startedDt = 0.0f
private

◆ startedWorld

Game::World* NavigationFeature::AgentManager::startedWorld = nullptr
private

the update which was started and not finished, and how far it steps

◆ stepping

Util::Array<dtCrowd*> NavigationFeature::AgentManager::stepping
private

the crowds the jobs step, signalled when the last is done

◆ steppingDone

Threading::Event NavigationFeature::AgentManager::steppingDone
private

The documentation for this class was generated from the following files:
  • /github/workspace/code/addons/navigationfeature/managers/agentmanager.h
  • /github/workspace/code/addons/navigationfeature/managers/agentmanager.cc