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

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

vrpn modifs

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