D:/simple_rts/src/Client.cpp

Go to the documentation of this file.
00001 #include "Client.h"
00002 
00003 #include "Game.h"
00004 #include "RTSCamera.h"
00005 #include "RTSCameraUpdater.h"
00006 #include "UnitSelecter.h"
00007 #include "Team.h"
00008 #include "FogOfWar.h"
00009 #include "ClientUpdater.h"
00010 
00011 #include "CEGUISchemeManager.h"
00012 #include "CEGUIWindowManager.h"
00013 #include "OgreMath.h"
00014 #include "OgreViewport.h"
00015 #include "OgreColourValue.h"
00016 using Ogre::Real;
00017 using Ogre::Viewport;
00018 using Ogre::ColourValue;
00019 
00020 namespace ASR
00021 {
00022         // ----------------------------------------------------------------------------
00023         Client::Client ( RenderWindow* window )
00024                 : mWindow ( window )
00025         {
00026                 // GUI
00027                 mGUIRenderer = NULL;
00028                 mGUISystem = NULL;
00029                 mGUIWindow = NULL;
00030 
00031                 mTeam = NULL;
00032                 mUnitSelecter = NULL;
00033                 mUpdater = NULL;
00034         }
00035 
00036 
00037         // ----------------------------------------------------------------------------
00038         Client::~Client ()
00039         {
00040                 // GUI
00041                 if ( mGUIWindow )
00042                         CEGUI::WindowManager::getSingleton().destroyWindow( mGUIWindow );
00043                 if ( mGUISystem )
00044                         delete mGUISystem;
00045                 if ( mGUIRenderer )
00046                         delete mGUIRenderer;
00047 
00048                 delete mUnitSelecter;
00049                 delete mUpdater;
00050 
00051                 delete mCameraUpdater;
00052                 delete mRTSCamera;
00053         }
00054 
00055 
00056         // ----------------------------------------------------------------------------
00057         void Client::createCamera ()
00058         {
00059                 mRTSCamera = new RTSCamera ( Game::getSingleton ().getSceneManager () );
00060 
00061                 // Create one viewport, entire window
00062                 Viewport* vp = mWindow->addViewport(mRTSCamera->getCamera());
00063                 vp->setBackgroundColour(ColourValue(0.1,0.1,0.1));
00064 
00065                 // Alter the camera aspect ratio to match the viewport
00066                 mRTSCamera->setAspectRatio( Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
00067 
00068                 _createGUI ();
00069 
00070                 mCameraUpdater = new RTSCameraUpdater ( mRTSCamera, mGUIRenderer );
00071                 Game::getSingleton ().addUpdater ( mCameraUpdater );
00072         }
00073 
00074 
00075         // ----------------------------------------------------------------------------
00076         void Client::_createGUI ()
00077         {
00078                 mGUIRenderer = new CEGUI::OgreCEGUIRenderer ( mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, Game::getSingleton ().getSceneManager () );
00079                 mGUISystem = new CEGUI::System ( mGUIRenderer );
00080 
00081                 CEGUI::Logger::getSingleton().setLoggingLevel( CEGUI::Informative );
00082 
00083                 CEGUI::SchemeManager::getSingleton().loadScheme ( (CEGUI::utf8*)"TaharezLook.scheme" );
00084                 mGUISystem->setDefaultMouseCursor( (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*) "MouseArrow" );
00085                 mGUISystem->setDefaultFont( (CEGUI::utf8*)"Tahoma-12" );
00086 
00087                 mGUIWindow = CEGUI::WindowManager::getSingleton().createWindow ( (CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"Sheet");
00088                 mGUISystem->setGUISheet( mGUIWindow );
00089         }
00090 
00091 
00092         // ----------------------------------------------------------------------------
00093         Team* Client::createTeam ( const String& teamName, const ColourValue& teamColor )
00094         {
00095                 OgreAssert ( mTeam == NULL, "Client already has a team" );
00096 
00097                 mTeam = Level::getSingleton().createTeam ( teamName, teamColor );
00098 
00099                 mUnitSelecter = new UnitSelecter ( mTeam, mRTSCamera->getCamera() );
00100                 Game::getSingleton ().addUpdater ( mUnitSelecter );
00101 
00102                 mUpdater = new ClientUpdater ( this );
00103                 Game::getSingleton ().addUpdater ( mUpdater );
00104 
00105                 return mTeam;
00106         }
00107 }

Generated on Sun Jun 25 19:23:43 2006 for Valors End by  doxygen 1.4.7