Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

MainGame Class Reference

#include <maingame.h>

Inheritance diagram for MainGame:

Inheritance graph
[legend]
Collaboration diagram for MainGame:

Collaboration graph
[legend]

Public Member Functions

 MainGame (const XRect r, const string &appName)
virtual ~MainGame (void)
virtual const bool SetupWindow (const Message &msg)
const bool InitDone (void)

Static Public Attributes

Galaxygalaxy = 0
PlayGamegame = 0

Protected Member Functions

virtual const bool MainLoop (void)
virtual const bool evMouseLClick (const CtrlMessage &msg)
virtual const bool evMouseButtonDown (const MouseMessage &msg)
virtual const bool evMessage (const UserMessage &msg)

Private Member Functions

void EnableWindow (void)
void PlayIntro (void)

Private Attributes

Form * f
Mix_Music * wave
vector< BqBase * > links
vector< Thread * > initTasks

Constructor & Destructor Documentation

MainGame::MainGame const XRect  r,
const string &  appName
 

Definition at line 108 of file maingame.cpp.

References galaxy, game, and initTasks.

00109 : View( r , appName , false ) , wave( 0 )
00110 {
00111         galaxy = new Galaxy();
00112         game = new PlayGame();
00113 
00114         initTasks.push_back( new InitStarName );
00115         initTasks.push_back( new InitPlanetInfo );
00116         initTasks.push_back( new InitPlanetSize );
00117         initTasks.push_back( new InitEcoZone );
00118         initTasks.push_back( new InitSpecies );
00119         initTasks.push_back( new InitGalaxyScreen );
00120         initTasks.push_back( new InitStarInfo );
00121 }

MainGame::~MainGame void   )  [virtual]
 

Definition at line 123 of file maingame.cpp.

References GalaxyScreen::bkgnd, eLast, eMainDialog, f, galaxy, game, GalaxyScreen::img, links, Galaxy::Reset(), Colony::ResetAllColonies(), Parameters::ResetInfo(), ExprParser::toDelinExprParser, and wave.

00124 {
00125         galaxy->Reset();
00126         Colony::ResetAllColonies();
00127         Parameters::ResetInfo();
00128 
00129         if( GalaxyScreen::img )
00130                 SDL_FreeSurface( GalaxyScreen::img );
00131         GalaxyScreen::img = 0;
00132         if( GalaxyScreen::bkgnd )
00133                 SDL_FreeSurface( GalaxyScreen::bkgnd );
00134         GalaxyScreen::bkgnd = 0;
00135 
00136         delete game;
00137         game = 0;
00138         delete galaxy;
00139         galaxy = 0;
00140 
00141         Mix_HaltMusic();
00142         Mix_HaltChannel( 0 );
00143         Mix_HaltChannel( 1 );
00144         if( wave )
00145                 Mix_FreeMusic( wave );
00146         wave = 0;
00147 
00148         Mix_CloseAudio();
00149 
00150         f->ShutdownDialog( this );
00151 
00152         for( int i = eMainDialog ; i < eLast ; i++ )
00153                 Free( i );
00154 
00155         for( vector<BqBase *>::iterator it = links.begin() ; it != links.end() ; ++it )
00156                 delete (*it);
00157         links.clear();
00158 
00159         {
00160                 for( vector<Uniform *>::iterator it = ExprParser::toDelinExprParser.begin() ; it != ExprParser::toDelinExprParser.end() ; ++it )
00161                         delete (*it);
00162                 ExprParser::toDelinExprParser.clear();
00163         }
00164 
00165         clear();
00166 }


Member Function Documentation

void MainGame::EnableWindow void   )  [private]
 

Definition at line 204 of file maingame.cpp.

References f, Cfg::GetCfg(), Cfg::Handler::GetCfgString(), Cfg::Handler::GetFilename(), and GetGalaxy().

Referenced by evMouseLClick(), and SetupWindow().

