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

Last change on this file since 164 was 162, checked in by Sanahuja Guillaume, 7 years ago

modifs pb crash fin simulateur

File size: 2.1 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[8]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"
[162]23#include <ISceneManager.h>
[8]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
[15]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);
[8]38}
39
[15]40Simulator_impl::~Simulator_impl() {
41 // printf("del Simulator_impl\n");
[8]42
[15]43 SafeStop();
44 Join();
[8]45
[15]46 for (size_t i = 0; i < models.size(); i++) {
47 models.at(i)->pimpl_->SafeStop();
48 models.at(i)->pimpl_->Join();
[162]49#ifdef GL
50 getGui()->getSceneManager()->getRootSceneNode()->removeChild(models.at(i)->pimpl_);
51#endif
[15]52 delete models.at(i);
53 }
[8]54
55#ifdef GL
[15]56 if (getGui() != NULL)
57 delete getGui();
[8]58#endif
59
[15]60 // printf("del Simulator_impl ok\n");
[8]61}
62
[15]63void Simulator_impl::Run(void) {
64 SetPeriodMS(optitrack_mstime);
[8]65
[15]66 while (ToBeStopped() == false) {
67 WaitPeriod();
68 // printf("%lld\n",GetTime());
69 mainloop();
70 for (size_t i = 0; i < models.size(); i++) {
71 models.at(i)->pimpl_->mainloop();
72 }
73 }
[8]74}
75
[15]76void Simulator_impl::RunSimu(void) {
77 if (models.size() == 0) {
78 self->Err("No model to run\n");
79 return;
80 }
[8]81
[15]82 for (size_t i = 0; i < models.size(); i++) {
83 models.at(i)->pimpl_->Start();
84 }
[8]85
[15]86 Start();
[8]87
88#ifdef GL
[15]89 if (getGui() != NULL) {
90 getGui()->pimpl_->RunGui(models, objects);
91 } else
[8]92#endif
[15]93 {
94 models.at(0)->pimpl_->Join();
95 }
[8]96
[15]97 SafeStop();
98 Join();
[8]99}
Note: See TracBrowser for help on using the repository browser.