diff options
author | Max Horn | 2002-08-18 22:47:11 +0000 |
---|---|---|
committer | Max Horn | 2002-08-18 22:47:11 +0000 |
commit | d354eaaf422cd7059c6997db14853d35d0111173 (patch) | |
tree | bdedf8abe1805e90a4f271a5ceac4dcf8a8f0090 | |
parent | 7604484caf2d5846a1cc1606c577fedc5791089c (diff) | |
download | scummvm-rg350-d354eaaf422cd7059c6997db14853d35d0111173.tar.gz scummvm-rg350-d354eaaf422cd7059c6997db14853d35d0111173.tar.bz2 scummvm-rg350-d354eaaf422cd7059c6997db14853d35d0111173.zip |
more code unification; as a side effect, simon can take advantage of the save path settings in the config file (inspired by patch #587694)
svn-id: r4770
-rw-r--r-- | engine.cpp | 33 | ||||
-rw-r--r-- | engine.h | 10 | ||||
-rw-r--r-- | insane.cpp | 12 | ||||
-rw-r--r-- | saveload.cpp | 24 | ||||
-rw-r--r-- | scumm.h | 1 | ||||
-rw-r--r-- | scummvm.cpp | 1 | ||||
-rw-r--r-- | simon/simon.cpp | 12 | ||||
-rw-r--r-- | simon/simon.h | 2 | ||||
-rw-r--r-- | simon/simonres.cpp | 2 | ||||
-rw-r--r-- | sound.cpp | 15 |
10 files changed, 58 insertions, 54 deletions
diff --git a/engine.cpp b/engine.cpp index 8e90280b0b..bd416f5f70 100644 --- a/engine.cpp +++ b/engine.cpp @@ -20,10 +20,11 @@ #include "stdafx.h" #include "engine.h" -#include "sound/mixer.h" #include "gameDetector.h" +#include "config-file.h" #include "scumm.h" #include "simon/simon.h" +#include "sound/mixer.h" /* FIXME - BIG HACK for MidiEmu */ OSystem *g_system = 0; @@ -34,6 +35,8 @@ Engine::Engine(GameDetector *detector, OSystem *syst) { _mixer = new SoundMixer(); + _gameDataPath = detector->_gameDataPath; + /* FIXME - BIG HACK for MidiEmu */ g_system = _system; g_mixer = _mixer; @@ -44,6 +47,34 @@ Engine::~Engine() delete _mixer; } +const char *Engine::getSavePath() const +{ + const char *dir = NULL; + +#ifdef _WIN32_WCE + dir = _gameDataPath; +#else + +#if !defined(MACOS_CARBON) + dir = getenv("SCUMMVM_SAVEPATH"); +#endif + + // If SCUMMVM_SAVEPATH was not specified, try to use game specific savepath from config + if (!dir || dir[0] == 0) + dir = scummcfg->get("savepath"); + + // If SCUMMVM_SAVEPATH was not specified, try to use general path from config + if (!dir || dir[0] == 0) + dir = scummcfg->get("savepath", "scummvm"); + + // If no save path was specified, use no directory prefix + if (dir == NULL) + dir = ""; +#endif + + return dir; +} + Engine *Engine::createFromDetector(GameDetector *detector, OSystem *syst) { Engine *engine; @@ -34,14 +34,22 @@ extern SoundMixer *g_mixer; class Engine { public: OSystem *_system; - SoundMixer *_mixer; +protected: + char *_gameDataPath; + +public: Engine(GameDetector *detector, OSystem *syst); virtual ~Engine(); // Invoke the main engine loop using this method virtual void go() = 0; + + // Get the save game dir path + const char *getSavePath() const; + + const char *getGameDataPath() const { return _gameDataPath; } // Create a new engine object based on the detector - either // a Scumm or a SimonState object currently. diff --git a/insane.cpp b/insane.cpp index 882a64ff08..ef9dd779eb 100644 --- a/insane.cpp +++ b/insane.cpp @@ -50,11 +50,11 @@ byte * SmushPlayer::loadTres() { FILE * f_tres; uint32 tmp, l; - sprintf((char *)buf, "%sVIDEO/DIGTXT.TRS", (byte *)_scumm->_gameDataPath); + sprintf((char *)buf, "%sVIDEO/DIGTXT.TRS", (byte *)_scumm->getGameDataPath()); f_tres = (FILE*)_scumm->fileOpen((char *)&buf, 1); if (f_tres == NULL) { - sprintf((char *)buf, "%svideo/digtxt.trs", (byte *)_scumm->_gameDataPath); + sprintf((char *)buf, "%svideo/digtxt.trs", (byte *)_scumm->getGameDataPath()); f_tres = (FILE*)_scumm->fileOpen((char *)&buf, 1); if (f_tres == NULL) return NULL; @@ -101,11 +101,11 @@ void SmushPlayer::loadFonts() { for (l = 0; l < SP_MAX_FONTS; l++) { _fonts [l] = NULL; - sprintf((char *)buf, "%sVIDEO/FONT%d.NUT", (char *)_scumm->_gameDataPath, l); + sprintf((char *)buf, "%sVIDEO/FONT%d.NUT", (char *)_scumm->getGameDataPath(), l); f_tres = (FILE*)_scumm->fileOpen((char *)buf, 1); if (f_tres == NULL) { - sprintf((char *)buf, "%svideo/font%d.nut", (char *)_scumm->_gameDataPath, l); + sprintf((char *)buf, "%svideo/font%d.nut", (char *)_scumm->getGameDataPath(), l); f_tres = (FILE*)_scumm->fileOpen((char *)buf, 1); if (f_tres == NULL) continue; @@ -425,11 +425,11 @@ uint32 SmushPlayer::nextBE32() { void SmushPlayer::openFile(byte *fileName) { byte buf[100]; - sprintf((char *)buf, "%sVIDEO/%s", (char *)_scumm->_gameDataPath, (char *)fileName); + sprintf((char *)buf, "%sVIDEO/%s", (char *)_scumm->getGameDataPath(), (char *)fileName); _in = (FILE*)_scumm->fileOpen((char *)buf, 1); if (_in == NULL) { - sprintf((char *)buf, "%svideo/%s", (char *)_scumm->_gameDataPath, (char *)fileName); + sprintf((char *)buf, "%svideo/%s", (char *)_scumm->getGameDataPath(), (char *)fileName); _in = (FILE*)_scumm->fileOpen((char *)buf, 1); } } diff --git a/saveload.cpp b/saveload.cpp index ea56271a80..16200bee9a 100644 --- a/saveload.cpp +++ b/saveload.cpp @@ -166,29 +166,7 @@ bool Scumm::loadState(int slot, bool compat) void Scumm::makeSavegameName(char *out, int slot, bool compatible) { - - const char *dir = NULL; - -#ifdef _WIN32_WCE - dir = _gameDataPath; -#else - -#if !defined(MACOS_CARBON) - dir = getenv("SCUMMVM_SAVEPATH"); -#endif - - // If SCUMMVM_SAVEPATH was not specified, try to use game specific savepath from config - if (!dir || dir[0] == 0) - dir = scummcfg->get("savepath"); - - // If SCUMMVM_SAVEPATH was not specified, try to use general path from config - if (!dir || dir[0] == 0) - dir = scummcfg->get("savepath", "scummvm"); - - // If no save path was specified, use no directory prefix - if (dir == NULL) - dir = ""; -#endif + const char *dir = getSavePath(); // snprintf should be used here, but it's not portable enough sprintf(out, "%s%s.%c%.2d", dir, _exe_name, compatible ? 'c' : 's', slot); @@ -412,7 +412,6 @@ public: /* Core variable definitions */ byte _gameId; const char *_gameText; - char *_gameDataPath; /* Core class/array definitions */ Gdi gdi; diff --git a/scummvm.cpp b/scummvm.cpp index c6ded6ab19..419fc07c8c 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -77,7 +77,6 @@ Scumm::Scumm (GameDetector *detector, OSystem *syst) _debugMode = detector->_debugMode; _bootParam = detector->_bootParam; - _gameDataPath = detector->_gameDataPath; _exe_name = detector->_exe_name; _gameId = detector->_gameId; _gameText = detector->_gameText; diff --git a/simon/simon.cpp b/simon/simon.cpp index 6b626964b6..c7e34ccbcb 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -126,7 +126,6 @@ SimonState::SimonState(GameDetector *detector, OSystem *syst) midi.set_driver(driver); _game = detector->_gameId; - _game_path = detector->_gameDataPath; /* Setup mixer */ if (!_mixer->bind_to_system(syst)) @@ -4541,16 +4540,7 @@ bool SimonState::save_game(uint slot, const char *caption) char *SimonState::gen_savename(int slot) { static char buf[256]; - const char *dir; - - /* perhaps getenv should be added to OSystem */ -#ifndef _WIN32_WCE - dir = getenv("SCUMMVM_SAVEPATH"); - if (dir == NULL) - dir = ""; -#else - dir = _game_path; -#endif + const char *dir = getSavePath(); sprintf(buf, "%sSAVE.%.3d", dir, slot); return buf; diff --git a/simon/simon.h b/simon/simon.h index f4e999d311..fce335b15a 100644 --- a/simon/simon.h +++ b/simon/simon.h @@ -110,8 +110,6 @@ struct GameSpecificSettings; class SimonState : public Engine { public: - char *_game_path; - byte *_vc_ptr; /* video code ptr */ uint32 *_game_offsets_ptr; diff --git a/simon/simonres.cpp b/simon/simonres.cpp index 3ee30ae90e..7b36d1f770 100644 --- a/simon/simonres.cpp +++ b/simon/simonres.cpp @@ -97,7 +97,7 @@ FILE *SimonState::fopen_maybe_lowercase(const char *filename) { FILE *in; char buf[256], dotbuf[256], *e; - const char *s = _game_path; + const char *s = _gameDataPath; if (filename == NULL || *filename == '\0') return NULL; @@ -684,10 +684,10 @@ void * Sound::openSfxFile() { #ifdef COMPRESSED_SOUND_FILE offset_table = NULL; - sprintf(buf, "%s%s.so3", _scumm->_gameDataPath, _scumm->_exe_name); + sprintf(buf, "%s%s.so3", _scumm->getGameDataPath(), _scumm->_exe_name); file = fopen(buf, "rb"); if (!file) { - sprintf(buf, "%smonster.so3", _scumm->_gameDataPath); + sprintf(buf, "%smonster.so3", _scumm->getGameDataPath()); file = fopen(buf, "rb"); } if (file != NULL) { @@ -725,10 +725,10 @@ void * Sound::openSfxFile() { return file; } #endif - sprintf(buf, "%s%s.sou", _scumm->_gameDataPath, _scumm->_exe_name); + sprintf(buf, "%s%s.sou", _scumm->getGameDataPath(), _scumm->_exe_name); file = fopen(buf, "rb"); if (!file) { - sprintf(buf, "%smonster.sou", _scumm->_gameDataPath); + sprintf(buf, "%smonster.sou", _scumm->getGameDataPath()); file = fopen(buf, "rb"); } return file; @@ -775,7 +775,7 @@ void Sound::playBundleMusic(int32 song) { char buf[256]; if (_numberBundleMusic == -1) { - sprintf(buf, "%s%smusic.bun", _scumm->_gameDataPath, _scumm->_exe_name); + sprintf(buf, "%s%smusic.bun", _scumm->getGameDataPath(), _scumm->_exe_name); if (_scumm->_bundle->openMusicFile((char*)&buf) == false) return; _musicBundleBufFinal = (byte*)malloc(OUTPUT_SIZE); @@ -884,6 +884,7 @@ void Sound::bundleMusicHandler(Scumm * scumm) { size = OUTPUT_SIZE; ptr = _musicBundleBufFinal; + byte * buffer = NULL; uint32 final_size = decode12BitsSample(ptr, &buffer, size); _scumm->_mixer->play_raw(NULL, buffer, final_size, rate, SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO); @@ -893,7 +894,7 @@ void Sound::playBundleSound(char *sound) { char buf[256]; byte * ptr; - sprintf(buf, "%s%svoice.bun", _scumm->_gameDataPath, _scumm->_exe_name); + sprintf(buf, "%s%svoice.bun", _scumm->getGameDataPath(), _scumm->_exe_name); _scumm->_bundle->openVoiceFile((char*)&buf); ptr = (byte *)malloc(1000000); if (_scumm->_bundle->decompressVoiceSampleByName(sound, ptr) == 0) { @@ -989,7 +990,7 @@ int Sound::getCachedTrack(int track) { _current_cache %= CACHE_TRACKS; // Not found, see if it exists - sprintf(track_name, "%strack%d.mp3", _scumm->_gameDataPath, track); + sprintf(track_name, "%strack%d.mp3", _scumm->getGameDataPath(), track); file = fopen(track_name, "rb"); _cached_tracks[current_index] = track; |