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,
nullptr);
38 m_tStepFunction = &CDefaultVisualization::NormalStep;
48 (this->*m_tStepFunction)();
59 void CDefaultVisualization::NormalStep() {
66 void CDefaultVisualization::RealTimeStep() {
70 ::gettimeofday(&m_tStepEndTime,
nullptr);
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(
static_cast<UInt32>(m_tStepWaitTime.tv_sec * 1e6 + m_tStepWaitTime.tv_usec));
80 ::gettimeofday(&m_tStepEndTime,
nullptr);
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;
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
CARGoSLog LOG(std::cout, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_GREEN))
virtual void PostExperiment()
Executes user-defined logic when the experiment finishes.
static Real GetSimulationClockTick()
Returns the simulation clock tick.
CLoopFunctions & GetLoopFunctions()
Returns a reference to the loop functions associated to the current experiment.
bool IsExperimentFinished() const
Returns true if the experiment has finished.
bool IsRealTimeClock() const
Returns true if the clock tick follows the real time.
void UpdateSpace()
Performs an update step of the space.
CSimulator & m_cSimulator
A reference to the simulator.