xoreos  0.0.5
gamethread.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <cassert>
26 
27 #include "src/version/version.h"
28 
29 #include "src/common/util.h"
30 #include "src/common/error.h"
31 #include "src/common/ustring.h"
32 #include "src/common/configman.h"
33 
34 #include "src/engines/gamethread.h"
36 
37 #include "src/graphics/windowman.h"
38 
39 #include "src/events/events.h"
40 
41 namespace Engines {
42 
44 }
45 
47  destroyThread();
48 }
49 
50 void GameThread::init(const Common::UString &baseDir, const std::list<const EngineProbe *> &probes) {
51  // Detecting the game
52 
53  _game.reset(EngineMan.probeGame(baseDir, probes));
54  if (!_game)
55  throw Common::Exception("Unable to detect the game");
56 
57  // Get the game description from the config, or alternatively
58  // construct one from the game name and platform.
59  Common::UString description;
60  if (!ConfigMan.getKey("description", description))
61  description = _game->getGameName(true);
62 
63  WindowMan.setWindowTitle(Common::UString(Version::getProjectName()) + " -- " + description);
64 
65  status("Detected game \"%s\"", _game->getGameName(false).c_str());
66 }
67 
69  if (ConfigMan.getBool("listlangs", false)) {
70  assert(_game);
71 
72  EngineMan.listLanguages(*_game);
73 
74  EventMan.requestQuit();
75  EventMan.doQuit();
76  return;
77  }
78 
79  if (!createThread("GameInstance"))
80  throw Common::Exception("Failed creating game logic thread");
81 }
82 
84  assert(_game);
85 
86  try {
87  EngineMan.run(*_game);
88  } catch (...) {
90  }
91 
92  EventMan.doQuit();
93 }
94 
95 } // End of namespace Engines
The thread the game logic runs in.
void init(const Common::UString &baseDir, const std::list< const EngineProbe *> &probes)
Definition: gamethread.cpp:50
A class holding an UTF-8 string.
Definition: ustring.h:48
bool destroyThread()
Definition: thread.cpp:64
The global config manager.
The global window manager.
#define EngineMan
Shortcut for accessing the sound manager.
Definition: enginemanager.h:74
Basic exceptions to throw.
bool createThread(const UString &name="")
Definition: thread.cpp:44
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
Utility templates and functions.
Basic xoreos version information.
The global events manager.
StackException Exception
Definition: error.h:59
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
Unicode string handling.
Common::ScopedPtr< GameInstance > _game
Definition: gamethread.h:49
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
void exceptionDispatcherError(const char *s,...)
Exception dispatcher that prints the exception as an error, and adds another reason on top...
Definition: error.cpp:143
void status(const char *s,...)
Definition: util.cpp:52
The global engine manager, omniscient about all engines.
const char * getProjectName()
Definition: version.cpp:84