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

Last change on this file since 76 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 1.9 KB
Line 
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
28using namespace flair::core;
29using namespace flair::simulator;
30
31Simulator_impl::Simulator_impl(Simulator *self, int optitrack_mstime,
32 float yaw_deg)
33 : vrpn_Connection_IP(), Thread(self, "simulator", 1) {
34 this->self = self;
35 this->optitrack_mstime = optitrack_mstime;
36 yaw_rad = Euler::ToRadian(yaw_deg);
37}
38
39Simulator_impl::~Simulator_impl() {
40 // printf("del Simulator_impl\n");
41
42 SafeStop();
43 Join();
44
45 for (size_t i = 0; i < models.size(); i++) {
46 models.at(i)->pimpl_->SafeStop();
47 models.at(i)->pimpl_->Join();
48 delete models.at(i);
49 }
50
51#ifdef GL
52 if (getGui() != NULL)
53 delete getGui();
54#endif
55
56 // printf("del Simulator_impl ok\n");
57}
58
59void Simulator_impl::Run(void) {
60 SetPeriodMS(optitrack_mstime);
61
62 while (ToBeStopped() == false) {
63 WaitPeriod();
64 // printf("%lld\n",GetTime());
65 mainloop();
66 for (size_t i = 0; i < models.size(); i++) {
67 models.at(i)->pimpl_->mainloop();
68 }
69 }
70}
71
72void Simulator_impl::RunSimu(void) {
73 if (models.size() == 0) {
74 self->Err("No model to run\n");
75 return;
76 }
77
78 for (size_t i = 0; i < models.size(); i++) {
79 models.at(i)->pimpl_->Start();
80 }
81
82 Start();
83
84#ifdef GL
85 if (getGui() != NULL) {
86 getGui()->pimpl_->RunGui(models, objects);
87 } else
88#endif
89 {
90 models.at(0)->pimpl_->Join();
91 }
92
93 SafeStop();
94 Join();
95}
Note: See TracBrowser for help on using the repository browser.