One topic is by jacmoe: here. But I can not compile it.
And another is by katoun here. He mentioned
but I have never seen it.the Loading Bar example from the Demos
So, can anybody suggest me a way to provide my game with Loading bar?
but I have never seen it.the Loading Bar example from the Demos
It was realy simple. The main feature was to believe that it can work!celic wrote: Please, let me know if you'll manage to implement the loading bar in your own application. Just curious, cause I had some problems with this
Code: Select all
ExampleLoadingBar mLoadingBar;
Code: Select all
virtual void loadResources(void); //!< loading of resources
Code: Select all
void CSeaBedApp::loadResources(void)
{
m_loading_bar->start(mWindow, 1, 1, 0.75);
// Initialise, parse scripts etc
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
m_loading_bar->finish();
}
No, I was able to get it to run with state manager fine.celic wrote:It doesn't work for me
I'm using the State Manager, could it be caused by it?
"And then one day you find ten years have got behind you
No one told you when to run, you missed the starting gun"
sure...here it iscelic wrote:Tzyr, could you share your code, cause I do something wrong, don't know where is the problem.
Thanks!
Code: Select all
// GameManager.cpp
#ifndef GameManager_H
#define GameManager_H
#include <vector>
#include <Ogre.h>
#include <OgreEventListeners.h>
#include <OgreSingleton.h>
#include "InputManager.h"
class GameState;
class GameManager : public Ogre::FrameListener, public Ogre::KeyListener, public Ogre::Singleton<GameManager> {
public:
GameManager();
~GameManager();
void start(GameState* state);
void changeState(GameState* state);
void pushState(GameState* state);
void popState();
static GameManager& getSingleton(void);
static GameManager* getSingletonPtr(void);
Ogre::RenderWindow *getWindow();
protected:
Ogre::Root* mRoot;
Ogre::RenderWindow* mRenderWindow;
Ogre::SceneManager* mSceneMgr;
Ogre::Viewport* mViewport;
Ogre::Camera* mCamera;
InputManager* mInputManager;
void setupResources(void);
bool configure(void);
void keyClicked(Ogre::KeyEvent* e);
void keyPressed(Ogre::KeyEvent* e);
void keyReleased(Ogre::KeyEvent* e);
bool frameStarted(const Ogre::FrameEvent& evt);
bool frameEnded(const Ogre::FrameEvent& evt);
private:
bool mExitGame;
std::vector<GameState*> mStates;
};
#endif
Code: Select all
// GameManager.cpp
#include <Ogre.h>
#include <OgreConfigFile.h>
#include <OgreKeyEvent.h>
#include "GameManager.h"
#include "InputManager.h"
#include "GameState.h"
using namespace Ogre;
template<> GameManager* Singleton<GameManager>::ms_Singleton = 0;
GameManager::GameManager() {
mRoot = 0;
mInputManager = 0;
}
GameManager::~GameManager() {
// clean up all the states
while(!mStates.empty()) {
mStates.back()->exit();
mStates.pop_back();
}
if (mInputManager)
delete mInputManager;
if (mRoot)
delete mRoot;
}
void GameManager::start(GameState* state) {
mRoot = new Root();
setupResources();
if (!configure()) return;
mRoot->addFrameListener(this);
mInputManager = new InputManager(mRoot->getAutoCreatedWindow());
mInputManager->getEventProcessor()->addKeyListener(this);
// set the initial flag before entering IntroState
changeState(state);
mRoot->startRendering();
}
void GameManager::changeState(GameState* state) {
// cleanup the current state
if (!mStates.empty()) {
mStates.back()->exit();
mStates.pop_back();
}
// store and init the new state
mStates.push_back(state);
mStates.back()->enter();
}
void GameManager::pushState(GameState* state) {
// pause current state
if (!mStates.empty()) {
mStates.back()->pause();
}
// store and init the new state
mStates.push_back(state);
mStates.back()->enter();
}
void GameManager::popState() {
// cleanup the current state
if (!mStates.empty()) {
mStates.back()->exit();
mStates.pop_back();
}
// resume previous state
if (!mStates.empty()) {
mStates.back()->resume();
}
}
void GameManager::setupResources(void) {
// Load resource paths from config file
ConfigFile cf;
cf.load("resources.cfg");
// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();
String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
bool GameManager::configure(void) {
// load config settings from ogre.cfg
if (!mRoot->restoreConfig()) {
// if there is no config file, show the configuration dialog
if (!mRoot->showConfigDialog()) {
return false;
}
}
// initialise and create a default rendering window
mRenderWindow = mRoot->initialise(true);
return true;
}
void GameManager::keyClicked(KeyEvent* e) {
// call keyClicked of current state
mStates.back()->keyClicked(e);
}
void GameManager::keyPressed(KeyEvent* e) {
// call keyPressed of current state
mStates.back()->keyPressed(e);
}
void GameManager::keyReleased(KeyEvent* e) {
// call keyReleased of current state
mStates.back()->keyReleased(e);
}
bool GameManager::frameStarted(const FrameEvent& evt) {
// call frameStarted of current state
return mStates.back()->frameStarted(evt);
}
bool GameManager::frameEnded(const FrameEvent& evt) {
if (mExitGame)
return false;
// call frameEnded of current state
return mStates.back()->frameEnded(evt);
}
GameManager* GameManager::getSingletonPtr(void) {
return ms_Singleton;
}
GameManager& GameManager::getSingleton(void) {
assert(ms_Singleton);
return *ms_Singleton;
}
Ogre::RenderWindow* GameManager::getWindow(void) {
return mRenderWindow;
}
Code: Select all
// GameState.h
#ifndef GameState_H
#define GameState_H
#include <Ogre.h>
#include "GameManager.h"
class GameState {
public:
virtual void enter() = 0;
virtual void exit() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
virtual void keyClicked(Ogre::KeyEvent* e) = 0;
virtual void keyPressed(Ogre::KeyEvent* e) = 0;
virtual void keyReleased(Ogre::KeyEvent* e) = 0;
virtual bool frameStarted(const Ogre::FrameEvent& evt) = 0;
virtual bool frameEnded(const Ogre::FrameEvent& evt) = 0;
void changeState(GameState* state) { GameManager::getSingletonPtr()->changeState(state); }
void pushState(GameState* state) { GameManager::getSingletonPtr()->pushState(state); }
void popState() { GameManager::getSingletonPtr()->popState(); }
Ogre::RenderWindow *getWindow() { return GameManager::getSingletonPtr()->getWindow(); }
protected:
GameState() { }
};
#endif
Code: Select all
// IntroState.h
#ifndef IntroState_H
#define IntroState_H
#include <Ogre.h>
#include "GameState.h"
#include "ExampleLoadingBar.h"
class IntroState : public GameState {
public:
void enter();
void exit();
void pause();
void resume();
void keyClicked(Ogre::KeyEvent* e);
void keyPressed(Ogre::KeyEvent* e);
void keyReleased(Ogre::KeyEvent* e);
bool frameStarted(const Ogre::FrameEvent& evt);
bool frameEnded(const Ogre::FrameEvent& evt);
static IntroState* getInstance() { return &mIntroState; }
protected:
IntroState() { }
Ogre::RenderWindow *mWindow;
Ogre::Root *mRoot;
Ogre::SceneManager* mSceneMgr;
Ogre::Viewport* mViewport;
Ogre::InputReader* mInputDevice;
Ogre::Camera* mCamera;
ExampleLoadingBar mLoadingBar;
bool mExitGame;
private:
static IntroState mIntroState;
};
#endif
Code: Select all
// IntroState.cpp
#include <Ogre.h>
#include <OgreKeyEvent.h>
#include "IntroState.h"
// #include "PlayState.h" <-- just continue with your playstates
using namespace Ogre;
IntroState IntroState::mIntroState;
void IntroState::enter() {
mInputDevice = InputManager::getSingletonPtr()->getInputDevice();
mRoot = Root::getSingletonPtr();
mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
mCamera = mSceneMgr->createCamera("IntroCamera");
mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera);
mViewport->setBackgroundColour(ColourValue(0.0, 0.0, 0.0));
// parse resources, displaying progress to screen
mLoadingBar.start(getWindow(), 1, 1, 1.0);
// Turn off rendering of everything except overlays
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
// Back to full rendering
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
mLoadingBar.finish();
mExitGame = false;
}
void IntroState::exit() {
mSceneMgr->clearScene();
mSceneMgr->removeAllCameras();
mRoot->getAutoCreatedWindow()->removeAllViewports();
}
void IntroState::pause() {}
void IntroState::resume() {}
void IntroState::keyClicked(KeyEvent* e) {}
void IntroState::keyPressed(KeyEvent* e) {
if (e->getKey() == KC_RETURN) {
// changeState(PlayState::getInstance());
}
if (e->getKey() == KC_ESCAPE) {
mExitGame = true;
}
e->consume();
}
void IntroState::keyReleased(KeyEvent* e) {}
bool IntroState::frameStarted(const FrameEvent& evt) {
return true;
}
bool IntroState::frameEnded(const FrameEvent& evt) {
if (mExitGame)
return false;
return true;
}
"And then one day you find ten years have got behind you
No one told you when to run, you missed the starting gun"
About what I wrote before...I had originally put the loading screen within GameManager::start()...it worked ok, but there is more benifit for me having the loading of resources within IntroState.Tzyr wrote:Just remember, you need to create a SceneManager object, along with a viewport and camera. Just put the ExampleLoadingBar.start(...) and finish() before and after you initiate your resources.
Code: Select all
// GameManager.cpp
void GameManager::start(GameState* state) {
mRoot = new Root();
setupResources();
if (!configure()) return;
mRoot->addFrameListener(this);
mInputManager = new InputManager(mRoot->getAutoCreatedWindow());
mInputManager->getEventProcessor()->addKeyListener(this);
mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
mCamera = mSceneMgr->createCamera("IntroCamera");
mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera);
mViewport->setBackgroundColour(ColourValue(0.0, 0.0, 0.0));
// parse resources, displaying progress to screen
mLoadingBar.start(mRenderWindow, 1, 1, 1.0);
// Turn off rendering of everything except overlays
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
// Back to full rendering
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
mLoadingBar.finish();
// unload before entering IntroState
mSceneMgr->clearScene();
mSceneMgr->removeAllCameras();
mRoot->getAutoCreatedWindow()->removeAllViewports();
changeState(state);
mRoot->startRendering();
}
bool GameManager::configure(void) {
// load config settings from ogre.cfg
if (!mRoot->restoreConfig()) {
// if there is no config file, show the configuration dialog
if (!mRoot->showConfigDialog()) {
return false;
}
}
// initialise and create a default rendering window
mRenderWindow = mRoot->initialise(true);
return true;
}
"And then one day you find ten years have got behind you
No one told you when to run, you missed the starting gun"
Here I think was the weak point of the code.. don't know..If you note, the only real change that I made was, remove :
ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
Code: Select all
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
Code: Select all
// Back to full rendering
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
Really eh? I am just starting to use CEGUI. I did not like it at first, but once you figure some things out, it's pretty nice. I still think the mouse moves a little slow though. But since it's just for menues in the game I'm working on, no problems yet.M&M wrote:I am using the ExampleLoadingBar approach, but i made my own class out of it and modified it abit. It now works pretty well, but there is another loading bar in CEGUI's code. I haven't tried it yet though but you might want to check it out if you've already implemented CEGUI or planning to.
hmm..interesting. Will have to look in on it. Cause yeah, would be nicer.M&M wrote:tyzr, you could add thisto the start() function in loading barCode: Select all
mSceneMgr->clearSpecialCaseRenderQueues(); mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
and thisto the finish(), you just need to get a pointer to mSceneMgr on the other classCode: Select all
// Back to full rendering mSceneMgr->clearSpecialCaseRenderQueues(); mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
"And then one day you find ten years have got behind you
No one told you when to run, you missed the starting gun"
Code: Select all
ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
yeah, i had that problem too. The ExampleLoading bar class isn't complete, there are several missing functions and code to handle updating the bar.Will have to look at it though. The one thing that I am trying to figure out, is if you have the resources already parsed, how to make the bar progress (or say it's finished). Cause it just does not seem to show the progress of loading, only parsing.
Code: Select all
void resourceLoadEnded(void)
{
}
Code: Select all
mLoadingBarElement->setWidth(
mLoadingBarElement->getWidth() + mProgressBarInc);
mWindow->update();
you probably forgot to "return scene to full rendering"After I added the loading bar code, there are no more shadows in the scene and the billboards became jagged
Code: Select all
// Back to full rendering
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
look for the ResourceGroupLoadEnded function, and then setwidth the bar to full width.Will have to look at it though. The one thing that I am trying to figure out, is if you have the resources already parsed, how to make the bar progress (or say it's finished). Cause it just does not seem to show the progress of loading, only parsing.
no problems with this, I did it... there is something elseM&M wrote:you probably forgot to "return scene to full rendering"After I added the loading bar code, there are no more shadows in the scene and the billboards became jaggedCode: Select all
// Back to full rendering mSceneMgr->clearSpecialCaseRenderQueues(); mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);