00205 {
00206         Cfg::Handler    &h = Cfg::GetCfg();
00207         Rsrc    res( h.GetFilename() );
00208         Window  *ContinueButton = f->GetArsObject( 4 );
00209         Window  *LoadButton = f->GetArsObject( 5 );
00210         Window  *SaveButton = f->GetArsObject( 6 );
00211 
00212         ContinueButton->EnableWindow( !h.GetCfgString( "SavedGames" , "0" ).empty() );
00213         LoadButton->EnableWindow( !h.GetCfgString( "SavedGames" , "1" ).empty() );
00214         SaveButton->EnableWindow( !GetGalaxy().empty() );
00215 
00216         SaveButton->UpdateWindow();
00217         ContinueButton->UpdateWindow();
00218         LoadButton->UpdateWindow();
00219 }

const bool MainGame::evMessage const UserMessage &  msg  )  [protected, virtual]
 

Definition at line 291 of file maingame.cpp.

References ArsPostMessage, f, and links.

00292 {
00293         const unsigned int i = msg.SubMessage();
00294 
00295         if( i < links.size() )
00296         {
00297                 f->ShutdownDialog( this );
00298                 
00299                 links[i]->MainLoop();
00300 
00301                 f->InitDialog( this );
00302                 f->Draw();
00303         }
00304         else if( i == 8 )
00305                 ArsPostMessage( Message( Message::APP_EXIT , 0 ) );
00306 /*
00307         else if( msg.SubMessage() == SAVE_GALAXY || msg.SubMessage() == LOAD_GALAXY )
00308                 return false;
00309         else if( msg.SubMessage() == SAVE_SPECIES )
00310         {
00311 
00312         }
00313 */
00314         return true;
00315 }

const bool MainGame::evMouseButtonDown const MouseMessage &  msg  )  [protected, virtual]
 

Definition at line 284 of file maingame.cpp.

00285 {
00286         View::evMouseButtonDown( msg );
00287 
00288         return false;
00289 }

const bool MainGame::evMouseLClick const CtrlMessage &  msg  )  [protected, virtual]
 

Definition at line 317 of file maingame.cpp.

References ArsPostMessage, EnableWindow(), f, links, S_FOCUS, S_HIGHLIGHT, and S_SELECTED.

00318 {
00319         const int i = ((Window *)msg.source)->GetId();
00320         bool doredraw = false;
00321         if( i < (int)links.size() )
00322                 doredraw = links[i]->MainLoop();
00323         else if( i == 8 )
00324                 ArsPostMessage( Message( Message::APP_EXIT , 0 ) );
00325 
00326         EnableWindow();
00327         if( doredraw )
00328         {
00329                 f->GetArsObject( i )->ResetState( S_SELECTED|S_HIGHLIGHT|S_FOCUS ); 
00330                 f->Draw();
00331         }
00332         return true;
00333 }

const bool MainGame::InitDone void   ) 
 

Definition at line 168 of file maingame.cpp.

References initTasks.

Referenced by MainLoop().

00169 {
00170         for( vector<Thread*>::iterator it = initTasks.begin() ;it != initTasks.end() ; ++it )
00171         {
00172                 (*it)->Wait();
00173                 delete *it;
00174         }
00175         initTasks.clear();
00176         return true;
00177 }

const bool MainGame::MainLoop void   )  [protected, virtual]
 

Definition at line 221 of file maingame.cpp.

References Ars::AddSound(), ArsSendMessage, eMainDialog, f, InitDone(), initTasks, PlayIntro(), S_ALIGN_LEFT, and S_ALIGN_TOP.

00222 {
00223         Graf::ShowMouse( false );
00224 
00225         f = Load( "MainDialog" , eMainDialog );
00226 
00227         ArsSendMessage( Message( Message::SETUP_WINDOW , this ) );
00228 
00229         if( f )
00230         {
00231                 f->InitDialog( this );
00232                 f->Draw();
00233         }
00234         SetTextAlign( S_ALIGN_TOP , S_ALIGN_LEFT );
00235 
00236         AddSound( "Splash-Greeting" , "Splash" , "Greeting" ).Configure( 1 );
00237 
00238         PlayIntro();
00239         for( vector<Thread*>::iterator it = initTasks.begin() ;it != initTasks.end() ; ++it )
00240                 (*it)->Start( 0 );
00241 
00242         InitDone();
00243 
00244         Graf::ShowMouse( true );
00245 
00246         while( View::MainLoop() )       ;
00247 
00248         return false;
00249 }

