Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Cytopia::Game Class Reference

#include <Game.hxx>

+ Collaboration diagram for Cytopia::Game:

Public Member Functions

 Game ()
 Creates a game. More...
 
virtual ~Game ()=default
 Destroy a game. More...
 
virtual void initialize ()
 starts setting up the game More...
 
virtual void run (bool SkipMenu=false)
 begins the game More...
 
virtual void shutdown ()
 ends the game More...
 
virtual void newGame (bool generateTerrain)
 
virtual void loadGame (const std::string &fileName)
 

Private Member Functions

void quit ()
 

Private Attributes

bool m_shutDown = false
 
GamePlay m_GamePlay
 

Detailed Description

Definition at line 24 of file Game.hxx.

Constructor & Destructor Documentation

◆ Game()

Cytopia::Game::Game ( )

Creates a game.

Initializes all GameServices and starts the threads

Definition at line 33 of file Game.cxx.

34 {
35  LOG(LOG_DEBUG) << "Created Game Object";
36  initialize();
37 }
+ Here is the call graph for this function:

◆ ~Game()

virtual Cytopia::Game::~Game ( )
virtualdefault

Destroy a game.

Member Function Documentation

◆ initialize()

void Cytopia::Game::initialize ( )
virtual

starts setting up the game

starts game initialization.

Definition at line 55 of file Game.cxx.

