diff options
-rw-r--r-- | engine.cpp | 27 | ||||
-rw-r--r-- | engine.h | 5 | ||||
-rw-r--r-- | main.cpp | 13 | ||||
-rw-r--r-- | scumm.h | 1 | ||||
-rw-r--r-- | scummvm.cpp | 100 | ||||
-rw-r--r-- | simon/simon.cpp | 5 | ||||
-rw-r--r-- | simon/simon.h | 2 | ||||
-rw-r--r-- | wince/pocketpc.cpp | 15 |
8 files changed, 78 insertions, 90 deletions
diff --git a/engine.cpp b/engine.cpp index 748b176d4d..272dbfa075 100644 --- a/engine.cpp +++ b/engine.cpp @@ -21,6 +21,8 @@ #include "engine.h" #include "sound/mixer.h" #include "gameDetector.h" +#include "scumm.h" +#include "simon/simon.h" /* FIXME - BIG HACK for MidiEmu */ OSystem *g_system = 0; @@ -40,3 +42,28 @@ Engine::~Engine() { delete _mixer; } + +Engine *Engine::createFromDetector(GameDetector *detector, OSystem *syst) +{ + Engine *engine; + + if (detector->_gameId >= GID_SIMON_FIRST && detector->_gameId <= GID_SIMON_LAST) { + // Simon the Sorcerer + detector->_gameId -= GID_SIMON_FIRST; + engine = new SimonState(detector, syst); + } else { + // Some kind of Scumm game + if (detector->_features & GF_OLD256) + engine = new Scumm_v3(detector, syst); + else if (detector->_features & GF_SMALL_HEADER) // this force loomCD as v4 + engine = new Scumm_v4(detector, syst); + else if (detector->_features & GF_AFTER_V7) + engine = new Scumm_v7(detector, syst); + else if (detector->_features & GF_AFTER_V6) // this force SamnmaxCD as v6 + engine = new Scumm_v6(detector, syst); + else + engine = new Scumm_v5(detector, syst); + } + + return engine; +} @@ -40,7 +40,12 @@ public: Engine(GameDetector *detector, OSystem *syst); virtual ~Engine(); + // Invoke the main engine loop using this method virtual void go() = 0; + + // Create a new engine object based on the detector - either + // a Scumm or a SimonState object currently. + static Engine *createFromDetector(GameDetector *detector, OSystem *syst); }; @@ -128,7 +128,6 @@ int main(int argc, char *argv[]) return (-1); OSystem *system = detector.createSystem(); - Engine *engine; { char *s = detector.getGameName(); @@ -139,16 +138,10 @@ int main(int argc, char *argv[]) free(s); } - /* Simon the Sorcerer? */ - if (detector._gameId >= GID_SIMON_FIRST && detector._gameId <= GID_SIMON_LAST) { - /* Simon the Sorcerer initialization */ - detector._gameId -= GID_SIMON_FIRST; - engine = SimonState::createFromDetector(&detector, system); - - } else { - engine = Scumm::createFromDetector(&detector, system); - } + // Create the game engine + Engine *engine = Engine::createFromDetector(&detector, system); + // Run the game engine engine->go(); delete scummcfg; @@ -1335,7 +1335,6 @@ public: Scumm(GameDetector *detector, OSystem *syst); virtual ~Scumm(); - static Scumm *createFromDetector(GameDetector *detector, OSystem *syst); void go(); void setupGUIColors(); diff --git a/scummvm.cpp b/scummvm.cpp index 9b64650fc6..c6ded6ab19 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -70,6 +70,8 @@ uint Scumm::getRandomNumberRng(uint min, uint max) Scumm::Scumm (GameDetector *detector, OSystem *syst) : Engine(detector, syst) { + OSystem::Property prop; + // Use g_scumm from error() ONLY g_scumm = this; @@ -105,6 +107,44 @@ Scumm::Scumm (GameDetector *detector, OSystem *syst) _sound->_sound_volume_master = 0; _sound->_sound_volume_sfx = detector->_sfx_volume; _sound->_sound_volume_music = detector->_music_volume; + + /* Initialize backend */ + syst->init_size(_realWidth, _realHeight); + prop.cd_num = detector->_cdrom; + syst->property(OSystem::PROP_OPEN_CD, &prop); + + /* Bind the mixer to the system => mixer will be invoked + * automatically when samples need to be generated */ + if (!_mixer->bind_to_system(syst)) { + warning("Sound initialization failed"); + if (detector->_use_adlib) { + _use_adlib = false; + detector->_use_adlib = false; + detector->_midi_driver = MD_NULL; + warning("Adlib music was selected, switching to midi null driver"); + } + } + _mixer->set_volume(kDefaultSFXVolume); + _mixer->set_music_volume(kDefaultMusicVolume); + + + // Init iMuse + if (detector->_use_adlib) { + _imuse = IMuse::create_adlib(syst, _mixer); + } else { + _imuse = IMuse::create_midi(syst, detector->createMidi()); + } + if (detector->_gameTempo != 0) + _imuse->property(IMuse::PROP_TEMPO_BASE, detector->_gameTempo); + _imuse->set_music_volume(_sound->_sound_volume_music); + + + // Load game from specified slot, if any + if (detector->_save_slot != -1) { + _saveLoadSlot = detector->_save_slot; + _saveLoadFlag = 2; + _saveLoadCompatible = false; + } } Scumm::~Scumm () @@ -1546,66 +1586,6 @@ void Scumm::launch() // _scummTimer = 0; } -Scumm *Scumm::createFromDetector(GameDetector *detector, OSystem *syst) -{ - Scumm *scumm; - OSystem::Property prop; - - if (detector->_features & GF_OLD256) - scumm = new Scumm_v3(detector, syst); - else if (detector->_features & GF_SMALL_HEADER) // this force loomCD as v4 - scumm = new Scumm_v4(detector, syst); - else if (detector->_features & GF_AFTER_V7) - scumm = new Scumm_v7(detector, syst); - else if (detector->_features & GF_AFTER_V6) // this force SamnmaxCD as v6 - scumm = new Scumm_v6(detector, syst); - else - scumm = new Scumm_v5(detector, syst); - - /* This initializes SDL */ - syst->init_size(scumm->_realWidth, scumm->_realHeight); - prop.cd_num = detector->_cdrom; - syst->property(OSystem::PROP_OPEN_CD, &prop); - - /* bind the mixer to the system => mixer will be invoked - * automatically when samples need to be generated */ - if (!scumm->_mixer->bind_to_system(syst)) { - warning("Sound initialization failed"); - if (detector->_use_adlib) { - scumm->_use_adlib = false; - detector->_use_adlib = false; - detector->_midi_driver = MD_NULL; - warning("Adlib music was selected, switching to midi null driver"); - } - } - scumm->_mixer->set_volume(kDefaultSFXVolume); - scumm->_mixer->set_music_volume(kDefaultMusicVolume); - - { - IMuse *imuse; - - if (detector->_use_adlib) { - imuse = IMuse::create_adlib(syst, scumm->_mixer); - } else { - imuse = IMuse::create_midi(syst, detector->createMidi()); - } - - if (detector->_gameTempo != 0) - imuse->property(IMuse::PROP_TEMPO_BASE, detector->_gameTempo); - - imuse->set_music_volume(scumm->_sound->_sound_volume_music); - scumm->_imuse = imuse; - } - - if (detector->_save_slot != -1) { - scumm->_saveLoadSlot = detector->_save_slot; - scumm->_saveLoadFlag = 2; - scumm->_saveLoadCompatible = false; - } - - return scumm; -} - void Scumm::go() { launch(); setupGUIColors(); diff --git a/simon/simon.cpp b/simon/simon.cpp index a379006052..6b626964b6 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -144,11 +144,6 @@ SimonState::~SimonState() delete [] _fcs_list; } -SimonState *SimonState::createFromDetector(GameDetector *detector, OSystem *syst) -{ - return new SimonState(detector, syst); -} - void palette_fadeout(uint32 *pal_values, uint num) { byte *p = (byte *)pal_values; diff --git a/simon/simon.h b/simon/simon.h index 5f43f7d019..f4e999d311 100644 --- a/simon/simon.h +++ b/simon/simon.h @@ -795,8 +795,6 @@ public: void vc_kill_thread(uint file, uint sprite); - static SimonState *createFromDetector(GameDetector *detector, OSystem *syst); - void set_dummy_cursor(); void set_volume(byte volume); diff --git a/wince/pocketpc.cpp b/wince/pocketpc.cpp index ba1b21e1b7..0bb9c1b21b 100644 --- a/wince/pocketpc.cpp +++ b/wince/pocketpc.cpp @@ -439,18 +439,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLin return (-1); OSystem *system = detector.createSystem(); - Engine *engine; - /* Simon the Sorcerer? */ - if (detector._gameId >= GID_SIMON_FIRST && detector._gameId <= GID_SIMON_LAST) { - /* Simon the Sorcerer. Completely different initialization */ - detector._gameId -= GID_SIMON_FIRST; - engine = SimonState::createFromDetector(&detector, system); - - } else { - engine = Scumm::createFromDetector(&detector, system); - - } + // Create the game engine + Engine *engine = Engine::createFromDetector(&detector, system); keypad_init(); load_key_mapping(); @@ -459,7 +450,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLin if (detector._gameId == GID_SAMNMAX || detector._gameId == GID_FT || detector._gameId == GID_DIG) hide_cursor = FALSE; - + // Run the game engine engine->go(); return 0; |