Advanced Ogre Framework         A young Ogre programmers Advanced Framework
Print

DemoApp.hpp

The DemoApp class is the central application organizing location. It only has two member variables:

  • the application state manager
  • an indicator of whether the application is to be shut down or not

 

//|||||||||||||||||||||||||||||||||||||||||||||||
 
#ifndef OGRE_DEMO_HPP
#define OGRE_DEMO_HPP
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
#include "AdvancedOgreFramework.hpp"
#include "AppStateManager.hpp"
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
class DemoApp
{
public:
	DemoApp();
	~DemoApp();
 
	void startDemo();
 
private:
	AppStateManager*	m_pAppStateManager;
};
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
#endif
 
//|||||||||||||||||||||||||||||||||||||||||||||||

 

DemoApp.cpp

The central application file, managing everything:

  • DemoApp(): Constructor
  • ~DemoApp(): Destructor
  • startDemo(): Starts the application:
  1. fires up the OgreFramework
  2. initializes Ogre (via the OgreFramework)
  3. create an AppStateManager instance
  4. creates the application states (MenuState, GameState and PauseState)
  5. orders the AppStateManager to start its main loop function
//|||||||||||||||||||||||||||||||||||||||||||||||
 
#include "DemoApp.hpp"
 
#include "MenuState.hpp"
#include "GameState.hpp"
#include "PauseState.hpp"
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
DemoApp::DemoApp()
{
	m_pAppStateManager = 0;
}
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
DemoApp::~DemoApp()
{
	delete m_pAppStateManager;
        delete OgreFramework::getSingletonPtr();
}
 
//|||||||||||||||||||||||||||||||||||||||||||||||
 
void DemoApp::startDemo()
{
	new OgreFramework();
	if(!OgreFramework::getSingletonPtr()->initOgre("AdvancedOgreFramework", 0, 0))
		return;
 
	OgreFramework::getSingletonPtr()->m_pLog->logMessage("Demo initialized!");
 
	m_pAppStateManager = new AppStateManager();
 
	MenuState::create(m_pAppStateManager, "MenuState");
	GameState::create(m_pAppStateManager, "GameState");
        PauseState::create(m_pAppStateManager, "PauseState");
 
	m_pAppStateManager->start(m_pAppStateManager->findByName("MenuState"));
}
 
//|||||||||||||||||||||||||||||||||||||||||||||||

 

Notes

1. If you want to, you can declare all the Ogre members in the OgreFramework class (Root, Camera, RenderWindow, SceneManager, ...) private and implement getter methods for them. This is mostly a matter of code style and one's preferences. You could also totally remove most of them as they are also singletons (e.g. Ogre::Root, Ogre::Log) and retrieve them via the singleton functions. It's up to you!

2. If Ogre::WindowEventUtilities::messagePump() doesn't work for you, try this instead:

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
{
   MSG msg;
   while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
   {
       if (msg.message == WM_QUIT)
          m_bShutdown = true;
       else
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
   }
}
#endif

 
3. In this forum post(external link) you will find a list of all needed changes in order to get this running with XCode on Mac.

Conclusion

Fatigued but happy, the little young programmer boy closed the secret book, feeling his head humming due to all the new great knowledge. However, with a satisfied smile on his face, he promised his teacher - the friendly Ogre - to test all these new valuable insights the next day after catching a big load of sleep...

 


Alias: Advanced_Ogre_Framework



Contributors to this page: Hazzr762 points  , Spacegaier6073 points  , Slappy251 points  , progman118 points  , jacmoe180265 points  , fsxfreak260 points  and DarkAnt347 points  .
Page last modified on Tuesday 10 of September, 2013 16:04:13 UTC by Hazzr762 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.