diff options
author | Max Horn | 2002-08-18 17:48:18 +0000 |
---|---|---|
committer | Max Horn | 2002-08-18 17:48:18 +0000 |
commit | edae5b06db08b3c614b1efc0fe49c214857cbcc8 (patch) | |
tree | 0e5092c1816feef55b4deebe5b9049468969db83 | |
parent | 97d127252bf5ae7958cd0ded27855be3c2188fa6 (diff) | |
download | scummvm-rg350-edae5b06db08b3c614b1efc0fe49c214857cbcc8.tar.gz scummvm-rg350-edae5b06db08b3c614b1efc0fe49c214857cbcc8.tar.bz2 scummvm-rg350-edae5b06db08b3c614b1efc0fe49c214857cbcc8.zip |
MAJOR change to the way how Engine objects are instantiated
svn-id: r4758
-rw-r--r-- | Makefile.common | 11 | ||||
-rw-r--r-- | engine.h | 21 | ||||
-rw-r--r-- | gameDetector.h | 8 | ||||
-rw-r--r-- | main.cpp | 80 | ||||
-rw-r--r-- | morphos/Makefile | 11 | ||||
-rw-r--r-- | scumm.h | 21 | ||||
-rw-r--r-- | scummvm.cpp | 88 | ||||
-rw-r--r-- | simon/simon.cpp | 23 | ||||
-rw-r--r-- | simon/simon.h | 15 | ||||
-rw-r--r-- | sound.h | 1 | ||||
-rw-r--r-- | sound/mididrv.cpp | 4 | ||||
-rw-r--r-- | sound/mixer.h | 1 | ||||
-rw-r--r-- | wince/pocketpc.cpp | 50 |
13 files changed, 141 insertions, 193 deletions
diff --git a/Makefile.common b/Makefile.common index 727e10eeb8..84256ef674 100644 --- a/Makefile.common +++ b/Makefile.common @@ -9,7 +9,7 @@ INCS = scumm.h scummsys.h stdafx.h OBJS += util.o newgui.o gui/widget.o gui/dialog.o \ gui/ListWidget.o gui/ScrollBarWidget.o \ actor.o akos.o boxes.o bundle.o config-file.o costume.o debug.o \ - debugrl.o gameDetector.o gfx.o gui.o insane.o main.o object.o \ + debugrl.o engine.o gameDetector.o gfx.o gui.o insane.o main.o object.o \ resource.o saveload.o scaler.o script.o script_v1.o script_v2.o \ scummvm.o sound.o string.o sys.o timer.o vars.o verbs.o \ sound/imuse.o sound/fmopl.o sound/mixer.o \ @@ -18,9 +18,12 @@ OBJS += util.o newgui.o gui/widget.o gui/dialog.o \ simon/simondebug.o simon/simonres.o simon/simonitems.o simon/simonverb.o \ sound/mididrv.o -DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \ - debugrl.h whatsnew.txt readme.txt copying.txt \ - scummvm.dsp scummvm.dsw sound/fmopl.h gui.h sound.h +DISTFILES=$(OBJS:.o=.cpp) Makefile scummvm.dsp scummvm.dsw stdafx.cpp \ + whatsnew.txt readme.txt copying.txt \ + actor.h akos.h boxes.h bundle.h cmdline.h config-file.h costume.h debug.h \ + debugrl.h engine.h fb2opengl.h gameDetector.h gapi_keys.h gfx.h gui.h guimaps.h \ + newgui.h object.h resource.h saveload.h scaler.h scumm.h scummsys.h smush.h \ + sound.h stdafx.h system.h timer.h util.h sound/fmopl.h all: scummvm$(EXEEXT) @@ -23,7 +23,13 @@ #include "scummsys.h" #include "system.h" -#include "sound/mixer.h" + +class SoundMixer; +class GameDetector; + +/* FIXME - BIG HACK for MidiEmu */ +extern OSystem *g_system; +extern SoundMixer *g_mixer; class Engine { public: @@ -31,15 +37,10 @@ public: SoundMixer *_mixer; - Engine() - { - _mixer = new SoundMixer(); - } - - ~Engine() - { - delete _mixer; - } + Engine(GameDetector *detector, OSystem *syst); + virtual ~Engine(); + + virtual void go() = 0; }; diff --git a/gameDetector.h b/gameDetector.h index 10013dabe4..4cbfa3453f 100644 --- a/gameDetector.h +++ b/gameDetector.h @@ -20,6 +20,12 @@ * */ +#ifndef GAMEDETECTOR_H +#define GAMEDETECTOR_H + +class OSystem; +class MidiDriver; + class GameDetector { public: int detectMain(int argc, char **argv); @@ -69,3 +75,5 @@ public: OSystem *createSystem(); MidiDriver *createMidi(); }; + +#endif @@ -21,22 +21,16 @@ */ #include "stdafx.h" +#include "engine.h" #include "scumm.h" #include "sound/mididrv.h" #include "gameDetector.h" -#include "gui.h" #include "simon/simon.h" #include "config-file.h" GameDetector detector; -Gui gui; -Scumm *g_scumm; -/* FIXME */ -OSystem *g_system; -SoundMixer *g_mixer; - -Config * scummcfg; +Config *scummcfg = 0; #if defined(QTOPIA) @@ -104,46 +98,6 @@ static void do_memory_test(void) { int main(int argc, char *argv[]) { -/* -Disabled this for now. What good does it do, anyway, we now have real config -files, and a proper port to MacOS classic should offer a dialog or so for any -game settings! - -#if defined(MACOS_SDL) - // support for config file for macos SDL port - - char *argitem; - char *argstr; - FILE *argf; - - if ((argf = fopen("configuration.macos", "r")) == NULL) { - error("Can't open configuration file.\n"); - exit(1); - } - - argc = 0; - argstr = (char *)malloc(64); - argstr = fgets(argstr, 64, argf); - if ((argitem = strchr(argstr, '\n')) != NULL) - *argitem = '\0'; - - argitem = strtok(argstr, " "); - - while (argitem != NULL) { - argv = (char **)realloc(argv, (argc + 1) * 8); - argv[argc] = (char *)malloc(64); - strcpy(argv[argc], argitem); - argc++; - - argitem = strtok(NULL, " "); - } - - free(argstr); - fclose(argf); - -#endif -*/ - #ifdef __DC__ extern void dc_init_hardware(); dc_init_hardware(); @@ -174,6 +128,7 @@ game settings! return (-1); OSystem *system = detector.createSystem(); + Engine *engine; { char *s = detector.getGameName(); @@ -186,32 +141,15 @@ game settings! /* Simon the Sorcerer? */ if (detector._gameId >= GID_SIMON_FIRST && detector._gameId <= GID_SIMON_LAST) { - /* Simon the Sorcerer. Completely different initialization */ - MidiDriver *midi = detector.createMidi(); - - SimonState *simon = SimonState::create(system, midi); - g_system = simon->_system; - g_mixer = &simon->_mixer[0]; - simon->_game = detector._gameId - GID_SIMON_FIRST; - simon->set_volume(detector._sfx_volume); - simon->_game_path = detector._gameDataPath; - simon->go(); + /* Simon the Sorcerer initialization */ + detector._gameId -= GID_SIMON_FIRST; + engine = SimonState::createFromDetector(&detector, system); } else { - Scumm *scumm = Scumm::createFromDetector(&detector, system); - g_scumm = scumm; - g_system = scumm->_system; - g_mixer = &scumm->_mixer[0]; - scumm->_sound->_sound_volume_master = 0; - scumm->_sound->_sound_volume_music = detector._music_volume; - scumm->_sound->_sound_volume_sfx = detector._sfx_volume; - - /* bind to Gui */ - scumm->_gui = &gui; - gui.init(scumm); /* Reinit GUI after loading a game */ - - scumm->go(); + engine = Scumm::createFromDetector(&detector, system); } + + engine->go(); delete scummcfg; diff --git a/morphos/Makefile b/morphos/Makefile index 00fd3992d1..abd5a5c994 100644 --- a/morphos/Makefile +++ b/morphos/Makefile @@ -14,14 +14,15 @@ INCS = scumm.h scummsys.h stdafx.h GUIOBJS = widget.o dialog.o newgui.o ListWidget.o ScrollBarWidget.o +SCUMMOBJS = actor.o akos.o boxes.o bundle.o costume.o debug.o debugrl.o gfx.o \ + object.o saveload.o script.o scummvm.o sound.o string.o sys.o vars.o verbs.o \ + script_v1.o script_v2.o gui.o imuse.o insane.o resource.o resource_v3.o resource_v4.o + SIMONOBJS = midi.o simon.o simondebug.o simonitems.o simonres.o simonsys.o simonverb.o simonvga.o -OBJS = actor.o akos.o boxes.o config-file.o costume.o gfx.o object.o resource.o \ - saveload.o script.o scummvm.o sound.o string.o sys.o verbs.o \ +OBJS = config-file.o engine.o gameDetector.o fmopl.o mixer.o mididrv.o util.o main.o \ morphos.o morphos_scaler.o morphos_sound.o morphos_start.o morphos_timer.o \ - script_v1.o script_v2.o debug.o gui.o imuse.o fmopl.o mixer.o mididrv.o \ - debugrl.o vars.o insane.o gameDetector.o resource_v3.o resource_v4.o \ - util.o main.o bundle.o $(GUIOBJS) $(SIMONOBJS) + $(GUIOBJS) $(SCUMMOBJS) $(SIMONOBJS) DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \ windows.cpp debugrl.h whatsnew.txt readme.txt copying.txt \ @@ -46,11 +46,8 @@ struct FindObjectInRoom; typedef void (Scumm::*OpcodeProc)(); -/* Use this one from error() ONLY */ +// Use g_scumm from error() ONLY extern Scumm *g_scumm; -/* BIG HACK for MidiEmu - FIXME */ -extern OSystem *g_system; -extern SoundMixer *g_mixer; /* System Wide Constants */ enum { @@ -370,8 +367,6 @@ public: /* Init functions, etc */ byte _fastMode; char *getGameName(); - Scumm(); // constructor - virtual ~Scumm(); /* video buffer */ byte *_videoBuffer; @@ -1337,6 +1332,9 @@ public: void launch(); + Scumm(GameDetector *detector, OSystem *syst); + virtual ~Scumm(); + static Scumm *createFromDetector(GameDetector *detector, OSystem *syst); void go(); @@ -1352,25 +1350,36 @@ public: class Scumm_v3 : public Scumm { public: + Scumm_v3(GameDetector *detector, OSystem *syst) : Scumm(detector, syst) {} + void readIndexFile(); virtual void loadCharset(int no); }; class Scumm_v4 : public Scumm_v3 { +public: + Scumm_v4(GameDetector *detector, OSystem *syst) : Scumm_v3(detector, syst) {} + void loadCharset(int no); }; class Scumm_v5 : public Scumm { +public: + Scumm_v5(GameDetector *detector, OSystem *syst) : Scumm(detector, syst) {} }; class Scumm_v6 : public Scumm { +public: + Scumm_v6(GameDetector *detector, OSystem *syst) : Scumm(detector, syst) {} }; class Scumm_v7 : public Scumm { +public: + Scumm_v7(GameDetector *detector, OSystem *syst) : Scumm(detector, syst) {} }; extern uint16 _debugLevel; diff --git a/scummvm.cpp b/scummvm.cpp index 991dd0c496..9b64650fc6 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -38,6 +38,10 @@ extern void GraphicsOff(void); #endif +// Use g_scumm from error() ONLY +Scumm *g_scumm = 0; + + void autosave(Scumm * scumm) { scumm->_doAutosave = true; @@ -63,15 +67,50 @@ uint Scumm::getRandomNumberRng(uint min, uint max) } -Scumm::Scumm (void) { +Scumm::Scumm (GameDetector *detector, OSystem *syst) + : Engine(detector, syst) +{ + // Use g_scumm from error() ONLY + g_scumm = this; + + _debugMode = detector->_debugMode; + _bootParam = detector->_bootParam; + _gameDataPath = detector->_gameDataPath; + _exe_name = detector->_exe_name; + _gameId = detector->_gameId; + _gameText = detector->_gameText; + _features = detector->_features; + _soundCardType = detector->_soundCardType; + _noSubtitles = detector->_noSubtitles; + _cdrom = detector->_cdrom; + _defaultTalkDelay = detector->_talkSpeed; + _use_adlib = detector->_use_adlib; + + if (_gameId == GID_ZAK256) { // FmTowns is 320x240 + _realWidth = 320; + _realHeight = 240; + } else { + _realWidth = 320; + _realHeight = 200; + } + + _gui = new Gui(); + _gui->init(this); + _newgui = new NewGui(this); _bundle = new Bundle(this); _timer = new Timer(this); _sound = new Sound(this); + + _sound->_sound_volume_master = 0; + _sound->_sound_volume_sfx = detector->_sfx_volume; + _sound->_sound_volume_music = detector->_music_volume; } -Scumm::~Scumm (void) { +Scumm::~Scumm () +{ delete [] _actors; + delete _gui; delete _newgui; delete _bundle; delete _timer; @@ -1513,26 +1552,15 @@ Scumm *Scumm::createFromDetector(GameDetector *detector, OSystem *syst) OSystem::Property prop; if (detector->_features & GF_OLD256) - scumm = new Scumm_v3; + scumm = new Scumm_v3(detector, syst); else if (detector->_features & GF_SMALL_HEADER) // this force loomCD as v4 - scumm = new Scumm_v4; + scumm = new Scumm_v4(detector, syst); else if (detector->_features & GF_AFTER_V7) - scumm = new Scumm_v7; + scumm = new Scumm_v7(detector, syst); else if (detector->_features & GF_AFTER_V6) // this force SamnmaxCD as v6 - scumm = new Scumm_v6; + scumm = new Scumm_v6(detector, syst); else - scumm = new Scumm_v5; - - scumm->_system = syst; - - - if (detector->_gameId == GID_ZAK256) { // FmTowns is 320x240 - scumm->_realWidth = 320; - scumm->_realHeight = 240; - } else { - scumm->_realWidth = 320; - scumm->_realHeight = 200; - } + scumm = new Scumm_v5(detector, syst); /* This initializes SDL */ syst->init_size(scumm->_realWidth, scumm->_realHeight); @@ -1543,7 +1571,8 @@ Scumm *Scumm::createFromDetector(GameDetector *detector, OSystem *syst) * automatically when samples need to be generated */ if (!scumm->_mixer->bind_to_system(syst)) { warning("Sound initialization failed"); - if (detector->_use_adlib) { + 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"); @@ -1552,30 +1581,9 @@ Scumm *Scumm::createFromDetector(GameDetector *detector, OSystem *syst) scumm->_mixer->set_volume(kDefaultSFXVolume); scumm->_mixer->set_music_volume(kDefaultMusicVolume); - /* HACK !!! */ - g_scumm = scumm; - g_system = scumm->_system; - g_mixer = &scumm->_mixer[0]; - /* END HACK */ - - scumm->_debugMode = detector->_debugMode; - scumm->_bootParam = detector->_bootParam; - scumm->_gameDataPath = detector->_gameDataPath; - scumm->_exe_name = detector->_exe_name; - scumm->_gameId = detector->_gameId; - scumm->_gameText = detector->_gameText; - scumm->_features = detector->_features; - scumm->_soundCardType = detector->_soundCardType; - scumm->_noSubtitles = detector->_noSubtitles; - scumm->_cdrom = detector->_cdrom; - scumm->_defaultTalkDelay = detector->_talkSpeed; - scumm->_sound->_sound_volume_sfx = detector->_sfx_volume; - scumm->_sound->_sound_volume_music = detector->_music_volume; { IMuse *imuse; - scumm->_use_adlib = detector->_use_adlib; - if (detector->_use_adlib) { imuse = IMuse::create_adlib(syst, scumm->_mixer); } else { diff --git a/simon/simon.cpp b/simon/simon.cpp index 23c07aba65..67ea4d9092 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -22,7 +22,9 @@ #include "stdafx.h" #include "simon.h" #include "simonintern.h" +#include "gameDetector.h" #include <errno.h> +#include <time.h> #ifdef _WIN32_WCE @@ -109,13 +111,23 @@ static const GameSpecificSettings simon2dos_settings = { }; -SimonState::SimonState() +SimonState::SimonState(GameDetector *detector, OSystem *syst) + : Engine(detector, syst) { + MidiDriver *driver = detector->createMidi(); + _dummy_item_1 = new Item(); _dummy_item_2 = new Item(); _dummy_item_3 = new Item(); _fcs_list = new FillOrCopyStruct[16]; + + /* Setup midi driver */ + midi.set_driver(driver); + + _game = detector->_gameId; + set_volume(detector->_sfx_volume); + _game_path = detector->_gameDataPath; } SimonState::~SimonState() @@ -127,14 +139,9 @@ SimonState::~SimonState() delete [] _fcs_list; } -SimonState *SimonState::create(OSystem *syst, MidiDriver *driver) +SimonState *SimonState::createFromDetector(GameDetector *detector, OSystem *syst) { - SimonState *s = new SimonState; - - s->_system = syst; - - /* Setup midi driver */ - s->midi.set_driver(driver); + SimonState *s = new SimonState(detector, syst); /* Setup mixer */ if (!s->_mixer->bind_to_system(syst)) diff --git a/simon/simon.h b/simon/simon.h index aed088aca3..5f43f7d019 100644 --- a/simon/simon.h +++ b/simon/simon.h @@ -22,10 +22,10 @@ #ifndef SIMON_H #define SIMON_H -#include <time.h> -#include <sys/stat.h> +#include <stdio.h> #include "engine.h" #include "simon/midi.h" +#include "sound/mixer.h" /* Various other settings */ //#define DUMP_CONTINOUS_MAINSCRIPT @@ -356,7 +356,7 @@ public: byte *_sdl_buf; byte *_sdl_buf_attached; - SimonState(); + SimonState(GameDetector *detector, OSystem *syst); virtual ~SimonState(); int allocGamePcVars(FILE *in); @@ -795,7 +795,7 @@ public: void vc_kill_thread(uint file, uint sprite); - static SimonState *create(OSystem *syst, MidiDriver *driver); + static SimonState *createFromDetector(GameDetector *detector, OSystem *syst); void set_dummy_cursor(); @@ -820,13 +820,6 @@ public: void NORETURN CDECL error(const char *errmsg, ...); void CDECL warning(const char *errmsg, ...); -void _2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, - int width, int height); -int Init_2xSaI(uint32 BitFormat); -void Super2xSaI(uint8 *srcPtr, uint32 srcPitch, - uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height); -void initializeHardware(); -void dx_set_palette(uint32 *colors, uint num); void palette_fadeout(uint32 *pal_values, uint num); #endif @@ -22,6 +22,7 @@ #define SOUND_H #include "scummsys.h" +#include "sound/mixer.h" class Scumm; diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp index de93ddc8eb..c261395c39 100644 --- a/sound/mididrv.cpp +++ b/sound/mididrv.cpp @@ -1118,7 +1118,7 @@ void MidiDriver_MIDIEMU::send(uint32 b) unsigned char note = (unsigned char)((b >> 8) & 0x7F); unsigned char vel = (unsigned char)((b >> 16) & 0x7F); int i, j; - int onl, on, nv; + int onl, on, nv = 0; unsigned char ins[11]; on = -1; if (ch[channel].on != 0) { @@ -1306,7 +1306,7 @@ int MidiDriver_MIDIEMU::midiemu_callback_thread(void *param) bool need_midi_data = true; for (;;) { - int number; + int number = 0; int i; if (need_midi_data) { diff --git a/sound/mixer.h b/sound/mixer.h index 3ffb9ceb81..3bf5aaf755 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -23,6 +23,7 @@ #ifndef MIXER_H #define MIXER_H +#include <stdio.h> #ifdef COMPRESSED_SOUND_FILE #include <mad.h> #endif diff --git a/wince/pocketpc.cpp b/wince/pocketpc.cpp index 407c984e4f..ba1b21e1b7 100644 --- a/wince/pocketpc.cpp +++ b/wince/pocketpc.cpp @@ -57,11 +57,7 @@ typedef int (*tTimeCallback)(int); typedef void SoundProc(void *param, byte *buf, int len); GameDetector detector; -Gui gui; -Scumm *g_scumm; SimonState *g_simon; -OSystem *g_system; -SoundMixer *g_mixer; Config *scummcfg; tTimeCallback timer_callback; int timer_interval; @@ -443,46 +439,28 @@ 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 */ - MidiDriver *midi = detector.createMidi(); - - keypad_init(); - load_key_mapping(); - hide_cursor = TRUE; - - g_simon = SimonState::create(system, midi); - g_system = g_simon->_system; - g_mixer = &g_simon->_mixer[0]; - g_simon->_game = detector._gameId - GID_SIMON_FIRST; - g_simon->set_volume(detector._sfx_volume); - g_simon->_game_path = detector._gameDataPath; - g_simon->go(); + detector._gameId -= GID_SIMON_FIRST; + engine = SimonState::createFromDetector(&detector, system); } else { - Scumm *scumm = Scumm::createFromDetector(&detector, system); - g_scumm = scumm; - g_system = scumm->_system; - g_mixer = &scumm->_mixer[0]; + engine = Scumm::createFromDetector(&detector, system); - scumm->_sound_volume_master = 0; - scumm->_sound_volume_music = detector._music_volume; - scumm->_sound_volume_sfx = detector._sfx_volume; - - keypad_init(); - load_key_mapping(); - - hide_cursor = TRUE; - if (scumm->_gameId == GID_SAMNMAX || scumm->_gameId == GID_FT || scumm->_gameId == GID_DIG) - hide_cursor = FALSE; - - /* bind to Gui */ - scumm->_gui = &gui; - gui.init(scumm); /* Reinit GUI after loading a game */ - scumm->go(); } + + keypad_init(); + load_key_mapping(); + + hide_cursor = TRUE; + if (detector._gameId == GID_SAMNMAX || detector._gameId == GID_FT || detector._gameId == GID_DIG) + hide_cursor = FALSE; + + + engine->go(); return 0; } |