00001
00002
00003
00004
00005 #include "eqPly.h"
00006
00007 #include "config.h"
00008 #include "localInitData.h"
00009
00010 #include <stdlib.h>
00011
00012 using namespace std;
00013
00014 namespace eqPly
00015 {
00016
00017 Application::Application( const LocalInitData& initData )
00018 : _initData( initData )
00019 {}
00020
00021 int Application::run()
00022 {
00023
00024 eq::ServerPtr server = new eq::Server;
00025 if( !connectServer( server ))
00026 {
00027 EQERROR << "Can't open server" << endl;
00028 return EXIT_FAILURE;
00029 }
00030
00031
00032 eq::ConfigParams configParams;
00033 Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00034
00035 if( !config )
00036 {
00037 EQERROR << "No matching config on server" << endl;
00038 disconnectServer( server );
00039 return EXIT_FAILURE;
00040 }
00041
00042
00043 eq::base::Clock clock;
00044
00045 config->setInitData( _initData );
00046 if( !config->init( ))
00047 {
00048 EQERROR << "Config initialization failed: "
00049 << config->getErrorMessage() << endl;
00050 server->releaseConfig( config );
00051 disconnectServer( server );
00052 return EXIT_FAILURE;
00053 }
00054
00055 EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00056 << endl;
00057
00058
00059 uint32_t maxFrames = _initData.getMaxFrames();
00060
00061 clock.reset();
00062 while( config->isRunning( ) && maxFrames-- )
00063 {
00064 config->startFrame();
00065
00066 config->finishFrame();
00067
00068 if( !config->needsRedraw( ))
00069 config->finishAllFrames();
00070
00071 while( !config->needsRedraw( ))
00072 {
00073 const eq::ConfigEvent* event = config->nextEvent();
00074 if( !config->handleEvent( event ))
00075 EQVERB << "Unhandled " << event << endl;
00076 }
00077 }
00078 const uint32_t frame = config->finishAllFrames();
00079 const float time = clock.getTimef();
00080 EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00081 << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00082 << endl;
00083
00084
00085 clock.reset();
00086 config->exit();
00087 EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<endl;
00088
00089
00090 server->releaseConfig( config );
00091 if( !disconnectServer( server ))
00092 EQERROR << "Client::disconnectServer failed" << endl;
00093
00094
00095 server = 0;
00096
00097 return EXIT_SUCCESS;
00098 }
00099
00100 bool Application::clientLoop()
00101 {
00102 if( !_initData.isResident( ))
00103 return eq::Client::clientLoop();
00104
00105
00106 while( true )
00107 {
00108 if( !eq::Client::clientLoop( ))
00109 return false;
00110 EQINFO << "One configuration run successfully executed" << endl;
00111 }
00112 return true;
00113 }
00114 }