void Agents::ReceivedAgentDesc(unsigned int agentId) { // Add new Agent if it doesn't exist if (!AgentExists(agentId)) AddAgent(new Agent(agentId)); // Update the (newly created?) Agent UpdateAgent(agentId); }
void CArena::MoveAgent(CAgent* pc_agent, TVector2d* pt_new_position) { unsigned int unOldArrayPosition = XYToArrayPosition(pc_agent->GetPosition()); unsigned int unNewArrayPosition = XYToArrayPosition(pt_new_position); pc_agent->SetPosition(pt_new_position); if (unOldArrayPosition != unNewArrayPosition) { RemoveAgent(pc_agent, unOldArrayPosition); AddAgent(pc_agent, unNewArrayPosition); } }
void UCrowdManager::RegisterAgent(ICrowdAgentInterface* Agent) { UpdateNavData(); FCrowdAgentData AgentData; #if WITH_RECAST if (DetourCrowd) { AddAgent(Agent, AgentData); } #endif ActiveAgents.Add(Agent, AgentData); }
void UCrowdManager::CreateCrowdManager() { ARecastNavMesh* RecastNavData = Cast<ARecastNavMesh>(MyNavData); FPImplRecastNavMesh* PImplNavMesh = RecastNavData ? RecastNavData->RecastNavMeshImpl : NULL; dtNavMesh* NavMeshPtr = PImplNavMesh ? PImplNavMesh->GetRecastMesh() : NULL; if (NavMeshPtr) { DetourCrowd = dtAllocCrowd(); } if (DetourCrowd) { DetourCrowd->init(MaxAgents, MaxAgentRadius, NavMeshPtr); DetourCrowd->setAgentCheckInterval(NavmeshCheckInterval); DetourCrowd->setSingleAreaVisibilityOptimization(bSingleAreaVisibilityOptimization); DetourCrowd->setPruneStartedOffmeshConnections(bPruneStartedOffmeshConnections); DetourCrowd->setEarlyReachTestOptimization(bEarlyReachTestOptimization); DetourCrowd->initAvoidance(MaxAvoidedAgents, MaxAvoidedWalls, FMath::Max(SamplingPatterns.Num(), 1)); for (int32 Idx = 0; Idx < SamplingPatterns.Num(); Idx++) { const FCrowdAvoidanceSamplingPattern& Info = SamplingPatterns[Idx]; if (Info.Angles.Num() > 0 && Info.Angles.Num() == Info.Radii.Num()) { DetourCrowd->setObstacleAvoidancePattern(Idx, Info.Angles.GetData(), Info.Radii.GetData(), Info.Angles.Num()); } } UpdateAvoidanceConfig(); AgentFlags.Reset(); AgentFlags.AddZeroed(MaxAgents); for (auto It = ActiveAgents.CreateIterator(); It; ++It) { AddAgent(It.Key(), It.Value()); } } }
void ai_agent::Process() { long temptime; //ISSUE!!!!: this method has a small desync issue, eventually causes an untracable crash, been crashing since queue manager was added //queueing issue insight: Entities list isnt matching up as anticipated, doesnt update till end of line is hit? wtf? //make a safe copy that doesnt get changed from main thread this->new_ai_count = this->ptrWorld->ask_ai_count; if (this->new_ai_count > 0) { //NO CODE CAN GO HERE //Instantly set false incase main thread gets a new unit call and wants this to be true this->ptrWorld->ask_newai = false; this->Entities = ptrWorld->Units; //using this var to replace --\/ ptrWorld->AIEntCount = this->Entities.size(); if (ptrWorld->AIEntCount != ptrWorld->Units.size()) { bool hmm = true; } //make a safe copy that doesnt get changed from main thread //this->new_ai_count = this->ptrWorld->ask_ai_count; ptrWorld->ai_count = 0; //ptrWorld->AI->ai_ms_count = 0; //this code, VERY BAD!!! FIX!!! ----- it works fine if NAVDATA IS PRECACHED DERP, otherwise this queue stalls all ai processing for (long i = ptrWorld->AIEntCount - this->new_ai_count; i < ptrWorld->AIEntCount; i++) { ptrWorld->ai_count++; Ent = Entities.at(i); if (!Ent->fullyCreated) { AddAgent(); this->ptrWorld->ask_ai_count--; } else { //if this happens, fix code bool bad = true; } } } /*while(true) { nodeInfo* blah = new nodeInfo[999999]; }*/ //if( ptrWorld->sim->get_ticks() > 1000 / THOUGHTS_PER_SECOND ) { temptime = ptrWorld->game_time->get_ticks(); if (ptrWorld->ai_process) { //Thread Think(); } ptrWorld->aiTime = ptrWorld->game_time->get_ticks() - temptime; if (ptrWorld->aiTime > ptrWorld->aiTimeTop) { ptrWorld->aiTimeTop = ptrWorld->aiTime; } ptrWorld->sim->start(); //if (Counter > THOUGHTS_PER_SECOND) { Counter = 0; } //this->MakeRandUnit(); //} }