|
From: <sik...@us...> - 2006-05-18 03:09:59
|
Revision: 23 Author: sik0fewl Date: 2006-05-17 20:09:48 -0700 (Wed, 17 May 2006) ViewCVS: http://svn.sourceforge.net/perceptioncrash/?rev=23&view=rev Log Message: ----------- Some housekeeping Modified Paths: -------------- trunk/perceptioncrash/src/GameManager.cpp trunk/perceptioncrash/src/game.cpp trunk/perceptioncrash/src/game.hpp trunk/perceptioncrash/src/graphics.cpp trunk/perceptioncrash/src/graphics.hpp trunk/perceptioncrash/src/input.cpp trunk/perceptioncrash/src/input.hpp trunk/perceptioncrash/src/main.cpp trunk/perceptioncrash/src/singleton.hpp Modified: trunk/perceptioncrash/src/GameManager.cpp =================================================================== --- trunk/perceptioncrash/src/GameManager.cpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/GameManager.cpp 2006-05-18 03:09:48 UTC (rev 23) @@ -112,7 +112,7 @@ while (seci.hasMoreElements()) { secName = seci.peekNextKey(); - ConfigFile::SettingsMultiMap * settings = seci.getNext(); + ConfigFile::SettingsMultiMap* settings = seci.getNext(); ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { Modified: trunk/perceptioncrash/src/game.cpp =================================================================== --- trunk/perceptioncrash/src/game.cpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/game.cpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,73 +1,86 @@ -#include "game.hpp" +#include <cmath> #include <boost/bind.hpp> -#include <cmath> +#include "game.hpp" Game::Game() - : key_quit(Input::getSingleton().createKey("quit", Ogre::KC_ESCAPE)), - key_up(Input::getSingleton().createKey("up", Ogre::KC_W)), - key_right(Input::getSingleton().createKey("right", Ogre::KC_D)), - key_down(Input::getSingleton().createKey("down", Ogre::KC_S)), - key_left(Input::getSingleton().createKey("left", Ogre::KC_A)) -{ - Input::getSingleton().register_mouselistener( boost::bind(&Game::mousemotion_listener, - this, _1, _2) ); + : mKeyQuit(Input::getSingleton().createKey("quit", Ogre::KC_ESCAPE)), + mKeyUp(Input::getSingleton().createKey("up", Ogre::KC_W)), + mKeyRight(Input::getSingleton().createKey("right", Ogre::KC_D)), + mKeyDown(Input::getSingleton().createKey("down", Ogre::KC_S)), + mKeyLeft(Input::getSingleton().createKey("left", Ogre::KC_A)) +{ + Input::getSingleton().registerMouseListener(boost::bind(&Game::mouseMotionListener, this, _1,_2)); } -void Game::run() { - +void +Game::run() +{ // This is all temporary stuff - Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "data/objects", - "FileSystem", - "General" ); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "data/maps/ogretestmap.zip", - "Zip", - Ogre::ResourceGroupManager::getSingleton().getWorldResourceGroupName() ); - Ogre::ResourceGroupManager::getSingleton().linkWorldGeometryToResourceGroup( - Ogre::ResourceGroupManager::getSingleton().getWorldResourceGroupName(), - "ogretestmap.bsp", Graphics::getSingleton().getSceneManagerPtr()); - - Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); - Ogre::ResourceGroupManager::getSingleton().loadResourceGroup( - Ogre::ResourceGroupManager::getSingleton().getWorldResourceGroupName(), - false, true); - + Ogre::ResourceGroupManager rgm = Ogre::ResourceGroupManager::getSingleton(); + rgm.addResourceLocation("data/objects", "FileSystem", "General"); + rgm.addResourceLocation("data/maps/ogretestmap.zip", "Zip", + rgm.getWorldResourceGroupName()); + + rgm.linkWorldGeometryToResourceGroup(rgm.getWorldResourceGroupName(), + "ogretestmap.bsp", + Graphics::getSingleton().getSceneManagerPtr()); + + rgm.initialiseAllResourceGroups(); + rgm.loadResourceGroup(rgm.getWorldResourceGroupName(), false, true); + Ogre::ViewPoint vp = Graphics::getSingleton().getSceneManagerPtr()->getSuggestedViewpoint(true); Graphics::getSingleton().getCameraPtr()->setPosition(vp.position); - Graphics::getSingleton().getCameraPtr()->pitch( Ogre::Degree(90) ); + Graphics::getSingleton().getCameraPtr()->pitch(Ogre::Degree(90)); Graphics::getSingleton().getCameraPtr()->rotate(vp.orientation); Graphics::getSingleton().getCameraPtr()->setFixedYawAxis(true, Ogre::Vector3::UNIT_Z); - - Graphics::getSingleton().getSceneManagerPtr()->setAmbientLight( Ogre::ColourValue(1, 1, 1) ); - - Ogre::Entity *myEntity = - Graphics::getSingleton().getSceneManagerPtr()->createEntity("Robot1", "robot.mesh"); - Ogre::SceneNode *myNode = - Graphics::getSingleton().getSceneManagerPtr()-> - getRootSceneNode()->createChildSceneNode("Robot1Node"); - myNode->attachObject(myEntity); - + + Graphics::getSingleton().getSceneManagerPtr()->setAmbientLight(Ogre::ColourValue(1, 1, 1)); + + Ogre::Entity* myEntity = Graphics::getSingleton().getSceneManagerPtr()->createEntity("Robot1", "robot.mesh"); + Ogre::SceneNode* myNode = Graphics::getSingleton().getSceneManagerPtr()->getRootSceneNode()->createChildSceneNode("Robot1Node"); + myNode->attachObject(myEntity); + // This is how the real game loop should go - while ( !key_quit->isDown() ) { - if ( !Graphics::getSingleton().getRootPtr()->_fireFrameStarted() ) break; + while (!mKeyQuit->isDown()) + { + if (!Graphics::getSingleton().getRootPtr()->_fireFrameStarted()) + break; - Think(); - - Graphics::getSingleton().Update(); + think(); - if ( !Graphics::getSingleton().getRootPtr()->_fireFrameEnded() ) break; - } + Graphics::getSingleton().update(); + + if (!Graphics::getSingleton().getRootPtr()->_fireFrameEnded()) + break; + } } -void Game::Think() { - if (key_up->isDown()) { Graphics::getSingleton().getCameraPtr()->moveRelative( Ogre::Vector3(0, 0, -2) ); } - if (key_right->isDown()) { Graphics::getSingleton().getCameraPtr()->moveRelative( Ogre::Vector3(2, 0, 0) ); } - if (key_down->isDown()) { Graphics::getSingleton().getCameraPtr()->moveRelative( Ogre::Vector3(0, 0, 2) ); } - if (key_left->isDown()) { Graphics::getSingleton().getCameraPtr()->moveRelative( Ogre::Vector3(-2, 0, 0) ); } +void +Game::think() +{ + if (mKeyUp->isDown()) + { + Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(0, 0, -2)); + } + if (mKeyRight->isDown()) + { + Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(2, 0, 0)); + } + if (mKeyDown->isDown()) + { + Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(0, 0, 2)); + } + if (mKeyLeft->isDown()) + { + Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(-2, 0, 0)); + } } -void Game::mousemotion_listener(Ogre::Real x, Ogre::Real y) { - Graphics::getSingleton().getCameraPtr()->yaw( Ogre::Radian(-x * 1.f) ); - Graphics::getSingleton().getCameraPtr()->pitch( Ogre::Radian(-y * 1.f) ); +void +Game::mouseMotionListener(Ogre::Real x, Ogre::Real y) +{ + Graphics::getSingleton().getCameraPtr()->yaw(Ogre::Radian(-x * 1.f)); + Graphics::getSingleton().getCameraPtr()->pitch(Ogre::Radian(-y * 1.f)); } Modified: trunk/perceptioncrash/src/game.hpp =================================================================== --- trunk/perceptioncrash/src/game.hpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/game.hpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,29 +1,31 @@ -#ifndef GAME_HPP -#define GAME_HPP +#ifndef PC_GAME_HPP +#define PC_GAME_HPP -#include "graphics.hpp" -#include "input.hpp" +#include <memory> #include <Ogre.h> #include <OgreEventListeners.h> #include <OgreKeyEvent.h> -#include <memory> +#include "graphics.hpp" +#include "input.hpp" -class Game { -public: - Game(); - void run(); - void Think(); - void mousemotion_listener(Ogre::Real, Ogre::Real); +class Game +{ + public: + Game(); -private: - input_key* key_quit; - input_key* key_up; - input_key* key_right; - input_key* key_down; - input_key* key_left; + void run(); + void think(); + void mouseMotionListener(Ogre::Real, Ogre::Real); + + private: + InputKey* mKeyQuit; + InputKey* mKeyUp; + InputKey* mKeyRight; + InputKey* mKeyDown; + InputKey* mKeyLeft; }; -#endif // GAME_HPP +#endif /*PC_GAME_HPP*/ Modified: trunk/perceptioncrash/src/graphics.cpp =================================================================== --- trunk/perceptioncrash/src/graphics.cpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/graphics.cpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,16 +1,17 @@ #include "graphics.hpp" graphics::graphics() - : m_pRoot(new Ogre::Root("plugins.cfg", "ogre.cfg", "ogre.log")), - m_pSmgr(m_pRoot->createSceneManager("BspSceneManager")) -{ + : mRoot(new Ogre::Root("plugins.cfg", "ogre.cfg", "ogre.log")), + mSmgr(mRoot->createSceneManager("BspSceneManager")) +{ // HACK This is setting either OpenGL or first thing it comes to - Ogre::RenderSystemList *renderers = m_pRoot->getAvailableRenderers(); - Ogre::RenderSystem *r = *renderers->begin(); // default + Ogre::RenderSystemList* renderers = mRoot->getAvailableRenderers(); + Ogre::RenderSystem* r = *renderers->begin(); // default - Ogre::RenderSystemList::iterator i; - for(i = renderers->begin(); i != renderers->end(); ++i) { - if ( Ogre::StringUtil::match((*i)->getName(), "*opengl*", false) ) + for (Ogre::RenderSystemList::iterator i = renderers->begin(); + i != renderers->end(); ++i) + { + if (Ogre::StringUtil::match((*i)->getName(), "*opengl*", false)) r = *i; } @@ -18,20 +19,19 @@ r->setConfigOption("Full Screen", "no"); r->setConfigOption("RTT Preferred Mode", "FBO"); r->setConfigOption("Video Mode", "800 x 600"); - - m_pRoot->setRenderSystem(r); - m_pWindow = m_pRoot->initialise(true, "Application"); - + + mRoot->setRenderSystem(r); + mWindow = mRoot->initialise(true, "Application"); + // Should probably change this stuff - m_pCamera = m_pSmgr->createCamera("camera"); - m_pCamera->setPosition(Ogre::Vector3(0.0f, 0.0f, 500.0f)); - m_pCamera->lookAt(Ogre::Vector3(0.0f, 0.0f, 0.0f)); - m_pCamera->setNearClipDistance(5.0f); - m_pCamera->setFarClipDistance(5000.0f); + mCamera = mSmgr->createCamera("camera"); + mCamera->setPosition(Ogre::Vector3(0.0f, 0.0f, 500.0f)); + mCamera->lookAt(Ogre::Vector3(0.0f, 0.0f, 0.0f)); + mCamera->setNearClipDistance(5.0f); + mCamera->setFarClipDistance(5000.0f); - m_pViewport = m_pWindow->addViewport( m_pCamera ); - m_pViewport->setBackgroundColour( Ogre::ColourValue(0.3f, 0.3f, 0.3f) ); + mViewport = mWindow->addViewport(mCamera); + mViewport->setBackgroundColour(Ogre::ColourValue(0.3f, 0.3f, 0.3f)); - m_pCamera->setAspectRatio( Ogre::Real(m_pViewport->getActualWidth()) / - Ogre::Real(m_pViewport->getActualHeight()) ); + mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); } Modified: trunk/perceptioncrash/src/graphics.hpp =================================================================== --- trunk/perceptioncrash/src/graphics.hpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/graphics.hpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,35 +1,42 @@ -#ifndef GRAPHICS_HPP -#define GRAPHICS_HPP +#ifndef PC_GRAPHICS_HPP +#define PC_GRAPHICS_HPP -#include "singleton.hpp" +#include <memory> #include <Ogre.h> #include <OgreEventListeners.h> #include <OgreKeyEvent.h> -#include <memory> +#include "singleton.hpp" -class graphics { -public: +class graphics +{ + public: graphics(); - - void Update() { m_pRoot->_updateAllRenderTargets(); } - - Ogre::Root* getRootPtr() const { return m_pRoot.get(); } - Ogre::RenderWindow* getWindowPtr() const { return m_pWindow; } - Ogre::SceneManager* getSceneManagerPtr() const { return m_pSmgr; } - Ogre::Camera* getCameraPtr() const { return m_pCamera; } - Ogre::Viewport* getViewportPtr() const { return m_pViewport; } - -private: - std::auto_ptr<Ogre::Root> m_pRoot; - Ogre::RenderWindow *m_pWindow; - Ogre::SceneManager *m_pSmgr; - Ogre::Camera *m_pCamera; - Ogre::Viewport *m_pViewport; + + void update() + { mRoot->_updateAllRenderTargets(); } + + Ogre::Root* getRootPtr() const + { return mRoot.get(); } + Ogre::RenderWindow* getWindowPtr() const + { return mWindow; } + Ogre::SceneManager* getSceneManagerPtr() const + { return mSmgr; } + Ogre::Camera* getCameraPtr() const + { return mCamera; } + Ogre::Viewport* getViewportPtr() const + { return mViewport; } + + private: + std::auto_ptr<Ogre::Root> mRoot; + + Ogre::RenderWindow* mWindow; + Ogre::SceneManager* mSmgr; + Ogre::Camera* mCamera; + Ogre::Viewport* mViewport; }; -typedef singleton<graphics> Graphics; +typedef Singleton<graphics> Graphics; -#endif // GRAPHICS.HPP - +#endif /* PC_GRAPHICS_HPP*/ Modified: trunk/perceptioncrash/src/input.cpp =================================================================== --- trunk/perceptioncrash/src/input.cpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/input.cpp 2006-05-18 03:09:48 UTC (rev 23) @@ -2,61 +2,82 @@ #include "graphics.hpp" input::input() - : m_pEventProcessor( new Ogre::EventProcessor ) + : mEventProcessor(new Ogre::EventProcessor) { - m_pEventProcessor->addKeyListener( this ); - m_pEventProcessor->addMouseMotionListener( this ); - m_pEventProcessor->initialise( Graphics::getSingleton().getWindowPtr() ); - m_pEventProcessor->startProcessingEvents(); + mEventProcessor->addKeyListener(this); + mEventProcessor->addMouseMotionListener(this); + mEventProcessor->initialise(Graphics::getSingleton().getWindowPtr()); + mEventProcessor->startProcessingEvents(); } - -input_key* input::createKey(std::string str, int keycode) { - if (m_Keys.find(str) == m_Keys.end()) - return m_Keys[str] = new input_key(keycode); - - return 0; + +InputKey* +input::createKey(std::string str, int keycode) +{ + if (mKeys.find(str) == mKeys.end()) + return mKeys[str] = new InputKey(keycode); + + return 0; } -input_key* input::findKey(std::string str) { - if (m_Keys.find(str) != m_Keys.end()) - return m_Keys[str]; - - return 0; +InputKey* +input::findKey(std::string str) +{ + if (mKeys.find(str) != mKeys.end()) + return mKeys[str]; + + return 0; } -void input::keyClicked(Ogre::KeyEvent *e) { - // TODO make some clicked code, probably not needed +void +input::keyClicked(Ogre::KeyEvent* e) +{ + // TODO make some clicked code, probably not needed } -void input::keyPressed(Ogre::KeyEvent *e) { - std::map<std::string, input_key*>::iterator i; - for (i = m_Keys.begin(); i != m_Keys.end(); ++i) { - if ( e->getKey() == i->second->getKey() ) { - i->second->setDown(); - } - } +void +input::keyPressed(Ogre::KeyEvent* e) +{ + std::map<std::string, InputKey*>::iterator i; + for (i = mKeys.begin(); i != mKeys.end(); ++i) + { + if (e->getKey() == i->second->getKey()) + { + i->second->setDown(); + } + } } -void input::keyReleased(Ogre::KeyEvent *e) { - std::map<std::string, input_key*>::iterator i; - for (i = m_Keys.begin(); i != m_Keys.end(); ++i) { - if ( e->getKey() == i->second->getKey() ) { - i->second->setDown(false); - } - } +void +input::keyReleased(Ogre::KeyEvent* e) +{ + std::map<std::string, InputKey*>::iterator i; + for (i = mKeys.begin(); i != mKeys.end(); ++i) + { + if (e->getKey() == i->second->getKey()) + { + i->second->setDown(false); + } + } } -void input::mouseMoved(Ogre::MouseEvent *e) { - std::list< boost::function<void (Ogre::Real, Ogre::Real)> >::iterator i; - for (i = m_MouseListeners.begin(); i != m_MouseListeners.end(); ++i) { - (*i)(e->getRelX(), e->getRelY()); - } +void +input::mouseMoved(Ogre::MouseEvent* e) +{ + std::list<boost::function<void(Ogre::Real, Ogre::Real)> >::iterator i; + for (i = mMouseListeners.begin(); i != mMouseListeners.end(); ++i) + { + (*i) (e->getRelX(), e->getRelY()); + } } -void input::mouseDragged(Ogre::MouseEvent *e){ +void +input::mouseDragged(Ogre::MouseEvent* e) +{ } -void input::mouseDragMoved(Ogre::MouseEvent *e) { - +void +input::mouseDragMoved(Ogre::MouseEvent* e) +{ + } Modified: trunk/perceptioncrash/src/input.hpp =================================================================== --- trunk/perceptioncrash/src/input.hpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/input.hpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,57 +1,63 @@ -#ifndef INPUT_HPP -#define INPUT_HPP +#ifndef PC_INPUT_HPP +#define PC_INPUT_HPP -#include "singleton.hpp" +#include <map> +#include <list> +#include <boost/function.hpp> + #include <Ogre.h> #include <OgreEventListeners.h> #include <OgreKeyEvent.h> -#include <boost/function.hpp> +#include "singleton.hpp" -#include <map> -#include <list> +class InputKey +{ + public: + InputKey(int key): mKeycode(key), mDown(false) { } -class input_key { -public: - input_key(int key) : keycode(key), down(false) { } - - int getKey() const { return keycode; } - bool isDown() const { return down; } - - void setDown(bool yes = true) { down = yes; } - -private: - int keycode; - bool down; + int getKey() const + { return mKeycode; } + bool isDown() const + { return mDown; } + + void setDown(bool yes = true) + { mDown = yes; } + + private: + int mKeycode; + bool mDown; }; -class input : public Ogre::KeyListener, public Ogre::MouseMotionListener { -public: +class input : public Ogre::KeyListener, + public Ogre::MouseMotionListener +{ + public: input(); - - input_key* createKey(std::string, int); - input_key* findKey(std::string); - - void keyClicked(Ogre::KeyEvent *); - void keyPressed(Ogre::KeyEvent *); - void keyReleased(Ogre::KeyEvent *); - - void mouseMoved(Ogre::MouseEvent *); - void mouseDragged(Ogre::MouseEvent *); - void mouseDragMoved(Ogre::MouseEvent *); - - void register_mouselistener(boost::function<void (Ogre::Real, Ogre::Real)> m) { - m_MouseListeners.push_back(m); - } - -private: - std::map<std::string, input_key*> m_Keys; - std::list< boost::function<void (Ogre::Real, Ogre::Real)> > m_MouseListeners; - std::auto_ptr<Ogre::EventProcessor> m_pEventProcessor; + InputKey* createKey(std::string, int); + InputKey* findKey(std::string); + + void keyClicked(Ogre::KeyEvent*); + void keyPressed(Ogre::KeyEvent*); + void keyReleased(Ogre::KeyEvent*); + + void mouseMoved(Ogre::MouseEvent*); + void mouseDragged(Ogre::MouseEvent*); + void mouseDragMoved(Ogre::MouseEvent*); + + void registerMouseListener(boost::function<void(Ogre::Real, Ogre::Real)> m) + { mMouseListeners.push_back(m); } + + private: + std::map<std::string,InputKey*> mKeys; + std::list<boost::function<void(Ogre::Real, Ogre::Real)> > mMouseListeners; + + std::auto_ptr<Ogre::EventProcessor> mEventProcessor; }; -typedef singleton<input> Input; +typedef + Singleton<input> Input; -#endif // INPUT_HPP +#endif /*PC_INPUT_HPP*/ Modified: trunk/perceptioncrash/src/main.cpp =================================================================== --- trunk/perceptioncrash/src/main.cpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/main.cpp 2006-05-18 03:09:48 UTC (rev 23) @@ -1,27 +1,32 @@ -#include "game.hpp" - #include <memory> #include <Ogre.h> #include <OgreErrorDialog.h> +#include "game.hpp" + #if OGRE_PLATFORM==OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" -INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) +INT WINAPI +WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) #else -int main(int argc, char **argv) +int +main(int argc, char **argv) #endif { Game game; - try { - game.run(); - } - catch (Ogre::Exception& e) { - std::auto_ptr<Ogre::ErrorDialog> tmpdlg(Ogre::PlatformManager::getSingleton().createErrorDialog()); - tmpdlg->display(e.getFullDescription()); - return 1; - } - return 0; + try + { + game.run(); + } + catch(Ogre::Exception& e) + { + std::auto_ptr<Ogre::ErrorDialog> tmpdlg(Ogre::PlatformManager::getSingleton().createErrorDialog()); + tmpdlg->display(e.getFullDescription()); + return 1; + } + + return 0; } Modified: trunk/perceptioncrash/src/singleton.hpp =================================================================== --- trunk/perceptioncrash/src/singleton.hpp 2006-05-18 02:10:53 UTC (rev 22) +++ trunk/perceptioncrash/src/singleton.hpp 2006-05-18 03:09:48 UTC (rev 23) @@ -2,19 +2,22 @@ #define SINGLETON_HPP template<class T> -class singleton { -public: - static T& getSingleton() { - static T instance; - return instance; - } - -private: - singleton(); - ~singleton(); - - singleton(singleton const&); - singleton& operator=(singleton const&); +class Singleton +{ + public: + static T& getSingleton() + { + static T instance; + + return instance; + } + + private: + Singleton(); + ~Singleton(); + + Singleton(Singleton const &); + Singleton& operator=(Singleton const &); }; #endif // SINGLETON_HPP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |