src/main.cpp File Reference

#include <string>
#include <guichan.hpp>
#include <guichan/sdl.hpp>
#include <guichan/opengl.hpp>
#include "Menu/CCGui.h"
#include "SDL.h"
#include "GLee.h"
#include "Log.h"
#include "Config.h"
#include "IGameState.h"
#include "MainMenu.h"
#include "Economy.h"
#include "Timer.h"
#include "font.h"
#include "SoundSystem.h"
#include "ResourceManager/ResourceManager.h"
#include "ResourceManager/IResourceFactory.h"
#include "ResourceManager/SoundFactory.h"
#include "ResourceManager/TextureFactory.h"
#include "ResourceManager/ShipFactory.h"
#include "ResourceManager/FontFactory.h"

Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

void prepExit ()
void init ()
int main (int argc, char **argv)

Variables

bool done = false
IGameStatecurrent
MainMenumainMenu
SDL_Surface * screen


Function Documentation

void init (  ) 

Definition at line 51 of file main.cpp.

References CCGui::CreateGui(), current, done, Config::GetWinHeight(), Config::GetWinWidth(), SoundSystem::Initialize(), ResourceManager::LoadXMLFile(), mainMenu, Log::Message(), IGameState::PrepareTopContainer(), Config::s_config, Log::s_log, ResourceManager::s_resourceManager, and IGameState::SetCurrentPtr().

Referenced by main().

00051             {
00052   auto_ptr<IResourceFactory> factory;
00053 
00054   int width = Config::s_config->GetWinWidth();
00055   int height = Config::s_config->GetWinHeight();
00056 
00057   glViewport(0, 0, width, height);
00058 
00059   IGameState::SetCurrentPtr(&current);
00060 
00061   Log::s_log->Message("Current state pointer set");
00062 
00063   Log::s_log->Message("Sound system initialized");
00064   SoundSystem::Initialize(Config::s_config->GetNumberALSources());
00065 
00066   factory.reset(new SoundFactory());
00067   ResourceManager::s_resourceManager->LoadXMLFile("data/SoundResources.xml", factory);
00068 
00069   factory.reset(new TextureFactory());
00070   ResourceManager::s_resourceManager->LoadXMLFile("data/TextureResources.xml", factory);
00071 
00072   factory.reset(new ShipFactory());
00073   ResourceManager::s_resourceManager->LoadXMLFile("data/ShipResources.xml", factory);
00074 
00075   factory.reset(new FontFactory());
00076   ResourceManager::s_resourceManager->LoadXMLFile("data/FontResources.xml", factory);
00077 
00078   if (!CCGui::CreateGui(width, height)) {
00079     throw new gcn::Exception("Gui creation error.");
00080   }
00081 
00082   Log::s_log->Message("Gui Created");
00083 
00084   // Set up the mainMenu to run first
00085   mainMenu = new MainMenu(&done);
00086   current = mainMenu;
00087   mainMenu->PrepareTopContainer();
00088 
00089   Log::s_log->Message("Main menu created");
00090 }

int main ( int  argc,
char **  argv 
)

Definition at line 92 of file main.cpp.

References current, CCGui::DestroyGui(), done, Config::GetWinHeight(), Config::GetWinWidth(), init(), ResourceManager::Initialize(), Timer::Initialize(), IGameState::Loop(), mainMenu, Log::Message(), Config::OpenConfig(), Log::OpenLog(), prepExit(), Timer::ResetTimer(), Config::s_config, Log::s_log, SoundSystem::s_soundSystem, screen, SoundSystem::Shutdown(), Timer::timer, and SoundSystem::Update().

