Privacy
An open-source, flexible 3D physical simulation framework
GraphicsTimer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011, 2012 DFKI GmbH Robotics Innovation Center
3  *
4  * This file is part of the MARS simulation framework.
5  *
6  * MARS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * MARS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MARS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "GraphicsTimer.h"
22 #include <mars/utils/misc.h>
23 #include <stdlib.h>
24 
25 namespace mars {
26  namespace app {
27 
30 
32  SimulatorInterface *sim_)
33  : graphics(graphics_), sim(sim_) {
34  graphicsTimer = new QTimer();
35  connect(graphicsTimer, SIGNAL(timeout()), this, SLOT(timerEvent()));
36  connect(this, SIGNAL(internalRun()), this, SLOT(runOnceInternal()),
37  Qt::QueuedConnection);
38  }
39 
41  char* marsTimerStepsize = getenv("MARS_GRAPHICS_UPDATE_TIME");
42  int updateTime = 10;
43  if(marsTimerStepsize) {
44  updateTime = atoi(marsTimerStepsize);
45  }
46  graphicsTimer->start(updateTime);
47  }
48 
50  graphicsTimer->stop();
51  }
52 
53 
55  runFinished=false;
56  emit internalRun();
57  while(!runFinished){
59  }
60  }
61 
63  timerEvent();
64  runFinished=true;
65  }
66 
68  if(sim->getAllowDraw() || !sim->getSyncGraphics()) {
69  if(graphics) {
70  graphics->draw();
71  }
72  else {
73  sim->finishedDraw();
74  }
75  }
76  }
77 
78  } // end of namespace app
79 } // end of namespace mars
void msleep(unsigned int milliseconds)
sleeps for at least the specified time.
Definition: misc.h:96
mars::interfaces::SimulatorInterface * sim
Definition: GraphicsTimer.h:57
GraphicsTimer(mars::interfaces::GraphicsManagerInterface *graphics_, mars::interfaces::SimulatorInterface *sim_)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
mars::interfaces::GraphicsManagerInterface * graphics
Definition: GraphicsTimer.h:56
virtual bool getSyncGraphics(void)=0