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