19 _previousTimeUS(0ULL),
20 _navMeshDebugDraw(false),
79 for (AITeamMap::value_type& team :
_aiTeams) {
80 if (!team.second->processInput(
_parentPool, deltaTimeUS)) {
88 for (AITeamMap::value_type& team :
_aiTeams) {
89 if (!team.second->processData(
_parentPool, deltaTimeUS)) {
97 for (AITeamMap::value_type& team :
_aiTeams) {
98 if (!team.second->update(
_parentPool, deltaTimeUS)) {
107 const AITeamMap::const_iterator it =
_aiTeams.find(teamID);
109 "AIManager error: attempt to register an AI Entity to a "
110 "non-existent team!");
111 it->second->addTeamMember(entity);
116 for (AITeamMap::value_type& team :
_aiTeams) {
123 const AITeamMap::const_iterator it =
_aiTeams.find(teamID);
125 "AIManager error: attempt to remove an AI Entity from a "
126 "non-existent team!");
127 it->second->removeTeamMember(entity);
133 std::unique_ptr<Navigation::NavigationMesh>& navMesh =
_navMeshes[radius];
134 if (navMesh ==
nullptr)
136 navMesh = std::make_unique<Navigation::NavigationMesh>(context, recastInterface,
parentScene);
143 for (AITeamMap::value_type& team :
_aiTeams)
145 team.second->addCrowd(radius, navMesh.get());
149 return navMesh.get();
156 const NavMeshMap::iterator it =
_navMeshes.find(radius);
167 for (AITeamMap::value_type& team :
_aiTeams)
169 team.second->removeCrowd(radius);
181 if ( team ==
nullptr )
183 team.reset(
new AITeam(
id, *
this ) );
193 const AITeamMap::iterator it =
_aiTeams.find(
id );
207 for (NavMeshMap::value_type& it :
_navMeshes) {
208 it.second->debugDraw(state);
218 for (NavMeshMap::value_type& it :
_navMeshes) {
219 if (forceAll || it.second->debugDraw()) {
220 it.second->draw(forceAll, bufferInOut, memCmdInOut);
std::atomic_bool _navMeshDebugDraw
std::atomic_bool _shouldStop
void toggleNavMeshDebugDraw(bool state)
Toggle debug draw for all NavMeshes.
std::atomic_bool _running
AIManager(Scene &parentScene, TaskPool &pool)
bool shouldStop() const noexcept
bool processInput(U64 deltaTimeUS)
sensors
bool updateEntities(U64 deltaTimeUS)
react
std::atomic_bool _pauseUpdate
bool destroyNavMesh(AIEntity::PresetAgentRadius radius)
void update(U64 deltaTimeUS)
Called at a fixed interval (preferably in a separate thread);.
bool registerEntity(U32 teamID, AIEntity *entity)
Navigation::NavigationMesh * addNavMesh(PlatformContext &context, Navigation::DivideRecast &recastInterface, Scene &parentScene, AIEntity::PresetAgentRadius radius)
Add a NavMesh.
void debugDraw(GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut, bool forceAll=true)
AITeam * registerTeam(U32 id)
Register an AI Team.
DELEGATE< void > _sceneCallback
void destroy()
Clear all AI related data (teams, entities, NavMeshes, etc);.
void unregisterEntity(U32 teamID, AIEntity *entity)
SharedMutex _navMeshMutex
bool processData(U64 deltaTimeUS)
think
bool unregisterTeam(U32 id)
Unregister an AI Team.
std::atomic_bool _updating
Scene & parentScene() noexcept
constexpr U16 TARGET_FRAME_RATE
Application desired framerate for physics and input simulations.
constexpr U8 TICK_DIVISOR
constexpr T SecondsToMicroseconds(U a) noexcept
Handle console commands that start with a forward slash.
std::lock_guard< mutex > LockGuard
std::shared_lock< mutex > SharedLock