//Run the app void Application::go() { Ogre::Timer loopTimer; long lastTick,currentTick; lastTick=loopTimer.getMillisecondsCPU(); float fpsStep = 1.0f/(float)FPS; float frameDelta; bool continueRunning=true; while(continueRunning) { Ogre::WindowEventUtilities::messagePump(); capture(); currentTick=loopTimer.getMillisecondsCPU(); frameDelta = (currentTick-lastTick)*0.001; static float logicUpdateCounter=0; logicUpdateCounter+=frameDelta; while (logicUpdateCounter>fpsStep) { logicUpdateCounter-=fpsStep; updateLogic(fpsStep); updateGraphics(fpsStep); } bool windowClosed = m_window->isClosed(); continueRunning &= ! windowClosed; bool renderFrameSuccess = m_root->renderOneFrame(); continueRunning &= renderFrameSuccess; continueRunning &= ! m_exitRequested; lastTick=currentTick; } }
void Application::go() { Ogre::Timer loopTimer; bool continueRunning = true; while ( continueRunning ) { Ogre::WindowEventUtilities::messagePump(); SimpleInputManager::capture(); // Update logic stuff float elapsedSeconds = loopTimer.getMicroseconds() * 1.0 / 1000000; updateLogic( elapsedSeconds ); // Update graphics stuff updateAnimations( elapsedSeconds ); bool windowClosed = m_window->isClosed(); continueRunning &= ! windowClosed; updateStats(); loopTimer.reset(); bool renderFrameSuccess = m_root->renderOneFrame(); continueRunning &= renderFrameSuccess; continueRunning &= ! m_exitRequested; } }
InputGnd::InputGnd(QGraphicsItem * parent) : GraphicElement(0,0,1,1,parent) { setOutputsOnTop(false); setPixmap(QPixmap(":/input/0.png")); setRotatable(false); setPortName("GND"); updateLogic(); }
void game::run(){ //TODO nanti harus diganti init(); drawCanvas(0,0,0,255); drawTextCentered("GRAPHICAT",9,50,3,255,0,0,255); drawTextCentered("PLANE SHOOTER",13,150,3,255,0,0,255); drawTextCentered("Press A or D to move ship left or right",39,250,1,255,0,0,255); drawTextCentered("Press J or L to rotate the ship turret",38,300,1,255,0,0,255); drawTextCentered("Press Space to shoot",20,350,1,255,0,0,255); drawTextCentered("Press Q to change weapon",24,400,1,255,0,0,255); printToScreen(); sleep(5); while (!gameOver()){ updateControls(); updateLogic(); drawScreen(); usleep(200); } usleep(500); drawTextCentered("YOU WIN",7,300,5,255,0,0,255); printToScreen(); usleep(500); finishPrinter(); resetTermios(); sleep(2); }
void Tetris::play(){ while (! m_Quit) { while ( m_Event.getEvent() ) { handleEvent( m_Event ); } updateLogic(); display(); //m_TimeManager.manageFPS(); } }
MainWindow::MainWindow(QWidget *parent) : QGLWidget(parent) { mainWindow = this; setMouseTracking(true); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updateGL())); connect(timer, SIGNAL(timeout()), this, SLOT(updateLogic())); timer->start(16); }
void Screen::run() { sf::Clock clock; while(director->application.IsOpened()) { sf::Event event; while(director->application.GetEvent(event)){ checkInput(); } updateLogic(); director->application.Clear(); drawThis(); director->application.Display(); } }
void Application::update() { bool continueRunning = true; Ogre::Timer loopTimer; while (continueRunning) { Ogre::WindowEventUtilities::messagePump(); SimpleInputManager::capture(); float elapsedSeconds = loopTimer.getMicroseconds() * 1.0 / 1000000; updateLogic( elapsedSeconds ); updateAnimations( elapsedSeconds ); m_NXOgreVisualDebugger->draw(); m_NXOgreVisualDebuggerNode->needUpdate(); m_NXOgreTimeController->advance(elapsedSeconds); updateOverlayInfo(); loopTimer.reset(); bool renderFrameSuccess = m_root->renderOneFrame(); if (!renderFrameSuccess || m_exitRequested) { continueRunning = false; } } }
bool Game::update( float dt ) { m_lastRealDt = dt; if (m_pauseUpdates) m_lastDt = 0.f; else m_lastDt = dt; DebugDrawer::getSingleton().clear(); #ifdef ENABLE_BULLET_DEBUG_DRAW if (s_EnableBulletDebugDraw) { g_debugPhysicsDrawer->setDebugMode(true); g_debugPhysicsDrawer->step(); m_physicsWorld->debugDrawWorld(); } else if (g_debugPhysicsDrawer->getDebugMode()) { g_debugPhysicsDrawer->setDebugMode(false); g_debugPhysicsDrawer->step(); } #endif updateInput(dt); if (m_pauseUpdates) updateLogic(0.f); else { const float logic_dt = dt * m_slomo; float logic_dt_left = logic_dt; m_logicTime += logic_dt; do { const float it_dt = std::min(logic_dt_left, dt); updateLogic(it_dt); logic_dt_left -= it_dt; } while (logic_dt_left > 0.001f); updatePhysics(logic_dt); } updateVisuals(dt); DebugDrawer::getSingleton().build(); if (s_ForceLowFramerate && dt < 0.1f) Sleep(100); if (!m_ogreRoot->renderOneFrame(dt)) return false; if (m_renderWindow->isClosed()) return false; if (m_exit) return false; return true; }
/******************************* Main... *********************************/ int main(int argc, char *argv[]) { clock_t inicial, previous, delta; double deltaTime; /*Primeiramente lemos os parametros passados:*/ interpretaParametros(argc, argv); /*Entao inicializamos nossas coisas, comecando com os graficos...*/ if (allegro_init() != 0) { printf("Incapaz de inicializar o Allegro...\n"); return 1; } set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0) != 0) { printf("Incapaz de setar o modo grafico/janela. \n"); return 2; } /* set the color palette */ set_palette(desktop_palette); srand( getRandomSeed() ); inicializaEntidades(); inicializaPassageiros(); inicializaBotes(); inicializaDesenho(); /*Qualquer codigo necessario para inicializacao de outras coisas vem aqui.*/ criaAsimov(); inicial = clock(); previous = 0; while (clock() - inicial < CLOCKS_PER_SEC*getTimeLimit() ) { delta = clock() - previous; if (delta > (double)CLOCKS_PER_SEC/(double)getFramesPerSec() ) { previous = clock(); /*Calculo da variacao de tempo (em segundo) entre o ciclo anterior e esse.*/ deltaTime = (double)delta/(double)CLOCKS_PER_SEC; /*===================================================*/ /*executa update aqui (desenho -> logica). */ /*update logico...*/ colisaoGeral(deltaTime); updateGameLogic(deltaTime); updateLogic(deltaTime); /*update grafico...*/ preparaPraDesenho(); updateDesenho(); /*Chama o update grafico de todas entidades...*/ updateScreen(); /*CHECK: >arrumar colisao pra setar a direcao certa depois de uma colisao (a normal da tangente da superficie naquele ponto) >pode ser necessario arrumar passageiro para que ele nao sete explicitamente sua direcao, mas sim que tome a cadeia de markov como "o quanto virar" para algum lado, assim poderemos ter que as entidades possam se mexer em qualquer direcao nesse incrivel mundo R2 continuo :P */ /*====================================================*/ } } /*Qualquer codigo necessario para finalizacao de outras coisas vem aqui.*/ /*Finalmente terminamos esses modulos do programa, liberando toda a memoria usada.*/ terminaDesenho(); allegro_exit(); terminaBotes(); terminaPassageiros(); terminaEntidades(); return 0; }
void NounShip::updateShip( dword nTick ) { PROFILE_FUNCTION(); // update despawn/docking logic.. updateDespawn(); // update the ships gadgets updateGadgets( nTick ); // update high-level AI updateLogic( nTick ); // repair / reload ship when in orbit if ( nTick >= m_nRepairTick ) { m_nRepairTick = nTick + DEFAULT_REPAIR_RATE; if ( inOrbit() ) { // handle ship repairs when in orbit around friendly planet with a ship yard NounPlanet * pPlanet = WidgetCast<NounPlanet>( orbiting() ); if ( pPlanet != NULL ) { if ( pPlanet->isFriend( this ) ) { repair( pPlanet, PLANET_REPAIR_RATE, true ); reload( pPlanet ); } else if ( (pPlanet->flags() & NounPlanet::FLAG_HYDROGEN) != 0 ) { // if planet has hydrogen, then refuel the jump drive if ( jumpDrive() != NULL ) jumpDrive()->reload( pPlanet ); } } } } if ( nTick >= m_nUpdateTick ) { m_nUpdateTick = nTick + SHIP_UPDATE_RATE; // update characteristics updateCharacter(); // update low-level AI updateCommand(); // update the repair queue updateRepairQueue(); // update the contact list updateContacts(); // drain off some damage from the damage list updateThreats(); } if ( m_bIncoming ) { ASSERT( userId() == 0 ); avoidCollision(); m_bIncoming = false; } updatePointDefense(); updateFireCheck(); }
void HUDElement::update(const PlayerLogicComponent &playerLogic) { if (updateLogic) { updateLogic(*this, playerLogic); } }
void GameSprite::update(float dt) { time_ += dt; updateLogic(); updatePosition(); }