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-06-12 17:34:06 +00:00
|
|
|
#include "asylum/asylum.h"
|
2009-06-15 14:37:23 +00:00
|
|
|
#include "asylum/respack.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
|
|
|
namespace Asylum {
|
|
|
|
|
|
|
|
AsylumEngine::AsylumEngine(OSystem *system, Common::Language language)
|
|
|
|
: Engine(system) {
|
2009-07-06 23:35:54 +00:00
|
|
|
|
|
|
|
Common::addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
|
|
|
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-06-12 12:40:18 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Data"));
|
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Vids"));
|
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("Music"));
|
|
|
|
|
|
|
|
_eventMan->registerRandomSource(_rnd, "asylum");
|
|
|
|
}
|
|
|
|
|
|
|
|
AsylumEngine::~AsylumEngine() {
|
|
|
|
//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-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::run() {
|
|
|
|
Common::Error err;
|
|
|
|
err = init();
|
|
|
|
if (err != Common::kNoError)
|
|
|
|
return err;
|
|
|
|
return go();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will do the same as subroutine at address 0041A500
|
|
|
|
Common::Error AsylumEngine::init() {
|
|
|
|
// initialize engine objects
|
|
|
|
|
2009-06-12 20:07:11 +00:00
|
|
|
initGraphics(640, 480, true);
|
2009-06-12 20:38:38 +00:00
|
|
|
|
2009-07-06 23:35:54 +00:00
|
|
|
_screen = new Screen(_system);
|
|
|
|
_sound = new Sound(_mixer);
|
|
|
|
_video = new Video(_mixer);
|
|
|
|
_console = new Console(this);
|
|
|
|
_interpreter = 0;
|
|
|
|
_mainMenu = 0;
|
|
|
|
_scene = 0;
|
2009-06-21 12:09:44 +00:00
|
|
|
_delayedVideoNumber = -1;
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-06-14 18:46:29 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::go() {
|
|
|
|
// initializing game
|
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-12 21:53:48 +00:00
|
|
|
// Play intro movie
|
|
|
|
// Disabled for quick testing
|
2009-06-20 10:26:04 +00:00
|
|
|
//_video->playVideo(0, kSubtitlesOn); // Note: this video has no subtitles
|
2009-06-13 23:16:07 +00:00
|
|
|
|
2009-06-18 09:41:31 +00:00
|
|
|
// Play first chapter movie (for testing)
|
2009-06-19 08:07:38 +00:00
|
|
|
//_video->playVideo(1, kSubtitlesOn);
|
2009-06-18 09:41:31 +00:00
|
|
|
|
2009-06-15 14:15:12 +00:00
|
|
|
// Set up the game's main scene
|
|
|
|
_scene = new Scene(_screen, _sound, 5);
|
2009-07-06 23:35:54 +00:00
|
|
|
|
|
|
|
// Set up the game's script interpreter
|
|
|
|
_interpreter = new Interpreter(_scene);
|
2009-06-15 12:28:19 +00:00
|
|
|
|
|
|
|
// Set up main menu
|
2009-06-15 14:15:12 +00:00
|
|
|
_mainMenu = new MainMenu(_screen, _sound, _scene);
|
2009-06-15 12:28:19 +00:00
|
|
|
|
|
|
|
// Enter first scene
|
2009-06-15 14:15:12 +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
|
|
|
}
|
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
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-06-21 12:09:44 +00:00
|
|
|
checkForDelayedVideo();
|
2009-06-13 13:40:48 +00:00
|
|
|
_system->updateScreen();
|
2009-07-06 23:35:54 +00:00
|
|
|
_interpreter->processActionLists();
|
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-06-13 19:38:25 +00:00
|
|
|
void AsylumEngine::checkForEvent(bool doUpdate) {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-06-13 13:40:48 +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-06-21 12:09:44 +00:00
|
|
|
if (_mainMenu->isActive() || _scene->isActive()) {
|
|
|
|
// 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
|
|
|
|
|
|
|
if (_mainMenu->isActive()) {
|
|
|
|
// Main menu active, pass events to it
|
|
|
|
_mainMenu->handleEvent(&ev, doUpdate);
|
2009-06-21 12:09:44 +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-06-15 12:28:19 +00:00
|
|
|
}
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-21 12:09:44 +00:00
|
|
|
void AsylumEngine::checkForDelayedVideo() {
|
|
|
|
if (_delayedVideoNumber >= 0) {
|
|
|
|
_sound->stopMusic();
|
|
|
|
_sound->stopSfx();
|
|
|
|
_video->playVideo(_delayedVideoNumber, kSubtitlesOn);
|
|
|
|
_delayedVideoNumber = -1;
|
|
|
|
|
|
|
|
if (_mainMenu->isActive()) {
|
|
|
|
_mainMenu->openMenu();
|
|
|
|
} else if (_scene->isActive()) {
|
|
|
|
_scene->enterScene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 12:40:18 +00:00
|
|
|
} // namespace Asylum
|