2008-11-14 21:32:20 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-06-07 17:14:42 +00:00
|
|
|
#include "groovie/groovie.h"
|
|
|
|
#include "groovie/cursor.h"
|
|
|
|
#include "groovie/detection.h"
|
|
|
|
#include "groovie/graphics.h"
|
|
|
|
#include "groovie/music.h"
|
|
|
|
#include "groovie/resource.h"
|
|
|
|
#include "groovie/roq.h"
|
|
|
|
#include "groovie/vdx.h"
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
#include "common/config-manager.h"
|
2010-05-04 11:59:22 +00:00
|
|
|
#include "common/debug-channels.h"
|
2008-11-14 21:32:20 +00:00
|
|
|
#include "common/events.h"
|
2010-05-11 15:41:31 +00:00
|
|
|
#include "common/macresman.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
|
2010-11-08 23:07:42 +00:00
|
|
|
#include "backends/audiocd/audiocd.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
#include "engines/util.h"
|
2010-06-07 17:14:42 +00:00
|
|
|
#include "graphics/fontman.h"
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/mixer.h"
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
namespace Groovie {
|
|
|
|
|
2009-02-15 10:32:06 +00:00
|
|
|
GroovieEngine::GroovieEngine(OSystem *syst, const GroovieGameDescription *gd) :
|
2009-09-24 10:58:00 +00:00
|
|
|
Engine(syst), _gameDescription(gd), _debugger(NULL), _script(NULL),
|
2009-01-08 23:06:08 +00:00
|
|
|
_resMan(NULL), _grvCursorMan(NULL), _videoPlayer(NULL), _musicPlayer(NULL),
|
2010-06-07 17:14:42 +00:00
|
|
|
_graphicsMan(NULL), _macResFork(NULL), _waitingForInput(false), _font(NULL) {
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Adding the default directories
|
2010-05-04 11:56:52 +00:00
|
|
|
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "groovie");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "media");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "system");
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Initialize the custom debug levels
|
2010-04-27 21:40:52 +00:00
|
|
|
DebugMan.addDebugChannel(kGroovieDebugAll, "All", "Debug everything");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugVideo, "Video", "Debug video and audio playback");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugResource, "Resource", "Debug resouce management");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugScript, "Script", "Debug the scripts");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugUnknown, "Unknown", "Report values of unknown data in files");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugHotspots, "Hotspots", "Show the hotspots");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugCursor, "Cursor", "Debug cursor decompression / switching");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugMIDI, "MIDI", "Debug MIDI / XMIDI files");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugScriptvars, "Scriptvars", "Print out any change to script variables");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugCell, "Cell", "Debug the cell game (in the microscope)");
|
|
|
|
DebugMan.addDebugChannel(kGroovieDebugFast, "Fast", "Play videos quickly, with no sound (unstable)");
|
2008-11-14 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GroovieEngine::~GroovieEngine() {
|
|
|
|
// Delete the remaining objects
|
|
|
|
delete _debugger;
|
|
|
|
delete _resMan;
|
2009-01-08 23:06:08 +00:00
|
|
|
delete _grvCursorMan;
|
2008-11-14 21:32:20 +00:00
|
|
|
delete _videoPlayer;
|
|
|
|
delete _musicPlayer;
|
|
|
|
delete _graphicsMan;
|
2009-09-24 10:58:00 +00:00
|
|
|
delete _script;
|
2010-05-11 15:41:31 +00:00
|
|
|
delete _macResFork;
|
2008-11-14 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
2009-03-01 09:12:32 +00:00
|
|
|
Common::Error GroovieEngine::run() {
|
2009-09-24 10:58:00 +00:00
|
|
|
_script = new Script(this, _gameDescription->version);
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
// Initialize the graphics
|
2009-08-21 13:57:03 +00:00
|
|
|
switch (_gameDescription->version) {
|
|
|
|
case kGroovieV2:
|
|
|
|
// Request the mode with the highest precision available
|
|
|
|
initGraphics(640, 480, true, NULL);
|
|
|
|
|
|
|
|
// Save the enabled mode as it can be both an RGB mode or CLUT8
|
|
|
|
_pixelFormat = _system->getScreenFormat();
|
|
|
|
_mode8bit = (_pixelFormat == Graphics::PixelFormat::createFormatCLUT8());
|
|
|
|
break;
|
|
|
|
case kGroovieT7G:
|
|
|
|
initGraphics(640, 480, true);
|
|
|
|
_pixelFormat = Graphics::PixelFormat::createFormatCLUT8();
|
|
|
|
break;
|
|
|
|
}
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Create debugger. It requires GFX to be initialized
|
|
|
|
_debugger = new Debugger(this);
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->setDebugger(_debugger);
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Create the graphics manager
|
|
|
|
_graphicsMan = new GraphicsMan(this);
|
|
|
|
|
|
|
|
// Create the resource and cursor managers and the video player
|
2010-06-07 17:14:42 +00:00
|
|
|
// Prepare the font too
|
2008-11-14 21:32:20 +00:00
|
|
|
switch (_gameDescription->version) {
|
|
|
|
case kGroovieT7G:
|
2010-07-01 18:47:27 +00:00
|
|
|
if (getPlatform() == Common::kPlatformMacintosh) {
|
2010-05-11 15:41:31 +00:00
|
|
|
_macResFork = new Common::MacResManager();
|
|
|
|
if (!_macResFork->open(_gameDescription->desc.filesDescriptions[0].fileName))
|
|
|
|
error("Could not open %s as a resource fork", _gameDescription->desc.filesDescriptions[0].fileName);
|
2010-06-07 17:14:42 +00:00
|
|
|
// The Macintosh release used system fonts. We use GUI fonts.
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
|
|
|
|
} else {
|
|
|
|
Common::File fontfile;
|
|
|
|
if (!fontfile.open("sphinx.fnt")) {
|
|
|
|
error("Couldn't open sphinx.fnt");
|
|
|
|
return Common::kNoGameDataFoundError;
|
|
|
|
} else if (!_sphinxFont.load(fontfile)) {
|
|
|
|
error("Error loading sphinx.fnt");
|
|
|
|
return Common::kUnknownError;
|
|
|
|
}
|
|
|
|
fontfile.close();
|
|
|
|
_font = &_sphinxFont;
|
2010-05-11 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_resMan = new ResMan_t7g(_macResFork);
|
|
|
|
_grvCursorMan = new GrvCursorMan_t7g(_system, _macResFork);
|
2008-11-14 21:32:20 +00:00
|
|
|
_videoPlayer = new VDXPlayer(this);
|
|
|
|
break;
|
|
|
|
case kGroovieV2:
|
|
|
|
_resMan = new ResMan_v2();
|
2009-01-08 23:06:08 +00:00
|
|
|
_grvCursorMan = new GrvCursorMan_v2(_system);
|
2008-11-14 21:32:20 +00:00
|
|
|
_videoPlayer = new ROQPlayer(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the music player
|
2010-07-01 18:47:27 +00:00
|
|
|
if (getPlatform() == Common::kPlatformMacintosh)
|
2009-07-05 09:34:54 +00:00
|
|
|
_musicPlayer = new MusicPlayerMac(this);
|
2010-05-11 15:41:31 +00:00
|
|
|
else
|
2009-07-05 09:34:54 +00:00
|
|
|
_musicPlayer = new MusicPlayerXMI(this, _gameDescription->version == kGroovieT7G ? "fat" : "sample");
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Load volume levels
|
|
|
|
syncSoundSettings();
|
|
|
|
|
|
|
|
// Get the name of the main script
|
|
|
|
Common::String filename = _gameDescription->desc.filesDescriptions[0].fileName;
|
|
|
|
if (_gameDescription->version == kGroovieT7G) {
|
|
|
|
// Run The 7th Guest's demo if requested
|
2010-05-11 15:41:31 +00:00
|
|
|
if (ConfMan.hasKey("demo_mode") && ConfMan.getBool("demo_mode"))
|
2010-07-01 18:47:27 +00:00
|
|
|
filename = "demo.grv";
|
|
|
|
else if (getPlatform() == Common::kPlatformMacintosh)
|
2010-05-11 15:41:31 +00:00
|
|
|
filename = "script.grv"; // Stored inside the executable's resource fork
|
2008-12-23 21:17:39 +00:00
|
|
|
} else if (_gameDescription->version == kGroovieV2) {
|
2008-11-14 21:32:20 +00:00
|
|
|
// Open the disk index
|
|
|
|
Common::File disk;
|
|
|
|
if (!disk.open(filename)) {
|
|
|
|
error("Couldn't open %s", filename.c_str());
|
|
|
|
return Common::kNoGameDataFoundError;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search the entry
|
|
|
|
bool found = false;
|
|
|
|
int index = 0;
|
|
|
|
while (!found && !disk.eos()) {
|
|
|
|
Common::String line = disk.readLine();
|
|
|
|
if (line.hasPrefix("title: ")) {
|
|
|
|
// A new entry
|
|
|
|
index++;
|
|
|
|
} else if (line.hasPrefix("boot: ") && index == _gameDescription->indexEntry) {
|
2009-01-07 23:05:28 +00:00
|
|
|
// It's the boot of the entry we're looking for,
|
2008-11-14 21:32:20 +00:00
|
|
|
// get the script filename
|
|
|
|
filename = line.c_str() + 6;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Couldn't find the entry
|
|
|
|
if (!found) {
|
|
|
|
error("Couldn't find entry %d in %s", _gameDescription->indexEntry, filename.c_str());
|
|
|
|
return Common::kUnknownError;
|
|
|
|
}
|
|
|
|
}
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
// Check the script file extension
|
|
|
|
if (!filename.hasSuffix(".grv")) {
|
|
|
|
error("%s isn't a valid script filename", filename.c_str());
|
|
|
|
return Common::kUnknownError;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the script
|
2009-09-24 10:58:00 +00:00
|
|
|
if (!_script->loadScript(filename)) {
|
2008-11-14 21:32:20 +00:00
|
|
|
error("Couldn't load the script file %s", filename.c_str());
|
|
|
|
return Common::kUnknownError;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should I load a saved game?
|
|
|
|
if (ConfMan.hasKey("save_slot")) {
|
|
|
|
// Get the requested slot
|
|
|
|
int slot = ConfMan.getInt("save_slot");
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->directGameLoad(slot);
|
2008-11-14 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the game files and the audio tracks aren't together run from
|
|
|
|
// the same cd
|
|
|
|
checkCD();
|
|
|
|
|
2008-12-30 10:19:16 +00:00
|
|
|
// Game timer counter
|
|
|
|
uint16 tmr = 0;
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
// Initialize the CD
|
|
|
|
int cd_num = ConfMan.getInt("cdrom");
|
|
|
|
if (cd_num >= 0)
|
2010-06-15 04:13:12 +00:00
|
|
|
_system->getAudioCDManager()->openCD(cd_num);
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
while (!shouldQuit()) {
|
2010-07-17 18:38:42 +00:00
|
|
|
// Give the debugger a chance to act
|
|
|
|
_debugger->onFrame();
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Handle input
|
|
|
|
Common::Event ev;
|
|
|
|
while (_eventMan->pollEvent(ev)) {
|
|
|
|
switch (ev.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
// CTRL-D: Attach the debugger
|
|
|
|
if ((ev.kbd.flags & Common::KBD_CTRL) && ev.kbd.keycode == Common::KEYCODE_d)
|
|
|
|
_debugger->attach();
|
|
|
|
|
|
|
|
// Send the event to the scripts
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->setKbdChar(ev.kbd.ascii);
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Continue the script execution to handle the key
|
|
|
|
_waitingForInput = false;
|
|
|
|
break;
|
|
|
|
|
2009-01-14 03:09:19 +00:00
|
|
|
case Common::EVENT_MAINMENU:
|
|
|
|
// Closing the GMM
|
2008-11-14 21:32:20 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2009-01-14 03:09:19 +00:00
|
|
|
// Continue the script execution, the mouse pointer
|
|
|
|
// may fall inside a different hotspot now
|
2008-11-14 21:32:20 +00:00
|
|
|
_waitingForInput = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
// Send the event to the scripts
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->setMouseClick(1);
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// Continue the script execution to handle
|
|
|
|
// the click
|
|
|
|
_waitingForInput = false;
|
|
|
|
break;
|
|
|
|
|
2009-08-21 13:57:03 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
// Send the event to the scripts (to skip the video)
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->setMouseClick(2);
|
2009-08-21 13:57:03 +00:00
|
|
|
break;
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
quitGame();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-07 23:05:28 +00:00
|
|
|
// The event loop may have triggered the quit status. In this case,
|
|
|
|
// stop the execution.
|
|
|
|
if (shouldQuit()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
if (_waitingForInput) {
|
2008-12-30 10:19:16 +00:00
|
|
|
// Still waiting for input, just update the mouse, game timer and then wait a bit more
|
2009-01-08 23:06:08 +00:00
|
|
|
_grvCursorMan->animate();
|
2008-11-14 21:32:20 +00:00
|
|
|
_system->updateScreen();
|
2008-12-30 10:19:16 +00:00
|
|
|
tmr++;
|
2009-01-01 15:06:43 +00:00
|
|
|
// Wait a little bit between increments. While mouse is moving, this triggers
|
2008-12-30 10:19:16 +00:00
|
|
|
// only negligably slower.
|
|
|
|
if (tmr > 4) {
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->timerTick();
|
2008-12-30 10:19:16 +00:00
|
|
|
tmr = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
_system->delayMillis(50);
|
|
|
|
} else if (_graphicsMan->isFading()) {
|
|
|
|
// We're waiting for a fading to end, let the CPU rest
|
|
|
|
// for a while and continue
|
|
|
|
_system->delayMillis(30);
|
|
|
|
} else {
|
|
|
|
// Everything's fine, execute another script step
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->step();
|
2008-11-14 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the screen if required
|
|
|
|
_graphicsMan->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2010-07-01 18:47:27 +00:00
|
|
|
Common::Platform GroovieEngine::getPlatform() const {
|
|
|
|
return _gameDescription->desc.platform;
|
|
|
|
}
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
bool GroovieEngine::hasFeature(EngineFeature f) const {
|
|
|
|
return
|
|
|
|
(f == kSupportsRTL) ||
|
|
|
|
(f == kSupportsLoadingDuringRuntime);
|
|
|
|
}
|
|
|
|
|
2008-11-15 18:56:39 +00:00
|
|
|
void GroovieEngine::errorString(const char *buf_input, char *buf_output, int buf_output_size) {
|
2008-11-30 21:16:04 +00:00
|
|
|
//snprintf(buf_output, buf_output_size, "%s%s\n", _script.getContext().c_str(), buf_input);
|
|
|
|
snprintf(buf_output, buf_output_size, "%s", buf_input);
|
2008-11-15 18:56:39 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 21:32:20 +00:00
|
|
|
void GroovieEngine::syncSoundSettings() {
|
2010-09-08 09:37:33 +00:00
|
|
|
bool mute = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
// Set the music volume
|
|
|
|
_musicPlayer->setUserVolume(mute ? 0 : ConfMan.getInt("music_volume"));
|
|
|
|
|
|
|
|
// Videos just contain one digital audio track, which can be used for
|
2009-06-14 22:10:17 +00:00
|
|
|
// both SFX or Speech, but the engine doesn't know what they contain, so
|
|
|
|
// we have to use just one volume setting for videos.
|
|
|
|
// We use "speech" because most users will want to change the videos
|
|
|
|
// volume when they can't hear the speech because of the music.
|
2010-09-08 09:37:33 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType,
|
|
|
|
mute ? 0 : ConfMan.getInt("speech_volume"));
|
2008-11-14 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GroovieEngine::canLoadGameStateCurrently() {
|
|
|
|
// TODO: verify the engine has been initialized
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error GroovieEngine::loadGameState(int slot) {
|
2009-09-24 10:58:00 +00:00
|
|
|
_script->directGameLoad(slot);
|
2008-11-14 21:32:20 +00:00
|
|
|
|
|
|
|
// TODO: Use specific error codes
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroovieEngine::waitForInput() {
|
|
|
|
_waitingForInput = true;
|
|
|
|
}
|
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
} // End of namespace Groovie
|