2004-04-12 21:51:26 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 The ScummVM project
|
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
2004-03-14 23:39:41 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "base/gameDetector.h"
|
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "backends/fs/fs.h"
|
|
|
|
|
|
|
|
#include "sound/mixer.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
|
|
|
|
|
|
|
#include "saga/gfx.h"
|
|
|
|
#include "saga/rscfile_mod.h"
|
|
|
|
#include "saga/render.h"
|
|
|
|
#include "saga/actor.h"
|
|
|
|
#include "saga/animation.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/cvar_mod.h"
|
2004-08-10 19:00:30 +00:00
|
|
|
#include "saga/events.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/font.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/game_mod.h"
|
|
|
|
#include "saga/game.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/isomap.h"
|
|
|
|
#include "saga/script.h"
|
2004-08-04 20:28:57 +00:00
|
|
|
#include "saga/scene.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sdata.h"
|
|
|
|
#include "saga/sndres.h"
|
2004-08-03 01:07:34 +00:00
|
|
|
#include "saga/sprite.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sound.h"
|
|
|
|
#include "saga/music.h"
|
|
|
|
#include "saga/game_mod.h"
|
2004-08-10 19:20:33 +00:00
|
|
|
#include "saga/palanim.h"
|
2004-03-14 23:39:41 +00:00
|
|
|
|
|
|
|
GameList Engine_SAGA_gameList() {
|
2004-05-01 23:42:22 +00:00
|
|
|
return Saga::GAME_GameList();
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DetectedGameList Engine_SAGA_detectGames(const FSList &fslist) {
|
2004-05-01 23:42:22 +00:00
|
|
|
return Saga::GAME_ProbeGame(fslist);
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine *Engine_SAGA_create(GameDetector *detector, OSystem *syst) {
|
2004-03-15 01:59:06 +00:00
|
|
|
return new Saga::SagaEngine(detector, syst);
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_PLUGIN("SAGA Engine", Engine_SAGA_gameList, Engine_SAGA_create, Engine_SAGA_detectGames)
|
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
#define R_MAX_TIME_DELTA 100
|
|
|
|
|
2004-07-31 23:33:14 +00:00
|
|
|
static void CF_quitfunc(int argc, char *argv[], void *refCon);
|
|
|
|
static void CF_testfunc(int argc, char *argv[], void *refCon);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-04-28 23:10:59 +00:00
|
|
|
SagaEngine *_vm = NULL;
|
|
|
|
|
2004-03-14 23:39:41 +00:00
|
|
|
SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
|
|
|
|
: Engine(syst) {
|
|
|
|
|
2004-10-01 06:45:13 +00:00
|
|
|
// The Linux version of Inherit the Earth puts all data files in an
|
|
|
|
// 'itedata' sub-directory, except for voices.rsc
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/itedata/");
|
|
|
|
|
|
|
|
// The Windows version of Inherit the Earth puts various data files in
|
|
|
|
// other subdirectories.
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/graphics/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/music/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/sound/");
|
2004-03-14 23:39:41 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
|
|
|
if (!_mixer->isReady()) {
|
|
|
|
warning("Sound initialization failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mixer->setVolume(ConfMan.getInt("sfx_volume") * ConfMan.getInt("master_volume") / 255);
|
|
|
|
|
2004-04-28 23:10:59 +00:00
|
|
|
_vm = this;
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SagaEngine::~SagaEngine() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SagaEngine::errorString(const char *buf1, char *buf2) {
|
|
|
|
strcpy(buf2, buf1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SagaEngine::go() {
|
2004-04-12 21:40:49 +00:00
|
|
|
int msec = 0;
|
|
|
|
|
2004-08-04 18:07:57 +00:00
|
|
|
_soundEnabled = 1;
|
|
|
|
_musicEnabled = 1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 18:31:33 +00:00
|
|
|
_console = new Console(this);
|
|
|
|
|
2004-07-31 23:33:14 +00:00
|
|
|
CVAR_RegisterFunc(CF_testfunc, "testfunc", "foo [ optional foo ]", R_CVAR_NONE, 0, -1, this);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-04 18:07:57 +00:00
|
|
|
CVAR_Register_I(&_soundEnabled, "sound", NULL, R_CVAR_CFG, 0, 1);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-04 18:07:57 +00:00
|
|
|
CVAR_Register_I(&_musicEnabled, "music", NULL, R_CVAR_CFG, 0, 1);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:33:14 +00:00
|
|
|
CVAR_RegisterFunc(CF_quitfunc, "quit", NULL, R_CVAR_NONE, 0, 0, this);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Process config file
|
2004-04-12 21:40:49 +00:00
|
|
|
// FIXME
|
|
|
|
/*
|
|
|
|
if (CFG_Read(NULL) != R_SUCCESS) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Couldn't read configuration file");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Process command line
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Detect game and open resource files
|
2004-04-12 21:40:49 +00:00
|
|
|
if (GAME_Init() != R_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize engine modules
|
2004-04-28 23:54:40 +00:00
|
|
|
_sndRes = new SndRes(this);
|
2004-08-10 19:00:30 +00:00
|
|
|
_events = new Events(this);
|
2004-08-03 00:06:18 +00:00
|
|
|
_font = new Font(this);
|
2004-08-03 01:07:34 +00:00
|
|
|
_sprite = new Sprite(this);
|
2004-08-01 13:34:20 +00:00
|
|
|
_anim = new Anim(this);
|
2004-08-01 22:48:40 +00:00
|
|
|
_script = new Script();
|
2004-08-01 19:53:29 +00:00
|
|
|
_sdata = new SData();
|
2004-08-06 01:39:17 +00:00
|
|
|
_interface = new Interface(this); // requires script module
|
2004-08-02 15:47:42 +00:00
|
|
|
_actor = new Actor(this);
|
2004-08-10 19:20:33 +00:00
|
|
|
_palanim = new PalAnim(this);
|
2004-08-04 20:28:57 +00:00
|
|
|
_scene = new Scene(this);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-04 20:28:57 +00:00
|
|
|
if (!_scene->initialized()) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Couldn't initialize scene module");
|
2004-04-12 21:40:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// System initialization
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// On some platforms, graphics initialization also initializes sound
|
|
|
|
// ( Win32 DirectX )... Music must be initialized before sound for
|
|
|
|
// native midi support
|
2004-04-29 03:52:59 +00:00
|
|
|
MidiDriver *driver = GameDetector::createMidi(GameDetector::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE));
|
|
|
|
if (!driver)
|
|
|
|
driver = MidiDriver_ADLIB_create(_mixer);
|
|
|
|
else if (ConfMan.getBool("native_mt32"))
|
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
|
|
|
|
2004-08-04 18:07:57 +00:00
|
|
|
_music = new Music(driver, _musicEnabled);
|
2004-04-29 05:13:18 +00:00
|
|
|
_music->hasNativeMT32(ConfMan.getBool("native_mt32"));
|
|
|
|
|
2004-08-04 18:07:57 +00:00
|
|
|
if (!_musicEnabled) {
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "Music disabled.");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-03-14 23:39:41 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize graphics
|
2004-08-01 12:06:12 +00:00
|
|
|
R_GAME_DISPLAYINFO disp_info;
|
|
|
|
GAME_GetDisplayInfo(&disp_info);
|
|
|
|
_gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h);
|
|
|
|
|
2004-08-02 15:44:18 +00:00
|
|
|
_isoMap = new IsoMap(_gfx);
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_render = new Render(this, _system);
|
2004-07-31 23:00:48 +00:00
|
|
|
if (!_render->initialized()) {
|
2004-04-12 21:40:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize system specific sound
|
2004-08-04 18:07:57 +00:00
|
|
|
_sound = new Sound(this, _mixer, _soundEnabled);
|
|
|
|
if (!_soundEnabled) {
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "Sound disabled.");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 18:31:33 +00:00
|
|
|
// Register engine modules
|
|
|
|
_console->reg(); // Register console cvars first
|
|
|
|
GAME_Register();
|
2004-08-04 20:28:57 +00:00
|
|
|
_scene->reg();
|
2004-08-02 15:47:42 +00:00
|
|
|
_actor->reg();
|
2004-08-01 22:48:40 +00:00
|
|
|
_script->reg();
|
2004-07-31 23:00:48 +00:00
|
|
|
_render->reg();
|
|
|
|
_anim->reg();
|
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Begin Main Engine Loop
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-04 20:28:57 +00:00
|
|
|
_scene->startScene();
|
2004-08-02 12:41:40 +00:00
|
|
|
uint32 currentTicks;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_render->getFlags() & RF_RENDERPAUSE) {
|
2004-05-01 13:19:15 +00:00
|
|
|
// Freeze time while paused
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2004-09-28 20:19:37 +00:00
|
|
|
currentTicks = _system->getMillis();
|
2004-08-02 12:41:40 +00:00
|
|
|
// Timer has rolled over after 49 days
|
|
|
|
if (currentTicks < _previousTicks)
|
|
|
|
msec = 0;
|
|
|
|
else {
|
|
|
|
msec = currentTicks - _previousTicks;
|
|
|
|
_previousTicks = currentTicks;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
if (msec > R_MAX_TIME_DELTA) {
|
|
|
|
msec = R_MAX_TIME_DELTA;
|
|
|
|
}
|
2004-08-02 15:47:42 +00:00
|
|
|
_actor->direct(msec);
|
2004-08-12 23:57:45 +00:00
|
|
|
_events->handleEvents(msec);
|
|
|
|
_script->SThreadExecThreads(msec);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-05-01 13:19:15 +00:00
|
|
|
// Per frame processing
|
2004-07-31 23:00:48 +00:00
|
|
|
_render->drawScene();
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
2004-05-01 13:19:15 +00:00
|
|
|
}
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SagaEngine::shutdown() {
|
2004-08-04 20:28:57 +00:00
|
|
|
delete _scene;
|
2004-08-02 15:47:42 +00:00
|
|
|
delete _actor;
|
2004-08-01 22:48:40 +00:00
|
|
|
delete _script;
|
2004-08-03 01:07:34 +00:00
|
|
|
delete _sprite;
|
2004-08-03 00:06:18 +00:00
|
|
|
delete _font;
|
2004-08-10 18:31:33 +00:00
|
|
|
delete _console;
|
2004-04-12 21:40:49 +00:00
|
|
|
CVAR_Shutdown();
|
2004-08-10 19:00:30 +00:00
|
|
|
delete _events;
|
2004-08-10 19:20:33 +00:00
|
|
|
delete _palanim;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-06 01:39:17 +00:00
|
|
|
delete _interface;
|
2004-07-31 23:00:48 +00:00
|
|
|
delete _render;
|
2004-08-02 15:44:18 +00:00
|
|
|
delete _isoMap;
|
2004-04-28 23:54:40 +00:00
|
|
|
delete _sndRes;
|
2004-08-01 19:53:29 +00:00
|
|
|
delete _sdata;
|
2004-05-01 13:19:15 +00:00
|
|
|
// Shutdown system modules */
|
2004-04-29 03:52:59 +00:00
|
|
|
delete _music;
|
2004-04-28 23:54:40 +00:00
|
|
|
delete _sound;
|
2004-07-31 13:34:43 +00:00
|
|
|
delete _anim;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-04-28 23:54:40 +00:00
|
|
|
_system->quit();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:33:14 +00:00
|
|
|
static void CF_quitfunc(int argc, char *argv[], void *refCon) {
|
|
|
|
((SagaEngine *)refCon)->shutdown();
|
2004-04-12 21:40:49 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2004-07-31 23:33:14 +00:00
|
|
|
static void CF_testfunc(int argc, char *argv[], void *refCon) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-08-10 18:31:33 +00:00
|
|
|
_vm->_console->print("Test function invoked: Got %d arguments.", argc);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
2004-08-10 18:31:33 +00:00
|
|
|
_vm->_console->print("Arg %d: %s", i, argv[i]);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 21:25:29 +00:00
|
|
|
} // End of namespace Saga
|