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
|
|
|
*
|
2006-02-09 15:12:44 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-01-10 22:06:49 +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"
|
2004-06-28 00:06:31 +00:00
|
|
|
#include "common/file.h"
|
2006-06-24 08:07:48 +00:00
|
|
|
#include "common/fs.h"
|
2007-03-17 00:53:21 +00:00
|
|
|
#include "common/events.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "engines/metaengine.h"
|
|
|
|
|
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"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
|
|
|
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[] = {
|
2003-10-04 00:52:27 +00:00
|
|
|
/* Broken Sword 2 */
|
2006-02-18 00:12:36 +00:00
|
|
|
{"sword2", "Broken Sword 2: The Smoking Mirror", 0, "players.clu" },
|
|
|
|
{"sword2alt", "Broken Sword 2: The Smoking Mirror (alt)", 0, "r2ctlns.ocx" },
|
|
|
|
{"sword2demo", "Broken Sword 2: 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
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
class Sword2MetaEngine : public MetaEngine {
|
|
|
|
public:
|
|
|
|
virtual const char *getName() const {
|
|
|
|
return "Broken Sword 2";
|
|
|
|
}
|
|
|
|
virtual const char *getCopyright() const {
|
|
|
|
return "Broken Sword Games (C) Revolution";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GameList getSupportedGames() const;
|
|
|
|
virtual GameDescriptor findGame(const char *gameid) const;
|
|
|
|
virtual GameList detectGames(const FSList &fslist) const;
|
|
|
|
|
|
|
|
virtual PluginError createInstance(OSystem *syst, Engine **engine) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
GameList Sword2MetaEngine::detectGames(const FSList &fslist) const {
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList detectedGames;
|
2006-04-08 11:21:04 +00:00
|
|
|
const Sword2::GameSettings *g;
|
2007-02-11 13:02:50 +00:00
|
|
|
FSList::const_iterator file;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-01 07:47:54 +00:00
|
|
|
// TODO: It would be nice if we had code here which distinguishes
|
|
|
|
// between the 'sword2' and 'sword2demo' targets. The current code
|
|
|
|
// can't do that since they use the same detectname.
|
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()) {
|
2007-06-05 21:02:35 +00:00
|
|
|
const char *fileName = file->getName().c_str();
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2006-07-22 14:39:54 +00:00
|
|
|
if (0 == scumm_stricmp(g->detectname, fileName)) {
|
2004-12-09 15:06:49 +00:00
|
|
|
// Match found, add to list of candidates, then abort inner loop.
|
2007-01-20 21:27:57 +00:00
|
|
|
detectedGames.push_back(GameDescriptor(g->gameid, g->description));
|
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()) {
|
2007-06-05 21:02:35 +00:00
|
|
|
const char *fileName = file->getName().c_str();
|
2007-02-11 13:02:50 +00:00
|
|
|
|
|
|
|
if (0 == scumm_stricmp("clusters", fileName)) {
|
|
|
|
FSList recList;
|
2007-06-05 21:02:35 +00:00
|
|
|
if (file->getChildren(recList, FilesystemNode::kListAll)) {
|
2008-02-02 00:54:52 +00:00
|
|
|
GameList recGames(detectGames(recList));
|
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
|
|
|
}
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
PluginError 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
|
|
|
|
|
|
|
FSList fslist;
|
|
|
|
FilesystemNode dir(ConfMan.get("path"));
|
2007-06-05 21:02:35 +00:00
|
|
|
if (!dir.getChildren(fslist, FilesystemNode::kListAll)) {
|
2006-08-23 04:26:01 +00:00
|
|
|
return kInvalidPathError;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
return kNoError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kNoGameDataFoundError;
|
2003-10-04 00:52:27 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 00:02:23 +00:00
|
|
|
REGISTER_PLUGIN(SWORD2, PLUGIN_TYPE_ENGINE, Sword2MetaEngine);
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
namespace Sword2 {
|
|
|
|
|
2006-04-15 20:36:41 +00:00
|
|
|
Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
|
2004-06-28 00:06:31 +00:00
|
|
|
// Add default file directories
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
|
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "SWORD2/");
|
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "VIDEO/");
|
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "clusters/");
|
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "sword2/");
|
|
|
|
Common::File::addDefaultDirectory(_gameDataPath + "video/");
|
2004-06-28 00:06:31 +00:00
|
|
|
|
2006-04-15 17:39:14 +00:00
|
|
|
if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo"))
|
2006-02-18 00:12:36 +00:00
|
|
|
_features = GF_DEMO;
|
|
|
|
else
|
|
|
|
_features = 0;
|
2007-09-19 08:40:12 +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
|
|
|
#ifdef SWORD2_DEBUG
|
2003-11-08 15:47:51 +00:00
|
|
|
_stepOneCycle = false;
|
2004-11-16 09:15:25 +00:00
|
|
|
_renderSkip = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_gamePaused = false;
|
2003-11-08 15:47:51 +00:00
|
|
|
_graphicsLevelFudged = false;
|
2004-11-15 08:22:16 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
_quit = false;
|
2007-09-19 13:55:05 +00:00
|
|
|
syst->getEventManager()->registerRandomSource(_rnd, "sword2");
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::readSettings() {
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
2005-02-20 15:38:48 +00:00
|
|
|
setSubtitles(ConfMan.getBool("subtitles"));
|
|
|
|
_sound->muteMusic(ConfMan.getBool("music_mute"));
|
|
|
|
_sound->muteSpeech(ConfMan.getBool("speech_mute"));
|
|
|
|
_sound->muteFx(ConfMan.getBool("sfx_mute"));
|
|
|
|
_sound->setReverseStereo(ConfMan.getBool("reverse_stereo"));
|
|
|
|
_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
|
|
|
|
|
|
|
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
|
|
|
|
2006-04-15 20:36:41 +00:00
|
|
|
int Sword2Engine::init() {
|
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;
|
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->beginGFXTransaction();
|
2006-04-15 20:36:41 +00:00
|
|
|
initCommonGFX(true);
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen = new Screen(this, 640, 480);
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->endGFXTransaction();
|
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);
|
|
|
|
|
|
|
|
_memory = new MemoryManager(this);
|
|
|
|
_resman = new ResourceManager(this);
|
2006-04-26 06:12:03 +00:00
|
|
|
|
|
|
|
if (!_resman->init())
|
|
|
|
return 1;
|
|
|
|
|
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();
|
2003-10-11 12:26:53 +00:00
|
|
|
initialiseFontResourceFlags();
|
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();
|
|
|
|
}
|
|
|
|
} else if (!_bootParam && saveExists()) {
|
|
|
|
int32 pars[2] = { 221, FX_LOOP };
|
|
|
|
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.
|
|
|
|
|
|
|
|
if (_quit)
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2004-11-15 08:22:16 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
startGame();
|
|
|
|
} else
|
|
|
|
startGame();
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->initialiseRenderCycle();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2004-11-15 08:22:16 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
int Sword2Engine::go() {
|
2004-11-15 08:22:16 +00:00
|
|
|
while (1) {
|
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
2004-11-15 08:22:16 +00:00
|
|
|
if (_stepOneCycle) {
|
|
|
|
pauseGame();
|
|
|
|
_stepOneCycle = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
KeyboardEvent *ke = keyboardEvent();
|
|
|
|
|
|
|
|
if (ke) {
|
2007-06-22 23:03:12 +00:00
|
|
|
if ((ke->kbd.flags == 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();
|
2007-06-22 23:03:12 +00:00
|
|
|
} else if (ke->kbd.flags == 0 || ke->kbd.flags == Common::KBD_SHIFT) {
|
|
|
|
switch (ke->kbd.keycode) {
|
2007-06-21 19:33:05 +00:00
|
|
|
case Common::KEYCODE_p:
|
2004-11-15 08:22:16 +00:00
|
|
|
if (_gamePaused)
|
|
|
|
unpauseGame();
|
|
|
|
else
|
|
|
|
pauseGame();
|
|
|
|
break;
|
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;
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
2007-06-21 19:33:05 +00:00
|
|
|
case Common::KEYCODE_SPACE:
|
2004-11-15 08:22:16 +00:00
|
|
|
if (_gamePaused) {
|
|
|
|
_stepOneCycle = true;
|
|
|
|
unpauseGame();
|
|
|
|
}
|
|
|
|
break;
|
2007-06-21 19:33:05 +00:00
|
|
|
case Common::KEYCODE_s:
|
2004-11-15 08:22:16 +00:00
|
|
|
_renderSkip = !_renderSkip;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip GameCycle if we're paused
|
|
|
|
if (!_gamePaused) {
|
|
|
|
_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.
|
|
|
|
|
|
|
|
if (_quit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// creates the debug text blocks
|
|
|
|
_debugger->buildDebugText();
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
2004-11-15 08:22:16 +00:00
|
|
|
// if not in console & '_renderSkip' is set, only render
|
|
|
|
// display once every 4 game-cycles
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
if (!_renderSkip || (_gameCycle % 4) == 0)
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->buildDisplay();
|
2004-11-15 08:22:16 +00:00
|
|
|
#else
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->buildDisplay();
|
2004-11-15 08:22:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
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::closeGame() {
|
2004-01-06 16:49:04 +00:00
|
|
|
_quit = true;
|
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:
|
|
|
|
if (event.kbd.flags == Common::KBD_CTRL) {
|
2007-01-03 07:36:44 +00:00
|
|
|
if (event.kbd.keycode == 'f') {
|
|
|
|
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;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_QUIT:
|
2004-05-09 13:32:04 +00:00
|
|
|
closeGame();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
void Sword2Engine::pauseGame() {
|
2004-11-16 09:15:25 +00:00
|
|
|
// Don't allow Pause while screen fading or while black
|
2005-02-19 14:02:16 +00:00
|
|
|
if (_screen->getFadeStatus() != RDFADE_NONE)
|
2003-07-28 01:44:38 +00:00
|
|
|
return;
|
2005-07-30 21:11:48 +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
|
|
|
_sound->pauseAllSound();
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->pauseGame();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
// If render level is at max, turn it down because palette-matching
|
|
|
|
// won't work when the palette is dimmed.
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
if (_screen->getRenderLevel() == 3) {
|
|
|
|
_screen->setRenderLevel(2);
|
2003-11-08 15:47:51 +00:00
|
|
|
_graphicsLevelFudged = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
|
|
|
// Don't dim it if we're single-stepping through frames
|
2003-11-03 07:47:42 +00:00
|
|
|
// dim the palette during the pause
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (!_stepOneCycle)
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->dimPalette();
|
2004-11-16 09:15:25 +00:00
|
|
|
#else
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->dimPalette();
|
2004-11-16 09:15:25 +00:00
|
|
|
#endif
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_gamePaused = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 08:22:16 +00:00
|
|
|
void Sword2Engine::unpauseGame() {
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->unpauseGame();
|
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->unpauseAllSound();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2006-02-12 19:33:45 +00:00
|
|
|
// Put back game screen palette; see screen.cpp
|
2005-02-19 14:02:16 +00:00
|
|
|
_screen->setFullPalette(-1);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// If graphics level at max, turn up again
|
2003-11-08 19:47:20 +00:00
|
|
|
if (_graphicsLevelFudged) {
|
2005-02-20 15:38:48 +00:00
|
|
|
_screen->setRenderLevel(3);
|
2003-11-08 15:47:51 +00:00
|
|
|
_graphicsLevelFudged = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_gamePaused = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-11-16 09:15:25 +00:00
|
|
|
// If mouse is about or we're in a chooser menu
|
2005-04-24 12:13:03 +00:00
|
|
|
if (!_mouse->getMouseStatus() || _mouse->isChoosing())
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->setMouse(NORMAL_MOUSE_ID);
|
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();
|
|
|
|
}
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|