56 {
57 #ifdef USE_MOFILEREADER
58  std::string moFilePath = fs::getBasePath();
59  moFilePath = moFilePath + "languages/" + Settings::instance().gameLanguage + "/Cytopia.mo";
60 
61  if (moFileLib::moFileReaderSingleton::GetInstance().ReadFile(moFilePath.c_str()) == moFileLib::moFileReader::EC_SUCCESS)
62  {
63  LOG(LOG_INFO) << "Loaded MO file " << moFilePath;
64  }
65  else
66  {
67  LOG(LOG_ERROR) << "Failed to load MO file " << moFilePath;
68  }
69 #endif
70 
71  // Register Callbacks
75 
76  // we need to instantiate the Map object to be able to send signals for new / load game
78 
79  LOG(LOG_DEBUG) << "Initialized Game Object";
80 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadGame()

void Cytopia::Game::loadGame ( const std::string fileName)
virtual

Definition at line 204 of file Game.cxx.

205 {
208 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newGame()

void Cytopia::Game::newGame ( bool  generateTerrain)
virtual

Definition at line 198 of file Game.cxx.

199 {
200  MapFunctions::instance().newMap(generateTerrain);
202 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quit()

void Cytopia::Game::quit ( )
private

Definition at line 39 of file Game.cxx.

40 {
41 #ifdef USE_AUDIO
42  auto &m_AudioMixer = AudioMixer::instance();
43  m_AudioMixer.stopAll();
44  if (!Settings::instance().audio3DStatus)
45  {
46  m_AudioMixer.play(SoundtrackID{"NegativeSelect"});
47  }
48  else
49  {
50  m_AudioMixer.play(SoundtrackID{"NegativeSelect"}, Coordinate3D{0, 0, -4});
51  }
52 #endif // USE_AUDIO
53 }
+ Here is the call graph for this function:

◆ run()

void Cytopia::Game::run ( bool  SkipMenu = false)
virtual

begins the game

starts running the game

Parameters
SkipMenuif the main menu should be skipped or not

Definition at line 82 of file Game.cxx.

83 {
85 
86  SDL_Event event;
87  EventManager &evManager = EventManager::instance();
88 
89  UIManager &uiManager = UIManager::instance();
90  uiManager.init();
91 
92  GameClock &gameClock = GameClock::instance();
93 
94 #ifdef USE_ANGELSCRIPT
95  ScriptEngine &scriptEngine = ScriptEngine::instance();
96  scriptEngine.init();
97  scriptEngine.loadScript(fs::getBasePath() + "/resources/test.as", ScriptCategory::BUILD_IN);
98 #endif
99 
100 #ifdef USE_AUDIO
101  if (!Settings::instance().audio3DStatus)
102  {
103  gameClock.addRealTimeClockTask(
104  []()
105  {
106  AudioMixer::instance().play(AudioTrigger::MainTheme);
107  return false;
108  },
109  0s, 8min);
110  gameClock.addRealTimeClockTask(
111  []()
112  {
113  AudioMixer::instance().play(AudioTrigger::NatureSounds);
114  return false;
115  },
116  0s, 3min);
117  }
118  else
119  {
120  gameClock.addRealTimeClockTask(
121  []()
122  {
123  AudioMixer::instance().play(AudioTrigger::MainTheme, Coordinate3D{0, 0.5, 0.1});
124  return false;
125  },
126  0s, 8min);
127  gameClock.addRealTimeClockTask(
128  []()
129  {
130  AudioMixer::instance().play(AudioTrigger::NatureSounds, Coordinate3D{0, 0, -2});
131  return false;
132  },
133  0s, 3min);
134  }
135 #endif // USE_AUDIO
136 
137  // FPS Counter variables
138  const float fpsIntervall = 1.0; // interval the fps counter is refreshed in seconds.
139  Uint32 fpsLastTime = SDL_GetTicks();
140  Uint32 fpsFrames = 0;
141 
142  uiManager.addPersistentMenu<GameTimeMenu>();
143  uiManager.addPersistentMenu<BuildMenu>();
144 
145  // GameLoop
146  while (!m_shutDown)
147  {
148 #ifdef MICROPROFILE_ENABLED
149  MICROPROFILE_SCOPEI("Map", "Gameloop", MP_GREEN);
150 #endif
151  SDL_RenderClear(WindowManager::instance().getRenderer());
152 
153  evManager.checkEvents(event);
154  gameClock.tick();
155 
156  // render the tileMap
157  if (MapFunctions::instance().getMap())
158  {
160  }
161 
162  // render the ui
163  // TODO: This is only temporary until the new UI is ready. Remove this afterwards
164  if (GameStates::instance().drawUI)
165  {
167  uiManager.drawUI();
168  }
169 #ifdef USE_ANGELSCRIPT
170  ScriptEngine::instance().framestep(1);
171 #endif
172 
173  // we need to instantiate the MapFunctions object so it's ready for new game
175 
176  fpsFrames++;
177 
178  if (fpsLastTime < SDL_GetTicks() - fpsIntervall * 1000)
179  {
180  fpsLastTime = SDL_GetTicks();
181  uiManager.setFPSCounterText("FPS: " + std::to_string(fpsFrames));
182  fpsFrames = 0;
183  }
184 
185 #ifdef MICROPROFILE_ENABLED
186  MicroProfileFlip(nullptr);
187 #endif
188  }
189 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shutdown()

void Cytopia::Game::shutdown ( )
virtual

ends the game

Definition at line 191 of file Game.cxx.

192 {
193  LOG(LOG_DEBUG) << "In shutdown";
194  TTF_Quit();
195  SDL_Quit();
196 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_GamePlay

GamePlay Cytopia::Game::m_GamePlay
private

Definition at line 59 of file Game.hxx.

◆ m_shutDown

bool Cytopia::Game::m_shutDown = false
private

Definition at line 57 of file Game.hxx.


The documentation for this class was generated from the following files:
MapFunctions::loadMapFromFile
void loadMapFromFile(const std::string &fileName)
Load Map from file.
Definition: MapFunctions.cxx:684
StrongType< string, struct SoundtrackIDTag >
GameClock
Game clock service. Implement two timers one real time timer and other game time timer.
Definition: GameClock.hxx:18
Cytopia::Game::loadGame
virtual void loadGame(const std::string &fileName)
Definition: Game.cxx:204
Camera::centerScreenOnMapCenter
void centerScreenOnMapCenter()
Centers camera on the middle of the map.
Definition: Camera.cxx:75
LOG
Definition: LOG.hxx:32
UIManager
Draws the UI to the screen.
Definition: UIManager.hxx:39
LOG_INFO
@ LOG_INFO
Definition: LOG.hxx:25
UIManager::setFPSCounterText
void setFPSCounterText(const std::string &fps)
Helper function to update the FPS Counter.
Definition: UIManager.cxx:142
Cytopia::Game::newGame
virtual void newGame(bool generateTerrain)
Definition: Game.cxx:198
UIManager::init
void init()
Parses the UiLayout.json files and creates UI Elements.
Coordinate3D
a 3-dimensional coordinate
Definition: AudioMixer.hxx:35
MapFunctions::getMap
Map * getMap()
Definition: MapFunctions.hxx:16
Map::renderMap
void renderMap() const
Render the elements contained in the Map.
Definition: Map.cxx:102
LOG_ERROR
@ LOG_ERROR
Definition: LOG.hxx:28
Cytopia::Game::m_shutDown
bool m_shutDown
Definition: Game.hxx:57
LOG_DEBUG
@ LOG_DEBUG
Definition: LOG.hxx:26
UIManager::drawUI
void drawUI()
Renders all UI Widgets.
Definition: UIManager.cxx:184
GameClock::tick
void tick(void)
This function provides the tick for both clocks.
Definition: GameClock.cxx:19
SettingsData::gameLanguage
std::string gameLanguage
the code for the current game language
Definition: Settings.hxx:145
GameTimeMenu
Definition: GameTimeMenu.hxx:6
BuildMenu
Definition: BuildMenu.hxx:74
getBasePath
std::string getBasePath()
Get base path (where Cytopia is being run)
Definition: Filesystem.cxx:77
EventManager::checkEvents
void checkEvents(SDL_Event &event)
Definition: EventManager.cxx:79
Cytopia::Game::m_GamePlay
GamePlay m_GamePlay
Definition: Game.hxx:59
MapFunctions::newMap
void newMap(bool generateTerrain=true)
Creates a new map object with terrain gen.
Definition: MapFunctions.cxx:671
WindowManager::renderScreen
void renderScreen()
Definition: WindowManager.cxx:231
SignalMediator::registerCbLoadGame
void registerCbLoadGame(std::function< void(const std::string &)> const &cb)
Definition: SignalMediator.hxx:36
SignalMediator::registerCbNewGame
void registerCbNewGame(std::function< void(bool)> const &cb)
Definition: SignalMediator.hxx:34
Signal::slot
std::function< R(Args...)> slot(instance &object, R(Class::*method)(Args...))
This function creates a std::function by binding object to the member function pointer method.
Definition: Signal.hxx:167
UIManager::addPersistentMenu
void addPersistentMenu(GameMenu::Ptr menu)
Definition: UIManager.cxx:174
SignalMediator::registerCbQuitGame
void registerCbQuitGame(std::function< void()> const &cb)
Definition: SignalMediator.hxx:35
AudioMixer::play
void play(const SoundtrackID &id, int effect=AL_EFFECT_NULL)
Plays a Soundtrack given its ID and optionally applies an effect.
Definition: AudioMixer.cxx:158
Singleton< Settings >::instance
static Settings & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
EventManager
Definition: EventManager.hxx:12
GamePlay::resetManagers
void resetManagers()
Definition: GamePlay.cxx:3
Cytopia::Game::initialize
virtual void initialize()
starts setting up the game
Definition: Game.cxx:55
GameClock::addRealTimeClockTask
GameClock::ClockTaskHndl addRealTimeClockTask(ClockCbk cbk, DelayType delay, PeriodType period=TimePointZero)
Add new real time clock task.
Definition: GameClock.inl.hxx:5
string
std::string string
Definition: AudioConfig.hxx:14
WindowManager::newImGuiFrame
void newImGuiFrame()
creates and renders a new ImGui frame
Definition: WindowManager.cxx:224