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

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

vrpn modifs

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