diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f5e21c61..f83453cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,6 @@ set(LIBDIR ${CMAKE_SOURCE_DIR}/libs) set(OENGINE_OGRE ${LIBDIR}/openengine/ogre/renderer.cpp - ${LIBDIR}/openengine/ogre/fader.cpp ${LIBDIR}/openengine/ogre/lights.cpp ${LIBDIR}/openengine/ogre/selectionbuffer.cpp ${LIBDIR}/openengine/ogre/imagerotate.cpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index d8966bdcf..14bf0ba17 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -33,7 +33,7 @@ add_openmw_dir (mwgui merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers savegamedialog - recharge mode videowidget backgroundimage itemwidget + recharge mode videowidget backgroundimage itemwidget screenfader ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 8b407c9ba..f1c69e622 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -331,6 +331,15 @@ namespace MWBase virtual void removeCurrentModal(MWGui::WindowModal* input) = 0; virtual void pinWindow (MWGui::GuiWindow window) = 0; + + /// Fade the screen in, over \a time seconds + virtual void fadeScreenIn(const float time) = 0; + /// Fade the screen out to black, over \a time seconds + virtual void fadeScreenOut(const float time) = 0; + /// Fade the screen to a specified percentage of black, over \a time seconds + virtual void fadeScreenTo(const int percent, const float time) = 0; + /// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading. + virtual void setScreenFactor (float factor) = 0; }; } diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 8fd3c17bf..a3a127d63 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -17,11 +17,6 @@ namespace Ogre namespace OEngine { - namespace Render - { - class Fader; - } - namespace Physic { class PhysicEngine; @@ -113,9 +108,6 @@ namespace MWBase virtual void readRecord (ESM::ESMReader& reader, int32_t type, const std::map& contentFileMap) = 0; - virtual OEngine::Render::Fader* getFader() = 0; - ///< \todo remove this function. Rendering details should not be exposed. - virtual MWWorld::CellStore *getExterior (int x, int y) = 0; virtual MWWorld::CellStore *getInterior (const std::string& name) = 0; diff --git a/apps/openmw/mwgui/screenfader.cpp b/apps/openmw/mwgui/screenfader.cpp new file mode 100644 index 000000000..c27737285 --- /dev/null +++ b/apps/openmw/mwgui/screenfader.cpp @@ -0,0 +1,111 @@ +#include "screenfader.hpp" + +namespace MWGui +{ + + ScreenFader::ScreenFader() + : WindowBase("openmw_screen_fader.layout") + , mMode(FadingMode_In) + , mRemainingTime(0.f) + , mTargetTime(0.f) + , mTargetAlpha(0.f) + , mCurrentAlpha(0.f) + , mStartAlpha(0.f) + , mFactor(1.f) + { + mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize()); + + setVisible(false); + } + + void ScreenFader::update(float dt) + { + if (mRemainingTime > 0) + { + if (mMode == FadingMode_In) + { + mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha); + if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha; + } + else if (mMode == FadingMode_Out) + { + mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha); + if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha; + } + + mRemainingTime -= dt; + } + + if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f) + mMainWidget->setVisible(false); + else + applyAlpha(); + } + + void ScreenFader::applyAlpha() + { + setVisible(true); + mMainWidget->setAlpha(1.f-((1.f-mCurrentAlpha) * mFactor)); + } + + void ScreenFader::fadeIn(float time) + { + if (time<0.f) return; + if (time==0.f) + { + mCurrentAlpha = 0.f; + applyAlpha(); + return; + } + + mStartAlpha = mCurrentAlpha; + mTargetAlpha = 0.f; + mMode = FadingMode_In; + mTargetTime = time; + mRemainingTime = time; + } + + void ScreenFader::fadeOut(const float time) + { + if (time<0.f) return; + if (time==0.f) + { + mCurrentAlpha = 1.f; + applyAlpha(); + return; + } + + mStartAlpha = mCurrentAlpha; + mTargetAlpha = 1.f; + mMode = FadingMode_Out; + mTargetTime = time; + mRemainingTime = time; + } + + void ScreenFader::fadeTo(const int percent, const float time) + { + if (time<0.f) return; + if (time==0.f) + { + mCurrentAlpha = percent/100.f; + applyAlpha(); + return; + } + + mStartAlpha = mCurrentAlpha; + mTargetAlpha = percent/100.f; + + if (mTargetAlpha == mStartAlpha) return; + else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out; + else mMode = FadingMode_In; + + mTargetTime = time; + mRemainingTime = time; + } + + void ScreenFader::setFactor(float factor) + { + mFactor = factor; + } + +} diff --git a/apps/openmw/mwgui/screenfader.hpp b/apps/openmw/mwgui/screenfader.hpp new file mode 100644 index 000000000..0fb1f2794 --- /dev/null +++ b/apps/openmw/mwgui/screenfader.hpp @@ -0,0 +1,39 @@ +#include "windowbase.hpp" + +namespace MWGui +{ + + class ScreenFader : public WindowBase + { + public: + ScreenFader(); + + void update(float dt); + + void fadeIn(const float time); + void fadeOut(const float time); + void fadeTo(const int percent, const float time); + + void setFactor (float factor); + + private: + enum FadingMode + { + FadingMode_In, + FadingMode_Out + }; + + void applyAlpha(); + + FadingMode mMode; + + float mRemainingTime; + float mTargetTime; + float mTargetAlpha; + float mCurrentAlpha; + float mStartAlpha; + + float mFactor; + }; + +} diff --git a/apps/openmw/mwgui/trainingwindow.cpp b/apps/openmw/mwgui/trainingwindow.cpp index babfe099f..c93c73063 100644 --- a/apps/openmw/mwgui/trainingwindow.cpp +++ b/apps/openmw/mwgui/trainingwindow.cpp @@ -2,8 +2,6 @@ #include -#include - #include "../mwbase/windowmanager.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -171,7 +169,7 @@ namespace MWGui MWBase::Environment::get().getMechanicsManager()->rest(false); MWBase::Environment::get().getMechanicsManager()->rest(false); - MWBase::Environment::get().getWorld ()->getFader()->fadeOut(0.25); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.25); mFadeTimeRemaining = 0.5; } @@ -183,6 +181,6 @@ namespace MWGui mFadeTimeRemaining -= dt; if (mFadeTimeRemaining <= 0) - MWBase::Environment::get().getWorld ()->getFader()->fadeIn(0.25); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.25); } } diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index ae191e764..d874cecfe 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -4,8 +4,6 @@ #include -#include - #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" @@ -156,7 +154,7 @@ namespace MWGui MWMechanics::CreatureStats& npcStats = mPtr.getClass().getCreatureStats(mPtr); npcStats.setGoldPool(npcStats.getGoldPool() + price); - MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(1); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); ESM::Position pos = *_sender->getUserData(); std::string cellname = _sender->getUserString("Destination"); bool interior = _sender->getUserString("interior") == "y"; @@ -179,8 +177,8 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Travel); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue); - MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0); - MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(1); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(0); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(1); } void TravelWindow::onCancelButtonClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 9c7757af9..1f97e13f1 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -2,8 +2,6 @@ #include -#include - #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" @@ -128,7 +126,7 @@ namespace MWGui MWBase::Environment::get().getStateManager()->quickSave("Autosave"); MWBase::World* world = MWBase::Environment::get().getWorld(); - world->getFader ()->fadeOut(0.2); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.2); setVisible(false); mProgressBar.setVisible (true); @@ -243,7 +241,7 @@ namespace MWGui void WaitDialog::stopWaiting () { - MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.2); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.2); mProgressBar.setVisible (false); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Rest); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_RestBed); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 5cd8899d8..608b6b2e3 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -65,6 +65,7 @@ #include "videowidget.hpp" #include "backgroundimage.hpp" #include "itemwidget.hpp" +#include "screenfader.hpp" namespace MWGui { @@ -112,6 +113,7 @@ namespace MWGui , mCompanionWindow(NULL) , mVideoBackground(NULL) , mVideoWidget(NULL) + , mScreenFader(NULL) , mTranslationDataStorage (translationDataStorage) , mCharGen(NULL) , mInputBlocker(NULL) @@ -267,6 +269,7 @@ namespace MWGui mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); trackWindow(mCompanionWindow, "companion"); + mScreenFader = new ScreenFader(); mInputBlocker = mGui->createWidget("",0,0,w,h,MyGUI::Align::Default,"Overlay"); @@ -357,6 +360,7 @@ namespace MWGui delete mCursorManager; delete mRecharge; delete mCompanionWindow; + delete mScreenFader; cleanupGarbage(); @@ -858,6 +862,8 @@ namespace MWGui mCompanionWindow->checkReferenceAvailable(); mConsole->checkReferenceAvailable(); mCompanionWindow->onFrame(); + + mScreenFader->update(frameDuration); } void WindowManager::changeCell(MWWorld::CellStore* cell) @@ -1688,4 +1694,24 @@ namespace MWGui updateVisible(); } + + void WindowManager::fadeScreenIn(const float time) + { + mScreenFader->fadeIn(time); + } + + void WindowManager::fadeScreenOut(const float time) + { + mScreenFader->fadeOut(time); + } + + void WindowManager::fadeScreenTo(const int percent, const float time) + { + mScreenFader->fadeTo(percent, time); + } + + void WindowManager::setScreenFactor(float factor) + { + mScreenFader->setFactor(factor); + } } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 8093d637e..565e442f9 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -86,6 +86,7 @@ namespace MWGui class CompanionWindow; class VideoWidget; class WindowModal; + class ScreenFader; class WindowManager : public MWBase::WindowManager { @@ -324,6 +325,15 @@ namespace MWGui virtual void pinWindow (MWGui::GuiWindow window); + /// Fade the screen in, over \a time seconds + virtual void fadeScreenIn(const float time); + /// Fade the screen out to black, over \a time seconds + virtual void fadeScreenOut(const float time); + /// Fade the screen to a specified percentage of black, over \a time seconds + virtual void fadeScreenTo(const int percent, const float time); + /// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading. + virtual void setScreenFactor (float factor); + private: bool mConsoleOnlyScripts; @@ -373,6 +383,7 @@ namespace MWGui CompanionWindow* mCompanionWindow; MyGUI::ImageBox* mVideoBackground; VideoWidget* mVideoWidget; + ScreenFader* mScreenFader; Translation::Storage& mTranslationDataStorage; Cursor* mSoftwareCursor; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 23edb3a7f..a1d34f12f 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -212,11 +212,6 @@ MWRender::Actors& RenderingManager::getActors(){ return *mActors; } -OEngine::Render::Fader* RenderingManager::getFader() -{ - return mRendering.getFader(); -} - MWRender::Camera* RenderingManager::getCamera() const { return mCamera; @@ -345,7 +340,7 @@ void RenderingManager::update (float duration, bool paused) MWWorld::Ptr player = world->getPlayerPtr(); int blind = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Blind).mMagnitude; - mRendering.getFader()->setFactor(std::max(0.f, 1.f-(blind / 100.f))); + MWBase::Environment::get().getWindowManager()->setScreenFactor(std::max(0.f, 1.f-(blind / 100.f))); setAmbientMode(); // player position diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index ea7905cf5..ef436931d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -4,8 +4,6 @@ #include "sky.hpp" #include "debugging.hpp" -#include - #include #include @@ -98,8 +96,6 @@ public: void toggleLight(); bool toggleRenderMode(int mode); - OEngine::Render::Fader* getFader(); - void removeCell (MWWorld::CellStore *store); /// \todo this function should be removed later. Instead the rendering subsystems should track diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 36848d44c..b487ac70f 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -3,8 +3,6 @@ #include -#include - #include #include #include @@ -248,7 +246,7 @@ namespace MWScript Interpreter::Type_Float time = runtime[0].mFloat; runtime.pop(); - MWBase::Environment::get().getWorld()->getFader()->fadeIn(time); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(time); } }; @@ -261,7 +259,7 @@ namespace MWScript Interpreter::Type_Float time = runtime[0].mFloat; runtime.pop(); - MWBase::Environment::get().getWorld()->getFader()->fadeOut(time); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(time); } }; @@ -277,7 +275,7 @@ namespace MWScript Interpreter::Type_Float time = runtime[0].mFloat; runtime.pop(); - MWBase::Environment::get().getWorld()->getFader()->fadeTo(alpha, time); + MWBase::Environment::get().getWindowManager()->fadeScreenTo(alpha, time); } }; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8dcef54ed..312fb9e36 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -4,8 +4,6 @@ #include -#include - #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" /// FIXME #include "../mwbase/soundmanager.hpp" @@ -406,7 +404,7 @@ namespace MWWorld void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { Nif::NIFFile::CacheLock lock; - MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.5); + MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5); Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen(); Loading::ScopedLoad load(loadingListener); @@ -432,7 +430,7 @@ namespace MWWorld world->rotateObject(world->getPlayerPtr(), x, y, z); world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true); - world->getFader()->fadeIn(0.5f); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5); return; } @@ -480,7 +478,7 @@ namespace MWWorld MWBase::Environment::get().getWorld()->adjustSky(); mCellChanged = true; - MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.5); + MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5); } void Scene::changeToExteriorCell (const ESM::Position& position) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f35ba0709..d57528864 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1555,11 +1555,6 @@ namespace MWWorld mWeatherManager->modRegion(regionid, chances); } - OEngine::Render::Fader* World::getFader() - { - return mRendering->getFader(); - } - Ogre::Vector2 World::getNorthVector (CellStore* cell) { MWWorld::CellRefList& statics = cell->get(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 59873c4f4..fad3dfd97 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -169,9 +169,6 @@ namespace MWWorld virtual void readRecord (ESM::ESMReader& reader, int32_t type, const std::map& contentFileMap); - virtual OEngine::Render::Fader* getFader(); - ///< \todo remove this function. Rendering details should not be exposed. - virtual CellStore *getExterior (int x, int y); virtual CellStore *getInterior (const std::string& name); diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 2135f4dde..54a4d0b63 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -80,6 +80,7 @@ set(MYGUI_FILES openmw_companion_window.layout openmw_savegame_dialog.layout openmw_recharge_dialog.layout + openmw_screen_fader.layout DejaVuLGCSansMono.ttf markers.png ../launcher/images/openmw.png diff --git a/files/mygui/openmw_layers.xml b/files/mygui/openmw_layers.xml index e66f3fc01..1df4841af 100644 --- a/files/mygui/openmw_layers.xml +++ b/files/mygui/openmw_layers.xml @@ -1,6 +1,7 @@ + diff --git a/files/mygui/openmw_screen_fader.layout b/files/mygui/openmw_screen_fader.layout new file mode 100644 index 000000000..fffd2e66e --- /dev/null +++ b/files/mygui/openmw_screen_fader.layout @@ -0,0 +1,7 @@ + + + + + + + diff --git a/libs/openengine/ogre/fader.cpp b/libs/openengine/ogre/fader.cpp deleted file mode 100644 index 20b9296da..000000000 --- a/libs/openengine/ogre/fader.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "fader.hpp" - -#include -#include -#include -#include -#include -#include -#include - - -using namespace Ogre; -using namespace OEngine::Render; - -Fader::Fader(Ogre::SceneManager* sceneMgr) - : mSceneMgr(sceneMgr) - , mMode(FadingMode_In) - , mRemainingTime(0.f) - , mTargetTime(0.f) - , mTargetAlpha(0.f) - , mCurrentAlpha(0.f) - , mStartAlpha(0.f) - , mFactor(1.f) -{ - // Create the fading material - MaterialPtr material = MaterialManager::getSingleton().create("FadeInOutMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); - Pass* pass = material->getTechnique(0)->getPass(0); - pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); - pass->setDepthWriteEnabled (false); - mFadeTextureUnit = pass->createTextureUnitState("black.png"); - mFadeTextureUnit->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue(0.f, 0.f, 0.f)); // always black colour - - mRectangle = new Ogre::Rectangle2D(true); - mRectangle->setCorners(-1.0, 1.0, 1.0, -1.0); - mRectangle->setMaterial("FadeInOutMaterial"); - mRectangle->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY-1); - // Use infinite AAB to always stay visible - Ogre::AxisAlignedBox aabInf; - aabInf.setInfinite(); - mRectangle->setBoundingBox(aabInf); - // Attach background to the scene - Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); - node->attachObject(mRectangle); - mRectangle->setVisible(false); - mRectangle->setVisibilityFlags (2048); -} - -Fader::~Fader() -{ - delete mRectangle; -} - -void Fader::update(float dt) -{ - if (mRemainingTime > 0) - { - if (mMode == FadingMode_In) - { - mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha); - if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha; - } - else if (mMode == FadingMode_Out) - { - mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha); - if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha; - } - - mRemainingTime -= dt; - } - - if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f) - mRectangle->setVisible(false); - else - applyAlpha(); -} - -void Fader::applyAlpha() -{ - mRectangle->setVisible(true); - mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 1.f-((1.f-mCurrentAlpha) * mFactor)); -} - -void Fader::fadeIn(float time) -{ - if (time<0.f) return; - if (time==0.f) - { - mCurrentAlpha = 0.f; - applyAlpha(); - return; - } - - mStartAlpha = mCurrentAlpha; - mTargetAlpha = 0.f; - mMode = FadingMode_In; - mTargetTime = time; - mRemainingTime = time; -} - -void Fader::fadeOut(const float time) -{ - if (time<0.f) return; - if (time==0.f) - { - mCurrentAlpha = 1.f; - applyAlpha(); - return; - } - - mStartAlpha = mCurrentAlpha; - mTargetAlpha = 1.f; - mMode = FadingMode_Out; - mTargetTime = time; - mRemainingTime = time; -} - -void Fader::fadeTo(const int percent, const float time) -{ - if (time<0.f) return; - if (time==0.f) - { - mCurrentAlpha = percent/100.f; - applyAlpha(); - return; - } - - mStartAlpha = mCurrentAlpha; - mTargetAlpha = percent/100.f; - - if (mTargetAlpha == mStartAlpha) return; - else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out; - else mMode = FadingMode_In; - - mTargetTime = time; - mRemainingTime = time; -} diff --git a/libs/openengine/ogre/fader.hpp b/libs/openengine/ogre/fader.hpp deleted file mode 100644 index 53124e2f6..000000000 --- a/libs/openengine/ogre/fader.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef OENGINE_OGRE_FADE_H -#define OENGINE_OGRE_FADE_H - -/* - A class that handles fading in the screen from black or fading it out to black. - - To achieve this, it uses a full-screen Rectangle2d - */ - -namespace Ogre -{ - class TextureUnitState; - class Rectangle2D; - class SceneManager; -} - -namespace OEngine { -namespace Render -{ - class Fader - { - public: - Fader(Ogre::SceneManager* sceneMgr); - ~Fader(); - - void update(float dt); - - void fadeIn(const float time); - void fadeOut(const float time); - void fadeTo(const int percent, const float time); - - void setFactor (float factor) { mFactor = factor; } - - private: - enum FadingMode - { - FadingMode_In, - FadingMode_Out - }; - - void applyAlpha(); - - Ogre::TextureUnitState* mFadeTextureUnit; - Ogre::Rectangle2D* mRectangle; - - FadingMode mMode; - - float mRemainingTime; - float mTargetTime; - float mTargetAlpha; - float mCurrentAlpha; - float mStartAlpha; - - float mFactor; - - Ogre::SceneManager* mSceneMgr; - }; - }} -#endif diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 8fcf615ba..78eff6aee 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -1,5 +1,4 @@ #include "renderer.hpp" -#include "fader.hpp" #include @@ -27,9 +26,6 @@ using namespace OEngine::Render; void OgreRenderer::cleanup() { - delete mFader; - mFader = NULL; - if (mWindow) Ogre::Root::getSingleton().destroyRenderTarget(mWindow); mWindow = NULL; @@ -46,7 +42,6 @@ void OgreRenderer::cleanup() void OgreRenderer::update(float dt) { - mFader->update(dt); } void OgreRenderer::screenshot(const std::string &file) @@ -161,8 +156,6 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& mScene = mRoot->createSceneManager(ST_GENERIC); - mFader = new Fader(mScene); - mCamera = mScene->createCamera("cam"); // Create one viewport, entire window diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index ad88b1606..c7ec2ec44 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -43,8 +43,6 @@ namespace OEngine std::string icon; }; - class Fader; - class WindowSizeListener { public: @@ -62,8 +60,6 @@ namespace OEngine OgreInit::OgreInit* mOgreInit; - Fader* mFader; - WindowSizeListener* mWindowListener; int mWindowWidth; @@ -79,7 +75,6 @@ namespace OEngine , mCamera(NULL) , mView(NULL) , mOgreInit(NULL) - , mFader(NULL) , mWindowListener(NULL) , mWindowWidth(0) , mWindowHeight(0) @@ -131,9 +126,6 @@ namespace OEngine /// Get the scene manager Ogre::SceneManager *getScene() { return mScene; } - /// Get the screen colour fader - Fader *getFader() { return mFader; } - /// Camera Ogre::Camera *getCamera() { return mCamera; }