mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
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
This commit is contained in:
parent
7604484caf
commit
d354eaaf42
33
engine.cpp
33
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;
|
||||
|
10
engine.h
10
engine.h
@ -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.
|
||||
|
12
insane.cpp
12
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);
|
||||
}
|
||||
}
|
||||
|
24
saveload.cpp
24
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);
|
||||
|
1
scumm.h
1
scumm.h
@ -412,7 +412,6 @@ public:
|
||||
/* Core variable definitions */
|
||||
byte _gameId;
|
||||
const char *_gameText;
|
||||
char *_gameDataPath;
|
||||
|
||||
/* Core class/array definitions */
|
||||
Gdi gdi;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -110,8 +110,6 @@ struct GameSpecificSettings;
|
||||
|
||||
class SimonState : public Engine {
|
||||
public:
|
||||
char *_game_path;
|
||||
|
||||
byte *_vc_ptr; /* video code ptr */
|
||||
|
||||
uint32 *_game_offsets_ptr;
|
||||
|
@ -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;
|
||||
|
15
sound.cpp
15
sound.cpp
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user