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/aurora/resman.h"
28 
29 #include "src/events/events.h"
30 
31 #include "src/sound/sound.h"
32 #include "src/sound/audiostream.h"
33 #include "src/sound/xactwavebank.h"
34 
36 
37 #include "src/engines/jade/game.h"
38 #include "src/engines/jade/jade.h"
41 #include "src/engines/jade/area.h"
43 
45 
47 
48 namespace Engines {
49 
50 namespace Jade {
51 
52 Game::Game(JadeEngine &engine, ::Engines::Console &console, Aurora::Platform platform) :
53  _engine(&engine), _platform(platform), _console(&console) {
54 
55  _functions.reset(new Functions(*this));
56 }
57 
59 }
60 
62  assert(_module);
63 
64  return *_module;
65 }
66 
67 void Game::run() {
68  try {
70  } catch (...) {
72  }
73 
74  _module.reset(new Module(*_console));
75 
76  while (!EventMan.quitRequested()) {
77  mainMenu();
78  runModule();
79  }
80 
81  _module.reset();
82 }
83 
86  fakePC->createFakePC();
87 
88  _module->usePC(fakePC.release());
89 
90  if (EventMan.quitRequested() || !_module->isLoaded()) {
91  _module->clear();
92  return;
93  }
94 
95  _module->enter();
96  EventMan.enableKeyRepeat(true);
97 
98  while (!EventMan.quitRequested() && _module->isRunning()) {
99  Events::Event event;
100  while (EventMan.pollEvent(event))
101  _module->addEvent(event);
102 
103  _module->processEventQueue();
104  EventMan.delay(10);
105  }
106 
107  EventMan.enableKeyRepeat(false);
108  _module->leave();
109 
110  _module->clear();
111 }
112 
114  stopMenuMusic();
115 
116  if (_musicBank) {
117  /* TODO: music.2da contains an entry for "mus_thm_MAINTHEME1", but this
118  * gives us a state number. We will probably need to throw that state
119  * number at the XACT SoundBank (xsb) somehow.
120  *
121  * Until that works, we'll get the main menu music by its index in the
122  * XACT WaveBank (xwb) instead.
123  */
124  static const size_t mainMenuMusic = 46;
125 
126  try {
127  Sound::AudioStream *stream = Sound::makeLoopingAudioStream(_musicBank->getWave(mainMenuMusic), 0);
128 
129  _menuMusic = SoundMan.playAudioStream(stream, Sound::kSoundTypeMusic);
130  SoundMan.startChannel(_menuMusic);
131 
132  } catch (...) {
134  }
135  }
136 }
137 
139  SoundMan.stopChannel(_menuMusic);
140 }
141 
143  EventMan.flushEvents();
144 
145  MainMenu menu(*_module, _console);
146 
147  _console->disableCommand("loadmodule", "not available in the main menu");
148  _console->disableCommand("exitmodule", "not available in the main menu");
149 
150  menu.show();
151  playMenuMusic();
152  menu.run();
153  stopMenuMusic();
154  menu.hide();
155 
156  _console->enableCommand("loadmodule");
157  _console->enableCommand("exitmodule");
158 }
159 
160 void Game::getModules(std::vector<Common::UString> &modules) {
161  modules.clear();
162 
163  std::list<Aurora::ResourceManager::ResourceID> ares;
164  ResMan.getAvailableResources(Aurora::kFileTypeARE, ares);
165 
166  for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator a = ares.begin(); a != ares.end(); ++a)
167  modules.push_back(a->name);
168 
169  std::sort(modules.begin(), modules.end(), Common::UString::iless());
170 }
171 
172 } // End of namespace Jade
173 
174 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Module & getModule()
Return the module context.
Definition: game.cpp:61
static XACTWaveBank * load(const Common::UString &name)
Load an XACT WaveBank, of either ASCII or Binary format.
Engine class handling Jade Empire.
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
Jade Empire engine functions.
The context handling the gameplay in Jade Empire.
uint32 run(uint32 startCode=kStartCodeNone)
Run the GUI.
Definition: gui.cpp:94
void show()
Show the GUI.
Definition: main.cpp:92
void hide()
Hide the GUI.
Definition: main.cpp:98
SDL_Event Event
Definition: types.h:42
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
void runModule()
Definition: game.cpp:84
void disableCommand(const Common::UString &cmd, const Common::UString &reason="")
Definition: console.cpp:972
void playMenuMusic()
Definition: game.cpp:113
Common::ScopedPtr< Module > _module
Definition: game.h:70
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:160
The global events manager.
The Jade Empire main menu.
The global sound manager, handling all sound output.
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
Jade (debug) console.
::Engines::Console * _console
Definition: game.h:75
An area.
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
A Jade module.
Definition: module.h:53
Common::ScopedPtr< Sound::XACTWaveBank > _musicBank
Definition: game.h:77
Generic audio input stream.
Definition: audiostream.h:70
void enableCommand(const Common::UString &cmd)
Definition: console.cpp:983
Static area data, GFF.
Definition: types.h:81
A module.
Generic Aurora engines utility functions.
AudioStream * makeLoopingAudioStream(RewindableAudioStream *stream, size_t loops)
Wrapper functionality to efficiently create a stream, which might be looped.
Common::ScopedPtr< Functions > _functions
Definition: game.h:71
Platform
Definition: types.h:429
Streaming audio.
void stopMenuMusic()
Definition: game.cpp:138
The global resource manager for Aurora resources.
Game(JadeEngine &engine, ::Engines::Console &console, Aurora::Platform platform)
Definition: game.cpp:52
Sound::ChannelHandle _menuMusic
Definition: game.h:78
An abstract XACT WaveBank, containing sound files.
A creature in a Jade Empire area.