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"
|
|
|
|
|
|
|
|
#include "saga.h"
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
#include "reinherit.h"
|
|
|
|
|
2004-04-27 11:22:13 +00:00
|
|
|
#include "systimer.h"
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
#include "rscfile_mod.h"
|
|
|
|
#include "render_mod.h"
|
|
|
|
#include "actor_mod.h"
|
|
|
|
#include "animation_mod.h"
|
|
|
|
#include "console_mod.h"
|
|
|
|
#include "cvar_mod.h"
|
|
|
|
#include "events_mod.h"
|
|
|
|
#include "actionmap_mod.h"
|
|
|
|
#include "font_mod.h"
|
|
|
|
#include "game_mod.h"
|
2004-05-01 23:42:22 +00:00
|
|
|
#include "game.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
#include "interface_mod.h"
|
|
|
|
#include "isomap_mod.h"
|
|
|
|
#include "script_mod.h"
|
|
|
|
#include "scene_mod.h"
|
2004-04-28 23:10:59 +00:00
|
|
|
#include "sndres.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
#include "sprite_mod.h"
|
|
|
|
#include "text_mod.h"
|
|
|
|
#include "objectmap_mod.h"
|
2004-04-28 23:54:40 +00:00
|
|
|
#include "sound.h"
|
2004-04-29 03:52:59 +00:00
|
|
|
#include "music.h"
|
2004-05-01 23:42:22 +00:00
|
|
|
#include "game_mod.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-04-25 14:42:14 +00:00
|
|
|
struct R_MAIN_DATA {
|
2004-04-12 21:40:49 +00:00
|
|
|
int sound_enabled;
|
|
|
|
int music_enabled;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
static void CF_quitfunc(int argc, char *argv[]);
|
|
|
|
static void CF_testfunc(int argc, char *argv[]);
|
|
|
|
|
|
|
|
static R_MAIN_DATA MainData;
|
|
|
|
|
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-04-12 21:40:49 +00:00
|
|
|
GAME_setGameDirectory(getGameDataPath());
|
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-05-01 13:19:15 +00:00
|
|
|
// Register engine modules
|
|
|
|
CON_Register(); // Register console cvars first
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
RENDER_Register();
|
|
|
|
GAME_Register();
|
|
|
|
|
|
|
|
ANIM_Register();
|
|
|
|
ACTIONMAP_Register();
|
|
|
|
OBJECTMAP_Register();
|
|
|
|
SCRIPT_Register();
|
|
|
|
ACTOR_Register();
|
|
|
|
SCENE_Register();
|
|
|
|
|
|
|
|
MainData.sound_enabled = 1;
|
2004-04-29 03:52:59 +00:00
|
|
|
MainData.music_enabled = 1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
CVAR_RegisterFunc(CF_testfunc, "testfunc", "foo [ optional foo ]", R_CVAR_NONE, 0, -1);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
CVAR_Register_I(&MainData.sound_enabled, "sound", NULL, R_CVAR_CFG, 0, 1);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
CVAR_Register_I(&MainData.music_enabled, "music", NULL, R_CVAR_CFG, 0, 1);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
CVAR_RegisterFunc(CF_quitfunc, "quit", NULL, R_CVAR_NONE, 0, 0);
|
|
|
|
|
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) {
|
|
|
|
R_printf(R_STDERR, "Couldn't read configuration file.\n");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
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) {
|
2004-05-01 13:19:15 +00:00
|
|
|
R_printf(R_STDERR, "Couldn't start the game: %s\n", GAME_GetErrS());
|
2004-04-12 21:40:49 +00:00
|
|
|
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-04-12 21:40:49 +00:00
|
|
|
EVENT_Init();
|
|
|
|
FONT_Init();
|
|
|
|
SPRITE_Init();
|
|
|
|
ANIM_Init();
|
|
|
|
ACTIONMAP_Init();
|
|
|
|
OBJECTMAP_Init();
|
|
|
|
ISOMAP_Init();
|
|
|
|
SCRIPT_Init();
|
2004-05-01 13:19:15 +00:00
|
|
|
INTERFACE_Init(); // requires script module
|
2004-04-12 21:40:49 +00:00
|
|
|
ACTOR_Init();
|
|
|
|
|
|
|
|
if (SCENE_Init() != R_SUCCESS) {
|
|
|
|
R_printf(R_STDERR, "Couldn't initialize scene module.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// System initialization
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Must initialize system timer module first
|
2004-04-12 21:40:49 +00:00
|
|
|
if (SYSTIMER_InitMSCounter() != R_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
_music = new Music(driver, MainData.music_enabled);
|
2004-04-29 05:13:18 +00:00
|
|
|
_music->hasNativeMT32(ConfMan.getBool("native_mt32"));
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
if (!MainData.music_enabled) {
|
|
|
|
R_printf(R_STDOUT, "Music disabled.\n");
|
|
|
|
}
|
2004-03-14 23:39:41 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize graphics
|
2004-05-01 19:41:47 +00:00
|
|
|
if (RENDER_Init(_system) != R_SUCCESS) {
|
2004-04-12 21:40:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize system specific sound
|
2004-04-29 01:24:18 +00:00
|
|
|
_sound = new Sound(this, _mixer, MainData.sound_enabled);
|
2004-04-12 21:40:49 +00:00
|
|
|
if (!MainData.sound_enabled) {
|
|
|
|
R_printf(R_STDOUT, "Sound disabled.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSINPUT_Init();
|
|
|
|
|
|
|
|
SYSTIMER_ResetMSCounter();
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Begin Main Engine Loop
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
SCENE_Start();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
#ifdef R_USE_CUSTOM_WININIT
|
|
|
|
if (ITESYS_CheckSignal()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (RENDER_GetFlags() & RF_RENDERPAUSE) {
|
2004-05-01 13:19:15 +00:00
|
|
|
// Freeze time while paused
|
2004-04-12 21:40:49 +00:00
|
|
|
SYSTIMER_ResetMSCounter();
|
|
|
|
} else {
|
|
|
|
msec = SYSTIMER_ReadMSCounter();
|
|
|
|
if (msec > R_MAX_TIME_DELTA) {
|
|
|
|
msec = R_MAX_TIME_DELTA;
|
|
|
|
}
|
|
|
|
ACTOR_Direct(msec);
|
|
|
|
EVENT_HandleEvents(msec);
|
|
|
|
STHREAD_ExecThreads(msec);
|
|
|
|
}
|
2004-05-01 13:19:15 +00:00
|
|
|
// Per frame processing
|
2004-04-12 21:40:49 +00:00
|
|
|
RENDER_DrawScene();
|
|
|
|
SYSTIMER_Sleep(0);
|
2004-05-01 13:19:15 +00:00
|
|
|
}
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SagaEngine::shutdown() {
|
2004-04-12 21:40:49 +00:00
|
|
|
SCENE_Shutdown();
|
|
|
|
ACTOR_Shutdown();
|
|
|
|
SCRIPT_Shutdown();
|
|
|
|
ANIM_Shutdown();
|
|
|
|
SPRITE_Shutdown();
|
|
|
|
OBJECTMAP_Shutdown();
|
|
|
|
FONT_Shutdown();
|
|
|
|
CON_Shutdown();
|
|
|
|
CVAR_Shutdown();
|
|
|
|
EVENT_Shutdown();
|
|
|
|
|
2004-04-28 23:54:40 +00:00
|
|
|
delete _sndRes;
|
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-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-05-01 13:19:15 +00:00
|
|
|
static void CF_quitfunc(int argc, char *argv[]) {
|
2004-04-28 23:54:40 +00:00
|
|
|
_vm->shutdown();
|
2004-04-12 21:40:49 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
static void CF_testfunc(int argc, char *argv[]) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
CON_Print("Test function invoked: Got %d arguments.", argc);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
CON_Print("Arg %d: %s", i, argv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-22 21:25:29 +00:00
|
|
|
} // End of namespace Saga
|