void MainGame::PlayIntro void   )  [private]
 

Definition at line 251 of file maingame.cpp.

References f, Cfg::GetCfg(), Cfg::Handler::GetCfgFile(), Ars::GetSound(), Ars::Preload(), and wave.

Referenced by MainLoop().

00252 {
00253         if( Cfg::GetCfg().GetCfgInt( "SetupScreen" , "PlayIntro" , 1 ) )
00254         {
00255                 Cfg::Handler    &h = Cfg::GetCfg( "@sounds" );
00256         
00257                 XMPEG   *mpeg = dynamic_cast<XMPEG *>( f->GetArsObject( 20 ) );
00258                 SMPEG_rewind( mpeg->GetMPEG() );
00259                 Mix_Chunk       *wave;
00260                 if( (wave = Mix_LoadWAV( h.GetCfgFile( "Splash" , "Intro" ).c_str() )) != 0 )
00261                         Mix_PlayChannel( 0 , wave , 0 );
00262                 mpeg->Play();
00263 
00264                 while( SMPEG_status( mpeg->GetMPEG() ) == SMPEG_PLAYING )
00265                         SDL_Delay( 10 );
00266                 
00267                 mpeg->EndPlay();
00268                 if( wave )
00269                         Mix_FreeChunk( wave );
00270 
00271                 mpeg->SetDirty();
00272                 UpdateWindow( true );
00273         }
00274         
00275         Cfg::Handler    &h = Cfg::GetCfg( "@sounds" );
00276         wave = Mix_LoadMUS( h.GetCfgFile( "music" , "MainScreen" ).c_str() );
00277         if( wave )
00278                 Mix_PlayMusic( wave , -1 );
00279         GetSound( "Splash-Greeting" ).Play();
00280 
00281         Preload( "SoundEvent" );
00282 }

const bool MainGame::SetupWindow const Message &  msg  )  [virtual]
 

Definition at line 179 of file maingame.cpp.

References bqObjectCreate(), cbObjCreateType, EnableWindow(), and links.

00180 {
00181         View::SetupWindow( msg );
00182 
00183         SetBgColor( Cfg::GetCfg().GetCfgColorHex( "Ars" , "back_color" , RGBColor( 0 , 0 , 0 ) ) );
00184 
00185         MessageServer::Instance().RegisterMessageClient( this , Message::CTRL_LCLICK );
00186         MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_BUTTONDOWN );
00187         MessageServer::Instance().RegisterMessageClient( this , Message::USER );
00188 
00189         links.push_back( new MainCredits( this ) );
00190         links.push_back( new HallOfFame( this ) );
00191         links.push_back( new Retire( this ) );
00192         links.push_back( new Parameters( this ) );
00193         links.push_back( new Continue( this ) );
00194         links.push_back( new MainLoad( this ) );
00195         links.push_back( new MainSave( this ) );
00196 
00197         EnableWindow();
00198 
00199         ArsApplication::objCreate.push_back( (cbObjCreateType)bqObjectCreate );
00200 
00201         return true;
00202 }


Field Documentation

Form* MainGame::f [private]
 

Definition at line 24 of file maingame.h.

Referenced by EnableWindow(), evMessage(), evMouseLClick(), MainLoop(), PlayIntro(), and ~MainGame().

Galaxy * MainGame::galaxy = 0 [static]
 

Definition at line 9 of file maingame.cpp.

Referenced by Parameters::CreateGalaxy(), GetGalaxy(), MainGame(), and ~MainGame().

PlayGame * MainGame::game = 0 [static]
 

Definition at line 16 of file maingame.cpp.

Referenced by GetGame(), MainGame(), and ~MainGame().

vector<Thread *> MainGame::initTasks [private]
 

Definition at line 28 of file maingame.h.

Referenced by InitDone(), MainGame(), and MainLoop().

vector<BqBase *> MainGame::links [private]
 

Definition at line 27 of file maingame.h.

Referenced by evMessage(), evMouseLClick(), SetupWindow(), and ~MainGame().

Mix_Music* MainGame::wave [private]
 

Definition at line 26 of file maingame.h.

Referenced by PlayIntro(), and ~MainGame().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:25 2003 for Borqueror by doxygen 1.3.3