2009-06-12 12:40:18 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-06-12 14:19:33 +00:00
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-06-12 12:40:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/file.h"
|
2009-08-05 05:41:32 +00:00
|
|
|
#include "common/EventRecorder.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-06-12 17:34:06 +00:00
|
|
|
#include "asylum/asylum.h"
|
2009-06-15 14:37:23 +00:00
|
|
|
#include "asylum/respack.h"
|
2009-08-08 12:38:17 +00:00
|
|
|
#include "asylum/shared.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
|
|
|
namespace Asylum {
|
|
|
|
|
|
|
|
AsylumEngine::AsylumEngine(OSystem *system, Common::Language language)
|
2009-07-08 19:17:47 +00:00
|
|
|
: Engine(system) {
|
|
|
|
|
|
|
|
Common::addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
2009-07-06 23:35:54 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelInput, "Input", "Input events debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelMenu, "Menu", "Menu debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelScripts, "Scripts", "Scripts debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging");
|
2009-08-19 22:19:25 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelScene, "Scene", "Scene process and draw debugging");
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Data"));
|
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Vids"));
|
2009-06-12 12:40:18 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Music"));
|
|
|
|
|
2009-08-05 05:41:32 +00:00
|
|
|
g_eventRec.registerRandomSource(_rnd, "asylum");
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AsylumEngine::~AsylumEngine() {
|
2009-07-09 11:18:15 +00:00
|
|
|
Common::clearAllDebugChannels();
|
|
|
|
|
2009-06-21 12:09:44 +00:00
|
|
|
delete _console;
|
2009-06-19 08:53:58 +00:00
|
|
|
delete _scene;
|
2009-06-14 14:31:23 +00:00
|
|
|
delete _mainMenu;
|
2009-06-13 23:16:07 +00:00
|
|
|
delete _video;
|
2009-06-13 23:03:37 +00:00
|
|
|
delete _sound;
|
|
|
|
delete _screen;
|
2009-08-07 12:03:23 +00:00
|
|
|
delete _encounter;
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::run() {
|
2009-07-08 19:17:47 +00:00
|
|
|
Common::Error err;
|
|
|
|
err = init();
|
|
|
|
if (err != Common::kNoError)
|
|
|
|
return err;
|
|
|
|
return go();
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Will do the same as subroutine at address 0041A500
|
|
|
|
Common::Error AsylumEngine::init() {
|
2009-06-12 20:07:11 +00:00
|
|
|
initGraphics(640, 480, true);
|
2009-06-12 20:38:38 +00:00
|
|
|
|
2009-07-09 11:18:15 +00:00
|
|
|
_screen = new Screen(_system);
|
|
|
|
_sound = new Sound(_mixer);
|
|
|
|
_video = new Video(_mixer);
|
|
|
|
_console = new Console(this);
|
|
|
|
_mainMenu = 0;
|
|
|
|
_scene = 0;
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-08-12 20:20:43 +00:00
|
|
|
Shared.setOSystem(_system);
|
2009-08-08 12:38:17 +00:00
|
|
|
Shared.setScreen(_screen);
|
|
|
|
Shared.setSound(_sound);
|
|
|
|
Shared.setVideo(_video);
|
|
|
|
|
2009-08-09 22:56:13 +00:00
|
|
|
_introPlaying = false;
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
return Common::kNoError;
|
2009-06-14 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::go() {
|
2009-06-12 12:40:18 +00:00
|
|
|
// TODO: save dialogue key codes into sntrm_k.txt (need to figure out why they use such thing)
|
|
|
|
// TODO: load startup configurations (address 0041A970)
|
|
|
|
// TODO: init unknown game stuffs (address 0040F430)
|
|
|
|
// TODO: if savegame exists on folder, than start NewGame()
|
|
|
|
|
2009-06-15 14:15:12 +00:00
|
|
|
// Set up the game's main scene
|
2009-08-08 12:38:17 +00:00
|
|
|
_scene = new Scene(5);
|
|
|
|
Shared.setScene(_scene);
|
2009-08-01 17:51:26 +00:00
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
// XXX This is just here for testing purposes. It is also defined
|
|
|
|
// in the processActionList() method when the necessary action is fired.
|
|
|
|
// Once the blowup puzzle testing is removed from checkForEvent(), this
|
|
|
|
// can be removed as well.
|
2009-08-08 12:38:17 +00:00
|
|
|
_scene->setBlowUpPuzzle(new BlowUpPuzzleVCR()); // this will be done by a Script command
|
2009-07-09 02:14:07 +00:00
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
// XXX This can probably also be rolled into the scene constructor.
|
2009-07-09 02:14:07 +00:00
|
|
|
// Investigate if this will fuck up the execution sequence though :P
|
2009-07-30 02:27:11 +00:00
|
|
|
ScriptMan.setScript(_scene->getDefaultActionList());
|
2009-06-15 12:28:19 +00:00
|
|
|
|
|
|
|
// Set up main menu
|
2009-08-08 12:38:17 +00:00
|
|
|
_mainMenu = new MainMenu();
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2009-08-07 12:03:23 +00:00
|
|
|
// XXX Testing
|
|
|
|
_encounter = new Encounter(_scene);
|
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
// TODO you should be able to skip this if you want. The original
|
|
|
|
// allows this through the /SKIP command line argument.
|
|
|
|
// Also, this routine is used to set game flags 4 and 12, so if we're
|
|
|
|
// skipping the intro, but not loading a save file, those flags
|
|
|
|
// need to be set somewhere else.
|
2009-08-10 11:53:45 +00:00
|
|
|
//playIntro();
|
2009-08-09 13:24:36 +00:00
|
|
|
|
2009-06-15 12:28:19 +00:00
|
|
|
// Enter first scene
|
2009-08-12 20:20:43 +00:00
|
|
|
Shared.setGameFlag(4);
|
|
|
|
Shared.setGameFlag(12);
|
2009-08-10 11:53:45 +00:00
|
|
|
_scene->enterScene();
|
2009-06-12 12:40:18 +00:00
|
|
|
|
|
|
|
while (!shouldQuit()) {
|
2009-06-13 19:38:25 +00:00
|
|
|
checkForEvent(true);
|
2009-06-28 11:59:25 +00:00
|
|
|
waitForTimer(55);
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
return Common::kNoError;
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-12 21:09:17 +00:00
|
|
|
|
2009-06-13 13:40:48 +00:00
|
|
|
void AsylumEngine::waitForTimer(int msec_delay) {
|
|
|
|
uint32 start_time = _system->getMillis();
|
|
|
|
|
|
|
|
while (_system->getMillis() < start_time + msec_delay) {
|
2009-06-13 19:38:25 +00:00
|
|
|
checkForEvent(false);
|
2009-07-09 11:23:42 +00:00
|
|
|
processDelayedEvents();
|
2009-06-13 13:40:48 +00:00
|
|
|
_system->updateScreen();
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
void AsylumEngine::playIntro() {
|
|
|
|
_video->playVideo(1, kSubtitlesOn);
|
2009-09-19 12:24:53 +00:00
|
|
|
if (_scene->worldstats()->musicCurrentResId != 0xFFFFFD66)
|
2009-08-09 15:50:19 +00:00
|
|
|
_sound->playMusic(_scene->getMusicPack(),
|
2009-09-19 12:24:53 +00:00
|
|
|
_scene->worldstats()->musicCurrentResId);
|
2009-08-09 13:24:36 +00:00
|
|
|
|
|
|
|
_screen->clearScreen();
|
|
|
|
|
2009-08-12 20:20:43 +00:00
|
|
|
Shared.setGameFlag(4);
|
|
|
|
Shared.setGameFlag(12);
|
2009-08-09 13:24:36 +00:00
|
|
|
|
|
|
|
ResourcePack *introRes = new ResourcePack(18);
|
|
|
|
|
|
|
|
_sound->playSfx(introRes, 7);
|
|
|
|
|
2009-08-09 22:56:13 +00:00
|
|
|
_introPlaying = true;
|
2009-08-09 13:24:36 +00:00
|
|
|
|
|
|
|
delete introRes;
|
|
|
|
}
|
|
|
|
|
2009-08-18 21:07:40 +00:00
|
|
|
void AsylumEngine::checkForEvent(bool doUpdate) { // k_sub_40AE30 (0040AE30)
|
2009-08-09 22:56:13 +00:00
|
|
|
|
|
|
|
// NOTE
|
|
|
|
// In the original version of Sanitarium, the control loop for the sound
|
|
|
|
// effect that played after the intro video involved a while loop that
|
|
|
|
// executed until the sound handle was released.
|
|
|
|
// This caused the application to be locked until the while loop's execution
|
|
|
|
// completed successfully. Our implementation circumvents this issue
|
|
|
|
// by moving the logic to the event loop and checking whether a flag is
|
|
|
|
// set to determine if control should be returned to the engine.
|
|
|
|
if (_introPlaying) {
|
|
|
|
if (!_sound->isSfxActive()) {
|
|
|
|
_introPlaying = false;
|
|
|
|
|
|
|
|
// TODO Since we've currently only got one sfx handle to play with in
|
|
|
|
// the sound class, entering the scene overwrites the "alarm" loop.
|
|
|
|
// This sound is technically supposed to play until the actor disables
|
|
|
|
// the alarm by flipping the switch. The sound class needs to be extended
|
|
|
|
// to be able to handle multiple handles.
|
|
|
|
// The currently active sound resources can probably also be buffered into
|
|
|
|
// the scene's soundResId[] array (seems that's the way the original worked,
|
|
|
|
// especially when you examine isSoundinList() or isSoundPlaying())
|
|
|
|
|
|
|
|
_scene->enterScene();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-13 13:40:48 +00:00
|
|
|
Common::Event ev;
|
|
|
|
|
|
|
|
if (_system->getEventManager()->pollEvent(ev)) {
|
|
|
|
if (ev.type == Common::EVENT_KEYDOWN) {
|
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_ESCAPE) {
|
2009-06-15 12:28:19 +00:00
|
|
|
// Toggle menu
|
|
|
|
if (_mainMenu->isActive()) {
|
|
|
|
_mainMenu->closeMenu();
|
2009-06-15 14:15:12 +00:00
|
|
|
_scene->enterScene();
|
2009-06-21 12:09:44 +00:00
|
|
|
} else if (_scene->isActive()) {
|
2009-06-15 12:28:19 +00:00
|
|
|
_mainMenu->openMenu();
|
2009-08-06 00:04:09 +00:00
|
|
|
} else if (_scene->getBlowUpPuzzle()->isActive()) {
|
|
|
|
_scene->getBlowUpPuzzle()->closeBlowUp();
|
2009-08-01 17:51:26 +00:00
|
|
|
_scene->enterScene();
|
2009-06-15 12:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-21 12:09:44 +00:00
|
|
|
|
2009-08-09 13:28:49 +00:00
|
|
|
// XXX: TEST ONLY
|
2009-08-01 17:51:26 +00:00
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_b) {
|
|
|
|
//_mainMenu->closeMenu();
|
2009-08-06 00:04:09 +00:00
|
|
|
_scene->getBlowUpPuzzle()->openBlowUp();
|
2009-08-01 17:51:26 +00:00
|
|
|
}
|
|
|
|
|
2009-06-21 12:09:44 +00:00
|
|
|
if (ev.kbd.flags == Common::KBD_CTRL) {
|
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_d)
|
|
|
|
_console->attach();
|
|
|
|
}
|
|
|
|
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-13 19:38:25 +00:00
|
|
|
|
|
|
|
if (doUpdate) {
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive() || _scene->isActive() || _scene->getBlowUpPuzzle()->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
// Copy background image
|
|
|
|
_screen->copyBackBufferToScreen();
|
|
|
|
|
|
|
|
if (_console->isAttached())
|
|
|
|
_console->onFrame();
|
2009-06-13 19:38:25 +00:00
|
|
|
}
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive())
|
2009-06-15 12:28:19 +00:00
|
|
|
// Main menu active, pass events to it
|
|
|
|
_mainMenu->handleEvent(&ev, doUpdate);
|
2009-08-09 13:28:49 +00:00
|
|
|
else if (_scene->isActive())
|
2009-06-15 12:28:19 +00:00
|
|
|
// Pass events to the game
|
2009-06-15 14:15:12 +00:00
|
|
|
_scene->handleEvent(&ev, doUpdate);
|
2009-08-09 13:28:49 +00:00
|
|
|
else if (_scene->getBlowUpPuzzle()->isActive())
|
2009-08-01 17:51:26 +00:00
|
|
|
// Pass events to BlowUp Puzzles
|
2009-08-06 00:04:09 +00:00
|
|
|
_scene->getBlowUpPuzzle()->handleEvent(&ev, doUpdate);
|
2009-08-09 22:56:13 +00:00
|
|
|
|
|
|
|
if (_introPlaying) {
|
|
|
|
|
|
|
|
}
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 11:23:42 +00:00
|
|
|
void AsylumEngine::processDelayedEvents() {
|
|
|
|
// check for a delayed video
|
2009-09-09 17:00:08 +00:00
|
|
|
int videoIdx = ScriptMan.delayedVideoIndex;
|
2009-07-09 02:14:07 +00:00
|
|
|
if (videoIdx >= 0) {
|
2009-06-21 12:09:44 +00:00
|
|
|
_sound->stopMusic();
|
|
|
|
_sound->stopSfx();
|
2009-07-09 02:14:07 +00:00
|
|
|
_video->playVideo(videoIdx, kSubtitlesOn);
|
2009-09-09 17:00:08 +00:00
|
|
|
ScriptMan.delayedVideoIndex = -1;
|
2009-06-21 12:09:44 +00:00
|
|
|
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
_mainMenu->openMenu();
|
2009-08-09 13:28:49 +00:00
|
|
|
else if (_scene->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
_scene->enterScene();
|
|
|
|
}
|
2009-07-07 13:59:11 +00:00
|
|
|
|
2009-07-09 11:23:42 +00:00
|
|
|
// check for a delayed scene change
|
2009-09-09 17:00:08 +00:00
|
|
|
int sceneIdx = ScriptMan.delayedSceneIndex;
|
|
|
|
if (sceneIdx >=0 && !ScriptMan.processing) {
|
2009-07-07 13:59:11 +00:00
|
|
|
_sound->stopMusic();
|
|
|
|
_sound->stopSfx();
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
if (_scene)
|
|
|
|
delete _scene;
|
2009-07-07 13:59:11 +00:00
|
|
|
|
2009-08-08 12:38:17 +00:00
|
|
|
_scene = new Scene(sceneIdx);
|
2009-08-09 13:24:36 +00:00
|
|
|
Shared.setScene(_scene);
|
2009-07-08 19:17:47 +00:00
|
|
|
_scene->enterScene();
|
2009-08-08 12:38:17 +00:00
|
|
|
|
2009-09-09 17:00:08 +00:00
|
|
|
ScriptMan.delayedSceneIndex = -1;
|
2009-07-30 02:27:11 +00:00
|
|
|
ScriptMan.setScript(_scene->getDefaultActionList());
|
2009-07-07 13:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 12:40:18 +00:00
|
|
|
} // namespace Asylum
|