/* ------------------------------------------------------------------------- * main * ----------------------------------------------------------------------- */ int main(int argc, char** argv) { OptionsCont& oc = OptionsCont::getOptions(); // give some application descriptions oc.setApplicationDescription("Router for the microscopic road traffic simulation SUMO based on junction turning ratios."); oc.setApplicationName("jtrrouter", "SUMO jtrrouter Version " VERSION_STRING); int ret = 0; RONet* net = 0; try { // initialise the application system (messaging, xml, options) XMLSubSys::init(); ROJTRFrame::fillOptions(); OptionsIO::setArgs(argc, argv); OptionsIO::getOptions(); if (oc.processMetaOptions(argc < 2)) { SystemFrame::close(); return 0; } XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net")); MsgHandler::initOutputOptions(); if (!ROJTRFrame::checkOptions()) { throw ProcessError(); } RandHelper::initRandGlobal(); std::vector<SUMOReal> defs = getTurningDefaults(oc); // load data ROLoader loader(oc, true, !oc.getBool("no-step-log")); net = new RONet(); initNet(*net, loader, defs); try { // parse and set the turn defaults first loadJTRDefinitions(*net, oc); // build routes computeRoutes(*net, loader, oc); } catch (XERCES_CPP_NAMESPACE::SAXParseException& e) { WRITE_ERROR(toString(e.getLineNumber())); ret = 1; } catch (XERCES_CPP_NAMESPACE::SAXException& e) { WRITE_ERROR(TplConvert::_2str(e.getMessage())); ret = 1; } if (MsgHandler::getErrorInstance()->wasInformed()) { throw ProcessError(); } } catch (const ProcessError& e) { if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; #ifndef _DEBUG } catch (const std::exception& e) { if (std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; } catch (...) { MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); ret = 1; #endif } delete net; SystemFrame::close(); if (ret == 0) { std::cout << "Success." << std::endl; } return ret; }
int main( int argC, char* argV[] ) { bool quit = false; init(); if ( argC > 1 ) initNet( argC, argV ); load_files(); float preTime; float curTime; preTime = SDL_GetTicks(); fly = new Fly ( 550.0f, 324.0f ); anim = new BAnimation ( 64, 64, 0.03f ); anim->AddFrame ( glFlyTexture ); anim->AddFrame ( loadTexture ( "images/Fly/fly_fly1.png", GL_RGBA, GL_LINEAR ) ); anim->AddFrame ( loadTexture ( "images/Fly/fly_fly2.png" ) ); anim->AddFrame ( loadTexture ( "images/Fly/fly_fly1.png" ) ); fly->SetAnimation ( anim ); fly->SetMainPlayerState ( true ); fly->SendNewPlayer (); while ( !quit ) { while ( SDL_PollEvent( &event ) ) { if ( event.type == SDL_QUIT ) { quit = true; } else if ( event.type == SDL_MOUSEMOTION ) { if ( length( mouseXpre, mouseYpre, mouseX, mouseY ) >= 20.0f ) { mouseXpre = mouseX; mouseYpre = mouseY; } mouseX = event.motion.x; mouseY = event.motion.y; mouseXrel = event.motion.xrel; mouseYrel = event.motion.yrel; } else if ( event.type == SDL_MOUSEBUTTONDOWN ) { } else if ( event.type == SDL_KEYDOWN ) { SDLKey key = event.key.keysym.sym; if ( key == SDLK_ESCAPE ) quit = true; if ( key == SDLK_f ) { FLAGS ^= SDL_FULLSCREEN; screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, FLAGS ); } if ( key == SDLK_RIGHT ) fly->Turn ( 1 ); if ( key == SDLK_LEFT ) fly->Turn (-1 ); if ( key == SDLK_UP ) fly->TurnZ ( -1 ); if ( key == SDLK_DOWN ) fly->TurnZ ( +1 ); if ( key == SDLK_m ) minimapEnabled = ! minimapEnabled; if ( key == SDLK_a ) anotherFly->TurnZ ( -1 ); if ( key == SDLK_s ) anotherFly->TurnZ ( +1 ); } else if ( event.type == SDL_KEYUP ) { SDLKey key = event.key.keysym.sym; if ( key == SDLK_a ) anotherFly->TurnZ ( +1 ); if ( key == SDLK_s ) anotherFly->TurnZ ( -1 ); if ( key == SDLK_RIGHT ) fly->Turn ( -1 ); if ( key == SDLK_LEFT ) fly->Turn ( +1 ); if ( key == SDLK_UP ) fly->TurnZ ( +1 ); if ( key == SDLK_DOWN ) fly->TurnZ ( -1 ); } } curTime = SDL_GetTicks(); dt = ( curTime - preTime ) / 1000; preTime = curTime; update(dt); render(); } clean_up(); return 0; }