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

Last change on this file since 218 was 218, checked in by Sanahuja Guillaume, 4 years ago

reduce delay between server and client for simulated vrpn

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