2007-05-30 21:56:52 +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.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:44:38 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-18 18:23:53 +00:00
|
|
|
#include "base/plugins.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
|
2003-10-08 21:59:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2012-02-22 14:33:29 +00:00
|
|
|
#include "common/events.h"
|
2004-06-28 00:06:31 +00:00
|
|
|
#include "common/file.h"
|
2006-06-24 08:07:48 +00:00
|
|
|
#include "common/fs.h"
|
2012-02-22 14:33:29 +00:00
|
|
|
#include "common/gui_options.h"
|
2008-07-29 05:05:04 +00:00
|
|
|
#include "common/savefile.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2012-03-25 13:31:27 +00:00
|
|
|
#include "common/translation.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "engines/metaengine.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
#include "engines/util.h"
|
2008-02-02 00:54:52 +00:00
|
|
|
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/defs.h"
|
|
|
|
#include "sword2/header.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/console.h"
|
|
|
|
#include "sword2/controls.h"
|
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/maketext.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/memory.h"
|
2005-02-19 14:02:16 +00:00
|
|
|
#include "sword2/mouse.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2005-02-20 15:38:48 +00:00
|
|
|
#include "sword2/router.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/screen.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/sound.h"
|
2009-04-07 19:52:46 +00:00
|
|
|
#include "sword2/saveload.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2009-03-15 11:36:16 +00:00
|
|
|
Common::Platform Sword2Engine::_platform;
|
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
struct GameSettings {
|
2006-01-21 13:01:20 +00:00
|
|
|
const char *gameid;
|
2003-12-13 00:20:01 +00:00
|
|
|
const char *description;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectname;
|
|
|
|
};
|
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
static const GameSettings sword2_settings[] = {
|
2010-01-03 21:20:05 +00:00
|
|
|
/* Broken Sword II */
|
|
|
|
{"sword2", "Broken Sword II: The Smoking Mirror", 0, "players.clu" },
|
|
|
|
{"sword2alt", "Broken Sword II: The Smoking Mirror (alt)", 0, "r2ctlns.ocx" },
|
|
|
|
{"sword2psx", "Broken Sword II: The Smoking Mirror (PlayStation)", 0, "screens.clu"},
|
|
|
|
{"sword2psxdemo", "Broken Sword II: The Smoking Mirror (PlayStation/Demo)", Sword2::GF_DEMO, "screens.clu"},
|
|
|
|
{"sword2demo", "Broken Sword II: The Smoking Mirror (Demo)", Sword2::GF_DEMO, "players.clu" },
|
2003-12-13 00:20:01 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2003-10-04 00:52:27 +00:00
|
|
|
};
|
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
} // End of namespace Sword2
|
|
|
|
|
2012-03-25 13:31:27 +00:00
|
|
|
static const ExtraGuiOption sword2ExtraGuiOption = {
|
|
|
|
_s("Show object labels"),
|
|
|
|
_s("Show labels for objects on mouse hover"),
|
|
|
|
"object_labels",
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
class Sword2MetaEngine : public MetaEngine {
|
|
|
|
public:
|
|
|
|
virtual const char *getName() const {
|
2011-05-22 11:46:57 +00:00
|
|
|
return "Sword2";
|
2008-02-02 00:54:52 +00:00
|
|
|
}
|
2009-03-05 12:04:58 +00:00
|
|
|
virtual const char *getOriginalCopyright() const {
|
2008-02-02 00:54:52 +00:00
|
|
|
return "Broken Sword Games (C) Revolution";
|
|
|
|
}
|
|
|
|
|
2008-08-15 18:15:14 +00:00
|
|
|
virtual bool hasFeature(MetaEngineFeature f) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
virtual GameList getSupportedGames() const;
|
2012-03-25 13:31:27 +00:00
|
|
|
virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
virtual GameDescriptor findGame(const char *gameid) const;
|
2008-09-03 11:22:51 +00:00
|
|
|
virtual GameList detectGames(const Common::FSList &fslist) const;
|
2008-07-29 05:05:04 +00:00
|
|
|
virtual SaveStateList listSaves(const char *target) const;
|
2008-11-09 19:30:09 +00:00
|
|
|
virtual int getMaximumSaveSlot() const;
|
2008-09-11 19:47:45 +00:00
|
|
|
virtual void removeSaveState(const char *target, int slot) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
virtual Common::Error createInstance(OSystem *syst, Engine **engine) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
};
|
|
|
|
|
2008-08-15 18:15:14 +00:00
|
|
|
bool Sword2MetaEngine::hasFeature(MetaEngineFeature f) const {
|
|
|
|
return
|
|
|
|
(f == kSupportsListSaves) ||
|
2008-10-26 16:42:08 +00:00
|
|
|
(f == kSupportsLoadingDuringStartup) ||
|
2008-08-15 18:15:14 +00:00
|
|
|
(f == kSupportsDeleteSave);
|
|
|
|
}
|
|
|
|
|
2008-11-04 16:11:40 +00:00
|
|
|
bool Sword2::Sword2Engine::hasFeature(EngineFeature f) const {
|
|
|
|
return
|
2009-02-07 06:47:19 +00:00
|
|
|
(f == kSupportsRTL) ||
|
2009-04-07 19:52:46 +00:00
|
|
|
(f == kSupportsSubtitleOptions) ||
|
|
|
|
(f == kSupportsSavingDuringRuntime) ||
|
|
|
|
(f == kSupportsLoadingDuringRuntime);
|
2008-11-04 16:11:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
GameList Sword2MetaEngine::getSupportedGames() const {
|
2006-04-08 11:21:04 +00:00
|
|
|
const Sword2::GameSettings *g = Sword2::sword2_settings;
|
2003-10-17 23:16:53 +00:00
|
|
|
GameList games;
|
2006-01-21 13:01:20 +00:00
|
|
|
while (g->gameid) {
|
2007-01-20 21:27:57 +00:00
|
|
|
games.push_back(GameDescriptor(g->gameid, g->description));
|
2003-12-13 00:20:01 +00:00
|
|
|
g++;
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2012-03-25 13:31:27 +00:00
|
|
|
const ExtraGuiOptions Sword2MetaEngine::getExtraGuiOptions(const Common::String &target) const {
|
|
|
|
ExtraGuiOptions options;
|
|
|
|
options.push_back(sword2ExtraGuiOption);
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
GameDescriptor Sword2MetaEngine::findGame(const char *gameid) const {
|
2006-04-08 11:21:04 +00:00
|
|
|
const Sword2::GameSettings *g = Sword2::sword2_settings;
|
2006-02-18 11:15:37 +00:00
|
|
|
while (g->gameid) {
|
2006-03-02 22:29:01 +00:00
|
|
|
if (0 == scumm_stricmp(gameid, g->gameid))
|
2006-02-18 11:15:37 +00:00
|
|
|
break;
|
|
|
|
g++;
|
|
|
|
}
|
2007-01-20 21:27:57 +00:00
|
|
|
return GameDescriptor(g->gameid, g->description);
|
2006-02-18 11:15:37 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 23:02:12 +00:00
|
|
|
bool isFullGame(const Common::FSList &fslist) {
|
|
|
|
Common::FSList::const_iterator file;
|
|
|
|
|
|
|
|
// We distinguish between the two versions by the presense of paris.clu
|
|
|
|
for (file = fslist.begin(); file != fslist.end(); ++file) {
|
|
|
|
if (!file->isDirectory()) {
|
|
|
|
if (file->getName().equalsIgnoreCase("paris.clu"))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameList detectGamesImpl(const Common::FSList &fslist, bool recursion = false) {
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList detectedGames;
|
2006-04-08 11:21:04 +00:00
|
|
|
const Sword2::GameSettings *g;
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList::const_iterator file;
|
2012-11-07 23:02:12 +00:00
|
|
|
bool isFullVersion = isFullGame(fslist);
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
for (g = Sword2::sword2_settings; g->gameid; ++g) {
|
2003-10-17 23:16:53 +00:00
|
|
|
// Iterate over all files in the given directory
|
2007-02-11 13:02:50 +00:00
|
|
|
for (file = fslist.begin(); file != fslist.end(); ++file) {
|
2004-12-09 15:06:49 +00:00
|
|
|
if (!file->isDirectory()) {
|
2012-11-07 23:02:12 +00:00
|
|
|
// The required game data files can be located in the game directory, or in
|
|
|
|
// a subdirectory called "clusters". In the latter case, we don't want to
|
|
|
|
// detect the game in that subdirectory, as this will detect the game twice
|
|
|
|
// when mass add is searching inside a directory. In this case, the first
|
|
|
|
// result (the game directory) will be correct, but the second result (the
|
|
|
|
// clusters subdirectory) will be wrong, as the optional speech, music and
|
|
|
|
// video data files will be ignored. Note that this fix will skip the game
|
|
|
|
// data files if the user has placed them inside a "clusters" subdirectory,
|
|
|
|
// or if he/she points ScummVM directly to the "clusters" directory of the
|
|
|
|
// game CD. Fixes bug #3049336.
|
|
|
|
Common::String directory = file->getParent().getName();
|
|
|
|
directory.toLowercase();
|
|
|
|
if (directory.hasPrefix("clusters") && directory.size() <= 9 && !recursion)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (file->getName().equalsIgnoreCase(g->detectname)) {
|
|
|
|
// Make sure that the sword2 demo is not mixed up with the
|
|
|
|
// full version, since they use the same filename for detection
|
|
|
|
if ((g->features == Sword2::GF_DEMO && isFullVersion) ||
|
|
|
|
(g->features == 0 && !isFullVersion))
|
|
|
|
continue;
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2004-12-09 15:06:49 +00:00
|
|
|
// Match found, add to list of candidates, then abort inner loop.
|
2011-10-23 22:43:37 +00:00
|
|
|
detectedGames.push_back(GameDescriptor(g->gameid, g->description, Common::UNK_LANG, Common::kPlatformUnknown, GUIO2(GUIO_NOMIDI, GUIO_NOASPECT)));
|
2004-12-09 15:06:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-11 13:02:50 +00:00
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-02-11 13:02:50 +00:00
|
|
|
if (detectedGames.empty()) {
|
|
|
|
// Nothing found -- try to recurse into the 'clusters' subdirectory,
|
|
|
|
// present e.g. if the user copied the data straight from CD.
|
|
|
|
for (file = fslist.begin(); file != fslist.end(); ++file) {
|
|
|
|
if (file->isDirectory()) {
|
2012-11-07 23:02:12 +00:00
|
|
|
if (file->getName().equalsIgnoreCase("clusters")) {
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList recList;
|
2008-10-02 16:58:59 +00:00
|
|
|
if (file->getChildren(recList, Common::FSNode::kListAll)) {
|
2012-11-07 23:02:12 +00:00
|
|
|
GameList recGames(detectGamesImpl(recList, true));
|
2007-02-11 13:02:50 +00:00
|
|
|
if (!recGames.empty()) {
|
|
|
|
detectedGames.push_back(recGames);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
return detectedGames;
|
2003-10-04 00:52:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 23:02:12 +00:00
|
|
|
GameList Sword2MetaEngine::detectGames(const Common::FSList &fslist) const {
|
|
|
|
return detectGamesImpl(fslist);
|
|
|
|
}
|
|
|
|
|
2008-07-29 05:05:04 +00:00
|
|
|
SaveStateList Sword2MetaEngine::listSaves(const char *target) const {
|
|
|
|
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
2010-03-18 15:54:40 +00:00
|
|
|
Common::StringArray filenames;
|
2008-07-29 05:05:04 +00:00
|
|
|
char saveDesc[SAVE_DESCRIPTION_LEN];
|
|
|
|
Common::String pattern = target;
|
|
|
|
pattern += ".???";
|
|
|
|
|
2009-05-29 14:38:22 +00:00
|
|
|
filenames = saveFileMan->listSavefiles(pattern);
|
2008-07-29 05:05:04 +00:00
|
|
|
sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
|
|
|
|
|
|
|
|
SaveStateList saveList;
|
2010-03-18 15:54:40 +00:00
|
|
|
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
|
2008-07-29 05:05:04 +00:00
|
|
|
// Obtain the last 3 digits of the filename, since they correspond to the save slot
|
|
|
|
int slotNum = atoi(file->c_str() + file->size() - 3);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-07-29 05:05:04 +00:00
|
|
|
if (slotNum >= 0 && slotNum <= 999) {
|
2009-05-29 14:38:22 +00:00
|
|
|
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
|
2008-07-29 05:05:04 +00:00
|
|
|
if (in) {
|
|
|
|
in->readUint32LE();
|
|
|
|
in->read(saveDesc, SAVE_DESCRIPTION_LEN);
|
2008-11-05 15:41:12 +00:00
|
|
|
saveList.push_back(SaveStateDescriptor(slotNum, saveDesc));
|
2008-07-29 05:05:04 +00:00
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return saveList;
|
|
|
|
}
|
|
|
|
|
2008-11-09 19:30:09 +00:00
|
|
|
int Sword2MetaEngine::getMaximumSaveSlot() const { return 999; }
|
|
|
|
|
2008-09-11 19:47:45 +00:00
|
|
|
void Sword2MetaEngine::removeSaveState(const char *target, int slot) const {
|
|
|
|
Common::String filename = target;
|
2011-06-02 03:38:47 +00:00
|
|
|
filename += Common::String::format(".%03d", slot);
|
2008-09-11 19:47:45 +00:00
|
|
|
|
2009-05-29 14:38:22 +00:00
|
|
|
g_system->getSavefileManager()->removeSavefile(filename);
|
2008-09-11 19:47:45 +00:00
|
|
|
}
|
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
Common::Error Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) const {
|
2006-08-23 04:26:01 +00:00
|
|
|
assert(syst);
|
2006-04-29 00:27:20 +00:00
|
|
|
assert(engine);
|
2006-08-23 04:26:01 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList fslist;
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::FSNode dir(ConfMan.get("path"));
|
|
|
|
if (!dir.getChildren(fslist, Common::FSNode::kListAll)) {
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2006-08-23 04:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invoke the detector
|
|
|
|
Common::String gameid = ConfMan.get("gameid");
|
2008-02-02 00:54:52 +00:00
|
|
|
GameList detectedGames = detectGames(fslist);
|
2006-08-23 04:26:01 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < detectedGames.size(); i++) {
|
2007-01-20 21:27:57 +00:00
|
|
|
if (detectedGames[i].gameid() == gameid) {
|
2006-08-23 04:26:01 +00:00
|
|
|
*engine = new Sword2::Sword2Engine(syst);
|
2008-11-05 17:24:56 +00:00
|
|
|
return Common::kNoError;
|
2006-08-23 04:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 17:24:56 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2003-10-04 00:52:27 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_DYNAMIC(SWORD2)
|
|
|
|
REGISTER_PLUGIN_DYNAMIC(SWORD2, PLUGIN_TYPE_ENGINE, Sword2MetaEngine);
|
|
|
|
#else
|
|
|
|
REGISTER_PLUGIN_STATIC(SWORD2, PLUGIN_TYPE_ENGINE, Sword2MetaEngine);
|
|
|
|
#endif
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
namespace Sword2 {
|
|
|
|
|
2011-05-16 14:35:10 +00:00
|
|
|
Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst), _rnd("sword2") {
|
2004-06-28 00:06:31 +00:00
|
|
|
// Add default file directories
|
2010-05-04 11:56:52 +00:00
|
|
|
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "clusters");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "sword2");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "video");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "smacks");
|
2012-01-07 05:20:27 +00:00
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "streams"); // PSX video
|
2004-06-28 00:06:31 +00:00
|
|
|
|
2009-04-18 08:37:22 +00:00
|
|
|
if (!scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo") || !scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2psxdemo"))
|
2006-02-18 00:12:36 +00:00
|
|
|
_features = GF_DEMO;
|
|
|
|
else
|
|
|
|
_features = 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-03-15 11:36:16 +00:00
|
|
|
// Check if we are running PC or PSX version.
|
2009-04-18 08:37:22 +00:00
|
|
|
if (!scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2psx") || !scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2psxdemo"))
|
2009-03-15 11:36:16 +00:00
|
|
|
Sword2Engine::_platform = Common::kPlatformPSX;
|
|
|
|
else
|
2013-05-02 22:26:58 +00:00
|
|
|
Sword2Engine::_platform = Common::kPlatformWindows;
|
2009-03-15 11:36:16 +00:00
|
|
|
|
2003-10-08 21:59:23 +00:00
|
|
|
_bootParam = ConfMan.getInt("boot_param");
|
|
|
|
_saveSlot = ConfMan.getInt("save_slot");
|
2003-08-02 02:31:36 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
_memory = NULL;
|
|
|
|
_resman = NULL;
|
2004-11-16 09:15:25 +00:00
|
|
|
_sound = NULL;
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen = NULL;
|
|
|
|
_mouse = NULL;
|
2004-11-16 09:15:25 +00:00
|
|
|
_logic = NULL;
|
2005-02-19 14:02:16 +00:00
|
|
|
_fontRenderer = NULL;
|
|
|
|
_debugger = NULL;
|
2004-11-16 09:15:25 +00:00
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
_keyboardEvent.pending = false;
|
|
|
|
_mouseEvent.pending = false;
|
|
|
|
|
2003-11-02 15:58:45 +00:00
|
|
|
_wantSfxDebug = false;
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
_gameCycle = 0;
|
2007-01-03 07:36:44 +00:00
|
|
|
_gameSpeed = 1;
|
2004-11-15 08:22:16 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
_gmmLoadSlot = -1; // Used to manage GMM Loading
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
Sword2Engine::~Sword2Engine() {
|
2003-10-26 15:42:49 +00:00
|
|
|
delete _debugger;
|
2003-11-08 15:47:51 +00:00
|
|
|
delete _sound;
|
2003-11-16 14:18:29 +00:00
|
|
|
delete _fontRenderer;
|
2005-02-19 14:02:16 +00:00
|
|
|
delete _screen;
|
|
|
|
delete _mouse;
|
2003-11-15 09:38:00 +00:00
|
|
|
delete _logic;
|
2003-11-16 14:18:29 +00:00
|
|
|
delete _resman;
|
|
|
|
delete _memory;
|
2003-10-12 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 19:31:23 +00:00
|
|
|
GUI::Debugger *Sword2Engine::getDebugger() {
|
|
|
|
return _debugger;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
void Sword2Engine::registerDefaultSettings() {
|
|
|
|
ConfMan.registerDefault("gfx_details", 2);
|
|
|
|
ConfMan.registerDefault("reverse_stereo", false);
|
|
|
|
}
|
|
|
|
|
2008-11-09 11:52:52 +00:00
|
|
|
void Sword2Engine::syncSoundSettings() {
|
2011-03-19 14:09:48 +00:00
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
2010-09-20 20:31:56 +00:00
|
|
|
bool mute = ConfMan.getBool("mute");
|
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
setSubtitles(ConfMan.getBool("subtitles"));
|
2010-07-23 19:52:58 +00:00
|
|
|
|
|
|
|
// Our own settings dialog can mute the music, speech and sound effects
|
|
|
|
// individually. ScummVM's settings dialog has one master mute setting.
|
|
|
|
|
2010-09-20 20:18:35 +00:00
|
|
|
if (ConfMan.hasKey("mute")) {
|
|
|
|
ConfMan.setBool("music_mute", ConfMan.getBool("mute"));
|
|
|
|
ConfMan.setBool("speech_mute", ConfMan.getBool("mute"));
|
|
|
|
ConfMan.setBool("sfx_mute", ConfMan.getBool("mute"));
|
|
|
|
|
2010-09-20 20:31:56 +00:00
|
|
|
if (!mute) // it is false
|
2010-09-20 20:18:35 +00:00
|
|
|
// So remove it in order to let individual volumes work
|
|
|
|
ConfMan.removeKey("mute", ConfMan.getActiveDomainName());
|
2010-07-23 19:52:58 +00:00
|
|
|
}
|
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
_sound->muteMusic(ConfMan.getBool("music_mute"));
|
|
|
|
_sound->muteSpeech(ConfMan.getBool("speech_mute"));
|
|
|
|
_sound->muteFx(ConfMan.getBool("sfx_mute"));
|
|
|
|
_sound->setReverseStereo(ConfMan.getBool("reverse_stereo"));
|
2008-11-09 11:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::readSettings() {
|
|
|
|
syncSoundSettings();
|
2005-02-20 15:38:48 +00:00
|
|
|
_mouse->setObjectLabels(ConfMan.getBool("object_labels"));
|
|
|
|
_screen->setRenderLevel(ConfMan.getInt("gfx_details"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::writeSettings() {
|
2006-04-16 19:23:14 +00:00
|
|
|
ConfMan.setInt("music_volume", _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType));
|
|
|
|
ConfMan.setInt("speech_volume", _mixer->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType));
|
|
|
|
ConfMan.setInt("sfx_volume", _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType));
|
|
|
|
ConfMan.setBool("music_mute", _sound->isMusicMute());
|
|
|
|
ConfMan.setBool("speech_mute", _sound->isSpeechMute());
|
|
|
|
ConfMan.setBool("sfx_mute", _sound->isFxMute());
|
|
|
|
ConfMan.setInt("gfx_details", _screen->getRenderLevel());
|
|
|
|
ConfMan.setBool("subtitles", getSubtitles());
|
|
|
|
ConfMan.setBool("object_labels", _mouse->getObjectLabels());
|
|
|
|
ConfMan.setInt("reverse_stereo", _sound->isReverseStereo());
|
2005-02-20 15:38:48 +00:00
|
|
|
|
2010-07-23 19:52:58 +00:00
|
|
|
// If even one sound type is unmuted, we can't say that all sound is
|
|
|
|
// muted.
|
|
|
|
|
|
|
|
if (!_sound->isMusicMute() || !_sound->isSpeechMute() || !_sound->isFxMute()) {
|
|
|
|
ConfMan.setBool("mute", false);
|
|
|
|
}
|
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
|
2007-01-03 07:36:44 +00:00
|
|
|
int Sword2Engine::getFramesPerSecond() {
|
|
|
|
return _gameSpeed * FRAMES_PER_SECOND;
|
|
|
|
}
|
|
|
|
|
2004-09-08 07:10:54 +00:00
|
|
|
/**
|
|
|
|
* The global script variables and player object should be kept open throughout
|
|
|
|
* the game, so that they are never expelled by the resource manager.
|
|
|
|
*/
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
void Sword2Engine::setupPersistentResources() {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->_scriptVars = _resman->openResource(1) + ResHeader::size();
|
2004-09-08 07:10:54 +00:00
|
|
|
_resman->openResource(CUR_PLAYER_ID);
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2009-03-01 04:42:46 +00:00
|
|
|
Common::Error Sword2Engine::run() {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Get some falling RAM and put it in your pocket, never let it slip
|
2004-11-15 08:22:16 +00:00
|
|
|
// away
|
|
|
|
|
2006-04-26 06:12:03 +00:00
|
|
|
_debugger = NULL;
|
|
|
|
_sound = NULL;
|
|
|
|
_fontRenderer = NULL;
|
|
|
|
_screen = NULL;
|
|
|
|
_mouse = NULL;
|
|
|
|
_logic = NULL;
|
|
|
|
_resman = NULL;
|
|
|
|
_memory = NULL;
|
|
|
|
|
2008-11-14 22:08:10 +00:00
|
|
|
initGraphics(640, 480, true);
|
|
|
|
_screen = new Screen(this, 640, 480);
|
2004-11-15 08:22:16 +00:00
|
|
|
|
|
|
|
// Create the debugger as early as possible (but not before the
|
2005-02-21 08:16:50 +00:00
|
|
|
// screen object!) so that errors can be displayed in it. In
|
2004-11-15 08:22:16 +00:00
|
|
|
// particular, we want errors about missing files to be clearly
|
|
|
|
// visible to the user.
|
|
|
|
|
|
|
|
_debugger = new Debugger(this);
|
|
|
|
|
2013-04-18 18:14:10 +00:00
|
|
|
_memory = new MemoryManager();
|
2004-11-15 08:22:16 +00:00
|
|
|
_resman = new ResourceManager(this);
|
2006-04-26 06:12:03 +00:00
|
|
|
|
|
|
|
if (!_resman->init())
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kUnknownError;
|
2006-04-26 06:12:03 +00:00
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
_logic = new Logic(this);
|
|
|
|
_fontRenderer = new FontRenderer(this);
|
|
|
|
_sound = new Sound(this);
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse = new Mouse(this);
|
2004-11-15 08:22:16 +00:00
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
registerDefaultSettings();
|
|
|
|
readSettings();
|
2004-11-15 08:22:16 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
initStartMenu();
|
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
// During normal gameplay, we care neither about mouse button releases
|
|
|
|
// nor the scroll wheel.
|
2005-07-09 13:21:21 +00:00
|
|
|
setInputEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-09-08 07:10:54 +00:00
|
|
|
setupPersistentResources();
|
2011-05-25 15:17:11 +00:00
|
|
|
initializeFontResourceFlags();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-29 15:30:10 +00:00
|
|
|
if (_features & GF_DEMO)
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->writeVar(DEMO, 1);
|
2003-12-29 15:30:10 +00:00
|
|
|
else
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->writeVar(DEMO, 0);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
if (_saveSlot != -1) {
|
|
|
|
if (saveExists(_saveSlot))
|
|
|
|
restoreGame(_saveSlot);
|
|
|
|
else {
|
2005-02-21 08:16:50 +00:00
|
|
|
RestoreDialog dialog(this);
|
2005-02-20 15:38:48 +00:00
|
|
|
if (!dialog.runModal())
|
2004-11-15 08:22:16 +00:00
|
|
|
startGame();
|
|
|
|
}
|
2009-04-07 19:52:46 +00:00
|
|
|
} else if (!_bootParam && saveExists() && !isPsx()) { // Initial load/restart panel disabled in PSX
|
|
|
|
int32 pars[2] = { 221, FX_LOOP }; // version because of missing panel resources
|
2004-11-15 08:22:16 +00:00
|
|
|
bool result;
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->setMouse(NORMAL_MOUSE_ID);
|
2004-11-15 08:22:16 +00:00
|
|
|
_logic->fnPlayMusic(pars);
|
2005-02-20 15:38:48 +00:00
|
|
|
|
|
|
|
StartDialog dialog(this);
|
|
|
|
|
2005-02-21 02:29:18 +00:00
|
|
|
result = (dialog.runModal() != 0);
|
2004-11-15 08:22:16 +00:00
|
|
|
|
|
|
|
// If the game is started from the beginning, the cutscene
|
|
|
|
// player will kill the music for us. Otherwise, the restore
|
|
|
|
// will either have killed the music, or done a crossfade.
|
|
|
|
|
2008-09-30 12:27:38 +00:00
|
|
|
if (shouldQuit())
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2004-11-15 08:22:16 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
startGame();
|
|
|
|
} else
|
|
|
|
startGame();
|
|
|
|
|
2011-05-25 15:17:11 +00:00
|
|
|
_screen->initializeRenderCycle();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
while (1) {
|
2010-07-17 18:38:42 +00:00
|
|
|
_debugger->onFrame();
|
2004-11-15 08:22:16 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Handle GMM Loading
|
|
|
|
if (_gmmLoadSlot != -1) {
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Hide mouse cursor and fade screen
|
|
|
|
_mouse->hideMouse();
|
|
|
|
_screen->fadeDown();
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Clean up and load game
|
|
|
|
_logic->_router->freeAllRouteMem();
|
|
|
|
|
|
|
|
// TODO: manage error handling
|
|
|
|
restoreGame(_gmmLoadSlot);
|
|
|
|
|
|
|
|
// Reset load slot
|
|
|
|
_gmmLoadSlot = -1;
|
|
|
|
|
|
|
|
// Show mouse
|
|
|
|
_mouse->addHuman();
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
KeyboardEvent *ke = keyboardEvent();
|
|
|
|
|
|
|
|
if (ke) {
|
2010-02-21 04:04:13 +00:00
|
|
|
if ((ke->kbd.hasFlags(Common::KBD_CTRL) && ke->kbd.keycode == Common::KEYCODE_d) || ke->kbd.ascii == '#' || ke->kbd.ascii == '~') {
|
2004-11-15 08:22:16 +00:00
|
|
|
_debugger->attach();
|
2010-02-21 04:04:13 +00:00
|
|
|
} else if (ke->kbd.hasFlags(0) || ke->kbd.hasFlags(Common::KBD_SHIFT)) {
|
2007-06-22 23:03:12 +00:00
|
|
|
switch (ke->kbd.keycode) {
|
2007-06-21 19:33:05 +00:00
|
|
|
case Common::KEYCODE_p:
|
2010-11-01 11:25:11 +00:00
|
|
|
if (isPaused()) {
|
|
|
|
_screen->dimPalette(false);
|
2008-11-09 14:32:24 +00:00
|
|
|
pauseEngine(false);
|
2010-11-01 11:25:11 +00:00
|
|
|
} else {
|
2008-11-09 14:32:24 +00:00
|
|
|
pauseEngine(true);
|
2010-11-01 11:25:11 +00:00
|
|
|
_screen->dimPalette(true);
|
|
|
|
}
|
2004-11-15 08:22:16 +00:00
|
|
|
break;
|
2009-01-31 07:57:41 +00:00
|
|
|
#if 0
|
|
|
|
// Disabled because of strange rumors about the
|
|
|
|
// credits running spontaneously every few
|
|
|
|
// minutes.
|
2007-06-21 19:33:05 +00:00
|
|
|
case Common::KEYCODE_c:
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (!_logic->readVar(DEMO) && !_mouse->isChoosing()) {
|
2005-10-17 06:45:54 +00:00
|
|
|
ScreenInfo *screenInfo = _screen->getScreenInfo();
|
2004-11-15 08:22:16 +00:00
|
|
|
_logic->fnPlayCredits(NULL);
|
2005-10-17 06:45:54 +00:00
|
|
|
screenInfo->new_palette = 99;
|
|
|
|
}
|
2004-11-15 08:22:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip GameCycle if we're paused
|
2010-11-01 11:25:11 +00:00
|
|
|
if (!isPaused()) {
|
2004-11-15 08:22:16 +00:00
|
|
|
_gameCycle++;
|
|
|
|
gameCycle();
|
|
|
|
}
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
// We can't use this as termination condition for the loop,
|
2004-11-15 08:22:16 +00:00
|
|
|
// because we want the break to happen before updating the
|
|
|
|
// screen again.
|
|
|
|
|
2008-09-30 12:27:38 +00:00
|
|
|
if (shouldQuit())
|
2004-11-15 08:22:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// creates the debug text blocks
|
|
|
|
_debugger->buildDebugText();
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->buildDisplay();
|
2004-11-15 08:22:16 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
void Sword2Engine::restartGame() {
|
|
|
|
ScreenInfo *screenInfo = _screen->getScreenInfo();
|
|
|
|
uint32 temp_demo_flag;
|
|
|
|
|
|
|
|
_mouse->closeMenuImmediately();
|
|
|
|
|
|
|
|
// Restart the game. To do this, we must...
|
|
|
|
|
|
|
|
// Stop music instantly!
|
|
|
|
_sound->stopMusic(true);
|
|
|
|
|
|
|
|
// In case we were dead - well we're not anymore!
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->writeVar(DEAD, 0);
|
2005-02-20 15:38:48 +00:00
|
|
|
|
|
|
|
// Restart the game. Clear all memory and reset the globals
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
temp_demo_flag = _logic->readVar(DEMO);
|
2005-02-20 15:38:48 +00:00
|
|
|
|
|
|
|
// Remove all resources from memory, including player object and
|
|
|
|
// global variables
|
|
|
|
_resman->removeAll();
|
|
|
|
|
|
|
|
// Reopen global variables resource and player object
|
|
|
|
setupPersistentResources();
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->writeVar(DEMO, temp_demo_flag);
|
2005-02-20 15:38:48 +00:00
|
|
|
|
|
|
|
// Free all the route memory blocks from previous game
|
|
|
|
_logic->_router->freeAllRouteMem();
|
|
|
|
|
|
|
|
// Call the same function that first started us up
|
|
|
|
startGame();
|
|
|
|
|
|
|
|
// Prime system with a game cycle
|
|
|
|
|
|
|
|
// Reset the graphic 'BuildUnit' list before a new logic list
|
|
|
|
// (see fnRegisterFrame)
|
|
|
|
_screen->resetRenderLists();
|
|
|
|
|
|
|
|
// Reset the mouse hot-spot list (see fnRegisterMouse and
|
|
|
|
// fnRegisterFrame)
|
|
|
|
_mouse->resetMouseList();
|
|
|
|
|
|
|
|
_mouse->closeMenuImmediately();
|
|
|
|
|
|
|
|
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
|
|
|
|
// - this is taken from fnInitBackground
|
|
|
|
// switch on scrolling (2 means first time on screen)
|
|
|
|
screenInfo->scroll_flag = 2;
|
|
|
|
|
|
|
|
if (_logic->processSession())
|
|
|
|
error("restart 1st cycle failed??");
|
|
|
|
|
|
|
|
// So palette not restored immediately after control panel - we want
|
|
|
|
// to fade up instead!
|
|
|
|
screenInfo->new_palette = 99;
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
bool Sword2Engine::checkForMouseEvents() {
|
2004-05-09 13:32:04 +00:00
|
|
|
return _mouseEvent.pending;
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
MouseEvent *Sword2Engine::mouseEvent() {
|
2004-05-09 13:32:04 +00:00
|
|
|
if (!_mouseEvent.pending)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_mouseEvent.pending = false;
|
|
|
|
return &_mouseEvent;
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
KeyboardEvent *Sword2Engine::keyboardEvent() {
|
2004-05-09 13:32:04 +00:00
|
|
|
if (!_keyboardEvent.pending)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_keyboardEvent.pending = false;
|
|
|
|
return &_keyboardEvent;
|
|
|
|
}
|
|
|
|
|
2005-07-09 13:21:21 +00:00
|
|
|
uint32 Sword2Engine::setInputEventFilter(uint32 filter) {
|
|
|
|
uint32 oldFilter = _inputEventFilter;
|
2004-05-09 13:32:04 +00:00
|
|
|
|
2005-07-09 13:21:21 +00:00
|
|
|
_inputEventFilter = filter;
|
2004-05-09 13:32:04 +00:00
|
|
|
return oldFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OSystem Event Handler. Full of cross platform goodness and 99% fat free!
|
|
|
|
*/
|
|
|
|
|
2005-07-09 13:21:21 +00:00
|
|
|
void Sword2Engine::parseInputEvents() {
|
2007-03-17 19:02:05 +00:00
|
|
|
Common::Event event;
|
2005-05-31 12:53:55 +00:00
|
|
|
|
2007-04-01 17:36:13 +00:00
|
|
|
while (_eventMan->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-02-21 04:04:13 +00:00
|
|
|
if (event.kbd.hasFlags(Common::KBD_CTRL)) {
|
|
|
|
if (event.kbd.keycode == Common::KEYCODE_f) {
|
2007-01-03 07:36:44 +00:00
|
|
|
if (_gameSpeed == 1)
|
|
|
|
_gameSpeed = 2;
|
|
|
|
else
|
|
|
|
_gameSpeed = 1;
|
|
|
|
}
|
|
|
|
}
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_KEYDOWN)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_keyboardEvent.pending = true;
|
2007-06-22 23:03:12 +00:00
|
|
|
_keyboardEvent.kbd = event.kbd;
|
2004-05-09 13:32:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_LEFTBUTTONDOWN)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_LEFTBUTTONDOWN;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_RIGHTBUTTONDOWN)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_RIGHTBUTTONDOWN;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_LEFTBUTTONUP)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_LEFTBUTTONUP;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONUP:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_RIGHTBUTTONUP)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_RIGHTBUTTONUP;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELUP:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_WHEELUP)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_WHEELUP;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELDOWN:
|
2005-07-09 13:21:21 +00:00
|
|
|
if (!(_inputEventFilter & RD_WHEELDOWN)) {
|
2004-05-09 13:32:04 +00:00
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_WHEELDOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
void Sword2Engine::gameCycle() {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Do one game cycle, that is run the logic session until a full loop
|
|
|
|
// has been performed.
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-15 09:38:00 +00:00
|
|
|
if (_logic->getRunList()) {
|
2003-09-20 18:33:24 +00:00
|
|
|
do {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Reset the 'BuildUnit' and mouse hot-spot lists
|
|
|
|
// before each new logic list. The service scripts
|
|
|
|
// will fill thrm through fnRegisterFrame() and
|
|
|
|
// fnRegisterMouse().
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->resetRenderLists();
|
|
|
|
_mouse->resetMouseList();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
// Keep going as long as new lists keep getting put in
|
|
|
|
// - i.e. screen changes.
|
2003-11-15 09:38:00 +00:00
|
|
|
} while (_logic->processSession());
|
2003-09-20 18:33:24 +00:00
|
|
|
} else {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Start the console and print the start options perhaps?
|
2003-11-08 15:47:51 +00:00
|
|
|
_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");
|
2003-09-20 18:33:24 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
// If this screen is wide, recompute the scroll offsets every cycle
|
2005-02-19 14:02:16 +00:00
|
|
|
ScreenInfo *screenInfo = _screen->getScreenInfo();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
if (screenInfo->scroll_flag)
|
|
|
|
_screen->setScrolling();
|
|
|
|
|
|
|
|
_mouse->mouseEngine();
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_sound->processFxQueue();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
void Sword2Engine::startGame() {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Boot the game straight into a start script. It's always George's
|
|
|
|
// script #1, but with different ScreenManager objects depending on
|
|
|
|
// if it's the demo or the full game, or if we're using a boot param.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-11-19 19:50:22 +00:00
|
|
|
int screen_manager_id = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
debug(5, "startGame() STARTING:");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
if (!_bootParam) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (_logic->readVar(DEMO))
|
2004-11-16 09:15:25 +00:00
|
|
|
screen_manager_id = 19; // DOCKS SECTION START
|
|
|
|
else
|
|
|
|
screen_manager_id = 949; // INTRO & PARIS START
|
|
|
|
} else {
|
|
|
|
// FIXME this could be validated against startup.inf for valid
|
|
|
|
// numbers to stop people shooting themselves in the foot
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
if (_bootParam != 0)
|
|
|
|
screen_manager_id = _bootParam;
|
|
|
|
}
|
2003-09-20 18:33:24 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->runResObjScript(screen_manager_id, CUR_PLAYER_ID, 1);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 15:28:15 +00:00
|
|
|
// FIXME: Move this to some better place?
|
|
|
|
|
2003-11-11 10:30:25 +00:00
|
|
|
void Sword2Engine::sleepUntil(uint32 time) {
|
2005-01-10 22:06:49 +00:00
|
|
|
while (getMillis() < time) {
|
2004-01-04 15:11:30 +00:00
|
|
|
// Make sure menu animations and fades don't suffer, but don't
|
|
|
|
// redraw the entire scene.
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->processMenu();
|
|
|
|
_screen->updateDisplay(false);
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
2003-10-05 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-09 14:32:24 +00:00
|
|
|
void Sword2Engine::pauseEngineIntern(bool pause) {
|
2010-11-01 11:25:11 +00:00
|
|
|
Engine::pauseEngineIntern(pause);
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2008-11-09 14:32:24 +00:00
|
|
|
if (pause) {
|
|
|
|
_screen->pauseScreen(true);
|
2008-05-23 17:54:47 +00:00
|
|
|
} else {
|
2008-11-09 13:50:41 +00:00
|
|
|
_screen->pauseScreen(false);
|
2008-05-23 17:54:47 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
2005-01-10 22:06:49 +00:00
|
|
|
uint32 Sword2Engine::getMillis() {
|
|
|
|
return _system->getMillis();
|
|
|
|
}
|
|
|
|
|
2011-06-02 12:11:38 +00:00
|
|
|
Common::Error Sword2Engine::saveGameState(int slot, const Common::String &desc) {
|
|
|
|
uint32 saveVal = saveGame(slot, (const byte *)desc.c_str());
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
if (saveVal == SR_OK)
|
|
|
|
return Common::kNoError;
|
|
|
|
else if (saveVal == SR_ERR_WRITEFAIL || saveVal == SR_ERR_FILEOPEN)
|
|
|
|
return Common::kWritingFailed;
|
|
|
|
else
|
|
|
|
return Common::kUnknownError;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sword2Engine::canSaveGameStateCurrently() {
|
|
|
|
bool canSave = true;
|
|
|
|
|
|
|
|
// No save if dead
|
|
|
|
if (_logic->readVar(DEAD))
|
|
|
|
canSave = false;
|
|
|
|
|
|
|
|
// No save if mouse not shown
|
|
|
|
else if (_mouse->getMouseStatus())
|
|
|
|
canSave = false;
|
|
|
|
// No save if inside a menu
|
|
|
|
else if (_mouse->getMouseMode() == MOUSE_system_menu)
|
|
|
|
canSave = false;
|
|
|
|
|
|
|
|
// No save if fading
|
|
|
|
else if (_screen->getFadeStatus())
|
|
|
|
canSave = false;
|
|
|
|
|
|
|
|
return canSave;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error Sword2Engine::loadGameState(int slot) {
|
|
|
|
|
|
|
|
// Prepare the game to load through GMM
|
|
|
|
_gmmLoadSlot = slot;
|
|
|
|
|
|
|
|
// TODO: error handling.
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sword2Engine::canLoadGameStateCurrently() {
|
|
|
|
bool canLoad = true;
|
|
|
|
|
|
|
|
// No load if mouse is disabled
|
|
|
|
if (_mouse->getMouseStatus())
|
|
|
|
canLoad = false;
|
|
|
|
// No load if mouse is in system menu
|
|
|
|
else if (_mouse->getMouseMode() == MOUSE_system_menu)
|
|
|
|
canLoad = false;
|
|
|
|
// No load if we are fading
|
|
|
|
else if (_screen->getFadeStatus())
|
|
|
|
canLoad = false;
|
|
|
|
|
|
|
|
// But if we are dead, ignore previous conditions
|
|
|
|
if (_logic->readVar(DEAD))
|
|
|
|
canLoad = true;
|
|
|
|
|
|
|
|
return canLoad;
|
|
|
|
}
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|