OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Game.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_GAME_H
20 #define OPENXCOM_GAME_H
21 
22 #include <list>
23 #include <string>
24 #include <SDL.h>
25 
26 namespace OpenXcom
27 {
28 
29 class State;
30 class Screen;
31 class Cursor;
32 class Language;
33 class ResourcePack;
34 class SavedGame;
35 class Ruleset;
36 class FpsCounter;
37 
44 class Game
45 {
46 private:
47  SDL_Event _event;
48  Screen *_screen;
49  Cursor *_cursor;
50  Language *_lang;
51  std::list<State*> _states, _deleted;
52  ResourcePack *_res;
53  SavedGame *_save;
54  Ruleset *_rules;
55  bool _quit, _init;
56  FpsCounter *_fpsCounter;
57  bool _mouseActive;
58  unsigned int _timeOfLastFrame;
59  int _timeUntilNextFrame;
60  static const double VOLUME_GRADIENT;
61 
62 public:
64  Game(const std::string &title);
66  ~Game();
68  void run();
70  void quit();
72  void setVolume(int sound, int music, int ui);
74  static double volumeExponent(int volume);
76  Screen *getScreen() const;
78  Cursor *getCursor() const;
80  FpsCounter *getFpsCounter() const;
82  void setState(State *state);
84  void pushState(State *state);
86  void popState();
88  Language *getLanguage() const;
90  void loadLanguage(const std::string &filename);
94  void setResourcePack(ResourcePack *res);
96  SavedGame *getSavedGame() const;
98  void setSavedGame(SavedGame *save);
100  Ruleset *getRuleset() const;
102  void loadRuleset();
104  void setMouseActive(bool active);
106  bool isState(State *state) const;
108  bool isQuitting() const;
110  void defaultLanguage();
112  void initAudio();
113 };
114 
115 }
116 
117 #endif
void loadRuleset()
Loads a new ruleset for the game.
Definition: Game.cpp:528
void run()
Starts the game's state machine.
Definition: Game.cpp:142
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Language * getLanguage() const
Gets the currently loaded language.
Definition: Game.cpp:436
The game data that gets written to disk when the game is saved.
Definition: SavedGame.h:80
bool isQuitting() const
Returns whether the game is shutting down.
Definition: Game.cpp:584
void popState()
Pops the last state from the state stack.
Definition: Game.cpp:425
void initAudio()
Sets up the audio.
Definition: Game.cpp:638
void defaultLanguage()
Sets up the default language.
Definition: Game.cpp:593
Ruleset * getRuleset() const
Gets the currently loaded ruleset.
Definition: Game.cpp:520
void quit()
Quits the game.
Definition: Game.cpp:320
FpsCounter * getFpsCounter() const
Gets the FpsCounter.
Definition: Game.cpp:387
void setState(State *state)
Resets the state stack to a new state.
Definition: Game.cpp:398
Contains strings used throughout the game for localization.
Definition: Language.h:42
ResourcePack * getResourcePack() const
Gets the currently loaded resource pack.
Definition: Game.cpp:482
void loadLanguage(const std::string &filename)
Loads a new language for the game.
Definition: Game.cpp:445
void setResourcePack(ResourcePack *res)
Sets a new resource pack for the game.
Definition: Game.cpp:491
Set of rules and stats for a game.
Definition: Ruleset.h:69
Screen * getScreen() const
Gets the game's display screen.
Definition: Game.cpp:369
void setMouseActive(bool active)
Sets whether the mouse cursor is activated.
Definition: Game.cpp:564
SavedGame * getSavedGame() const
Gets the currently loaded saved game.
Definition: Game.cpp:501
Packs of external game media.
Definition: ResourcePack.h:50
void setSavedGame(SavedGame *save)
Sets a new saved game for the game.
Definition: Game.cpp:510
Cursor * getCursor() const
Gets the game's cursor.
Definition: Game.cpp:378
Game(const std::string &title)
Creates a new game and initializes SDL.
Definition: Game.cpp:53
static double volumeExponent(int volume)
Adjusts a linear volume level to an exponential one.
Definition: Game.cpp:361
Mouse cursor that replaces the system cursor.
Definition: Cursor.h:34
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
void pushState(State *state)
Pushes a new state into the state stack.
Definition: Game.cpp:413
Counts the amount of frames each second and displays them in a NumberText surface.
Definition: FpsCounter.h:36
void setVolume(int sound, int music, int ui)
Sets the game's audio volume.
Definition: Game.cpp:338
~Game()
Cleans up all the game's resources and shuts down SDL.
Definition: Game.cpp:112
A display screen, handles rendering onto the game window.
Definition: Screen.h:40
bool isState(State *state) const
Returns whether current state is the param state.
Definition: Game.cpp:575