xoreos  0.0.5
sonic.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/util.h"
28 #include "src/common/error.h"
29 #include "src/common/filelist.h"
30 #include "src/common/readstream.h"
31 #include "src/common/configman.h"
32 
33 #include "src/aurora/resman.h"
34 #include "src/aurora/language.h"
35 #include "src/aurora/talkman.h"
36 #include "src/aurora/ndsrom.h"
37 
38 #include "src/events/events.h"
39 
40 #include "src/graphics/graphics.h"
41 #include "src/graphics/font.h"
42 
45 
50 
56 #include "src/engines/sonic/game.h"
57 
58 namespace Engines {
59 
60 namespace Sonic {
61 
63  _console.reset(new Console(*this));
64 }
65 
67 }
68 
70  switch (language) {
72  return "test_e";
74  return "test_f";
76  return "test_g";
78  return "test_i";
80  return "test_s";
82  return "test_j";
83  default:
84  break;
85  }
86 
87  return "";
88 }
89 
91  switch (language) {
93  return "strings";
95  return "strings_fr-fr";
97  return "strings_de-de";
99  return "strings_it-it";
101  return "strings_es-es";
103  return "strings_ja-jp";
104  default:
105  break;
106  }
107 
108  return "";
109 }
110 
112  Aurora::Platform UNUSED(platform),
113  std::vector<Aurora::Language> &languages) const {
114  try {
115  Aurora::NDSFile nds(target);
116 
117  for (size_t i = 0; i < Aurora::kLanguageMAX; i++) {
120  if (herf.empty() || tlk.empty())
121  continue;
122 
123  if (!nds.hasResource(herf + ".herf") || !nds.hasResource(tlk + ".tlk"))
124  continue;
125 
126  languages.push_back((Aurora::Language) i);
127  }
128 
129  } catch (...) {
130  }
131 
132  return true;
133 }
134 
136  language = _language;
137  return true;
138 }
139 
141  Aurora::Language language;
142  if (!evaluateLanguage(false, language))
143  return false;
144 
145  if (_language == language)
146  return true;
147 
148  try {
149 
150  loadLanguageFiles(language);
151  _language = language;
152 
153  } catch (...) {
154 
155  // Roll back
157  return false;
158 
159  }
160 
161  return true;
162 }
163 
165  assert(_game);
166 
167  return *_game;
168 }
169 
171  init();
172  if (EventMan.quitRequested())
173  return;
174 
175  CursorMan.hideCursor();
176  CursorMan.set();
177  CursorMan.showCursor();
178 
179  _game.reset(new Game(*this, *_console));
180  _game->run();
181 
182  deinit();
183 }
184 
187  GfxMan.setGUISize(kScreenWidth, 2 * kScreenHeight);
188 
189  // Force to the screen size of the Nintendo DS (2 screens of 256x192)
190  WindowMan.setWindowSize(kScreenWidth, 2 * kScreenHeight);
191 
192  LoadProgress progress(8);
193 
194  progress.step("Declare languages");
196 
197  if (evaluateLanguage(true, _language))
198  status("Setting the language to %s", LangMan.getLanguageName(_language).c_str());
199  else
200  warning("Failed to detect this game's language");
201 
202  progress.step("Loading user game config");
203  initConfig();
204 
205  initResources(progress);
206  if (EventMan.quitRequested())
207  return;
208 
209  progress.step("Initializing internal game config");
210  initGameConfig();
211 
212  progress.step("Successfully initialized the engine");
213 }
214 
216  static const Aurora::LanguageManager::Declaration kLanguageDeclarations[] = {
223  };
224 
225  LangMan.addLanguages(kLanguageDeclarations, ARRAYSIZE(kLanguageDeclarations));
226 }
227 
229  ResMan.setHasSmall(true);
230  ResMan.setHashAlgo(Common::kHashDJB2);
231 
232  progress.step("Indexing the ROM file");
233  ResMan.registerDataBase(_target);
234 
235  progress.step("Indexing the main HERF file");
236  indexMandatoryArchive("test.herf", 10);
237 
238  loadLanguageFiles(progress, _language);
239 
240  progress.step("Registering files and formats");
244 
245  GfxMan.setOrthogonal(0.0f, 1000.0f);
246  GfxMan.setCullFace(false);
247 }
248 
250  for (size_t i = 0; i < ARRAYSIZE(kFiles); i++)
251  ResMan.declareResource(kFiles[i]);
252 }
253 
255  TalkMan.removeTable(_languageTLK);
256 
258 }
259 
261  progress.step(Common::UString::format("Indexing language files (%s)",
262  LangMan.getLanguageName(language).c_str()));
263 
264  loadLanguageFiles(language);
265 }
266 
269  LangMan.setCurrentLanguage(language);
270 
271  Common::UString herf = getLanguageHERF(language) + ".herf";
272 
274 
275  Common::UString tlk = getLanguageTLK(language);
276 
277  TalkMan.addTable(tlk, "", false, 0, &_languageTLK);
278 }
279 
281 }
282 
284 }
285 
287  _game.reset();
288 
290 }
291 
292 } // End of namespace Sonic
293 
294 } // End of namespace Engines
static const float kScreenHeight
Definition: types.h:35
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
GameID
Definition: types.h:393
Generic Aurora engines resource utility functions.
The global graphics manager.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
NFTR font, used by Sonic.
Definition: fontman.h:50
A class holding an UTF-8 string.
Definition: ustring.h:48
The global config manager.
void initResources(LoadProgress &progress)
Definition: sonic.cpp:228
Common::ScopedPtr< Console > _console
Definition: engine.h:87
bool evaluateLanguage(bool find, Aurora::Language &language) const
Definition: engine.cpp:198
bool changeLanguage()
Change the game&#39;s current language.
Definition: sonic.cpp:140
djb2 hash function by Daniel J. Bernstein.
Definition: hash.h:39
Aurora::Language _language
Definition: sonic.h:65
void run()
Run the game.
Definition: sonic.cpp:170
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
The context handling the gameplay in Sonic Chronicles: The Dark Brotherhood.
Engine class handling Sonic Chronicles: The Dark Brotherhood.
Language
Definition: language.h:46
bool hasResource(Common::UString name) const
Does the Nintendo DS ROM contain a certain resource?
Definition: ndsrom.cpp:141
The Aurora font manager.
Basic Sonic Chronicles: The Dark Brotherhood types and defines.
void deindexResources(Common::ChangeID &changeID)
Remove previously added resources from the ResourceManager.
Definition: resources.cpp:164
bool getLanguage(Aurora::Language &language) const
Return the game&#39;s current language.
Definition: sonic.cpp:135
Sonic Chronicles: The Dark Brotherhood (debug) console.
Basic exceptions to throw.
void indexMandatoryArchive(const Common::UString &file, uint32 priority, const std::vector< byte > &password, Common::ChangeID *changeID)
Definition: resources.cpp:36
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
Game & getGame()
Return the context running the actual game.
Definition: sonic.cpp:164
static const float kScreenWidth
Definition: types.h:34
The global events manager.
Types and functions related to language.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
static const char *const kFiles[]
Definition: files.h:32
void warning(const char *s,...)
Definition: util.cpp:33
#define CursorMan
Shortcut for accessing the cursor manager.
Definition: cursorman.h:129
Basic reading stream interfaces.
static Common::UString getLanguageHERF(Aurora::Language language)
Definition: sonic.cpp:69
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
The Aurora cursor manager.
Displaying the progress in loading a game.
Nintendo DS ROM parsing.
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
Common::UString _target
Definition: engine.h:85
bool detectLanguages(Aurora::GameID game, const Common::UString &target, Aurora::Platform platform, std::vector< Aurora::Language > &languages) const
Detect which languages this game instance supports.
Definition: sonic.cpp:111
void registerModelLoader(ModelLoader *loader)
Definition: model.cpp:37
#define LangMan
Shortcut for accessing the language manager.
Definition: language.h:275
Common::ChangeID _languageTLK
Definition: sonic.h:68
The global talk manager for Aurora strings.
Common::ScopedPtr< Game > _game
Definition: sonic.h:70
void step(const Common::UString &description)
Take a step in advancing the progress.
void status(const char *s,...)
Definition: util.cpp:52
Common::ChangeID _languageHERF
Definition: sonic.h:67
Generic Aurora engines utility functions.
All currently known resource file names in Sonic Chronicles: The Dark Brotherhood.
A list of files.
static Common::UString getLanguageTLK(Aurora::Language language)
Definition: sonic.cpp:90
A class encapsulating Nintendo DS ROM access.
Definition: ndsrom.h:45
void loadLanguageFiles(LoadProgress &progress, Aurora::Language language)
Definition: sonic.cpp:260
Windows codepage 1252 (Western European, Latin alphabet).
Definition: encoding.h:51
Sonic Chronicles: The Dark Brotherhood model loader.
Platform
Definition: types.h:429
A font.
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
The global resource manager for Aurora resources.
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
Generic Aurora engines model functions.