source: flair-src/trunk/lib/FlairSimulator/src/Simulator_impl.cpp@ 8

Last change on this file since 8 was 8, checked in by Sanahuja Guillaume, 6 years ago

simulator

File size: 1.8 KB
Line 
1// created: 2013/03/25
2// filename: Simulator_impl.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: classe de base du Simulator
10//
11/*********************************************************************/
12
13#include "Simulator_impl.h"
14#include "Simulator.h"
15#include "Euler.h"
16#ifdef GL
17#include "Gui.h"
18#include "Gui_impl.h"
19#endif
20#include "Model.h"
21#include "Model_impl.h"
22#include <unistd.h>
23
24using namespace flair::core;
25using namespace flair::simulator;
26
27Simulator_impl::Simulator_impl(Simulator* self,int optitrack_mstime,float yaw_deg): vrpn_Connection_IP(), Thread(self,"simulator",1)
28{
29 this->self=self;
30 this->optitrack_mstime=optitrack_mstime;
31 yaw_rad=Euler::ToRadian(yaw_deg);
32}
33
34Simulator_impl::~Simulator_impl()
35{
36 //printf("del Simulator_impl\n");
37
38 SafeStop();
39 Join();
40
41 for(size_t i=0;i<models.size();i++)
42 {
43 models.at(i)->pimpl_->SafeStop();
44 models.at(i)->pimpl_->Join();
45 delete models.at(i);
46 }
47
48#ifdef GL
49 if(getGui()!=NULL) delete getGui();
50#endif
51
52 //printf("del Simulator_impl ok\n");
53}
54
55void Simulator_impl::Run(void)
56{
57 SetPeriodMS(optitrack_mstime);
58
59 while(ToBeStopped()==false)
60 {
61 WaitPeriod();
62//printf("%lld\n",GetTime());
63 mainloop();
64 for(size_t i=0;i<models.size();i++)
65 {
66 models.at(i)->pimpl_->mainloop();
67 }
68 }
69}
70
71
72void Simulator_impl::RunSimu(void)
73{
74 if(models.size()==0)
75 {
76 self->Err("No model to run\n");
77 return;
78 }
79
80 for(size_t i=0;i<models.size();i++)
81 {
82 models.at(i)->pimpl_->Start();
83 }
84
85 Start();
86
87#ifdef GL
88 if(getGui()!=NULL)
89 {
90 getGui()->pimpl_->RunGui(models,objects);
91 }
92 else
93#endif
94 {
95 models.at(0)->pimpl_->Join();
96 }
97
98 SafeStop();
99 Join();
100}
Note: See TracBrowser for help on using the repository browser.