void CommandTester::startNext() { Q_ASSERT(!m_action); m_abort = false; m_restart = false; if (!hasCommands()) return; Command *command = &m_commands[0]; if (command->matchCmd.isEmpty()) { commandPassed(true); } else { m_action = new Action(this); const QString text = getTextData(m_data); m_action->setInput(text.toUtf8()); m_action->setData(m_data); const QString arg = getTextData(m_action->input()); m_action->setCommand(command->matchCmd, QStringList(arg)); connect(m_action, SIGNAL(actionFinished(Action*)), SLOT(actionFinished())); m_action->start(); } }
bool Client::processCommands() { if (!hasCommands()) return false; processCommand(); return true; }
int EqPly::run() { // 1. connect to server eq::ServerPtr server = new eq::Server; if( !connectServer( server )) { LBERROR << "Can't open server" << std::endl; return EXIT_FAILURE; } // 2. choose config eq::fabric::ConfigParams configParams; Config* config = static_cast<Config*>(server->chooseConfig( configParams )); if( !config ) { LBERROR << "No matching config on server" << std::endl; disconnectServer( server ); return EXIT_FAILURE; } // 3. init config lunchbox::Clock clock; config->setInitData( _initData ); if( !config->init( )) { LBWARN << "Error during initialization: " << config->getError() << std::endl; server->releaseConfig( config ); disconnectServer( server ); return EXIT_FAILURE; } if( config->getError( )) LBWARN << "Error during initialization: " << config->getError() << std::endl; LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms" << std::endl; // 4. run main loop uint32_t maxFrames = _initData.getMaxFrames(); int lastFrame = 0; clock.reset(); while( config->isRunning( ) && maxFrames-- ) { config->startFrame(); if( config->getError( )) LBWARN << "Error during frame start: " << config->getError() << std::endl; config->finishFrame(); if( config->getAnimationFrame() == 1 ) { const float time = clock.resetTimef(); const size_t nFrames = config->getFinishedFrame() - lastFrame; lastFrame = config->getFinishedFrame(); LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ " << ( nFrames / time * 1000.f) << " FPS)" << std::endl; } while( !config->needRedraw( )) // wait for an event requiring redraw { if( hasCommands( )) // execute non-critical pending commands { processCommand(); config->handleEvents(); // non-blocking } else // no pending commands, block on user event { const eq::EventICommand& event = config->getNextEvent(); if( !config->handleEvent( event )) LBVERB << "Unhandled " << event << std::endl; } } config->handleEvents(); // process all pending events } const uint32_t frame = config->finishAllFrames(); const float time = clock.resetTimef(); const size_t nFrames = frame - lastFrame; LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ " << ( nFrames / time * 1000.f) << " FPS)" << std::endl; // 5. exit config clock.reset(); config->exit(); LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl; // 6. cleanup and exit server->releaseConfig( config ); if( !disconnectServer( server )) LBERROR << "Client::disconnectServer failed" << std::endl; return EXIT_SUCCESS; }
void CommandTester::commandPassed(bool passed) { Q_ASSERT(hasCommands()); const Command command = m_commands.takeFirst(); emit commandPassed(command, passed); }
int Client::run( const int argc, char** argv ) { // 0. Init local client if( !initLocal( argc, argv )) { LBERROR << "Can't init client" << std::endl; return EXIT_FAILURE; } // 1. connect to server eq::ServerPtr server = new eq::Server; if( !connectServer( server )) { LBERROR << "Can't open server" << std::endl; exitLocal(); return EXIT_FAILURE; } // 2. choose config eq::fabric::ConfigParams configParams; Config* config = static_cast< Config * >( server->chooseConfig( configParams )); if( !config ) { LBERROR << "No matching config on server" << std::endl; disconnectServer( server ); exitLocal(); return EXIT_FAILURE; } FrameData& frameData = config->getFrameData(); frameData.setup( _impl->_applicationParameters, _impl->_rendererParameters ); frameData.getVolumeSettings()->setURI( _impl->_applicationParameters.dataFileName); // 3. init config lunchbox::Clock clock; if( !config->init( argc, argv )) { server->releaseConfig( config ); disconnectServer( server ); exitLocal(); return EXIT_FAILURE; } LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms" << std::endl; // 4. run main loop uint32_t maxFrames = _impl->_applicationParameters.maxFrames; frameData.getCameraSettings()->setDefaultCameraPosition( _impl->_applicationParameters.cameraPosition ); frameData.getCameraSettings()->setDefaultCameraLookAt( _impl->_applicationParameters.cameraLookAt ); clock.reset(); while( config->isRunning() && maxFrames-- ) { if( !config->frame()) // If not valid, reset maxFrames maxFrames++; if( _impl->_idleFunc ) _impl->_idleFunc(); // order is important to latency while( !config->needRedraw( )) // wait for an event requiring redraw { if( hasCommands( )) // execute non-critical pending commands { processCommand(); config->handleEvents(); // non-blocking } else // no pending commands, block on user event { // Poll ZeroEq subscribers at least every 100 ms in handleEvents const eq::EventICommand& event = config->getNextEvent( 100 ); if( event.isValid( )) config->handleEvent( event ); config->handleEvents(); // non-blocking } } config->handleEvents(); // process all pending events } const uint32_t frame = config->finishAllFrames(); const float time = clock.getTimef(); LBLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame << " frames @ " << ( frame / time * 1000.f) << " FPS)" << std::endl; // 5. exit config clock.reset(); config->exit(); LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl; // 6. cleanup and exit server->releaseConfig( config ); if( !disconnectServer( server )) LBERROR << "Client::disconnectServer failed" << std::endl; server = 0; exitLocal(); return EXIT_SUCCESS; }