loading screen
parent
4977c33e4c
commit
2b339f6c0f
@ -0,0 +1,108 @@
|
||||
#include "loadingscreen.hpp"
|
||||
|
||||
#include <OgreRenderWindow.h>
|
||||
#include <OgreRoot.h>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/inputmanager.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
LoadingScreen::LoadingScreen(Ogre::SceneManager* sceneMgr, Ogre::RenderWindow* rw, MWBase::WindowManager& parWindowManager)
|
||||
: mSceneMgr(sceneMgr)
|
||||
, mWindow(rw)
|
||||
, WindowBase("openmw_loading_screen.layout", parWindowManager)
|
||||
, mLoadingOn(false)
|
||||
, mLastRenderTime(0.f)
|
||||
{
|
||||
getWidget(mLoadingText, "LoadingText");
|
||||
}
|
||||
|
||||
LoadingScreen::~LoadingScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void LoadingScreen::setLoadingProgress (const std::string& stage, int depth, int current, int total)
|
||||
{
|
||||
if (!mLoadingOn)
|
||||
loadingOn();
|
||||
|
||||
if (depth == 0)
|
||||
{
|
||||
mCurrentCellLoading = current;
|
||||
mTotalCellsLoading = total;
|
||||
|
||||
mCurrentRefLoading = 0;
|
||||
|
||||
}
|
||||
if (depth == 1)
|
||||
{
|
||||
mCurrentRefLoading = current;
|
||||
mTotalRefsLoading = total;
|
||||
}
|
||||
|
||||
if (mTotalCellsLoading == 0)
|
||||
{
|
||||
loadingOff();
|
||||
return;
|
||||
}
|
||||
|
||||
float refProgress;
|
||||
if (mTotalRefsLoading <= 1)
|
||||
refProgress = 0;
|
||||
else
|
||||
refProgress = float(mCurrentRefLoading) / float(mTotalRefsLoading-1);
|
||||
|
||||
float progress = (float(mCurrentCellLoading)+refProgress) / float(mTotalCellsLoading);
|
||||
assert(progress <= 1 && progress >= 0);
|
||||
if (progress >= 1)
|
||||
{
|
||||
loadingOff();
|
||||
return;
|
||||
}
|
||||
|
||||
mLoadingText->setCaption(stage + "... " + Ogre::StringConverter::toString(progress));
|
||||
|
||||
static float loadingScreenFps = 40.f;
|
||||
|
||||
//if (mTimer.getMilliseconds () > mLastRenderTime + (1.f/loadingScreenFps) * 1000.f)
|
||||
{
|
||||
mLastRenderTime = mTimer.getMilliseconds ();
|
||||
|
||||
|
||||
// Turn off rendering except the GUI
|
||||
mSceneMgr->clearSpecialCaseRenderQueues();
|
||||
// SCRQM_INCLUDE with RENDER_QUEUE_OVERLAY does not work.
|
||||
for (int i = 0; i < Ogre::RENDER_QUEUE_MAX; ++i)
|
||||
{
|
||||
if (i > 10 && i < 90)
|
||||
mSceneMgr->addSpecialCaseRenderQueue(i);
|
||||
}
|
||||
mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
|
||||
|
||||
// always update input before rendering something, otherwise mygui goes crazy when something was entered in the frame before
|
||||
// (e.g. when using "coc" console command, it would enter an infinite loop and crash due to overflow)
|
||||
MWBase::Environment::get().getInputManager()->update(0, true);
|
||||
|
||||
mWindow->update();
|
||||
|
||||
// resume 3d rendering
|
||||
mSceneMgr->clearSpecialCaseRenderQueues();
|
||||
mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadingScreen::loadingOn()
|
||||
{
|
||||
setVisible(true);
|
||||
mLoadingOn = true;
|
||||
}
|
||||
|
||||
|
||||
void LoadingScreen::loadingOff()
|
||||
{
|
||||
setVisible(false);
|
||||
mLoadingOn = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
#ifndef MWGUI_LOADINGSCREEN_H
|
||||
#define MWGUI_LOADINGSCREEN_H
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreResourceGroupManager.h>
|
||||
|
||||
#include "window_base.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class LoadingScreen : public WindowBase
|
||||
{
|
||||
public:
|
||||
LoadingScreen(Ogre::SceneManager* sceneMgr, Ogre::RenderWindow* rw, MWBase::WindowManager& parWindowManager);
|
||||
virtual ~LoadingScreen();
|
||||
|
||||
void setLoadingProgress (const std::string& stage, int depth, int current, int total);
|
||||
|
||||
private:
|
||||
Ogre::SceneManager* mSceneMgr;
|
||||
Ogre::RenderWindow* mWindow;
|
||||
|
||||
unsigned long mLastRenderTime;
|
||||
Ogre::Timer mTimer;
|
||||
|
||||
MyGUI::TextBox* mLoadingText;
|
||||
|
||||
int mCurrentCellLoading;
|
||||
int mTotalCellsLoading;
|
||||
int mCurrentRefLoading;
|
||||
int mTotalRefsLoading;
|
||||
|
||||
|
||||
bool mLoadingOn;
|
||||
|
||||
void loadingOn();
|
||||
void loadingOff();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<!-- The entire screen -->
|
||||
<Widget type="Widget" layer="LoadingScreen" position="0 0 300 300" name="_Main">
|
||||
|
||||
<Widget type="Widget" skin="HUD_Box" position="0 200 300 80" align="Bottom HCenter">
|
||||
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" position="30 35 240 24" name="LoadingText">
|
||||
<Property key="Caption" value="Asdf"/>
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
</MyGUI>
|
Loading…
Reference in New Issue