7 #include <argos3/core/simulator/visualization/default_visualization.h>
8 #include <argos3/core/simulator/space/space.h>
9 #include <argos3/core/simulator/loop_functions.h>
18 static Real TVTimeToHumanReadable(::timeval& t_time) {
20 static_cast<Real>(t_time.tv_sec) +
21 static_cast<Real>(t_time.tv_usec * 10e-6);
31 m_tStepFunction = &CDefaultVisualization::RealTimeStep;
32 timerclear(&m_tStepClockTime);
34 ::gettimeofday(&m_tStepStartTime, NULL);
38 m_tStepFunction = &CDefaultVisualization::NormalStep;
48 (this->*m_tStepFunction)();
59 void CDefaultVisualization::NormalStep() {
66 void CDefaultVisualization::RealTimeStep() {
70 ::gettimeofday(&m_tStepEndTime, NULL);
72 timersub(&m_tStepEndTime, &m_tStepStartTime, &m_tStepElapsedTime);
74 if(!timercmp(&m_tStepElapsedTime, &m_tStepClockTime, >)) {
76 timersub(&m_tStepClockTime, &m_tStepElapsedTime, &m_tStepWaitTime);
78 ::usleep(m_tStepWaitTime.tv_sec * 1e6 + m_tStepWaitTime.tv_usec);
80 ::gettimeofday(&m_tStepEndTime, NULL);
83 LOGERR <<
"[WARNING] Clock tick took "
84 << TVTimeToHumanReadable(m_tStepElapsedTime)
85 <<
" sec, more than the expected "
86 << TVTimeToHumanReadable(m_tStepClockTime)
91 m_tStepStartTime.tv_sec = m_tStepEndTime.tv_sec;
92 m_tStepStartTime.tv_usec = m_tStepEndTime.tv_usec;
CSimulator & m_cSimulator
A reference to the simulator.
float Real
Collects all ARGoS code.
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
CLoopFunctions & GetLoopFunctions()
Returns a reference to the loop functions associated to the current experiment.
bool IsExperimentFinished() const
Returns true if the experiment has finished.
void UpdateSpace()
Performs an update step of the space.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
virtual void PostExperiment()
Executes user-defined logic when the experiment finishes.
static Real GetSimulationClockTick()
Returns the simulation clock tick.
The namespace containing all the ARGoS related code.
bool IsRealTimeClock() const
Returns true if the clock tick follows the real time.