Ejemplo n.º 1
0
bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
    try
    {
        mEnvironment.setFrameDuration (evt.timeSinceLastFrame);

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

        // 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()->getMode()==MWGui::GM_Game)
            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()->getMode()!=MWGui::GM_Game);

        if (MWBase::Environment::get().getWindowManager()->getMode()==MWGui::GM_Game)
            MWBase::Environment::get().getWorld()->doPhysics (movement, mEnvironment.getFrameDuration());

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

        // update GUI
        Ogre::RenderWindow* window = mOgre->getWindow();
        MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(),
                                                 window->getTriangleCount(),
                                                 window->getBatchCount());

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

    return true;
}
Ejemplo n.º 2
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;
}