00092                                 {
00093   unsigned int ticks;
00094   int width, height;
00095 
00096   Log::OpenLog(true);
00097   Timer::Initialize();
00098   Config::OpenConfig("Config.xml");
00099   ResourceManager::Initialize();
00100 
00101   width = Config::s_config->GetWinWidth();
00102   height = Config::s_config->GetWinHeight();
00103 
00104   /* Information about the current video settings. */
00105   const SDL_VideoInfo* info = NULL;
00106 
00107   /* Color depth in bits of our window. */
00108   int bpp = 0;
00109   /* Flags we will pass into SDL_SetVideoMode. */
00110   int flags = 0;
00111 
00112   // Flags for SDL_Init
00113   int initFlags = 0;
00114 
00115   if (Config::s_config->CheckSDLParachute()) {
00116     initFlags = SDL_INIT_VIDEO;
00117   } else {
00118     initFlags = SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE;
00119   }
00120 
00121   /* First, initialize SDL's video subsystem. */
00122   if(SDL_Init(initFlags) < 0) {
00123     // Failed to initialize
00124     Log::s_log->Message("Video initialization failed: %s", SDL_GetError());
00125 
00126     prepExit();
00127 
00128     exit(1);
00129   }
00130 
00131   /* Let's get some video information. */
00132   info = SDL_GetVideoInfo();
00133   if(!info) {
00134     /* This should probably never happen. */
00135     Log::s_log->Message("Video query failed: %s", SDL_GetError());
00136 
00137     prepExit();
00138 
00139     exit(1);
00140   }
00141 
00142   Log::s_log->Message("Got video info");
00143 
00144   /*
00145    * We get the bpp we will request from
00146    * the display. On X11, VidMode can't change
00147    * resolution, so this is probably being overly
00148    * safe. Under Win32, ChangeDisplaySettings
00149    * can change the bpp.
00150    */
00151   bpp = info->vfmt->BitsPerPixel;
00152 
00153   /*
00154    * Now, we want to setup our requested
00155    * window attributes for our OpenGL window.
00156    * We want *at least* 5 bits of red, green
00157    * and blue. We also want at least a 16-bit
00158    * depth buffer.
00159    *
00160    * The last thing we do is request a double
00161    * buffered window. '1' turns on double
00162    * buffering, '0' turns it off.
00163    *
00164    * Note that we do not use SDL_DOUBLEBUF in
00165    * the flags to SDL_SetVideoMode. That does
00166    * not affect the GL attribute state, only
00167    * the standard 2D blitting setup.
00168    */
00169   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
00170   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
00171   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
00172   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
00173   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
00174 
00175   // Request an OpenGL window
00176   if (Config::s_config->CheckFullscreen()) {
00177     flags = SDL_OPENGL | SDL_FULLSCREEN;
00178   } else {
00179     flags = SDL_OPENGL;
00180   }
00181 
00182   // Set the window name
00183   SDL_WM_SetCaption("Crown and Cutlass", "Crown and Cutlass");
00184   //SDL_ShowCursor(0);
00185 
00186   /*
00187    * Set the video mode
00188    */
00189   screen = SDL_SetVideoMode(width, height, bpp, flags);
00190   if(screen == 0) {
00191     /*
00192      * This could happen for a variety of reasons,
00193      * including DISPLAY not being set, the specified
00194      * resolution not being available, etc.
00195      */
00196     Log::s_log->Message("Video mode set failed: %s", SDL_GetError());
00197 
00198     prepExit();
00199 
00200     exit(1);
00201   }
00202 
00203   SDL_EnableUNICODE(1);
00204   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
00205 
00206   Log::s_log->Message("Video mode set");
00207 
00208   // Make sure the video card supports the necessary extensions
00209   // Note: this needs to happen after we have a valid opengl rendering context
00210   if (!Config::s_config->CheckExtensions()) {
00211     Log::s_log->Message("Error: Your video card does not support the necessary extensions");
00212     prepExit();
00213     exit(1);
00214   }
00215   Log::s_log->Message("Extensions verified");
00216 
00217   try {
00218     init();
00219 
00220     Log::s_log->Message("Crown and Cutlass initialized sucessfully\n");
00221 
00222     while(!done && (current != NULL)) {
00223       ticks = Timer::timer->ResetTimer();
00224 
00225       SoundSystem::s_soundSystem->Update(ticks);
00226 
00227       current->Loop(ticks);
00228     }
00229   } catch (gcn::Exception e) {
00230     Log::s_log->Message("Uncaught guichan exception in %s line %d (%s)", e.getFilename().c_str(), e.getLine(), e.getMessage().c_str());
00231   } catch (gcn::Exception* e) {
00232     Log::s_log->Message("Uncaught guichan exception in %s line %d (%s)", e->getFilename().c_str(), e->getLine(), e->getMessage().c_str());
00233   } catch (const char *e) {
00234     Log::s_log->Message("Uncaught exception (%s)", e);
00235   } catch (string e) {
00236     Log::s_log->Message("Uncaught exception (%s)", e.c_str());
00237   } catch (...) {
00238     Log::s_log->Message("Uncaught exception");
00239   }
00240 
00241   delete mainMenu;
00242 
00243   CCGui::DestroyGui();
00244 
00245   // Don't delete current!
00246   // We only created the main menu, whatever created current will delete it
00247   //delete current;
00248 
00249   SoundSystem::Shutdown();
00250 
00251   prepExit();
00252 
00253   return 0;
00254 }

void prepExit (  ) 

Definition at line 37 of file main.cpp.

References Config::CloseConfig(), Log::CloseLog(), Log::Message(), Log::s_log, Timer::Shutdown(), and ResourceManager::Shutdown().

Referenced by main().

00037                 {
00038   SDL_Quit();
00039   Log::s_log->Message("SDL shutdown");
00040 
00041   ResourceManager::Shutdown();
00042 
00043   Config::CloseConfig();
00044 
00045   Timer::Shutdown();
00046 
00047   Log::s_log->Message("Shutdown successful");
00048   Log::CloseLog();
00049 }


Variable Documentation

IGameState* current

Definition at line 32 of file main.cpp.

Referenced by init(), main(), and IGameState::SetCurrentPtr().

bool done = false

Definition at line 30 of file main.cpp.

Referenced by init(), main(), and IGameState::TakeScreenshot().

MainMenu* mainMenu

Definition at line 33 of file main.cpp.

Referenced by init(), and main().

SDL_Surface* screen

Definition at line 35 of file main.cpp.

Referenced by main().


Generated on Mon Jan 8 22:34:13 2007 for CrownandCutlass by  doxygen 1.4.7