diff --git a/src/simulator/AirController.cpp b/src/simulator/AirController.cpp index fdeff0f..af7a8a2 100644 --- a/src/simulator/AirController.cpp +++ b/src/simulator/AirController.cpp @@ -29,20 +29,16 @@ #include #include -namespace atcsim{ +namespace atcsim { AirController::AirController() { - // TODO Auto-generated constructor stub - + // TODO(my_username): Auto-generated constructor stub } - AirController::~AirController() { - // TODO Auto-generated destructor stub + // TODO(my_username): Auto-generated destructor stub } - void -AirController::doWork() -{ +AirController::doWork() { std::list flights = Airport::getInstance()->getFlights(); std::list::iterator it; @@ -62,16 +58,12 @@ AirController::doWork() r3.pos = pos3; r3.speed = 15.0; - for(it = flights.begin(); it!=flights.end(); ++it) - { - if((*it)->getRoute()->empty()) - { +for(it = flights.begin(); it != flights.end(); ++it) { + if ((*it)->getRoute()->empty()) { (*it)->getRoute()->push_back(r3); (*it)->getRoute()->push_front(r2); (*it)->getRoute()->push_front(r1); - (*it)->getRoute()->push_front(r0); - } - } + (*it)->getRoute()->push_front(r0);} + } } - } // namespace atcsim diff --git a/src/simulator/AirController.h b/src/simulator/AirController.h index cd0bfd6..4abf75e 100644 --- a/src/simulator/AirController.h +++ b/src/simulator/AirController.h @@ -22,21 +22,21 @@ * along with ATCSim. If not, see . */ -#ifndef AIRCONTROLLER_H_ -#define AIRCONTROLLER_H_ +#ifndef SRC_SIMULATOR_AIRCONTROLLER_H_ +#define SRC_SIMULATOR_AIRCONTROLLER_H_ #include "Singleton.h" namespace atcsim{ class AirController: public Singleton { -public: - AirController(); - virtual ~AirController(); + public: + AirController(); + virtual ~AirController(); - void doWork(); + void doWork(); }; }; // namespace atcsim -#endif /* AIRCONTROLLER_H_ */ +#endif // SRC_SIMULATOR_AIRCONTROLLER_H_ diff --git a/src/simulator/Airport.cpp b/src/simulator/Airport.cpp index 8485b90..8a4c2cf 100644 --- a/src/simulator/Airport.cpp +++ b/src/simulator/Airport.cpp @@ -28,599 +28,529 @@ #include #include // -//#ifdef __APPLE__ -//#include -//#include -//#else -//#include -//#include -//#endif +// #ifdef __APPLE__ +// #include +// #include +// #else +// #include +// #include +// #endif #include -namespace atcsim{ +namespace atcsim { Airport::Airport() { + flights.clear(); - flights.clear(); + gettimeofday(&last_ts, NULL); + crono = last_ts.tv_sec*1000000 + last_ts.tv_usec; - gettimeofday(&last_ts, NULL); - crono = last_ts.tv_sec*1000000 + last_ts.tv_usec; + final_pos.set_x(LANDING_POS_X); + final_pos.set_y(LANDING_POS_Y); + final_pos.set_z(LANDING_POS_Z); - final_pos.set_x(LANDING_POS_X); - final_pos.set_y(LANDING_POS_Y); - final_pos.set_z(LANDING_POS_Z); + srand(time(NULL)); + sec = 0; + points = INIT_POINTS; + max_flights = INIT_MAX_FLIGHTS; + SimTimeMod = 1.0; + storm = NULL; - srand (time(NULL)); - sec = 0; - points = INIT_POINTS; - max_flights = INIT_MAX_FLIGHTS; - SimTimeMod = 1.0; - storm = NULL; + pthread_mutex_init(&mutex, NULL); - pthread_mutex_init(&mutex, NULL); - - acum_ = 0; + acum_ = 0; any_landing_ = false; } Airport::~Airport() { - std::list::iterator it; - for(it = flights.begin(); it!=flights.end(); ++it) - delete(*it); - flights.clear(); + std::list::iterator it; +for(it = flights.begin(); it != flights.end(); ++it) + delete(*it); + flights.clear(); } void -Airport::checkFinishStorm() -{ - float x, y, z, dist; - - x = storm->getPosition().get_x(); - y = storm->getPosition().get_y(); +Airport::checkFinishStorm() { + float x, y, z, dist; - dist = sqrt(x*x+y*y); + x = storm->getPosition().get_x(); + y = storm->getPosition().get_y(); - if(sqrt(x*x+y*y)>(AIRPORT_DISTANCE_MAX*1.5)) - { - delete storm; - storm=NULL; - std::cerr<<"Storm gone"< (AIRPORT_DISTANCE_MAX*1.5)) { + delete storm; + storm = NULL; + std::cerr << "Storm gone" << std::endl; + } } - void -Airport::generate_storm() -{ - - float angle, x, y, z, rad, height, bearing, speed; - - //Storm Pos - angle = toRadians((float)(rand() % 360 - 180)); - x = fabs(AIRPORT_DISTANCE_MAX*1.5 * cos(angle)); //Only positive, for GyV3D!!!!!!!!!!! - y = AIRPORT_DISTANCE_MAX*1.5 * sin(angle); - z = ((float)rand() / RAND_MAX)*(STORM_MIN_ELEVATION-STORM_MIN_ELEVATION)+STORM_MIN_ELEVATION; - - //Storm height - height = ((float)rand() / RAND_MAX)*(STORM_MAX_HEIGHT-STORM_MIN_HEIGHT)+STORM_MIN_HEIGHT; - - //Radius - rad = ((float)rand() / RAND_MAX)*(STORM_MAX_RAD-STORM_MIN_RAD)+STORM_MIN_RAD; - - //Bearing - bearing = toRadians((float)(rand() % 360 - 180)); - - //Speed - speed = ((float)rand() / RAND_MAX)*(STORM_MAX_SPEED-STORM_MIN_SPEED)+STORM_MIN_SPEED; - Position ipos(x, y, z); - storm = new Storm(ipos, bearing, speed, rad, height); - +Airport::generate_storm() { + float angle, x, y, z, rad, height, bearing, speed; + // Storm Pos + angle = toRadians(static_cast(rand() % 360 - 180)); + x = fabs(AIRPORT_DISTANCE_MAX*1.5 * cos(angle)); // Only positive, for GyV3D!!!!!!!!!!! + y = AIRPORT_DISTANCE_MAX*1.5 * sin(angle); + z = (static_cast(rand()) / RAND_MAX)*(STORM_MIN_ELEVATION-STORM_MIN_ELEVATION)+STORM_MIN_ELEVATION; + + // Storm height + height = (static_cast(rand()) / RAND_MAX)*(STORM_MAX_HEIGHT-STORM_MIN_HEIGHT)+STORM_MIN_HEIGHT; + + // Radius + rad = (static_cast(rand()) / RAND_MAX)*(STORM_MAX_RAD-STORM_MIN_RAD)+STORM_MIN_RAD; + + // Bearing + bearing = toRadians(static_cast(rand() % 360 - 180)); + + // Speed + speed = (static_cast(rand()) / RAND_MAX)*(STORM_MAX_SPEED-STORM_MIN_SPEED)+STORM_MIN_SPEED; + Position ipos(x, y, z); + storm = new Storm(ipos, bearing, speed, rad, height); } void -Airport::generate_flight() -{ - - - std::cerr<<"Generate new flight"; - float angle, x, y, z; - float bear, inc; - char id[6]; +Airport::generate_flight() { + std::cerr << "Generate new flight"; + float angle, x, y, z; + float bear, inc; + char id[6]; - angle = toRadians((float)(rand() % 360 - 180)); + angle = toRadians(static_cast(rand() % 360 - 180)); - x = fabs(AIRPORT_DISTANCE_MAX * cos(angle)); //Only positive, for GyV3D!!!!!!!!!!! - y = AIRPORT_DISTANCE_MAX * sin(angle); - z = FLIGHT_HEIGHT + (float)(rand() % 2000); + x = fabs(AIRPORT_DISTANCE_MAX * cos(angle)); // Only positive, for GyV3D!!!!!!!!!!! + y = AIRPORT_DISTANCE_MAX * sin(angle); + z = FLIGHT_HEIGHT + static_cast(rand() % 2000); - Position ipos(x, y, z); - Position pos0(0.0, 0.0, 0.0); + Position ipos(x, y, z); + Position pos0(0.0, 0.0, 0.0); - pos0.angles(ipos, bear, inc); + pos0.angles(ipos, bear, inc); - sprintf(id, "IB%4.4d", sec++); - std::cerr<<": ["<setFocused(true); - } - - if(flights.size() > 1) - { - (*focus)->setFocused(false); - - if(++focus == flights.end()) - focus = flights.begin(); - }else - focus = flights.begin(); +if(flights.size() == 1) { + focus = flights.begin(); + (*focus)->setFocused(true); +} - (*focus)->setFocused(true); +if(flights.size() > 1) { + (*focus)->setFocused(false); +if(++focus == flights.end()) + focus = flights.begin(); +} else { + focus = flights.begin(); + (*focus)->setFocused(true); } void -Airport::step() -{ - - //pthread_mutex_lock (&mutex); - float delta_t; - struct timeval tv; - std::list::iterator it; - long ta, tb; - - gettimeofday(&tv, NULL); - - ta = tv.tv_sec*1000000 + tv.tv_usec; - tb = last_ts.tv_sec*1000000 + last_ts.tv_usec; - - delta_t =((float)(ta-tb)) /1000000.0; - last_ts = tv; - acum_ = acum_ + (delta_t * SimTimeMod)*1000000.0; -//En la siguiente funcion realizar un acumulador que se inicialice a 0 en cada cambio -//de nivel el cual es tal que acum =0, y va cambiando segun acum = acum +(differencial del tiempo * factor de aceleracion) - if(acum_>INC_DIFF) - { - max_flights += INC_PEN; - //std::cerr<<"Increase flights in "<update(SimTimeMod*delta_t); - //std::cerr<<"["<<(*it)->getId()<<"] on the way"<draw(); - } - - pthread_mutex_lock (&mutex); - checkLandings(); - checkCollisions(); - checkCrashes(); - pthread_mutex_unlock (&mutex); - } - - pthread_mutex_lock (&mutex); - - if(storm==NULL) - { - generate_storm(); - } - else - { - storm->update(SimTimeMod * delta_t); - checkFlightsInStorm(); - checkFinishStorm(); - } - pthread_mutex_unlock (&mutex); +Airport::step() { + // pthread_mutex_lock (&mutex); + float delta_t; + struct timeval tv; + std::list::iterator it; + int64 ta, tb; + + gettimeofday(&tv, NULL); + + ta = tv.tv_sec*1000000 + tv.tv_usec; + tb = last_ts.tv_sec*1000000 + last_ts.tv_usec; + + delta_t =(static_cast(ta-tb)) /1000000.0; + last_ts = tv; + acum_ = acum_ + (delta_t * SimTimeMod)*1000000.0; +// En la siguiente funcion realizar un acumulador que se inicialice a 0 en cada cambio +// de nivel el cual es tal que acum =0, y va cambiando segun acum = acum +(differencial del tiempo * factor de aceleracion) +if(acum_ > INC_DIFF) { + max_flights += INC_PEN; + // std::cerr<<"Increase flights in "<update(SimTimeMod*delta_t); + // std::cerr<<"["<<(*it)->getId()<<"] on the way"<draw(); +} + pthread_mutex_lock(&mutex); + checkLandings(); + checkCollisions(); + checkCrashes(); + pthread_mutex_unlock(&mutex); +} + pthread_mutex_lock(&mutex); +if(storm == NULL) { + generate_storm(); +} else { + storm->update(SimTimeMod * delta_t); + checkFlightsInStorm(); + checkFinishStorm(); +} + pthread_mutex_unlock(&mutex); +if(flights.size() < max_flights) { + pthread_mutex_lock(&mutex); + generate_flight(); + pthread_mutex_unlock(&mutex); +} } std::list::iterator -Airport::removeFlight(std::string id) -{ - std::list::iterator it; - - it=flights.begin(); - - while(it != flights.end()) - { - if((*it)->getId().compare(id) == 0) - { - if((*it)==(*focus)) - { - delete(*it); - focus = flights.erase(it); - (*focus)->setFocused(true); - return focus; - }else - { - delete(*it); - it = flights.erase(it); - return it; - } - } - it++; - } - return flights.begin(); - +Airport::removeFlight(std::string id) { + std::list::iterator it; + + it = flights.begin(); + +while(it != flights.end()) { +if((*it)->getId().compare(id) == 0) { +if((*it) == (*focus)) { + delete(*it); + focus = flights.erase(it); + (*focus)->setFocused(true); + return focus; +} else { + delete(*it); + it = flights.erase(it); + return it; +} +} + it++; +} + return flights.begin(); } void -Airport::checkCollisions() -{ - if(flights.empty()) return; +Airport::checkCollisions() { +if(flights.empty()) return; - std::list::iterator i,j; - bool removed = false; + std::list::iterator i, j; + bool removed = false; - i = flights.begin(); + i = flights.begin(); - while(i != flights.end()) - { - j = i; +while(i != flights.end()) { + j = i; - if(j!=flights.end()) j++; +if(j != flights.end()) j++; - while(j != flights.end()) - { - if( (*i)->getPosition().distance((*j)->getPosition()) < COLLISION_DISTANCE) - { - std::cerr<<"Collision between "<<(*i)->getId()<<" and "<<(*j)->getId()<getId()); - j = removeFlight((*j)->getId()); - points += COLLISION_POINTS; - return; //Avoid not valid iterator. Only one collision per cycle - } - j++; - } - i++; - } +while(j != flights.end()) { +if((*i)->getPosition().distance((*j)->getPosition()) < COLLISION_DISTANCE) { + std::cerr << "Collision between " << (*i)->getId() << " and " << (*j)->getId() << std::endl; + i = removeFlight((*i)->getId()); + j = removeFlight((*j)->getId()); + points += COLLISION_POINTS; + return; // Avoid not valid iterator. Only one collision per cycle +} + j++; +} + i++; +} } void -Airport::checkFlightsInStorm() -{ - if(flights.empty() || storm==NULL ) return; +Airport::checkFlightsInStorm() { +if(flights.empty() || storm == NULL ) return; - std::list::iterator it; + std::list::iterator it; - for(it = flights.begin(); it != flights.end(); ++it) - { - bool in=false; - float xf,yf, zf, xs, ys, zs; - float dist; +for(it = flights.begin(); it != flights.end(); ++it) { + bool in = false; + float xf, yf, zf, xs, ys, zs; + float dist; - xf = (*it)->getPosition().get_x(); - yf = (*it)->getPosition().get_y(); - zf = (*it)->getPosition().get_z(); - xs = storm->getPosition().get_x(); - ys = storm->getPosition().get_y(); - zs = storm->getPosition().get_z(); + xf = (*it)->getPosition().get_x(); + yf = (*it)->getPosition().get_y(); + zf = (*it)->getPosition().get_z(); + xs = storm->getPosition().get_x(); + ys = storm->getPosition().get_y(); + zs = storm->getPosition().get_z(); - dist = sqrt((xf-xs)*(xf-xs)+(yf-ys)*(yf-ys)); + dist = sqrt((xf-xs)*(xf-xs)+(yf-ys)*(yf-ys)); - in = dist < storm->getRadious() && fabs(zs-zf)getHeight(); - (*it)->setInStorm(in); + in = dist < storm->getRadious() && fabs(zs-zf) < storm->getHeight(); + (*it)->setInStorm(in); - //std::cerr<<"["<<(*it)->getId()<<" = "<getRadious()<getId()<<" = "<getRadious()<::iterator it; - - it = flights.begin(); - while(it != flights.end()) - { - if((*it)->getPosition().get_z()getId()<getId()); - points += CRASH_HEIGHT_POINTS; - }else if(toDegrees(fabs((*it)->getInclination())) > CRASH_INC) - { - std::cerr<<"[Inc] Crash of "<<(*it)->getId()<getId()); - points += CRASH_INC_POINTS; - }else if( (*it)->getSpeed()getId()<getId()); - points += CRASH_SPEED_POINTS; - }else - it++; - } +Airport::checkCrashes() { +if(flights.empty()) return; + + std::list::iterator it; + + it = flights.begin(); +while(it != flights.end()) { +if ((*it)->getPosition().get_z() < CRASH_Z) { + std::cerr << "[PoZ]Crash of " << (*it)->getId() << std::endl; + it = removeFlight((*it)->getId()); + points += CRASH_HEIGHT_POINTS; +} else if (toDegrees(fabs((*it)->getInclination())) > CRASH_INC) { + std::cerr << "[Inc] Crash of " << (*it)->getId() << std::endl; + it = removeFlight((*it)->getId()); + points += CRASH_INC_POINTS; +} else if ((*it)->getSpeed() < CRASH_SPEED) { + std::cerr << "[Spd] Crash of " << (*it)->getId() << std::endl; + it = removeFlight((*it)->getId()); + points += CRASH_SPEED_POINTS; +} else { + it++; +} } void -Airport::checkLandings() -{ - if(flights.empty()) return; - - //pthread_mutex_lock (&mutex); - std::list::iterator it; +Airport::checkLandings() { +if(flights.empty()) return; - it = flights.begin(); + // pthread_mutex_lock (&mutex); + std::list::iterator it; - while(it != flights.end()) - { + it = flights.begin(); - if((final_pos.distance((*it)->getPosition()) < LANDING_DIST) && - (toDegrees(normalizePi(fabs((*it)->getBearing() - toRadians(LANDING_BEAR))))getSpeed()getPosition()) < LANDING_DIST) && +(toDegrees(normalizePi(fabs((*it)->getBearing() - toRadians(LANDING_BEAR)))) < LANDING_BEAR_MAX_ERROR) && +((*it)->getSpeed() < LANDING_SPEED)) { + std::cerr << "Flight " << (*it)->getId() << " landed" << std::endl; + points += static_cast(*it)->getPoints(); - std::cerr<<"Flight "<<(*it)->getId()<<" landed"<getPoints(); + it = removeFlight((*it)->getId()); - it = removeFlight((*it)->getId()); - - std::cerr<<"*"; - - any_landing_ = false; + std::cerr << "*"; + any_landing_ = false; - return; - }else - it++; - } - //pthread_mutex_unlock (&mutex); + return; +} else { + it++; +} + // pthread_mutex_unlock (&mutex); } void -Airport::UpdateSimTime(float inc) -{ - SimTimeMod = SimTimeMod + inc; +Airport::UpdateSimTime(float inc) { + SimTimeMod = SimTimeMod + inc; - if(SimTimeMod < 0) SimTimeMod = 0; +if(SimTimeMod < 0) SimTimeMod = 0; } ATCDisplay::ATCDStorm -Airport::getStorm(const Ice::Current&) -{ - pthread_mutex_lock (&mutex); - ATCDisplay::ATCDStorm ret; +Airport::getStorm(const Ice::Current&) { + pthread_mutex_lock(&mutex); + ATCDisplay::ATCDStorm ret; + +if(storm == NULL) { + ret.valid = false; + return ret; +} else { + ret.valid = true; + + ATCDisplay::ATCDPosition p; + p.x = storm->getPosition().get_x(); + p.y = storm->getPosition().get_y(); + p.z = storm->getPosition().get_z(); + + ret.pos = p; + ret.bearing = storm->getBearing(); + ret.height = storm->getHeight(); + ret.radious = storm->getRadious(); + ret.speed = storm->getSpeed(); + + pthread_mutex_unlock(&mutex); + return ret; +} + +ATCDisplay::ATCDFlights +Airport::getFlights(const Ice::Current&) { + pthread_mutex_lock(&mutex); + + // std::cerr<<"["<::iterator it; - if(storm==NULL) - { - ret.valid =false; - return ret; - }else - ret.valid =true; +for(it = flights.begin(); it != flights.end(); ++it) { + // std::cerr<<"A"; - ATCDisplay::ATCDPosition p; - p.x = storm->getPosition().get_x(); - p.y = storm->getPosition().get_y(); - p.z = storm->getPosition().get_z(); + std::list::iterator itr; + ATCDisplay::ATCDRoute atcdr; + atcdr.clear(); - ret.pos = p; - ret.bearing = storm->getBearing(); - ret.height = storm->getHeight(); - ret.radious = storm->getRadious(); - ret.speed = storm->getSpeed(); +for(itr = (*it)->getRoute()->begin(); itr != (*it)->getRoute()->end(); ++itr) { + // std::cerr<<"B"; + Route r = (*itr); - pthread_mutex_unlock (&mutex); - return ret; + ATCDisplay::ATCDPosition p; + p.name = r.pos.get_name(); + p.x = r.pos.get_x(); + p.y = r.pos.get_y(); + p.z = r.pos.get_z(); + + atcdr.push_back(p); } -ATCDisplay::ATCDFlights -Airport::getFlights(const Ice::Current&) -{ - - pthread_mutex_lock (&mutex); - - //std::cerr<<"["<::iterator it; - - for(it= flights.begin(); it!=flights.end(); ++it) - { - //std::cerr<<"A"; - - std::list::iterator itr; - ATCDisplay::ATCDRoute atcdr; - atcdr.clear(); - - for(itr= (*it)->getRoute()->begin(); itr!=(*it)->getRoute()->end(); ++itr) - { - //std::cerr<<"B"; - Route r= (*itr); - - ATCDisplay::ATCDPosition p; - p.name = r.pos.get_name(); - p.x = r.pos.get_x(); - p.y = r.pos.get_y(); - p.z = r.pos.get_z(); - - atcdr.push_back(p); - } - - //std::cerr<<"C"; - ATCDisplay::ATCDPosition fp; - fp.name = (*it)->getPosition().get_name(); - fp.x = (*it)->getPosition().get_x(); - fp.y = (*it)->getPosition().get_y(); - fp.z = (*it)->getPosition().get_z(); - - //std::cerr<<"D"; - ATCDisplay::ATCDFlight f; - f.speed = (*it)->getSpeed(); - f.focused = (*it)->getFocused(); - f.points = (*it)->getPoints(); - f.id = (*it)->getId(); - f.bearing = (*it)->getBearing(); - f.collisionRadious = COLLISION_DISTANCE; - f.flightRoute = atcdr; - f.inclination = (*it)->getInclination(); - f.pos = fp; - //std::cerr<<"E"; - ret.push_back(f); - } - - //std::cerr<<"]"<getPosition().get_name(); + fp.x = (*it)->getPosition().get_x(); + fp.y = (*it)->getPosition().get_y(); + fp.z = (*it)->getPosition().get_z(); + + // std::cerr<<"D"; + ATCDisplay::ATCDFlight f; + f.speed = (*it)->getSpeed(); + f.focused = (*it)->getFocused(); + f.points = (*it)->getPoints(); + f.id = (*it)->getId(); + f.bearing = (*it)->getBearing(); + f.collisionRadious = COLLISION_DISTANCE; + f.flightRoute = atcdr; + f.inclination = (*it)->getInclination(); + f.pos = fp; + // std::cerr<<"E"; + ret.push_back(f); +} + + // std::cerr<<"]"<displayText(points_txt, GUI::win_width-300, 25, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_TIMES_ROMAN_24); +// textDisplay->displayText(points_txt, GUI::win_width-300, 25, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_TIMES_ROMAN_24); // -// snprintf(points_txt, 255, "Time speed: x%3.1f", SimTimeMod); -// textDisplay->displayText(points_txt, 10, GUI::win_height-5, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// char help_txt[255]; -// strcpy(help_txt, "Press Mouse3 and move mouse to change orientation"); -// textDisplay->displayText(help_txt, GUI::win_width-310, GUI::win_height-5, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, " Change flight info"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-200, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Move camera forward"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-180, GUI::win_width, -//GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "<+>Speed up time"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-160, GUI::win_width, -//GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "<->Slow down time"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-140, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Move camera backward"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-120, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Move camera side left"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-100, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Move camera side right"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-80, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Reset camera position"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-60, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Center camera in flight"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-40, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); -// strcpy(help_txt, "Finish"); -// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-20, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// snprintf(points_txt, 255, "Time speed: x%3.1f", SimTimeMod); +// textDisplay->displayText(points_txt, 10, GUI::win_height-5, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// char help_txt[255]; +// strcpy(help_txt, "Press Mouse3 and move mouse to change orientation"); +// textDisplay->displayText(help_txt, GUI::win_width-310, GUI::win_height-5, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, " Change flight info"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-200, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Move camera forward"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-180, GUI::win_width, +// GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "<+>Speed up time"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-160, GUI::win_width, +// GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "<->Slow down time"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-140, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Move camera backward"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-120, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Move camera side left"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-100, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Move camera side right"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-80, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Reset camera position"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-60, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Center camera in flight"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-40, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); +// strcpy(help_txt, "Finish"); +// textDisplay->displayText(help_txt, GUI::win_width-160, GUI::win_height-20, GUI::win_width, GUI::win_height, WHITE, GLUT_BITMAP_HELVETICA_12); // -//} +// } diff --git a/src/simulator/Airport.h b/src/simulator/Airport.h index 113e5a0..820b925 100644 --- a/src/simulator/Airport.h +++ b/src/simulator/Airport.h @@ -22,8 +22,8 @@ * along with ATCSim. If not, see . */ -#ifndef SIMULATOR_AIRPORT_H__ -#define SIMULATOR_AIRPORT_H__ +#ifndef SRC_SIMULATOR_AIRPORT_H_ +#define SRC_SIMULATOR_AIRPORT_H_ #include "Singleton.h" #include "Flight.h" @@ -33,71 +33,68 @@ #include -namespace atcsim{ +namespace atcsim { -class Airport: public Singleton, public ATCDisplay::AirportInterface -{ -public: - Airport(); - virtual ~Airport(); +class Airport: public Singleton, public ATCDisplay::AirportInterface { + public: + Airport(); + virtual ~Airport(); - void step(); - //void draw(); + void step(); + // void draw(); - void NextFocus(); + void NextFocus(); - std::list getFlights() {return flights;}; - Storm* getStorm() {return storm;}; - Flight* getFocused(){return (*focus);}; - void UpdateSimTime(float inc); + std::list getFlights() {return flights;} + Storm* getStorm() {return storm;} + Flight* getFocused() {return (*focus);} + void UpdateSimTime(float inc) - virtual ATCDisplay::ATCDFlights getFlights(const Ice::Current&); - virtual ATCDisplay::ATCDStorm getStorm(const Ice::Current&); - virtual ATCDisplay::ATCDAirport getAirportInfo(const Ice::Current&); - virtual void UpdateSimT(float inc, const Ice::Current&); - virtual void NextFocus(const Ice::Current&); - virtual float getSimT(const Ice::Current&); - virtual int getMaxFlights(const Ice::Current&); - virtual int getPoints(const Ice::Current&); + virtual ATCDisplay::ATCDFlights getFlights(const Ice::Current&); + virtual ATCDisplay::ATCDStorm getStorm(const Ice::Current&); + virtual ATCDisplay::ATCDAirport getAirportInfo(const Ice::Current&); + virtual void UpdateSimT(float inc, const Ice::Current&); + virtual void NextFocus(const Ice::Current&); + virtual float getSimT(const Ice::Current&); + virtual int getMaxFlights(const Ice::Current&); + virtual int getPoints(const Ice::Current&); void book_landing() {any_landing_ = true;} bool is_booked_landing() { return any_landing_;} -private: + private: + void checkLandings(); + void checkCollisions(); + void checkCrashes(); + void checkFinishStorm(); + void generate_flight(); + void generate_storm(); + void checkFlightsInStorm(); - void checkLandings(); - void checkCollisions(); - void checkCrashes(); - void checkFinishStorm(); - void generate_flight(); - void generate_storm(); - void checkFlightsInStorm(); + std::list::iterator removeFlight(std::string id); - std::list::iterator removeFlight(std::string id); + std::list flights; + std::list::iterator focus; - std::list flights; - std::list::iterator focus; + Storm *storm; - Storm *storm; + struct timeval last_ts; + Position final_pos; + int sec; + int points; + int max_flights; + int64 crono; + int64 SimTimeMod; - struct timeval last_ts; - Position final_pos; - int sec; - int points; - int max_flights; - long crono; - float SimTimeMod; + pthread_mutex_t mutex; - pthread_mutex_t mutex; - - float acum_; + float acum_; bool any_landing_; - }; -}; // namespace atcsim +} // namespace atcsim -#endif // SIMULATOR_AIRPORT_H__ +#endif // SRC_SIMULATOR_AIRPORT_H_