ScummVM
lastexpress.cpp
Go to the documentation of this file.
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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 this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
24 
26 #include "lastexpress/data/font.h"
27 
28 #include "lastexpress/game/logic.h"
30 #include "lastexpress/game/state.h"
31 
32 #include "lastexpress/menu/menu.h"
33 
36 
37 #include "lastexpress/graphics.h"
38 #include "lastexpress/helpers.h"
39 #include "lastexpress/resource.h"
40 
41 #include "common/config-manager.h"
42 #include "common/debug-channels.h"
43 #include "common/error.h"
44 #include "common/fs.h"
45 
46 #include "engines/util.h"
47 
48 const char *g_actionNames[] = {"None", "Action1", "Action2", "ExitCompartment", "Action4", "ExcuseMeCath", "ExcuseMe", "INVALID", "Knock", "OpenDoor", "Action10", "Action11", "Default", "INVALID", "INVALID", "INVALID", "Action16", "DrawScene", "Callback"};
49 const char *g_directionNames[] = { "None", "Up", "Down", "Left", "Right", "Switch"};
50 const char *g_entityNames[] = { "Player", "Anna", "August", "Mertens", "Coudert", "Pascale", "Waiter1", "Waiter2", "Cooks", "Verges", "Tatiana", "Vassili", "Alexei", "Abbot", "Milos", "Vesna", "Ivo", "Salko", "Kronos", "Kahina", "Francois", "MmeBoutarel", "Boutarel", "Rebecca", "Sophie", "Mahmud", "Yasmin", "Hadija", "Alouan", "Gendarmes", "Max", "Chapters", "Train", "Tables0", "Tables1", "Tables2", "Tables3", "Tables4", "Tables5", "Entity39"};
51 
52 
53 namespace LastExpress {
54 
56  Engine(syst), _gameDescription(gd),
57  _debugger(NULL), _random("lastexpress"), _cursor(NULL),
58  _font(NULL), _logic(NULL), _menu(NULL),
59  _lastFrameCount(0),
60  _graphicsMan(NULL), _resMan(NULL),
61  _sceneMan(NULL), _soundMan(NULL),
62  _eventMouse(NULL), _eventTick(NULL),
63  _eventMouseBackup(NULL), _eventTickBackup(NULL)
64  {
65  // Setup mixer
67 
68  // Adding the default directories
69  const Common::FSNode gameDataDir(ConfMan.get("path"));
70  SearchMan.addSubDirectoryMatching(gameDataDir, "data");
71 
72  // Initialize the custom debug levels
73  DebugMan.addDebugChannel(kLastExpressDebugGraphics, "Graphics", "Debug graphics & animation/sequence playback");
74  DebugMan.addDebugChannel(kLastExpressDebugResource, "Resource", "Debug resource management");
75  DebugMan.addDebugChannel(kLastExpressDebugCursor, "Cursor", "Debug cursor handling");
76  DebugMan.addDebugChannel(kLastExpressDebugSound, "Sound", "Debug sound playback");
77  DebugMan.addDebugChannel(kLastExpressDebugSubtitle, "Subtitle", "Debug subtitles");
78  DebugMan.addDebugChannel(kLastExpressDebugSavegame, "Savegame", "Debug savegames");
79  DebugMan.addDebugChannel(kLastExpressDebugLogic, "Logic", "Debug logic");
80  DebugMan.addDebugChannel(kLastExpressDebugScenes, "Scenes", "Debug scenes & hotspots");
81  DebugMan.addDebugChannel(kLastExpressDebugUnknown, "Unknown", "Debug unknown data");
82 }
83 
85  // Delete the remaining objects
86  SAFE_DELETE(_cursor);
87  SAFE_DELETE(_font);
88  SAFE_DELETE(_logic);
89  SAFE_DELETE(_menu);
90  SAFE_DELETE(_graphicsMan);
91  SAFE_DELETE(_resMan);
92  SAFE_DELETE(_sceneMan);
93  SAFE_DELETE(_soundMan);
94  //_debugger is deleted by Engine
95 
96  // Cleanup event handlers
97  SAFE_DELETE(_eventMouse);
98  SAFE_DELETE(_eventTick);
99  SAFE_DELETE(_eventMouseBackup);
100  SAFE_DELETE(_eventTickBackup);
101 
102  // Zero passed pointers
103  _gameDescription = NULL;
104 }
105 
106 // TODO: which error should we return when some game files are missing/corrupted?
108  // Initialize the graphics
109  const Graphics::PixelFormat dataPixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
110  initGraphics(640, 480, &dataPixelFormat);
111 
112  // We do not support color conversion
113  if (_system->getScreenFormat() != dataPixelFormat)
115 
116  // Create debugger. It requires GFX to be initialized
117  _debugger = new Debugger(this);
119 
120  // Start the resource and graphics managers
121  _resMan = new ResourceManager(isDemo());
124 
126 
127  // Load the cursor data
129  if (!_cursor)
131 
132  // Load the font data
133  _font = _resMan->loadFont();
134  if (!_font)
136 
137  // Start scene manager
138  _sceneMan = new SceneManager(this);
140 
141  // Game logic
142  _logic = new Logic(this);
143 
144  // Sound manager
145  _soundMan = new SoundManager(this);
146 
147  // Menu
148  _menu = new Menu(this);
149  _menu->show(false, kSavegameTypeIndex, 0);
150 
151  while (!shouldQuit()) {
154 
155  if (handleEvents())
156  continue;
157  }
158 
159  return Common::kNoError;
160 }
161 
163  // the original game has a timer running at 60Hz incrementing a dedicated variable
164  return (uint64)_system->getMillis() * 60 / 1000;
165 }
166 
168  Common::Event ev;
169  if (!_eventMan->pollEvent(ev))
170  return;
171 
172  switch (ev.type) {
175  break;
176 
179  break;
180 
181  default:
182  break;
183  }
184 }
185 
187  // Make sure all the subsystems have been initialized
188  if (!_debugger || !_graphicsMan)
189  error("[LastExpressEngine::handleEvents] Called before the required subsystems have been initialized");
190 
191  // Execute stored commands
192  if (_debugger->hasCommand()) {
194 
195  // re-attach the debugger
196  _debugger->attach();
197  }
198 
199  // Handle input
200  Common::Event ev;
201  while (_eventMan->pollEvent(ev)) {
202  switch (ev.type) {
203 
206  //if (ev.kbd.keycode == Common::KEYCODE_ESCAPE)
207  // quitGame();
208 
209  break;
210 
212  // Closing the GMM
213 
218 
219  {
220  // Adjust frameInterval flag
221  uint32 frameCounter = getFrameCounter();
222  if (frameCounter < _lastFrameCount + 30)
224  _lastFrameCount = frameCounter;
225  }
226 
227  if (_eventMouse && _eventMouse->isValid())
228  (*_eventMouse)(ev);
229  break;
230 
235 
236  if (_eventMouse && _eventMouse->isValid())
237  (*_eventMouse)(ev);
238  break;
239 
241  if (_eventMouse && _eventMouse->isValid())
242  (*_eventMouse)(ev);
243  break;
244 
245  case Common::EVENT_QUIT:
246  quitGame();
247  break;
248 
249  default:
250  break;
251  }
252  }
253 
254  // Game tick event
255  if (_eventTick && _eventTick->isValid())
256  (*_eventTick)(ev);
257 
258  // Update the screen
259  _graphicsMan->update();
261  _system->delayMillis(50);
262 
263  // The event loop may have triggered the quit status. In this case,
264  // stop the execution.
265  if (shouldQuit()) {
266  return true;
267  }
268 
269  return false;
270 }
271 
276  if (_eventMouseBackup != NULL || _eventTickBackup != NULL)
277  error("[LastExpressEngine::backupEventHandlers] backup event handlers are already set");
278 
281 }
282 
284  if (_eventMouseBackup == NULL || _eventTickBackup == NULL)
285  error("[LastExpressEngine::restoreEventHandlers] restore called before backing up the event handlers");
286 
287  // Cleanup previous event handlers
288  SAFE_DELETE(_eventMouse);
289  SAFE_DELETE(_eventTick);
290 
293 
294  _eventMouseBackup = NULL;
295  _eventTickBackup = NULL;
296 }
297 
300  SAFE_DELETE(_eventMouse);
301 
303  SAFE_DELETE(_eventTick);
304 
305  _eventMouse = mouse;
306  _eventTick = tick;
307 }
308 
313  return (f == kSupportsRTL);
314 }
315 
316 } // End of namespace LastExpress
LastExpress::SoundQueue::updateQueue
void updateQueue()
Definition: queue.cpp:81
menu.h
OSystem::updateScreen
virtual void updateScreen()=0
Flush the whole screen, that is render the current content of the screen framebuffer to the display.
LastExpress::State::Flags::mouseRightClick
bool mouseRightClick
Definition: state.h:574
Glk::Level9::f
FILE * f
Definition: level9_main.cpp:155
LastExpress::LastExpressEngine::_resMan
ResourceManager * _resMan
Definition: lastexpress.h:128
LastExpress::LastExpressEngine::hasFeature
bool hasFeature(EngineFeature f) const override
Misc Engine.
Definition: lastexpress.cpp:312
Engine
Definition: engine.h:60
LastExpress::LastExpressEngine::_eventTickBackup
EventHandler::EventFunction * _eventTickBackup
Definition: lastexpress.h:137
Common::Event::type
EventType type
The type of the event.
Definition: events.h:173
lastexpress.h
queue.h
LastExpress::Logic::getGameState
State * getGameState()
Definition: logic.h:62
LastExpress::kLastExpressDebugSavegame
Definition: debug.h:40
g_entityNames
const char * g_entityNames[]
Definition: lastexpress.cpp:50
OSystem::getScreenFormat
virtual Graphics::PixelFormat getScreenFormat() const =0
Determine the pixel format currently in use for screen rendering.
LastExpress::LastExpressEngine::_sceneMan
SceneManager * _sceneMan
Definition: lastexpress.h:129
util.h
Engine::shouldQuit
static bool shouldQuit()
Return whether the ENGINE should quit respectively should return to the launcher.
Definition: engine.cpp:791
Common::EventManager::pollEvent
virtual bool pollEvent(Event &event)=0
Get the next event in the event queue.
Engine::_system
OSystem * _system
Definition: engine.h:62
LastExpress::LastExpressEngine::backupEventHandlers
void backupEventHandlers()
Event Handling.
Definition: lastexpress.cpp:275
Engine::setDebugger
void setDebugger(GUI::Debugger *debugger)
Sets the engine's debugger.
Definition: engine.h:196
Common::EVENT_LBUTTONUP
Definition: events.h:54
g_directionNames
const char * g_directionNames[]
Definition: lastexpress.cpp:49
LastExpress::LastExpressEngine::_logic
Logic * _logic
Definition: lastexpress.h:120
uint64
unsigned long long uint64
Definition: osys_n64_base.cpp:36
LastExpress::Debugger
Definition: debug.h:48
LastExpress::LastExpressEngine::_eventTick
EventHandler::EventFunction * _eventTick
Definition: lastexpress.h:134
font.h
config-manager.h
LastExpress::LastExpressEngine::~LastExpressEngine
~LastExpressEngine() override
Definition: lastexpress.cpp:84
LastExpress::LastExpressEngine::LastExpressEngine
LastExpressEngine(OSystem *syst, const ADGameDescription *gd)
Definition: lastexpress.cpp:55
uint32
unsigned int uint32
Definition: cdtypes.h:26
LastExpress::SoundManager
Definition: sound.h:35
LastExpress::LastExpressEngine::_gameDescription
const ADGameDescription * _gameDescription
Definition: lastexpress.h:110
Common::Error
An Error instance pairs an error code with string description providing more details about the error.
Definition: error.h:77
error
void NORETURN_PRE error(const char *s,...)
Definition: textconsole.cpp:67
error.h
LastExpress::LastExpressEngine::pollEvents
void pollEvents()
Definition: lastexpress.cpp:167
LastExpress::Menu::show
void show(bool doSavegame, SavegameType type, uint32 value)
Definition: menu.cpp:297
logic.h
LastExpress::LastExpressEngine::handleEvents
bool handleEvents()
Definition: lastexpress.cpp:186
LastExpress::LastExpressEngine::_soundMan
SoundManager * _soundMan
Definition: lastexpress.h:130
LastExpress::ResourceManager
Definition: resource.h:37
Common::EVENT_QUIT
Definition: events.h:66
Common::EVENT_RBUTTONDOWN
Definition: events.h:55
Engine::syncSoundSettings
virtual void syncSoundSettings()
Notify the engine that the sound settings in the config manager may have changed and that it hence sh...
Definition: engine.cpp:627
LastExpress::LastExpressEngine::_font
Font * _font
Definition: lastexpress.h:119
ADGameDescription
Definition: advancedDetector.h:83
LastExpress::LastExpressEngine::getGameLogic
Logic * getGameLogic() const
Definition: lastexpress.h:86
LastExpress::LastExpressEngine::_debugger
Debugger * _debugger
Definition: lastexpress.h:114
LastExpress::LastExpressEngine::getFrameCounter
uint32 getFrameCounter() const
Definition: lastexpress.cpp:162
LastExpress::kLastExpressDebugSubtitle
Definition: debug.h:39
LastExpress::LastExpressEngine::isDemo
bool isDemo() const
Definition: detection.cpp:256
sound.h
Engine::kSupportsRTL
'Return to launcher' feature is supported, i.e., EVENT_RTL is handled either directly,...
Definition: engine.h:136
LastExpress::kLastExpressDebugResource
Definition: debug.h:36
LastExpress::State::Flags::mouseRightPressed
bool mouseRightPressed
Definition: state.h:577
Common::EVENT_KEYDOWN
A key was pressed, details in Event::kbd.
Definition: events.h:48
Engine::EngineFeature
EngineFeature
A feature in this context means an ability of the engine which can be either available or not.
Definition: engine.h:124
fs.h
LastExpress
This is the namespace of the LastExpress engine.
Definition: animation.cpp:40
LastExpress::Debugger::callCommand
void callCommand()
Definition: debug.cpp:152
LastExpress::State::getGameFlags
Flags * getGameFlags()
Definition: state.h:641
LastExpress::LastExpressEngine::_eventMouseBackup
EventHandler::EventFunction * _eventMouseBackup
Definition: lastexpress.h:136
Engine::quitGame
static void quitGame()
Request the engine to quit.
Definition: engine.cpp:784
OSystem::delayMillis
virtual void delayMillis(uint msecs)=0
Delay/sleep for the specified amount of milliseconds.
LastExpress::ResourceManager::loadFont
Font * loadFont() const
Definition: resource.cpp:226
Common::Functor1::isValid
virtual bool isValid() const =0
OSystem::getMillis
virtual uint32 getMillis(bool skipRecord=false)=0
Get the number of milliseconds since the program was started.
LastExpress::GraphicsManager::update
void update()
Definition: graphics.cpp:55
LastExpress::LastExpressEngine::restoreEventHandlers
void restoreEventHandlers()
Definition: lastexpress.cpp:283
graphics.h
LastExpress::LastExpressEngine::_lastFrameCount
uint32 _lastFrameCount
Definition: lastexpress.h:124
scenes.h
resource.h
Common::FSNode
FSNode, short for "File System Node", provides an abstraction for file paths, allowing for portable f...
Definition: fs.h:58
LastExpress::LastExpressEngine::_cursor
Cursor * _cursor
Definition: lastexpress.h:118
LastExpress::kSavegameTypeIndex
Definition: shared.h:586
LastExpress::Logic
Definition: logic.h:44
LastExpress::SoundQueue::updateSubtitles
void updateSubtitles()
Definition: queue.cpp:261
LastExpress::Menu
Definition: menu.h:43
state.h
LastExpress::LastExpressEngine::setEventHandlers
void setEventHandlers(EventHandler::EventFunction *eventMouse, EventHandler::EventFunction *eventTick)
Definition: lastexpress.cpp:298
LastExpress::kLastExpressDebugSound
Definition: debug.h:38
LastExpress::kLastExpressDebugLogic
Definition: debug.h:41
helpers.h
Engine::_eventMan
Common::EventManager * _eventMan
Definition: engine.h:67
LastExpress::Debugger::hasCommand
bool hasCommand() const
Definition: debug.cpp:112
LastExpress::GraphicsManager
Definition: graphics.h:30
LastExpress::State::Flags::mouseLeftPressed
bool mouseLeftPressed
Definition: state.h:576
LastExpress::State::Flags::mouseLeftClick
bool mouseLeftClick
Definition: state.h:573
Common::EVENT_MAINMENU
Definition: events.h:62
Common::Event
Data structure for an event.
Definition: events.h:170
LastExpress::SoundManager::getQueue
SoundQueue * getQueue()
Definition: sound.h:67
LastExpress::kLastExpressDebugScenes
Definition: debug.h:42
LastExpress::SceneManager
Definition: scenes.h:38
LastExpress::kLastExpressDebugGraphics
Definition: debug.h:35
LastExpress::LastExpressEngine::_menu
Menu * _menu
Definition: lastexpress.h:121
Common::EVENT_RBUTTONUP
Definition: events.h:56
LastExpress::State::Flags::frameInterval
bool frameInterval
Definition: state.h:568
OSystem
Interface for ScummVM backends.
Definition: system.h:114
Common::kNoError
No error occurred.
Definition: error.h:45
LastExpress::kLastExpressDebugCursor
Definition: debug.h:37
LastExpress::kArchiveCd1
Definition: shared.h:465
LastExpress::ResourceManager::loadArchive
bool loadArchive(ArchiveIndex type)
Definition: resource.cpp:72
Common::kNoGameDataFoundError
Engine initialization: No game data was found in the specified location.
Definition: error.h:46
LastExpress::kLastExpressDebugUnknown
Definition: debug.h:43
Common::EVENT_LBUTTONDOWN
Definition: events.h:53
LastExpress::LastExpressEngine::run
Common::Error run() override
Init the engine and start its main loop.
Definition: lastexpress.cpp:107
cursor.h
initGraphics
void initGraphics(int width, int height, const Graphics::PixelFormat *format)
Definition: engine.cpp:288
g_actionNames
const char * g_actionNames[]
Definition: lastexpress.cpp:48
LastExpress::ResourceManager::loadCursor
Cursor * loadCursor() const
Definition: resource.cpp:209
GUI::Debugger::attach
virtual void attach(const char *entry=nullptr)
'Attach' the debugger.
Definition: debugger.cpp:157
LastExpress::LastExpressEngine::_eventMouse
EventHandler::EventFunction * _eventMouse
Definition: lastexpress.h:133
Graphics::PixelFormat
A pixel format description.
Definition: pixelformat.h:136
LastExpress::SceneManager::loadSceneDataFile
void loadSceneDataFile(ArchiveIndex archive)
Definition: scenes.cpp:70
debug-channels.h
LastExpress::LastExpressEngine::_graphicsMan
GraphicsManager * _graphicsMan
Definition: lastexpress.h:127
Common::EVENT_MOUSEMOVE
The mouse moved, details in Event::mouse.
Definition: events.h:52
Common::Functor1
Generic functor object for unary function objects.
Definition: func.h:428
Common::kUnsupportedColorMode
Engine initialization: Engine does not support backend's color mode.
Definition: error.h:48