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-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-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-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"
|
|
|
|
#include "sci/gfx/operations.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-02-17 18:16:48 +00:00
|
|
|
SciEngine::SciEngine(OSystem *syst, const SciGameDescription *desc)
|
2009-10-03 20:49:18 +00:00
|
|
|
: Engine(syst), _gameDescription(desc), _system(syst) {
|
2009-02-17 18:16:48 +00:00
|
|
|
// Put your engine in a sane state, but do nothing big yet;
|
|
|
|
// in particular, do not load data from files; rather, if you
|
|
|
|
// need to do such things, do them from init().
|
|
|
|
|
|
|
|
// However this is the place to specify all default directories
|
|
|
|
//File::addDefaultDirectory(_gameDataPath + "sound/");
|
|
|
|
//printf("%s\n", _gameDataPath.c_str());
|
|
|
|
|
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-02-17 18:16:48 +00:00
|
|
|
printf("SciEngine::SciEngine\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SciEngine::~SciEngine() {
|
|
|
|
// Dispose your resources here
|
|
|
|
printf("SciEngine::~SciEngine\n");
|
|
|
|
|
|
|
|
// Remove all of our debug levels here
|
2009-02-20 21:26:31 +00:00
|
|
|
Common::clearAllDebugChannels();
|
|
|
|
|
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
|
|
|
initGraphics(320, 200, false);
|
|
|
|
|
|
|
|
// Create debugger console. It requires GFX to be initialized
|
2009-02-21 18:46:03 +00:00
|
|
|
_console = new Console(this);
|
2009-02-17 18:16:48 +00:00
|
|
|
|
|
|
|
// Additional setup.
|
|
|
|
printf("SciEngine::init\n");
|
|
|
|
|
|
|
|
/* bool end = false;
|
|
|
|
Common::EventManager *em = _system->getEventManager();
|
|
|
|
while (!end) {
|
|
|
|
Common::Event ev;
|
|
|
|
if (em->pollEvent(ev)) {
|
|
|
|
if (ev.type == Common::EVENT_KEYDOWN) {
|
|
|
|
end = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_system->delayMillis(10);
|
|
|
|
} */
|
|
|
|
|
|
|
|
// FIXME/TODO: Move some of the stuff below to init()
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-04 21:44:39 +00:00
|
|
|
const uint32 flags = getFlags();
|
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-02-23 04:31:11 +00:00
|
|
|
printf("No resources found, aborting...\n");
|
2009-02-17 18:16:48 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 12:02:37 +00:00
|
|
|
_kernel = new Kernel(_resMan);
|
|
|
|
_vocabulary = new Vocabulary(_resMan);
|
2009-10-08 08:00:30 +00:00
|
|
|
SciGuiScreen *screen = new SciGuiScreen();
|
|
|
|
SciGuiPalette *palette = new SciGuiPalette(_resMan, screen);
|
|
|
|
SciGuiCursor *cursor = new SciGuiCursor(_resMan, palette);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-08 08:00:30 +00:00
|
|
|
// We'll set the GUI below
|
|
|
|
_gamestate = new EngineState(_resMan, _kernel, _vocabulary, NULL, cursor, flags);
|
|
|
|
|
|
|
|
// Gui change
|
|
|
|
//_gamestate->_gui = new SciGui(_gamestate, screen, palette, cursor); // new
|
|
|
|
_gamestate->_gui = new SciGui32(_gamestate, screen, palette, cursor); // old
|
2009-05-15 09:04:21 +00:00
|
|
|
|
2009-06-04 21:44:39 +00:00
|
|
|
if (script_init_engine(_gamestate))
|
2009-02-17 18:16:48 +00:00
|
|
|
return Common::kUnknownError;
|
2009-02-15 06:10:59 +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-09-22 01:08:42 +00:00
|
|
|
strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "/");
|
2009-02-15 06:10:59 +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-09-25 10:11:31 +00:00
|
|
|
ConfMan.registerDefault("dither_mode", "0");
|
2009-09-01 20:28:44 +00:00
|
|
|
|
2009-02-21 15:30:47 +00:00
|
|
|
// Default config:
|
2009-02-15 06:10:59 +00:00
|
|
|
gfx_options_t gfx_options;
|
2009-04-01 20:32:45 +00:00
|
|
|
|
|
|
|
#ifdef CUSTOM_GRAPHICS_OPTIONS
|
2009-02-15 06:10:59 +00:00
|
|
|
gfx_options.pic0_unscaled = 1;
|
2009-09-03 07:01:48 +00:00
|
|
|
gfx_options.pic0_dither_mode = (DitherMode)ConfMan.getInt("dither_mode");
|
2009-02-15 06:10:59 +00:00
|
|
|
gfx_options.pic0_brush_mode = GFX_BRUSH_MODE_RANDOM_ELLIPSES;
|
|
|
|
gfx_options.pic0_line_mode = GFX_LINE_MODE_CORRECT;
|
|
|
|
for (int i = 0; i < GFX_RESOURCE_TYPES_NR; i++) {
|
|
|
|
gfx_options.res_conf.assign[i] = NULL;
|
|
|
|
gfx_options.res_conf.mod[i] = NULL;
|
|
|
|
}
|
2009-04-01 20:32:45 +00:00
|
|
|
gfx_options.workarounds = 0;
|
2009-02-21 15:30:47 +00:00
|
|
|
// Default config ends
|
2009-04-01 20:32:45 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-10-06 19:57:55 +00:00
|
|
|
gfxop_init(&gfx_state, &gfx_options, _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-06-03 14:09:25 +00:00
|
|
|
if (game_init_sound(_gamestate, 0)) {
|
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-10-08 14:37:55 +00:00
|
|
|
_gamestate->_gui->init(_gamestate->usesOldGfxFunctions());
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-09-23 10:55:35 +00:00
|
|
|
printf("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_engine(_gamestate); // Uninitialize game state
|
|
|
|
script_free_breakpoints(_gamestate);
|
2009-02-22 21:38:46 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
gfxop_exit(&gfx_state);
|
|
|
|
|
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 {
|
|
|
|
return _gameDescription->desc.gameid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Language SciEngine::getLanguage() const {
|
|
|
|
return _gameDescription->desc.language;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Platform SciEngine::getPlatform() const {
|
|
|
|
return _gameDescription->desc.platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-03 14:09:25 +00:00
|
|
|
_gamestate->_sound.sfx_suspend(pause);
|
2009-06-02 19:03:43 +00:00
|
|
|
_mixer->pauseAll(pause);
|
|
|
|
}
|
|
|
|
|
2009-02-20 14:45:28 +00:00
|
|
|
} // End of namespace Sci
|