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.
|
2004-04-09 12:36:06 +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
|
2004-10-15 06:06:47 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-09 12:36:06 +00:00
|
|
|
* 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.
|
2004-04-09 12:36:06 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
#include "kyra/kyra_v1.h"
|
2009-05-27 14:40:37 +00:00
|
|
|
#include "kyra/sound_intern.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/resource.h"
|
2007-07-29 16:33:11 +00:00
|
|
|
#include "kyra/timer.h"
|
2008-05-06 20:50:27 +00:00
|
|
|
#include "kyra/debugger.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
|
2011-04-28 13:39:17 +00:00
|
|
|
#include "common/error.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/debug-channels.h"
|
|
|
|
|
2006-04-08 11:21:04 +00:00
|
|
|
namespace Kyra {
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
KyraEngine_v1::KyraEngine_v1(OSystem *system, const GameFlags &flags)
|
2011-05-16 14:35:10 +00:00
|
|
|
: Engine(system), _flags(flags), _rnd("kyra") {
|
2006-04-27 00:39:10 +00:00
|
|
|
_res = 0;
|
|
|
|
_sound = 0;
|
|
|
|
_text = 0;
|
2007-07-29 16:31:29 +00:00
|
|
|
_staticres = 0;
|
2007-07-29 16:33:11 +00:00
|
|
|
_timer = 0;
|
2008-04-29 15:12:09 +00:00
|
|
|
_emc = 0;
|
2008-05-06 20:50:27 +00:00
|
|
|
_debugger = 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-07-21 17:00:07 +00:00
|
|
|
if (_flags.platform == Common::kPlatformAmiga)
|
|
|
|
_gameSpeed = 50;
|
|
|
|
else
|
|
|
|
_gameSpeed = 60;
|
2007-07-29 16:33:11 +00:00
|
|
|
_tickLength = (uint8)(1000.0 / _gameSpeed);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-10-10 09:06:15 +00:00
|
|
|
_trackMap = 0;
|
|
|
|
_trackMapSize = 0;
|
|
|
|
_lastMusicCommand = -1;
|
|
|
|
_curSfxFile = _curMusicTheme = -1;
|
|
|
|
|
2008-03-28 00:53:54 +00:00
|
|
|
_gameToLoad = -1;
|
|
|
|
|
2008-05-12 12:42:10 +00:00
|
|
|
_mouseState = -1;
|
2008-05-12 12:57:42 +00:00
|
|
|
_deathHandler = -1;
|
2008-05-12 12:42:10 +00:00
|
|
|
|
2007-07-29 16:31:29 +00:00
|
|
|
memset(_flagsTable, 0, sizeof(_flagsTable));
|
2007-06-08 23:04:13 +00:00
|
|
|
|
2008-11-03 19:51:34 +00:00
|
|
|
_isSaveAllowed = false;
|
|
|
|
|
2008-12-25 03:00:24 +00:00
|
|
|
_mouseX = _mouseY = 0;
|
|
|
|
|
2006-11-13 12:00:36 +00:00
|
|
|
// sets up all engine specific debug levels
|
2010-04-27 21:40:52 +00:00
|
|
|
DebugMan.addDebugChannel(kDebugLevelScriptFuncs, "ScriptFuncs", "Script function debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelScript, "Script", "Script interpreter debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprite debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelScreen, "Screen", "Screen debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSound, "Sound", "Sound debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelAnimator, "Animator", "Animator debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelGUI, "GUI", "GUI debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSequence, "Sequence", "Sequence debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelMovie, "Movie", "Movie debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelTimer, "Timer", "Timer debug level");
|
2006-04-27 00:39:10 +00:00
|
|
|
}
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
::GUI::Debugger *KyraEngine_v1::getDebugger() {
|
2008-05-06 20:50:27 +00:00
|
|
|
return _debugger;
|
|
|
|
}
|
|
|
|
|
2008-05-23 13:37:56 +00:00
|
|
|
void KyraEngine_v1::pauseEngineIntern(bool pause) {
|
2011-07-04 18:20:46 +00:00
|
|
|
Engine::pauseEngineIntern(pause);
|
|
|
|
if (_sound)
|
|
|
|
_sound->pause(pause);
|
2008-05-23 13:37:56 +00:00
|
|
|
_timer->pause(pause);
|
|
|
|
}
|
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
Common::Error KyraEngine_v1::init() {
|
2006-04-27 00:39:10 +00:00
|
|
|
// Setup mixer
|
2010-07-21 19:20:10 +00:00
|
|
|
syncSoundSettings();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-04-29 14:22:04 +00:00
|
|
|
if (!_flags.useDigSound) {
|
2008-06-26 19:42:59 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns) {
|
2008-04-29 14:22:04 +00:00
|
|
|
if (_flags.gameID == GI_KYRA1)
|
|
|
|
_sound = new SoundTowns(this, _mixer);
|
|
|
|
else
|
2008-06-26 19:42:59 +00:00
|
|
|
_sound = new SoundTownsPC98_v2(this, _mixer);
|
|
|
|
} else if (_flags.platform == Common::kPlatformPC98) {
|
|
|
|
if (_flags.gameID == GI_KYRA1)
|
2008-08-02 23:11:31 +00:00
|
|
|
_sound = new SoundPC98(this, _mixer);
|
2008-06-26 19:42:59 +00:00
|
|
|
else
|
|
|
|
_sound = new SoundTownsPC98_v2(this, _mixer);
|
2009-07-17 16:07:57 +00:00
|
|
|
} else if (_flags.platform == Common::kPlatformAmiga) {
|
|
|
|
_sound = new SoundAmiga(this, _mixer);
|
2008-04-29 14:22:04 +00:00
|
|
|
} else {
|
2011-06-05 16:28:05 +00:00
|
|
|
// In Kyra 1 users who have specified a default MT-32 device in the launcher settings
|
|
|
|
// will get MT-32 music, otherwise AdLib. In Kyra 2 and LoL users who have specified a
|
|
|
|
// default GM device in the launcher will get GM music, otherwise AdLib. Users who want
|
|
|
|
// MT-32 music in Kyra2 or LoL have to select this individually (since we assume that
|
|
|
|
// most users rather have a GM device than a MT-32 device).
|
|
|
|
// Users who want PC speaker sound always have to select this individually for all
|
|
|
|
// Kyra games.
|
|
|
|
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_PCSPK | MDT_MIDI | MDT_ADLIB | ((_flags.gameID == GI_KYRA2 || _flags.gameID == GI_LOL) ? MDT_PREFER_GM : MDT_PREFER_MT32));
|
|
|
|
if (MidiDriver::getMusicType(dev) == MT_ADLIB) {
|
|
|
|
_sound = new SoundAdLibPC(this, _mixer);
|
2009-05-27 14:40:37 +00:00
|
|
|
} else {
|
2011-06-05 16:28:05 +00:00
|
|
|
Sound::kType type;
|
|
|
|
const MusicType midiType = MidiDriver::getMusicType(dev);
|
|
|
|
|
|
|
|
if (midiType == MT_PCSPK || midiType == MT_NULL)
|
|
|
|
type = Sound::kPCSpkr;
|
|
|
|
else if (midiType == MT_MT32 || ConfMan.getBool("native_mt32"))
|
|
|
|
type = Sound::kMidiMT32;
|
|
|
|
else
|
|
|
|
type = Sound::kMidiGM;
|
|
|
|
|
|
|
|
MidiDriver *driver = 0;
|
|
|
|
|
|
|
|
if (MidiDriver::getMusicType(dev) == MT_PCSPK) {
|
|
|
|
driver = new MidiDriver_PCSpeaker(_mixer);
|
|
|
|
} else {
|
|
|
|
driver = MidiDriver::createMidi(dev);
|
|
|
|
if (type == Sound::kMidiMT32)
|
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(driver);
|
|
|
|
|
|
|
|
SoundMidiPC *soundMidiPc = new SoundMidiPC(this, _mixer, driver, type);
|
|
|
|
_sound = soundMidiPc;
|
|
|
|
assert(_sound);
|
|
|
|
|
|
|
|
// Unlike some SCUMM games, it's not that the MIDI sounds are
|
|
|
|
// missing. It's just that at least at the time of writing they
|
|
|
|
// are decidedly inferior to the AdLib ones.
|
|
|
|
if (ConfMan.getBool("multi_midi")) {
|
|
|
|
SoundAdLibPC *adlib = new SoundAdLibPC(this, _mixer);
|
|
|
|
assert(adlib);
|
|
|
|
|
|
|
|
_sound = new MixedSoundDriver(this, _mixer, soundMidiPc, adlib);
|
|
|
|
}
|
2008-04-29 14:22:04 +00:00
|
|
|
}
|
2006-03-28 15:15:36 +00:00
|
|
|
}
|
2009-07-17 14:05:22 +00:00
|
|
|
|
|
|
|
assert(_sound);
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
2007-01-29 18:15:14 +00:00
|
|
|
|
2008-04-04 18:09:19 +00:00
|
|
|
if (_sound)
|
|
|
|
_sound->updateVolumeSettings();
|
2008-04-29 14:22:04 +00:00
|
|
|
|
2006-07-08 12:23:44 +00:00
|
|
|
_res = new Resource(this);
|
|
|
|
assert(_res);
|
2007-10-09 05:40:20 +00:00
|
|
|
_res->reset();
|
2008-08-02 23:11:31 +00:00
|
|
|
|
|
|
|
if (_flags.isDemo) {
|
|
|
|
// HACK: check whether this is the HOF demo or the LOL demo.
|
|
|
|
// The LOL demo needs to be detected and run as KyraEngine_HoF,
|
|
|
|
// but the static resource loader and the sequence player will
|
|
|
|
// need correct IDs.
|
|
|
|
if (_res->exists("scene1.cps"))
|
2009-03-04 00:45:34 +00:00
|
|
|
#ifdef ENABLE_LOL
|
2008-08-02 23:11:31 +00:00
|
|
|
_flags.gameID = GI_LOL;
|
2009-03-04 00:45:34 +00:00
|
|
|
#else
|
2010-09-18 10:55:16 +00:00
|
|
|
error("Lands of Lore demo is not supported in this build");
|
2009-03-04 00:45:34 +00:00
|
|
|
#endif // !ENABLE_LOL
|
2008-08-02 23:11:31 +00:00
|
|
|
}
|
|
|
|
|
2006-03-18 14:43:18 +00:00
|
|
|
_staticres = new StaticResource(this);
|
|
|
|
assert(_staticres);
|
2006-05-19 07:34:24 +00:00
|
|
|
if (!_staticres->init())
|
|
|
|
error("_staticres->init() failed");
|
2008-04-06 14:41:25 +00:00
|
|
|
if (!screen()->init())
|
|
|
|
error("screen()->init() failed");
|
2007-07-29 16:33:11 +00:00
|
|
|
_timer = new TimerManager(this, _system);
|
|
|
|
assert(_timer);
|
2008-01-27 15:56:56 +00:00
|
|
|
setupTimers();
|
2008-04-29 15:12:09 +00:00
|
|
|
_emc = new EMCInterpreter(this);
|
|
|
|
assert(_emc);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-29 16:33:11 +00:00
|
|
|
setupOpcodeTable();
|
2008-01-27 15:56:56 +00:00
|
|
|
readSettings();
|
2006-02-09 12:19:53 +00:00
|
|
|
|
2008-03-28 00:53:54 +00:00
|
|
|
if (ConfMan.hasKey("save_slot")) {
|
|
|
|
_gameToLoad = ConfMan.getInt("save_slot");
|
|
|
|
if (!saveFileLoadable(_gameToLoad))
|
|
|
|
_gameToLoad = -1;
|
|
|
|
}
|
2008-09-14 19:48:40 +00:00
|
|
|
|
2009-10-03 20:42:26 +00:00
|
|
|
setupKeyMap();
|
|
|
|
|
2008-09-14 19:48:40 +00:00
|
|
|
// Prevent autosave on game startup
|
|
|
|
_lastAutosave = _system->getMillis();
|
2008-03-28 00:53:54 +00:00
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
KyraEngine_v1::~KyraEngine_v1() {
|
2010-05-17 23:29:44 +00:00
|
|
|
for (Common::Array<const Opcode *>::iterator i = _opcodes.begin(); i != _opcodes.end(); ++i)
|
2008-04-20 15:16:58 +00:00
|
|
|
delete *i;
|
|
|
|
_opcodes.clear();
|
2009-10-03 20:42:26 +00:00
|
|
|
_keyMap.clear();
|
2008-04-20 15:16:58 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
delete _res;
|
2008-04-06 15:35:30 +00:00
|
|
|
delete _staticres;
|
2006-01-13 23:06:04 +00:00
|
|
|
delete _sound;
|
2006-01-02 22:58:59 +00:00
|
|
|
delete _text;
|
2007-07-29 16:33:11 +00:00
|
|
|
delete _timer;
|
2008-04-29 15:12:09 +00:00
|
|
|
delete _emc;
|
2008-05-06 20:50:27 +00:00
|
|
|
delete _debugger;
|
2006-02-09 12:19:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
Common::Point KyraEngine_v1::getMousePos() const {
|
2007-04-01 17:36:13 +00:00
|
|
|
Common::Point mouse = _eventMan->getMousePos();
|
2007-07-29 16:31:29 +00:00
|
|
|
|
2007-03-18 18:27:52 +00:00
|
|
|
if (_flags.useHiResOverlay) {
|
|
|
|
mouse.x >>= 1;
|
|
|
|
mouse.y >>= 1;
|
|
|
|
}
|
2007-04-15 16:41:20 +00:00
|
|
|
|
2007-07-29 16:31:29 +00:00
|
|
|
return mouse;
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::setMousePos(int x, int y) {
|
2008-03-16 02:00:14 +00:00
|
|
|
if (_flags.useHiResOverlay) {
|
|
|
|
x <<= 1;
|
|
|
|
y <<= 1;
|
|
|
|
}
|
|
|
|
_system->warpMouse(x, y);
|
|
|
|
}
|
|
|
|
|
2009-05-24 14:33:41 +00:00
|
|
|
int KyraEngine_v1::checkInput(Button *buttonList, bool mainLoop, int eventFlag) {
|
2009-01-21 15:36:31 +00:00
|
|
|
_isSaveAllowed = mainLoop;
|
2008-12-16 17:40:34 +00:00
|
|
|
updateInput();
|
|
|
|
_isSaveAllowed = false;
|
|
|
|
|
2009-05-29 12:28:39 +00:00
|
|
|
if (mainLoop)
|
|
|
|
checkAutosave();
|
|
|
|
|
2008-12-16 17:40:34 +00:00
|
|
|
int keys = 0;
|
|
|
|
int8 mouseWheel = 0;
|
|
|
|
|
2010-07-26 17:03:45 +00:00
|
|
|
while (!_eventList.empty()) {
|
2008-12-16 17:40:34 +00:00
|
|
|
Common::Event event = *_eventList.begin();
|
|
|
|
bool breakLoop = false;
|
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-02-17 16:18:23 +00:00
|
|
|
if (event.kbd.keycode >= Common::KEYCODE_1 && event.kbd.keycode <= Common::KEYCODE_9 &&
|
2010-02-21 04:04:13 +00:00
|
|
|
(event.kbd.hasFlags(Common::KBD_CTRL) || event.kbd.hasFlags(Common::KBD_ALT)) && mainLoop) {
|
2010-02-17 16:18:23 +00:00
|
|
|
int saveLoadSlot = 9 - (event.kbd.keycode - Common::KEYCODE_0) + 990;
|
2008-12-16 17:40:34 +00:00
|
|
|
|
2010-02-21 04:04:13 +00:00
|
|
|
if (event.kbd.hasFlags(Common::KBD_CTRL)) {
|
2010-02-19 14:05:55 +00:00
|
|
|
if (saveFileLoadable(saveLoadSlot))
|
|
|
|
loadGameStateCheck(saveLoadSlot);
|
2008-12-16 17:40:34 +00:00
|
|
|
_eventList.clear();
|
|
|
|
breakLoop = true;
|
|
|
|
} else {
|
|
|
|
char savegameName[14];
|
2010-02-17 16:18:23 +00:00
|
|
|
sprintf(savegameName, "Quicksave %d", event.kbd.keycode - Common::KEYCODE_0);
|
2010-10-28 23:57:24 +00:00
|
|
|
saveGameStateIntern(saveLoadSlot, savegameName, 0);
|
2008-12-16 17:40:34 +00:00
|
|
|
}
|
2010-02-21 04:04:13 +00:00
|
|
|
} else if (event.kbd.hasFlags(Common::KBD_CTRL)) {
|
2010-02-17 16:18:23 +00:00
|
|
|
if (event.kbd.keycode == Common::KEYCODE_d) {
|
2009-05-18 23:14:37 +00:00
|
|
|
if (_debugger)
|
|
|
|
_debugger->attach();
|
2010-07-26 17:03:45 +00:00
|
|
|
breakLoop = true;
|
2010-02-17 16:18:23 +00:00
|
|
|
} else if (event.kbd.keycode == Common::KEYCODE_q) {
|
2008-12-16 17:40:34 +00:00
|
|
|
quitGame();
|
2009-05-18 23:14:37 +00:00
|
|
|
}
|
2009-10-04 17:38:15 +00:00
|
|
|
} else {
|
2009-11-07 15:06:25 +00:00
|
|
|
KeyMap::const_iterator keycode = _keyMap.find(event.kbd.keycode);
|
|
|
|
if (keycode != _keyMap.end())
|
|
|
|
keys = keycode->_value;
|
|
|
|
else
|
|
|
|
keys = 0;
|
2009-05-17 21:52:31 +00:00
|
|
|
|
2009-05-17 21:55:24 +00:00
|
|
|
// When we got an keypress, which we might need to handle,
|
|
|
|
// break the event loop and pass it to GUI code.
|
2009-05-17 21:52:31 +00:00
|
|
|
if (keys)
|
|
|
|
breakLoop = true;
|
2008-12-16 17:40:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_LBUTTONUP: {
|
2009-06-01 17:50:30 +00:00
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
2009-06-06 12:18:39 +00:00
|
|
|
if (_flags.useHiResOverlay) {
|
|
|
|
_mouseX >>= 1;
|
|
|
|
_mouseY >>= 1;
|
|
|
|
}
|
2008-12-16 17:40:34 +00:00
|
|
|
keys = (event.type == Common::EVENT_LBUTTONDOWN ? 199 : (200 | 0x800));
|
|
|
|
breakLoop = true;
|
|
|
|
} break;
|
|
|
|
|
2009-02-01 19:27:01 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONUP: {
|
2009-06-01 17:50:30 +00:00
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
2009-06-06 12:18:39 +00:00
|
|
|
if (_flags.useHiResOverlay) {
|
|
|
|
_mouseX >>= 1;
|
|
|
|
_mouseY >>= 1;
|
|
|
|
}
|
2009-02-15 03:36:30 +00:00
|
|
|
keys = (event.type == Common::EVENT_RBUTTONDOWN ? 201 : (202 | 0x800));
|
2009-02-01 19:27:01 +00:00
|
|
|
breakLoop = true;
|
|
|
|
} break;
|
|
|
|
|
2008-12-16 17:40:34 +00:00
|
|
|
case Common::EVENT_WHEELUP:
|
|
|
|
mouseWheel = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_WHEELDOWN:
|
|
|
|
mouseWheel = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
if (_debugger)
|
2008-12-16 17:40:34 +00:00
|
|
|
_debugger->onFrame();
|
|
|
|
|
|
|
|
if (breakLoop)
|
|
|
|
break;
|
|
|
|
|
|
|
|
_eventList.erase(_eventList.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
GUI *guiInstance = gui();
|
2009-05-21 17:49:51 +00:00
|
|
|
if (guiInstance) {
|
|
|
|
if (keys)
|
2009-05-24 14:33:41 +00:00
|
|
|
return guiInstance->processButtonList(buttonList, keys | eventFlag, mouseWheel);
|
2009-05-21 17:49:51 +00:00
|
|
|
else
|
|
|
|
return guiInstance->processButtonList(buttonList, 0, mouseWheel);
|
|
|
|
} else {
|
2008-12-16 17:40:34 +00:00
|
|
|
return keys;
|
2009-05-21 17:49:51 +00:00
|
|
|
}
|
2008-12-16 17:40:34 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 20:42:26 +00:00
|
|
|
void KyraEngine_v1::setupKeyMap() {
|
2011-06-02 22:39:07 +00:00
|
|
|
struct KeyMapEntry {
|
|
|
|
Common::KeyCode kcScummVM;
|
|
|
|
int16 kcDOS;
|
|
|
|
int16 kcPC98;
|
2009-10-03 20:42:26 +00:00
|
|
|
};
|
|
|
|
|
2011-06-02 22:39:07 +00:00
|
|
|
#define KC(x) Common::KEYCODE_##x
|
|
|
|
static const KeyMapEntry keys[] = {
|
|
|
|
{ KC(SPACE), 61, 53 },
|
|
|
|
{ KC(RETURN), 43, 29 },
|
|
|
|
{ KC(UP), 96, 68 },
|
|
|
|
{ KC(KP8), 96, 68 },
|
|
|
|
{ KC(RIGHT), 102, 73 },
|
|
|
|
{ KC(KP6), 102, 73 },
|
|
|
|
{ KC(DOWN), 98, 76 },
|
|
|
|
{ KC(KP2), 98, 76 },
|
|
|
|
{ KC(KP5), 97, 72 },
|
|
|
|
{ KC(LEFT), 92, 71 },
|
|
|
|
{ KC(KP4), 92, 71 },
|
|
|
|
{ KC(HOME), 91, 67 },
|
|
|
|
{ KC(KP7), 91, 67 },
|
|
|
|
{ KC(PAGEUP), 101, 69 },
|
|
|
|
{ KC(KP9), 101, 69 },
|
|
|
|
{ KC(F1), 112, 99 },
|
|
|
|
{ KC(F2), 113, 100 },
|
|
|
|
{ KC(F3), 114, 101 },
|
|
|
|
{ KC(o), 25, 25 },
|
|
|
|
{ KC(r), 20, 20 },
|
|
|
|
{ KC(SLASH), 55, 55 },
|
|
|
|
{ KC(ESCAPE), 110, 1 },
|
|
|
|
};
|
|
|
|
#undef KC
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-03 20:42:26 +00:00
|
|
|
_keyMap.clear();
|
|
|
|
|
2011-06-02 22:39:07 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(keys); i++)
|
|
|
|
_keyMap[keys[i].kcScummVM] = (_flags.platform == Common::kPlatformPC98) ? keys[i].kcPC98 : keys[i].kcDOS;
|
2009-10-03 20:42:26 +00:00
|
|
|
}
|
|
|
|
|
2008-12-16 17:40:34 +00:00
|
|
|
void KyraEngine_v1::updateInput() {
|
|
|
|
Common::Event event;
|
|
|
|
|
2009-04-18 03:15:34 +00:00
|
|
|
bool updateScreen = false;
|
|
|
|
|
2008-12-16 17:40:34 +00:00
|
|
|
while (_eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-02-17 16:18:23 +00:00
|
|
|
if (event.kbd.keycode == Common::KEYCODE_PERIOD || event.kbd.keycode == Common::KEYCODE_ESCAPE ||
|
2009-02-14 00:51:07 +00:00
|
|
|
event.kbd.keycode == Common::KEYCODE_SPACE || event.kbd.keycode == Common::KEYCODE_RETURN ||
|
|
|
|
event.kbd.keycode == Common::KEYCODE_UP || event.kbd.keycode == Common::KEYCODE_RIGHT ||
|
|
|
|
event.kbd.keycode == Common::KEYCODE_DOWN || event.kbd.keycode == Common::KEYCODE_LEFT)
|
|
|
|
_eventList.push_back(Event(event, true));
|
2010-02-21 04:04:13 +00:00
|
|
|
else if (event.kbd.keycode == Common::KEYCODE_q && event.kbd.hasFlags(Common::KBD_CTRL))
|
2008-12-16 17:40:34 +00:00
|
|
|
quitGame();
|
|
|
|
else
|
|
|
|
_eventList.push_back(event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2009-02-14 00:51:07 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2008-12-16 17:40:34 +00:00
|
|
|
_eventList.push_back(Event(event, true));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2009-04-18 03:15:34 +00:00
|
|
|
if (screen()->isMouseVisible())
|
|
|
|
updateScreen = true;
|
2009-05-22 22:28:06 +00:00
|
|
|
break;
|
2008-12-16 17:40:34 +00:00
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2009-02-14 00:51:07 +00:00
|
|
|
case Common::EVENT_RBUTTONUP:
|
2008-12-16 17:40:34 +00:00
|
|
|
case Common::EVENT_WHEELUP:
|
|
|
|
case Common::EVENT_WHEELDOWN:
|
|
|
|
_eventList.push_back(event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-04-18 03:15:34 +00:00
|
|
|
|
|
|
|
if (updateScreen)
|
2009-08-19 16:19:55 +00:00
|
|
|
_system->updateScreen();
|
2008-12-16 17:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine_v1::removeInputTop() {
|
|
|
|
if (!_eventList.empty())
|
|
|
|
_eventList.erase(_eventList.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KyraEngine_v1::skipFlag() const {
|
|
|
|
for (Common::List<Event>::const_iterator i = _eventList.begin(); i != _eventList.end(); ++i) {
|
|
|
|
if (i->causedSkip)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine_v1::resetSkipFlag(bool removeEvent) {
|
|
|
|
for (Common::List<Event>::iterator i = _eventList.begin(); i != _eventList.end(); ++i) {
|
|
|
|
if (i->causedSkip) {
|
|
|
|
if (removeEvent)
|
|
|
|
_eventList.erase(i);
|
|
|
|
else
|
|
|
|
i->causedSkip = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
int KyraEngine_v1::setGameFlag(int flag) {
|
2009-06-07 20:43:43 +00:00
|
|
|
assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable));
|
2006-02-11 08:31:13 +00:00
|
|
|
_flagsTable[flag >> 3] |= (1 << (flag & 7));
|
|
|
|
return 1;
|
2005-12-10 15:52:38 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
int KyraEngine_v1::queryGameFlag(int flag) const {
|
2009-06-07 20:43:43 +00:00
|
|
|
assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable));
|
2006-02-11 08:31:13 +00:00
|
|
|
return ((_flagsTable[flag >> 3] >> (flag & 7)) & 1);
|
2005-12-10 15:52:38 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
int KyraEngine_v1::resetGameFlag(int flag) {
|
2009-06-07 20:43:43 +00:00
|
|
|
assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable));
|
2006-02-11 08:31:13 +00:00
|
|
|
_flagsTable[flag >> 3] &= ~(1 << (flag & 7));
|
|
|
|
return 0;
|
2005-12-26 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::delayUntil(uint32 timestamp, bool updateTimers, bool update, bool isMainLoop) {
|
2009-06-01 23:38:56 +00:00
|
|
|
const uint32 curTime = _system->getMillis();
|
|
|
|
if (curTime > timestamp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32 del = timestamp - curTime;
|
|
|
|
while (del && !shouldQuit()) {
|
|
|
|
uint32 step = MIN<uint32>(del, _tickLength);
|
|
|
|
delay(step, update, isMainLoop);
|
|
|
|
del -= step;
|
2005-11-18 23:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::delay(uint32 amount, bool update, bool isMainLoop) {
|
2007-07-29 16:31:29 +00:00
|
|
|
_system->delayMillis(amount);
|
2005-12-09 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::delayWithTicks(int ticks) {
|
2007-07-29 16:31:29 +00:00
|
|
|
delay(ticks * _tickLength);
|
2005-12-09 23:02:16 +00:00
|
|
|
}
|
2006-04-08 11:21:04 +00:00
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::registerDefaultSettings() {
|
2009-05-17 21:55:24 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns)
|
2008-09-14 14:58:37 +00:00
|
|
|
ConfMan.registerDefault("cdaudio", true);
|
2008-07-05 08:20:10 +00:00
|
|
|
if (_flags.fanLang != Common::UNK_LANG) {
|
|
|
|
// HACK/WORKAROUND: Since we can't use registerDefault here to overwrite
|
|
|
|
// the global subtitles settings, we're using this hack to enable subtitles
|
|
|
|
// for fan translations
|
|
|
|
const Common::ConfigManager::Domain *cur = ConfMan.getActiveDomain();
|
2010-03-29 20:31:23 +00:00
|
|
|
if (!cur || (cur && cur->getVal("subtitles").empty()))
|
2008-07-05 08:20:10 +00:00
|
|
|
ConfMan.setBool("subtitles", true);
|
|
|
|
}
|
2008-01-27 15:30:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::readSettings() {
|
2008-01-27 15:30:53 +00:00
|
|
|
_configWalkspeed = ConfMan.getInt("walkspeed");
|
2008-02-07 23:31:13 +00:00
|
|
|
_configMusic = 0;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-02-07 23:31:13 +00:00
|
|
|
if (!ConfMan.getBool("music_mute")) {
|
2009-05-17 22:12:36 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns)
|
2008-09-14 15:35:40 +00:00
|
|
|
_configMusic = ConfMan.getBool("cdaudio") ? 2 : 1;
|
|
|
|
else
|
|
|
|
_configMusic = 1;
|
2008-02-07 23:31:13 +00:00
|
|
|
}
|
2008-01-27 15:30:53 +00:00
|
|
|
_configSounds = ConfMan.getBool("sfx_mute") ? 0 : 1;
|
|
|
|
|
2008-04-29 15:12:09 +00:00
|
|
|
if (_sound) {
|
|
|
|
_sound->enableMusic(_configMusic);
|
|
|
|
_sound->enableSFX(_configSounds);
|
|
|
|
}
|
2008-01-27 15:30:53 +00:00
|
|
|
|
|
|
|
bool speechMute = ConfMan.getBool("speech_mute");
|
|
|
|
bool subtitles = ConfMan.getBool("subtitles");
|
|
|
|
|
|
|
|
if (!speechMute && subtitles)
|
|
|
|
_configVoice = 2; // Voice & Text
|
|
|
|
else if (!speechMute && !subtitles)
|
|
|
|
_configVoice = 1; // Voice only
|
|
|
|
else
|
|
|
|
_configVoice = 0; // Text only
|
|
|
|
|
|
|
|
setWalkspeed(_configWalkspeed);
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::writeSettings() {
|
2008-01-27 15:30:53 +00:00
|
|
|
bool speechMute, subtitles;
|
|
|
|
|
|
|
|
ConfMan.setInt("walkspeed", _configWalkspeed);
|
|
|
|
ConfMan.setBool("music_mute", _configMusic == 0);
|
2009-05-17 22:49:25 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns)
|
2008-02-07 23:31:13 +00:00
|
|
|
ConfMan.setBool("cdaudio", _configMusic == 2);
|
2008-01-27 15:30:53 +00:00
|
|
|
ConfMan.setBool("sfx_mute", _configSounds == 0);
|
|
|
|
|
|
|
|
switch (_configVoice) {
|
|
|
|
case 0: // Text only
|
|
|
|
speechMute = true;
|
|
|
|
subtitles = true;
|
|
|
|
break;
|
|
|
|
case 1: // Voice only
|
|
|
|
speechMute = false;
|
|
|
|
subtitles = false;
|
|
|
|
break;
|
|
|
|
default: // Voice & Text
|
|
|
|
speechMute = false;
|
|
|
|
subtitles = true;
|
|
|
|
}
|
|
|
|
|
2008-04-29 15:12:09 +00:00
|
|
|
if (_sound) {
|
|
|
|
if (!_configMusic)
|
|
|
|
_sound->beginFadeOut();
|
|
|
|
_sound->enableMusic(_configMusic);
|
|
|
|
_sound->enableSFX(_configSounds);
|
|
|
|
}
|
2008-01-27 15:30:53 +00:00
|
|
|
|
|
|
|
ConfMan.setBool("speech_mute", speechMute);
|
|
|
|
ConfMan.setBool("subtitles", subtitles);
|
|
|
|
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
bool KyraEngine_v1::speechEnabled() {
|
2008-01-27 15:30:53 +00:00
|
|
|
return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2);
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
bool KyraEngine_v1::textEnabled() {
|
2008-01-27 15:30:53 +00:00
|
|
|
return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2);
|
|
|
|
}
|
|
|
|
|
2009-06-21 20:10:45 +00:00
|
|
|
int KyraEngine_v1::convertVolumeToMixer(int value) {
|
2008-04-04 18:02:50 +00:00
|
|
|
value -= 2;
|
|
|
|
return (value * Audio::Mixer::kMaxMixerVolume) / 95;
|
|
|
|
}
|
|
|
|
|
2009-06-21 20:10:45 +00:00
|
|
|
int KyraEngine_v1::convertVolumeFromMixer(int value) {
|
2008-04-04 18:02:50 +00:00
|
|
|
return (value * 95) / Audio::Mixer::kMaxMixerVolume + 2;
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::setVolume(kVolumeEntry vol, uint8 value) {
|
2008-04-04 18:02:50 +00:00
|
|
|
switch (vol) {
|
|
|
|
case kVolumeMusic:
|
2009-06-21 20:10:45 +00:00
|
|
|
ConfMan.setInt("music_volume", convertVolumeToMixer(value));
|
2008-04-04 18:02:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kVolumeSfx:
|
2009-06-21 20:10:45 +00:00
|
|
|
ConfMan.setInt("sfx_volume", convertVolumeToMixer(value));
|
2008-04-04 18:02:50 +00:00
|
|
|
break;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-04 18:02:50 +00:00
|
|
|
case kVolumeSpeech:
|
2009-06-21 20:10:45 +00:00
|
|
|
ConfMan.setInt("speech_volume", convertVolumeToMixer(value));
|
2008-04-04 18:02:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resetup mixer
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
2008-04-04 18:09:19 +00:00
|
|
|
if (_sound)
|
|
|
|
_sound->updateVolumeSettings();
|
2008-04-04 18:02:50 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
uint8 KyraEngine_v1::getVolume(kVolumeEntry vol) {
|
2008-04-04 18:02:50 +00:00
|
|
|
switch (vol) {
|
|
|
|
case kVolumeMusic:
|
2009-06-21 20:10:45 +00:00
|
|
|
return convertVolumeFromMixer(ConfMan.getInt("music_volume"));
|
2008-04-04 18:02:50 +00:00
|
|
|
|
|
|
|
case kVolumeSfx:
|
2009-06-21 20:10:45 +00:00
|
|
|
return convertVolumeFromMixer(ConfMan.getInt("sfx_volume"));
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-04 18:02:50 +00:00
|
|
|
case kVolumeSpeech:
|
|
|
|
if (speechEnabled())
|
2009-06-21 20:10:45 +00:00
|
|
|
return convertVolumeFromMixer(ConfMan.getInt("speech_volume"));
|
2008-04-04 18:02:50 +00:00
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2008-11-09 12:07:20 +00:00
|
|
|
void KyraEngine_v1::syncSoundSettings() {
|
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
2010-08-05 14:41:00 +00:00
|
|
|
// We need to use this here to allow the subtitle options to be changed
|
|
|
|
// through the GMM's options dialog.
|
|
|
|
readSettings();
|
|
|
|
|
2008-11-09 12:07:20 +00:00
|
|
|
if (_sound)
|
|
|
|
_sound->updateVolumeSettings();
|
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
} // End of namespace Kyra
|