Пример #1
0
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
    try
    {
        mEnvironment.setFrameDuration (evt.timeSinceLastFrame);

        // update input
        MWBase::Environment::get().getInputManager()->update(evt.timeSinceLastFrame, false);

        // sound
        if (mUseSound)
            MWBase::Environment::get().getSoundManager()->update (evt.timeSinceLastFrame);

        // global scripts
        MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();

        bool changed = MWBase::Environment::get().getWorld()->hasCellChanged();

        // local scripts
        executeLocalScripts(); // This does not handle the case where a global script causes a cell
                               // change, followed by a cell change in a local script during the same
                               // frame.

        // passing of time
        if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
            MWBase::Environment::get().getWorld()->advanceTime (
                mEnvironment.getFrameDuration()*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);


        if (changed) // keep change flag for another frame, if cell changed happend in local script
            MWBase::Environment::get().getWorld()->markCellAsUnchanged();

        // update actors
        std::vector<std::pair<std::string, Ogre::Vector3> > movement;
        MWBase::Environment::get().getMechanicsManager()->update (movement, mEnvironment.getFrameDuration(),
            MWBase::Environment::get().getWindowManager()->isGuiMode());

        if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
            MWBase::Environment::get().getWorld()->doPhysics (movement, mEnvironment.getFrameDuration());

        // update world
        MWBase::Environment::get().getWorld()->update (evt.timeSinceLastFrame, MWBase::Environment::get().getWindowManager()->isGuiMode());

        // update GUI
        Ogre::RenderWindow* window = mOgre->getWindow();
        unsigned int tri, batch;
        MWBase::Environment::get().getWorld()->getTriangleBatchCount(tri, batch);
        MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(), tri, batch);

        MWBase::Environment::get().getWindowManager()->onFrame(evt.timeSinceLastFrame);
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error in framelistener: " << e.what() << std::endl;
    }

    return true;
}
Пример #2
0
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
    try
    {
        float frametime = std::min(evt.timeSinceLastFrame, 0.2f);

        mEnvironment.setFrameDuration (frametime);

        // update input
        MWBase::Environment::get().getInputManager()->update(frametime, false);

        // sound
        if (mUseSound)
            MWBase::Environment::get().getSoundManager()->update(frametime);

        // GUI active? Most game processing will be paused, but scripts still run.
        bool guiActive = MWBase::Environment::get().getWindowManager()->isGuiMode();

        // Main menu opened? Then scripts are also paused.
        bool paused = MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu);

        // update game state
        MWBase::Environment::get().getStateManager()->update (frametime);

        if (MWBase::Environment::get().getStateManager()->getState()==
            MWBase::StateManager::State_Running)
        {
            if (!paused)
            {
                // global scripts
                MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();

                // local scripts
                executeLocalScripts();

                MWBase::Environment::get().getWorld()->markCellAsUnchanged();
            }

            if (!guiActive)
                MWBase::Environment::get().getWorld()->advanceTime(
                    frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
        }


        // update actors
        if (MWBase::Environment::get().getStateManager()->getState()!=
            MWBase::StateManager::State_NoGame)
        {
            MWBase::Environment::get().getMechanicsManager()->update(frametime,
                guiActive);
        }

        if (MWBase::Environment::get().getStateManager()->getState()==
            MWBase::StateManager::State_Running)
        {
            MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
            if(!guiActive && player.getClass().getCreatureStats(player).isDead())
                MWBase::Environment::get().getStateManager()->endGame();
        }

        // update world
        if (MWBase::Environment::get().getStateManager()->getState()!=
            MWBase::StateManager::State_NoGame)
        {
            MWBase::Environment::get().getWorld()->update(frametime, guiActive);
        }

        // update GUI
        MWBase::Environment::get().getWindowManager()->onFrame(frametime);
        if (MWBase::Environment::get().getStateManager()->getState()!=
            MWBase::StateManager::State_NoGame)
        {
            Ogre::RenderWindow* window = mOgre->getWindow();
            unsigned int tri, batch;
            MWBase::Environment::get().getWorld()->getTriangleBatchCount(tri, batch);
            MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(), tri, batch);

            MWBase::Environment::get().getWindowManager()->update();
        }
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error in framelistener: " << e.what() << std::endl;
    }

    return true;
}
Пример #3
0
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
    try
    {
        float frametime = std::min(evt.timeSinceLastFrame, 0.2f);

        mEnvironment.setFrameDuration (frametime);

        // update input
        MWBase::Environment::get().getInputManager()->update(frametime, false);

        // sound
        if (mUseSound)
            MWBase::Environment::get().getSoundManager()->update(frametime);

        bool paused = MWBase::Environment::get().getWindowManager()->isGuiMode();

        // update game state
        MWBase::Environment::get().getStateManager()->update (frametime);

        if (MWBase::Environment::get().getStateManager()->getState()==
            MWBase::StateManager::State_Running)
        {
            // global scripts
            MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();

            bool changed = MWBase::Environment::get().getWorld()->hasCellChanged();

            // local scripts
            executeLocalScripts(); // This does not handle the case where a global script causes a
                                    // cell change, followed by a cell change in a local script during
                                    // the same frame.

            if (changed) // keep change flag for another frame, if cell changed happened in local script
                MWBase::Environment::get().getWorld()->markCellAsUnchanged();

            if (!paused)
                MWBase::Environment::get().getWorld()->advanceTime(
                    frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
        }


        // update actors
        MWBase::Environment::get().getMechanicsManager()->update(frametime,
            paused);

        if (MWBase::Environment::get().getStateManager()->getState()==
            MWBase::StateManager::State_Running)
        {
            MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
            if(!paused && player.getClass().getCreatureStats(player).isDead())
                MWBase::Environment::get().getStateManager()->endGame();
        }

        // update world
        MWBase::Environment::get().getWorld()->update(frametime, paused);

        // update GUI
        Ogre::RenderWindow* window = mOgre->getWindow();
        unsigned int tri, batch;
        MWBase::Environment::get().getWorld()->getTriangleBatchCount(tri, batch);
        MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(), tri, batch);

        MWBase::Environment::get().getWindowManager()->onFrame(frametime);
        MWBase::Environment::get().getWindowManager()->update();
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error in framelistener: " << e.what() << std::endl;
    }

    return true;
}
Пример #4
0
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
    try
    {
        mEnvironment.mFrameDuration = evt.timeSinceLastFrame;

        // sound
        if (mUseSound)
        {
            mEnvironment.mSoundManager->playPlaylist();

            mEnvironment.mSoundManager->update (evt.timeSinceLastFrame);
        }

        // update GUI
        Ogre::RenderWindow* window = mOgre->getWindow();
        mEnvironment.mWindowManager->wmUpdateFps(window->getLastFPS(),
                                                 window->getTriangleCount(),
                                                 window->getBatchCount());

        mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration);

        // global scripts
        mEnvironment.mGlobalScripts->run (mEnvironment);

        bool changed = mEnvironment.mWorld->hasCellChanged();

        // local scripts
        executeLocalScripts(); // This does not handle the case where a global script causes a cell
                               // change, followed by a cell change in a local script during the same
                               // frame.

        // passing of time
        if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
            mEnvironment.mWorld->advanceTime (
                mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600);


        if (changed) // keep change flag for another frame, if cell changed happend in local script
            mEnvironment.mWorld->markCellAsUnchanged();

        // update actors
        std::vector<std::pair<std::string, Ogre::Vector3> > movement;
        mEnvironment.mMechanicsManager->update (movement);

        if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
            mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration);

        // update world
        mEnvironment.mWorld->update (evt.timeSinceLastFrame);

        // report focus object (for debugging)
        if (mReportFocus)
            updateFocusReport (mEnvironment.mFrameDuration);
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error in framelistener: " << e.what() << std::endl;
    }

    return true;
}