2009-02-17 15:20:21 +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$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
2009-02-15 08:20:53 +00:00
|
|
|
#include "engines/advancedDetector.h"
|
2009-02-15 11:03:21 +00:00
|
|
|
#include "sci/sci.h"
|
2009-07-03 14:22:50 +00:00
|
|
|
#include "sci/debug.h"
|
2009-02-20 21:26:31 +00:00
|
|
|
#include "sci/console.h"
|
2009-12-04 17:38:24 +00:00
|
|
|
#include "sci/event.h"
|
2009-05-11 13:31:17 +00:00
|
|
|
|
2009-02-27 02:23:40 +00:00
|
|
|
#include "sci/engine/state.h"
|
2009-02-24 05:51:55 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-28 13:20:30 +00:00
|
|
|
#include "sci/gfx/operations.h" // fog GfxState
|
2009-10-30 12:33:05 +00:00
|
|
|
#ifdef INCLUDE_OLDGFX
|
2009-10-04 14:59:51 +00:00
|
|
|
#include "sci/gfx/gfx_state_internal.h" // required for GfxContainer, GfxPort, GfxVisual
|
2009-10-03 20:49:18 +00:00
|
|
|
#include "sci/gui32/gui32.h"
|
2009-10-30 12:33:05 +00:00
|
|
|
#endif
|
2009-11-04 09:36:18 +00:00
|
|
|
#include "sci/sfx/audio.h"
|
2009-11-12 15:24:11 +00:00
|
|
|
#include "sci/sfx/soundcmd.h"
|
2009-10-28 13:20:30 +00:00
|
|
|
#include "sci/gui/gui.h"
|
2009-12-21 14:32:54 +00:00
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
#include "sci/gui/gui_dummy.h"
|
|
|
|
#endif
|
2009-10-06 19:57:55 +00:00
|
|
|
#include "sci/gui/gui_palette.h"
|
2009-10-07 12:47:53 +00:00
|
|
|
#include "sci/gui/gui_cursor.h"
|
2009-10-07 23:04:13 +00:00
|
|
|
#include "sci/gui/gui_screen.h"
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-03-07 19:23:47 +00:00
|
|
|
#include "sci/gfx/gfx_resource.h"
|
|
|
|
#include "sci/gfx/gfx_tools.h"
|
|
|
|
|
2009-02-20 14:45:28 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
class GfxDriver;
|
2009-02-21 10:23:36 +00:00
|
|
|
|
2009-10-09 23:19:53 +00:00
|
|
|
SciEngine::SciEngine(OSystem *syst, const ADGameDescription *desc)
|
2009-10-03 20:49:18 +00:00
|
|
|
: Engine(syst), _gameDescription(desc), _system(syst) {
|
2009-02-20 21:26:31 +00:00
|
|
|
_console = NULL;
|
|
|
|
|
2009-02-17 18:16:48 +00:00
|
|
|
// Set up the engine specific debug levels
|
2009-02-20 20:11:12 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelError, "Error", "Script error debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelNodes, "Lists", "Lists and nodes debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelGraphics, "Graphics", "Graphics debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelStrings, "Strings", "Strings debugging");
|
2009-05-30 15:40:49 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelMemory, "Memory", "Memory debugging");
|
2009-02-20 20:11:12 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelFuncCheck, "Func", "Function parameter debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelBresen, "Bresenham", "Bresenham algorithms debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelGfxDriver, "Gfxdriver", "Gfx driver debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelBaseSetter, "Base", "Base Setter debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelParser, "Parser", "Parser debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelMenu, "Menu", "Menu handling debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSaid, "Said", "Said specs debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelFile, "File", "File I/O debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelTime, "Time", "Time debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelRoom, "Room", "Room number debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelAvoidPath, "Pathfinding", "Pathfinding debugging");
|
2009-03-01 21:48:39 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelDclInflate, "DCL", "DCL inflate debugging");
|
2009-05-30 15:40:49 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelVM, "VM", "VM debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelScripts, "Scripts", "Notifies when scripts are unloaded");
|
2009-07-06 10:39:22 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelGC, "GC", "Garbage Collector debugging");
|
2009-09-06 21:56:49 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelSci0Pic, "Sci0Pic", "SCI0 pic drawing debugging");
|
2009-02-17 18:16:48 +00:00
|
|
|
|
2009-07-07 06:53:53 +00:00
|
|
|
_gamestate = 0;
|
2009-10-15 15:17:54 +00:00
|
|
|
|
2009-10-31 17:55:03 +00:00
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "actors"); // KQ6 hi-res portraits
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "aud"); // resource.aud and audio files
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "avi"); // AVI movie files for Windows versions
|
|
|
|
//SearchMan.addSubDirectoryMatching(_gameDataDir, "patches"); // resource patches
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "seq"); // SEQ movie files for DOS versions
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "wav"); // speech files in WAV format
|
2009-12-27 22:34:12 +00:00
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "sfx"); // music/sound files in WAV format
|
2009-02-17 18:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SciEngine::~SciEngine() {
|
|
|
|
// Remove all of our debug levels here
|
2009-02-20 21:26:31 +00:00
|
|
|
Common::clearAllDebugChannels();
|
|
|
|
|
2009-11-04 09:36:18 +00:00
|
|
|
delete _audio;
|
2009-07-11 23:45:54 +00:00
|
|
|
delete _kernel;
|
|
|
|
delete _vocabulary;
|
2009-02-20 21:26:31 +00:00
|
|
|
delete _console;
|
2009-09-02 12:02:37 +00:00
|
|
|
delete _resMan;
|
2009-02-17 18:16:48 +00:00
|
|
|
}
|
|
|
|
|
2009-03-01 04:42:46 +00:00
|
|
|
Common::Error SciEngine::run() {
|
2009-02-17 18:16:48 +00:00
|
|
|
// FIXME/TODO: Move some of the stuff below to init()
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-09-02 12:02:37 +00:00
|
|
|
_resMan = new ResourceManager();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-09-02 12:02:37 +00:00
|
|
|
if (!_resMan) {
|
2009-10-10 00:07:19 +00:00
|
|
|
warning("No resources found, aborting");
|
2009-02-17 18:16:48 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 10:54:19 +00:00
|
|
|
// Scale the screen, if needed
|
2009-12-21 14:32:54 +00:00
|
|
|
bool upscaledHires = (!strcmp(getGameID(), "kq6")
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
|| getSciVersion() >= SCI_VERSION_2
|
|
|
|
#endif
|
|
|
|
) && getPlatform() == Common::kPlatformWindows;
|
2009-10-31 14:38:25 +00:00
|
|
|
|
|
|
|
// TODO: Detect japanese editions and set upscaledHires on those as well
|
|
|
|
// TODO: Possibly look at first picture resource and determine if its hires or not
|
2009-10-31 10:54:19 +00:00
|
|
|
|
|
|
|
// Initialize graphics-related parts
|
2009-10-31 14:38:25 +00:00
|
|
|
SciGuiScreen *screen = new SciGuiScreen(_resMan, 320, 200, upscaledHires); // invokes initGraphics()
|
2009-10-08 08:00:30 +00:00
|
|
|
SciGuiPalette *palette = new SciGuiPalette(_resMan, screen);
|
2009-10-29 14:16:20 +00:00
|
|
|
SciGuiCursor *cursor = new SciGuiCursor(_resMan, palette, screen);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-31 10:54:19 +00:00
|
|
|
// Create debugger console. It requires GFX to be initialized
|
|
|
|
_console = new Console(this);
|
|
|
|
|
2009-12-26 13:53:59 +00:00
|
|
|
_kernel = new Kernel(_resMan, getGameID());
|
2009-10-31 10:54:19 +00:00
|
|
|
_vocabulary = new Vocabulary(_resMan);
|
2009-11-04 09:36:18 +00:00
|
|
|
_audio = new AudioPlayer(_resMan);
|
2009-10-31 10:54:19 +00:00
|
|
|
|
2009-11-04 14:22:17 +00:00
|
|
|
SegManager *segMan = new SegManager(_resMan);
|
|
|
|
|
2009-10-08 08:00:30 +00:00
|
|
|
// We'll set the GUI below
|
2009-11-04 14:22:17 +00:00
|
|
|
_gamestate = new EngineState(_resMan, _kernel, _vocabulary, segMan, NULL, _audio);
|
2009-12-04 17:38:24 +00:00
|
|
|
_gamestate->_event = new SciEvent();
|
2009-10-08 08:00:30 +00:00
|
|
|
|
2009-10-11 16:47:01 +00:00
|
|
|
if (script_init_engine(_gamestate))
|
|
|
|
return Common::kUnknownError;
|
|
|
|
|
2009-12-21 14:32:54 +00:00
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
if (getSciVersion() >= SCI_VERSION_2) {
|
|
|
|
// Falsify the Views with a Dummy GUI
|
2009-12-24 14:18:16 +00:00
|
|
|
//_gamestate->_gui = new SciGuiDummy(_gamestate, screen, palette, cursor);
|
|
|
|
_gamestate->_gui = new SciGui(_gamestate, screen, palette, cursor); // new
|
2009-12-21 14:32:54 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
2009-10-30 12:33:05 +00:00
|
|
|
#ifdef INCLUDE_OLDGFX
|
2009-12-08 21:22:22 +00:00
|
|
|
#ifndef USE_OLDGFX
|
|
|
|
_gamestate->_gui = new SciGui(_gamestate, screen, palette, cursor); // new
|
|
|
|
#else
|
|
|
|
_gamestate->_gui = new SciGui32(_gamestate, screen, palette, cursor); // old
|
|
|
|
#endif
|
2009-10-30 12:33:05 +00:00
|
|
|
#else
|
2009-12-21 14:32:54 +00:00
|
|
|
_gamestate->_gui = new SciGui(_gamestate, screen, palette, cursor);
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
}
|
2009-10-30 12:33:05 +00:00
|
|
|
#endif
|
2009-05-15 09:04:21 +00:00
|
|
|
|
2009-06-03 14:09:25 +00:00
|
|
|
if (game_init(_gamestate)) { /* Initialize */
|
2009-05-29 13:07:14 +00:00
|
|
|
warning("Game initialization failed: Aborting...");
|
2009-02-17 18:16:48 +00:00
|
|
|
// TODO: Add an "init failed" error?
|
|
|
|
return Common::kUnknownError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 14:53:58 +00:00
|
|
|
script_adjust_opcode_formats(_gamestate);
|
|
|
|
|
2009-05-14 23:10:04 +00:00
|
|
|
// Set the savegame dir (actually, we set it to a fake value,
|
|
|
|
// since we cannot let the game control where saves are stored)
|
2009-12-26 01:20:12 +00:00
|
|
|
// Some SCI1.1 games (e.g. SQ4CD) complain if this is empty
|
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
if (getSciVersion() >= SCI_VERSION_2)
|
|
|
|
strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "");
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "/");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-12-25 18:59:15 +00:00
|
|
|
SciVersion soundVersion = _gamestate->detectDoSoundType();
|
|
|
|
|
|
|
|
_gamestate->_soundCmd = new SoundCommandParser(_resMan, segMan, _audio, soundVersion);
|
2009-11-12 15:24:11 +00:00
|
|
|
|
2009-04-27 11:12:08 +00:00
|
|
|
GfxState gfx_state;
|
2009-06-06 10:21:48 +00:00
|
|
|
_gamestate->gfx_state = &gfx_state;
|
2009-03-18 11:07:29 +00:00
|
|
|
|
2009-09-01 20:28:44 +00:00
|
|
|
// Assign default values to the config manager, in case settings are missing
|
2009-10-25 20:53:07 +00:00
|
|
|
ConfMan.registerDefault("undither", "true");
|
|
|
|
screen->unditherSetState(ConfMan.getBool("undither"));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-28 13:20:30 +00:00
|
|
|
#ifdef INCLUDE_OLDGFX
|
2009-10-25 20:53:07 +00:00
|
|
|
gfxop_init(&gfx_state, _resMan, screen, palette, 1);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-03 14:09:25 +00:00
|
|
|
if (game_init_graphics(_gamestate)) { // Init interpreter graphics
|
2009-05-29 13:07:14 +00:00
|
|
|
warning("Game initialization failed: Error in GFX subsystem. Aborting...");
|
2009-02-17 18:16:48 +00:00
|
|
|
return Common::kUnknownError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
2009-11-04 11:52:11 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-12-26 00:50:09 +00:00
|
|
|
#ifdef USE_OLD_MUSIC_FUNCTIONS
|
2009-12-25 18:59:15 +00:00
|
|
|
if (game_init_sound(_gamestate, 0, soundVersion)) {
|
2009-05-29 13:07:14 +00:00
|
|
|
warning("Game initialization failed: Error in sound subsystem. Aborting...");
|
2009-02-17 18:16:48 +00:00
|
|
|
return Common::kUnknownError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
2009-12-26 00:50:09 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-08 14:37:55 +00:00
|
|
|
_gamestate->_gui->init(_gamestate->usesOldGfxFunctions());
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-10-10 00:07:19 +00:00
|
|
|
debug("Emulating SCI version %s\n", getSciVersionDesc(getSciVersion()).c_str());
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-03 14:09:25 +00:00
|
|
|
game_run(&_gamestate); // Run the game
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-03 14:09:25 +00:00
|
|
|
game_exit(_gamestate);
|
|
|
|
script_free_breakpoints(_gamestate);
|
2009-02-22 21:38:46 +00:00
|
|
|
|
2009-11-12 15:24:11 +00:00
|
|
|
delete _gamestate->_soundCmd;
|
|
|
|
delete _gamestate->_gui;
|
2009-12-04 17:38:24 +00:00
|
|
|
delete _gamestate->_event;
|
2009-11-04 14:22:17 +00:00
|
|
|
delete segMan;
|
2009-10-13 16:22:07 +00:00
|
|
|
delete cursor;
|
2009-10-06 19:57:55 +00:00
|
|
|
delete palette;
|
2009-10-06 12:26:13 +00:00
|
|
|
delete screen;
|
2009-06-03 14:09:25 +00:00
|
|
|
delete _gamestate;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-28 13:20:30 +00:00
|
|
|
#ifdef INCLUDE_OLDGFX
|
2009-02-15 06:10:59 +00:00
|
|
|
gfxop_exit(&gfx_state);
|
2009-10-28 13:20:30 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-15 08:20:53 +00:00
|
|
|
return Common::kNoError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 14:22:50 +00:00
|
|
|
// Invoked by error() when a severe error occurs
|
2009-05-11 13:31:17 +00:00
|
|
|
GUI::Debugger *SciEngine::getDebugger() {
|
2009-07-07 06:53:53 +00:00
|
|
|
if (_gamestate) {
|
|
|
|
ExecStack *xs = &(_gamestate->_executionStack.back());
|
2009-09-17 13:21:19 +00:00
|
|
|
xs->addr.pc.offset = g_debugState.old_pc_offset;
|
|
|
|
xs->sp = g_debugState.old_sp;
|
2009-07-07 06:53:53 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 13:21:19 +00:00
|
|
|
g_debugState.runningStep = 0; // Stop multiple execution
|
|
|
|
g_debugState.seeking = kDebugSeekNothing; // Stop special seeks
|
2009-07-03 14:22:50 +00:00
|
|
|
|
|
|
|
return _console;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used to obtain the engine's console in order to print messages to it
|
|
|
|
Console *SciEngine::getSciDebugger() {
|
2009-05-11 13:31:17 +00:00
|
|
|
return _console;
|
|
|
|
}
|
|
|
|
|
2009-02-20 14:45:28 +00:00
|
|
|
const char* SciEngine::getGameID() const {
|
2009-10-09 23:19:53 +00:00
|
|
|
return _gameDescription->gameid;
|
2009-02-20 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Language SciEngine::getLanguage() const {
|
2009-10-09 23:19:53 +00:00
|
|
|
return _gameDescription->language;
|
2009-02-20 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Platform SciEngine::getPlatform() const {
|
2009-10-09 23:19:53 +00:00
|
|
|
return _gameDescription->platform;
|
2009-02-20 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 SciEngine::getFlags() const {
|
2009-05-14 09:12:27 +00:00
|
|
|
return _gameDescription->flags;
|
2009-02-20 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
Common::String SciEngine::getSavegameName(int nr) const {
|
2009-07-25 10:26:17 +00:00
|
|
|
return _targetName + Common::String::printf(".%03d", nr);
|
2009-02-20 23:41:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 01:17:24 +00:00
|
|
|
Common::String SciEngine::getSavegamePattern() const {
|
|
|
|
return _targetName + ".???";
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String SciEngine::wrapFilename(const Common::String &name) const {
|
|
|
|
return _targetName + "-" + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String SciEngine::unwrapFilename(const Common::String &name) const {
|
|
|
|
Common::String prefix = name + "-";
|
|
|
|
if (name.hasPrefix(prefix.c_str()))
|
|
|
|
return Common::String(name.c_str() + prefix.size());
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-06-02 19:03:43 +00:00
|
|
|
void SciEngine::pauseEngineIntern(bool pause) {
|
2009-12-20 13:38:13 +00:00
|
|
|
#ifdef USE_OLD_MUSIC_FUNCTIONS
|
2009-06-03 14:09:25 +00:00
|
|
|
_gamestate->_sound.sfx_suspend(pause);
|
2009-12-20 13:38:13 +00:00
|
|
|
#endif
|
2009-06-02 19:03:43 +00:00
|
|
|
_mixer->pauseAll(pause);
|
|
|
|
}
|
|
|
|
|
2009-02-20 14:45:28 +00:00
|
|
|
} // End of namespace Sci
|