double Simulation::RunBody(double maxSimTime) { //needed to control the execution time PART 1 //in the case you want to run in no faster than realtime //time_t starttime, endtime; //time(&starttime); //take the current time from the pedestrian double t = Pedestrian::GetGlobalTime(); //frame number. This function can be called many times, static int frameNr = (int) (1+t/_deltaT); // Frame Number //########## //PROBLEMATIC: time when frame should be printed out // possibly skipped when using the following lines // NEEDS TO BE FIXED! int writeInterval = (int) ((1./_fps)/_deltaT+0.5); writeInterval = (writeInterval<=0) ? 1 : writeInterval; // mustn't be <= 0 // ########## //process the queue for incoming pedestrians //important since the number of peds is used //to break the main simulation loop ProcessAgentsQueue(); _nPeds = _building->GetAllPedestrians().size(); std::cout << "\n"; std::string description = "Evacutation "; ProgressBar *bar = new ProgressBar(_nPeds, description); // bar->SetFrequencyUpdate(10); #ifdef _WINDOWS bar->SetStyle("|","-"); #else bar->SetStyle("\u2588", "-"); //for linux #endif int initialnPeds = _nPeds; // main program loop while ((_nPeds || (!_agentSrcManager.IsCompleted()&& _gotSources) ) && t<maxSimTime) { t = 0+(frameNr-1)*_deltaT; //process the queue for incoming pedestrians ProcessAgentsQueue(); if (t>Pedestrian::GetMinPremovementTime()) { //update the linked cells _building->UpdateGrid(); // update the positions _operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get(), _periodic); //update the events _em->ProcessEvent(); //here we could place router-tasks (calc new maps) that can use multiple cores AND we have 't' //update quickestRouter if (_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST)) { FFRouter* ffrouter = dynamic_cast<FFRouter*>(_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST)); if (ffrouter->MustReInit()) { ffrouter->ReInit(); ffrouter->SetRecalc(t); } } //update the routes and locations UpdateRoutesAndLocations(); //other updates //someone might have left the building _nPeds = _building->GetAllPedestrians().size(); } // update the global time Pedestrian::SetGlobalTime(t); // write the trajectories if (0==frameNr%writeInterval) { _iod->WriteFrame(frameNr/writeInterval, _building.get()); } if(!_gotSources && !_periodic && _config->print_prog_bar()) // Log->ProgressBar(initialnPeds, initialnPeds-_nPeds, t); bar->Progressed(initialnPeds-_nPeds); else if ((!_gotSources) && ((frameNr < 100 && frameNr % 10 == 0) || (frameNr > 100 && frameNr % 100 == 0))) printf("time: %6.2f (%4.0f) | Agents: %6ld / %d [%4.1f%%]\n", t , maxSimTime, _nPeds, initialnPeds, (double)(initialnPeds-_nPeds)/initialnPeds*100); // needed to control the execution time PART 2 // time(&endtime); // double timeToWait=t-difftime(endtime, starttime); // clock_t goal = timeToWait*1000 + clock(); // while (goal > clock()); ++frameNr; } return t; }