xoreos  0.0.5
game.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/common/error.h"
28 #include "src/common/filelist.h"
29 #include "src/common/filepath.h"
30 
31 #include "src/aurora/resman.h"
32 #include "src/aurora/talkman.h"
33 
34 #include "src/events/events.h"
35 
41 
43 
44 namespace Engines {
45 
46 namespace DragonAge {
47 
49  _engine(&engine), _console(&console) {
50 
51  _functions.reset(new Functions(*this));
52 }
53 
55 }
56 
58  assert(_campaigns);
59 
60  return *_campaigns;
61 }
62 
63 void Game::run() {
64  _campaigns.reset(new Campaigns(*_console, *this));
65 
66  while (!EventMan.quitRequested()) {
67  runCampaigns();
68  }
69 
70  _campaigns.reset();
71 }
72 
74  const Campaign *singlePlayer = _campaigns->findCampaign("Single Player");
75  if (!singlePlayer)
76  throw Common::Exception("Can't find the default single player campaign");
77 
78  _campaigns->load(*singlePlayer);
79 
80  if (EventMan.quitRequested() || !_campaigns->isLoaded())
81  return;
82 
83  Creature *fakePC = new Creature;
84  fakePC->createFakePC();
85 
86  _campaigns->usePC(fakePC);
87  _campaigns->enter();
88 
89  EventMan.enableKeyRepeat(true);
90 
91  while (!EventMan.quitRequested() && _campaigns->isRunning()) {
92  Events::Event event;
93  while (EventMan.pollEvent(event))
94  _campaigns->addEvent(event);
95 
96  _campaigns->processEventQueue();
97  EventMan.delay(10);
98  }
99 
100  EventMan.enableKeyRepeat(false);
101  _campaigns->leave();
102  _campaigns->unload();
103 }
104 
105 void Game::loadResources(const Common::UString &dir, uint32 priority, ChangeList &res) {
106  indexOptionalDirectory(dir + "/data" , 0, 0, priority + 10, res);
107  indexOptionalDirectory(dir + "/data/abilities" , 0, 0, priority + 11, res);
108  indexOptionalDirectory(dir + "/data/movies" , 0, 0, priority + 12, res);
109  indexOptionalDirectory(dir + "/data/talktables", 0, 0, priority + 13, res);
110  indexOptionalDirectory(dir + "/data/cursors" , 0, 0, priority + 14, res);
111  indexOptionalDirectory(dir + "/textures" , 0, -1, priority + 15, res);
112  indexOptionalDirectory(dir + "/audio" , 0, -1, priority + 16, res);
113  indexOptionalDirectory(dir + "/env" , 0, -1, priority + 17, res);
114  indexOptionalDirectory(dir + "/patch" , 0, 0, priority + 18, res);
115 
116  loadResourceDir(dir + "/data" , priority + 100, res);
117  loadResourceDir(dir + "/data/abilities", priority + 200, res);
118 
119  loadResourceDir(dir + "/patch", 0x40000000 | priority, res);
120 
121  indexOptionalDirectory(dir + "/override", 0, -1, 0x40000000 | (priority + 499), res);
122 }
123 
124 void Game::loadTexturePack(const Common::UString &dir, uint32 priority,
125  ChangeList &res, TextureQuality quality) {
126 
127  static const char * const kTextureQualityName[kTextureQualityMAX] = { "high", "medium" };
128 
129  if (((uint)quality) >= kTextureQualityMAX)
130  throw Common::Exception("Invalid texture quality level");
131 
132  loadResourceDir(dir + "/textures/" + kTextureQualityName[quality], priority + 300, res);
133 }
134 
135 void Game::loadTalkTables(const Common::UString &dir, uint32 priority, ChangeList &res) {
137  _engine->getLanguage(language);
138 
139  loadTalkTables(dir, priority, res, language);
140 }
141 
142 void Game::loadTalkTables(const Common::UString &dir, uint32 priority, ChangeList &res,
143  Aurora::Language language) {
144 
145  if (EventMan.quitRequested())
146  return;
147 
148  const Common::UString tlkDir =
149  Common::FilePath::findSubDirectory(ResMan.getDataBase(), dir + "/data/talktables", true);
150 
151  Common::FileList files(tlkDir, 0);
152 
153  files.sort(true);
154  files.relativize(tlkDir);
155 
156  const Common::UString languageTLK = DragonAgeEngine::getLanguageString(language) + ".tlk";
157  for (Common::FileList::const_iterator f = files.begin(); f != files.end(); ++f) {
158  if (!f->toLower().endsWith(languageTLK))
159  continue;
160 
161  Common::UString tlk = *f;
162  tlk.truncate(tlk.size() - languageTLK.size());
163 
164  loadTalkTable(tlk, language, priority++, res);
165  }
166 }
167 
169  uint32 priority, ChangeList &changes) {
170 
172  Common::UString tlkF = tlk + DragonAgeEngine::getLanguageString(language) + "_f";
173 
174  changes.push_back(Common::ChangeID());
175  TalkMan.addTable(tlkM, tlkF, false, priority, &changes.back());
176 }
177 
178 void Game::loadResourceDir(const Common::UString &dir, uint32 priority, ChangeList &changes) {
179  if (EventMan.quitRequested())
180  return;
181 
182  Common::FileList files(Common::FilePath::findSubDirectory(ResMan.getDataBase(), dir, true), 0);
183 
184  files.sort(true);
185  files.relativize(ResMan.getDataBase());
186 
187  for (Common::FileList::const_iterator f = files.begin(); f != files.end(); ++f)
189  indexMandatoryArchive("/" + *f, priority++, changes);
190 }
191 
193  for (std::list<Common::ChangeID>::iterator t = changes.begin(); t != changes.end(); ++t)
194  TalkMan.removeTable(*t);
195 
196  changes.clear();
197 }
198 
199 } // End of namespace DragonAge
200 
201 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Game(DragonAgeEngine &engine, ::Engines::Console &console)
Definition: game.cpp:48
Common::ScopedPtr< Functions > _functions
Definition: game.h:82
static void loadResourceDir(const Common::UString &dir, uint32 priority, ChangeList &changes)
Definition: game.cpp:178
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
static void loadTexturePack(const Common::UString &dir, uint32 priority, ChangeList &res, TextureQuality quality)
Definition: game.cpp:124
A class holding an UTF-8 string.
Definition: ustring.h:48
bool getLanguage(Aurora::Language &language) const
Return the game&#39;s current language.
Definition: dragonage.cpp:122
Engine class handling Dragon Age: Origins.
static UString getExtension(const UString &p)
Return a file name&#39;s extension.
Definition: filepath.cpp:93
The context holding a Dragon Age: Origins campaign.
A creature in a Dragon Age: Origins area.
bool equalsIgnoreCase(const UString &str) const
Definition: ustring.cpp:218
Campaigns & getCampaigns()
Return the campaigns context.
Definition: game.cpp:57
void truncate(const iterator &it)
Definition: ustring.cpp:343
std::list< UString >::const_iterator const_iterator
Definition: filelist.h:37
Language
Definition: language.h:46
bool indexOptionalDirectory(const Common::UString &dir, const char *glob, int depth, uint32 priority, Common::ChangeID *changeID)
Add a directory to the resource manager, if it exists.
Definition: resources.cpp:133
static Common::UString getLanguageString(Aurora::Language language)
Return the string Dragon Age: Origins uses to representing this language.
Definition: dragonage.cpp:60
std::list< Common::ChangeID > ChangeList
Definition: resources.h:41
SDL_Event Event
Definition: types.h:42
Basic exceptions to throw.
void indexMandatoryArchive(const Common::UString &file, uint32 priority, const std::vector< byte > &password, Common::ChangeID *changeID)
Definition: resources.cpp:36
The context handling the gameplay in Dragon Age: Origins.
The global events manager.
Common::ScopedPtr< Campaigns > _campaigns
Definition: game.h:81
::Engines::Console * _console
Definition: game.h:84
StackException Exception
Definition: error.h:59
static void loadTalkTable(const Common::UString &tlk, Aurora::Language language, uint32 priority, ChangeList &changes)
Definition: game.cpp:168
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
void relativize(const Common::UString &basePath)
Express all files in this archive as relative to the given base path.
Definition: filelist.cpp:81
static void unloadTalkTables(ChangeList &changes)
Unload this set of talk tables.
Definition: game.cpp:192
static void loadResources(const Common::UString &dir, uint32 priority, ChangeList &res)
Load all game resource archives found in this directory.
Definition: game.cpp:105
size_t size() const
Return the size of the string, in characters.
Definition: ustring.cpp:241
A class representing an undoable change.
Definition: changeid.h:35
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
A list of files.
Definition: filelist.h:35
void loadTalkTables(const Common::UString &dir, uint32 priority, ChangeList &res)
Load all talk tables in the current language found in this directory.
Definition: game.cpp:135
Dragon Age: Origins engine functions.
const_iterator begin() const
Return a const_iterator pointing to the beginning of the list.
Definition: filelist.cpp:94
A list of files.
void sort(bool caseInsensitive)
Sort this list alphabetically.
Definition: filelist.cpp:74
The context managing and running the Dragon Age: Origins campaigns.
void createFakePC()
Create a fake player character creature for testing purposes.
Definition: creature.cpp:120
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
const_iterator end() const
Return a const_iterator pointing past the end of the list.
Definition: filelist.cpp:98
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318
unsigned int uint
Definition: types.h:211
DragonAgeEngine * _engine
Definition: game.h:79