OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
OpenXcom::Game Class Reference

The core of the game engine, manages the game's entire contents and structure. More...

#include <Game.h>

Public Member Functions

 Game (const std::string &title)
 Creates a new game and initializes SDL. More...
 
 ~Game ()
 Cleans up all the game's resources and shuts down SDL. More...
 
void run ()
 Starts the game's state machine. More...
 
void quit ()
 Quits the game. More...
 
void setVolume (int sound, int music, int ui)
 Sets the game's audio volume. More...
 
ScreengetScreen () const
 Gets the game's display screen. More...
 
CursorgetCursor () const
 Gets the game's cursor. More...
 
FpsCountergetFpsCounter () const
 Gets the FpsCounter. More...
 
void setState (State *state)
 Resets the state stack to a new state. More...
 
void pushState (State *state)
 Pushes a new state into the state stack. More...
 
void popState ()
 Pops the last state from the state stack. More...
 
LanguagegetLanguage () const
 Gets the currently loaded language. More...
 
void loadLanguage (const std::string &filename)
 Loads a new language for the game. More...
 
ResourcePackgetResourcePack () const
 Gets the currently loaded resource pack. More...
 
void setResourcePack (ResourcePack *res)
 Sets a new resource pack for the game. More...
 
SavedGamegetSavedGame () const
 Gets the currently loaded saved game. More...
 
void setSavedGame (SavedGame *save)
 Sets a new saved game for the game. More...
 
RulesetgetRuleset () const
 Gets the currently loaded ruleset. More...
 
void loadRuleset ()
 Loads a new ruleset for the game. More...
 
void setMouseActive (bool active)
 Sets whether the mouse cursor is activated. More...
 
bool isState (State *state) const
 Returns whether current state is the param state. More...
 
bool isQuitting () const
 Returns whether the game is shutting down. More...
 
void defaultLanguage ()
 Sets up the default language. More...
 
void initAudio ()
 Sets up the audio. More...
 

Static Public Member Functions

static double volumeExponent (int volume)
 Adjusts a linear volume level to an exponential one.
 

Detailed Description

The core of the game engine, manages the game's entire contents and structure.

Takes care of encapsulating all the core SDL commands, provides access to all the game's resources and contains a stack state machine to handle all the initializations, events and blits of each state, as well as transitions.

Constructor & Destructor Documentation

OpenXcom::Game::Game ( const std::string &  title)

Creates a new game and initializes SDL.

Starts up SDL with all the subsystems and SDL_mixer for audio processing, creates the display screen and sets up the cursor.

Parameters
titleTitle of the game window.
OpenXcom::Game::~Game ( )

Cleans up all the game's resources and shuts down SDL.

Deletes the display screen, cursor, states and shuts down all the SDL subsystems.

Member Function Documentation

void OpenXcom::Game::defaultLanguage ( )

Sets up the default language.

Loads the most appropriate language given current system and game options.

Cursor * OpenXcom::Game::getCursor ( ) const

Gets the game's cursor.

Returns the mouse cursor used by the game.

Returns
Pointer to the cursor.
FpsCounter * OpenXcom::Game::getFpsCounter ( ) const

Gets the FpsCounter.

Returns the FpsCounter used by the game.

Returns
Pointer to the FpsCounter.
Language * OpenXcom::Game::getLanguage ( ) const

Gets the currently loaded language.

Returns the language currently in use by the game.

Returns
Pointer to the language.
ResourcePack * OpenXcom::Game::getResourcePack ( ) const

Gets the currently loaded resource pack.

Returns the resource pack currently in use by the game.

Returns
Pointer to the resource pack.
Ruleset * OpenXcom::Game::getRuleset ( ) const

Gets the currently loaded ruleset.

Returns the ruleset currently in use by the game.

Returns
Pointer to the ruleset.
SavedGame * OpenXcom::Game::getSavedGame ( ) const

Gets the currently loaded saved game.

Returns the saved game currently in use by the game.

Returns
Pointer to the saved game.
Screen * OpenXcom::Game::getScreen ( ) const

Gets the game's display screen.

Returns the display screen used by the game.

Returns
Pointer to the screen.
void OpenXcom::Game::initAudio ( )

Sets up the audio.

Initializes the audio subsystem.

bool OpenXcom::Game::isQuitting ( ) const

Returns whether the game is shutting down.

Checks if the game is currently quitting.

Returns
whether the game is shutting down or not.
bool OpenXcom::Game::isState ( State state) const

Returns whether current state is the param state.

Returns whether current state is *state.

Parameters
stateThe state to test against the stack state
Returns
Is state the current state?
void OpenXcom::Game::loadLanguage ( const std::string &  filename)

Loads a new language for the game.

Changes the language currently in use by the game.

Parameters
filenameFilename of the language file.
void OpenXcom::Game::loadRuleset ( )

Loads a new ruleset for the game.

Loads the rulesets specified in the game options.

void OpenXcom::Game::popState ( )

Pops the last state from the state stack.

Pops the last state from the top of the stack.

Since states can't actually be deleted mid-cycle, it's moved into a separate queue which is cleared at the start of every cycle, so the transition is seamless.

void OpenXcom::Game::pushState ( State state)

Pushes a new state into the state stack.

Pushes a new state into the top of the stack and initializes it.

The new state will be used once the next game cycle starts.

Parameters
statePointer to the new state.
void OpenXcom::Game::quit ( )

Quits the game.

Stops the state machine and the game is shut down.

void OpenXcom::Game::run ( )

Starts the game's state machine.

The state machine takes care of passing all the events from SDL to the active state, running any code within and blitting all the states and cursor to the screen.

This is run indefinitely until the game quits.

void OpenXcom::Game::setMouseActive ( bool  active)

Sets whether the mouse cursor is activated.

Sets whether the mouse is activated.

If it is, mouse events are processed, otherwise they are ignored and the cursor is hidden.

Parameters
activeIs mouse activated?
void OpenXcom::Game::setResourcePack ( ResourcePack res)

Sets a new resource pack for the game.

Sets a new resource pack for the game to use.

Parameters
resPointer to the resource pack.
void OpenXcom::Game::setSavedGame ( SavedGame save)

Sets a new saved game for the game.

Sets a new saved game for the game to use.

Parameters
savePointer to the saved game.
void OpenXcom::Game::setState ( State state)

Resets the state stack to a new state.

Pops all the states currently in stack and pushes in the new state.

A shortcut for cleaning up all the old states when they're not necessary like in one-way transitions.

Parameters
statePointer to the new state.
void OpenXcom::Game::setVolume ( int  sound,
int  music,
int  ui 
)

Sets the game's audio volume.

Changes the audio volume of the music and sound effect channels.

Parameters
soundSound volume, from 0 to MIX_MAX_VOLUME.
musicMusic volume, from 0 to MIX_MAX_VOLUME.
uiUI volume, from 0 to MIX_MAX_VOLUME.

The documentation for this class was generated from the following files: