diff options
author | Jonathan Gray | 2003-06-14 14:58:08 +0000 |
---|---|---|
committer | Jonathan Gray | 2003-06-14 14:58:08 +0000 |
commit | eb808a8d4c5484e79c573485a1e2819275082eee (patch) | |
tree | 06b827bef2c6892d768b0f9837a0b590521c4486 /simon | |
parent | 12edf335f38d24995298d7d4df1cf26329b340bf (diff) | |
download | scummvm-rg350-eb808a8d4c5484e79c573485a1e2819275082eee.tar.gz scummvm-rg350-eb808a8d4c5484e79c573485a1e2819275082eee.tar.bz2 scummvm-rg350-eb808a8d4c5484e79c573485a1e2819275082eee.zip |
make file objects stack based where possible, fixes a bunch of leaks
svn-id: r8476
Diffstat (limited to 'simon')
-rw-r--r-- | simon/res.cpp | 44 | ||||
-rw-r--r-- | simon/simon.cpp | 11 | ||||
-rw-r--r-- | simon/sound.cpp | 68 |
3 files changed, 61 insertions, 62 deletions
diff --git a/simon/res.cpp b/simon/res.cpp index 162290fb5d..95032c8e1a 100644 --- a/simon/res.cpp +++ b/simon/res.cpp @@ -95,52 +95,52 @@ static const char *const opcode_arg_table_simon2dos[256] = { }; void SimonEngine::loadGamePcFile(const char *filename) { - File * in = new File(); + File in; int num_inited_objects; int i, file_size; /* read main gamepc file */ - in->open(filename, _gameDataPath); - if (in->isOpen() == false) { + in.open(filename, _gameDataPath); + if (in.isOpen() == false) { char *filename2; filename2 = (char *)malloc(strlen(filename) + 2); strcpy(filename2, filename); strcat(filename2, "."); - in->open(filename2, _gameDataPath); + in.open(filename2, _gameDataPath); free(filename2); - if (in->isOpen() == false) + if (in.isOpen() == false) error("Can't open gamepc file '%s' or '%s.'", gss->gamepc_filename, gss->gamepc_filename); } - num_inited_objects = allocGamePcVars(in); + num_inited_objects = allocGamePcVars(&in); allocItem1(); loginPlayer(); - readGamePcText(in); + readGamePcText(&in); for (i = 2; i < num_inited_objects; i++) { - readItemFromGamePc(in, _itemarray_ptr[i]); + readItemFromGamePc(&in, _itemarray_ptr[i]); } - readSubroutineBlock(in); + readSubroutineBlock(&in); - in->close(); + in.close(); /* Read list of TABLE resources */ - in->open("TBLLIST", _gameDataPath); - if (in->isOpen() == false) { - in->open("TBLLIST.", _gameDataPath); - if (in->isOpen() == false) + in.open("TBLLIST", _gameDataPath); + if (in.isOpen() == false) { + in.open("TBLLIST.", _gameDataPath); + if (in.isOpen() == false) error("Can't open table resources file 'TBLLIST' or 'TBLLIST.'"); } - file_size = in->size(); + file_size = in.size(); _tbl_list = (byte *)malloc(file_size); if (_tbl_list == NULL) error("Out of memory for strip table list"); - in->read(_tbl_list, file_size); - in->close(); + in.read(_tbl_list, file_size); + in.close(); /* Remember the current state */ _subroutine_list_org = _subroutine_list; @@ -148,16 +148,16 @@ void SimonEngine::loadGamePcFile(const char *filename) { _tablesheap_curpos_org = _tablesheap_curpos; /* Read list of TEXT resources */ - in->open("STRIPPED.TXT", _gameDataPath); - if (in->isOpen() == false) + in.open("STRIPPED.TXT", _gameDataPath); + if (in.isOpen() == false) error("Can't open text resources file 'STRIPPED.TXT'"); - file_size = in->size(); + file_size = in.size(); _stripped_txt_mem = (byte *)malloc(file_size); if (_stripped_txt_mem == NULL) error("Out of memory for strip text list"); - in->read(_stripped_txt_mem, file_size); - in->close(); + in.read(_stripped_txt_mem, file_size); + in.close(); } void SimonEngine::readGamePcText(File *in) { diff --git a/simon/simon.cpp b/simon/simon.cpp index d209fddeed..592575af9c 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -4764,18 +4764,17 @@ void SimonEngine::loadMusic (uint music) { midi.loadSMF (_game_file, music); } else { char buf[50]; - File *f = new File(); + File f; sprintf(buf, "MOD%d.MUS", music); - f->open(buf, _gameDataPath); - if (f->isOpen() == false) { + f.open(buf, _gameDataPath); + if (f.isOpen() == false) { warning("Can't load music from '%s'", buf); return; } if (_game & GF_DEMO) - midi.loadS1D (f); + midi.loadS1D (&f); else - midi.loadSMF (f, music); - delete f; + midi.loadSMF (&f, music); } midi.startTrack (0); diff --git a/simon/sound.cpp b/simon/sound.cpp index df27b1d0b0..bb115943fe 100644 --- a/simon/sound.cpp +++ b/simon/sound.cpp @@ -46,73 +46,73 @@ SimonSound::SimonSound(const byte game, const GameSpecificSettings *gss, const c _voice_file = false; _ambient_playing = 0; - File *file = new File(); - File *file2 = new File(); + File file; + File file2; const char *s; #ifdef USE_MAD - file->open(gss->mp3_filename, gameDataPath); - if (file->isOpen() == false) { + file.open(gss->mp3_filename, gameDataPath); + if (file.isOpen() == false) { #endif // for simon2 mac/amiga, only read index file if (_game == GAME_SIMON2MAC) { - file->open("voices.idx", gameDataPath); - if (file->isOpen() == false) { + file.open("voices.idx", gameDataPath); + if (file.isOpen() == false) { warning("Can't open voice index file 'voices.idx'"); } else { - file->seek(0, SEEK_END); - int end = file->pos(); - file->seek(0, SEEK_SET); + file.seek(0, SEEK_END); + int end = file.pos(); + file.seek(0, SEEK_SET); _filenums = (uint16 *)malloc(end / 3 + 1); _offsets = (uint32 *)malloc((end / 6) * 4 + 1); for (int i = 1; i <= end / 6; i++) { - _filenums[i] = file->readUint16BE(); - _offsets[i] = file->readUint32BE(); + _filenums[i] = file.readUint16BE(); + _offsets[i] = file.readUint32BE(); } _voice_file = true; } } else if (_game & GF_WIN) { s = gss->wav_filename; - file->open(s, gameDataPath); - if (file->isOpen() == false) { + file.open(s, gameDataPath); + if (file.isOpen() == false) { warning("Can't open voice file %s", s); } else { _voice_file = true; - _voice = new WavSound(_mixer, file); + _voice = new WavSound(_mixer, &file); } } else if (_game & GF_TALKIE) { s = gss->voc_filename; - file->open(s, gameDataPath); - if (file->isOpen() == false) { + file.open(s, gameDataPath); + if (file.isOpen() == false) { warning("Can't open voice file %s", s); } else { _voice_file = true; - _voice = new VocSound(_mixer, file); + _voice = new VocSound(_mixer, &file); } } #ifdef USE_MAD } else { _voice_file = true; - _voice = new MP3Sound(_mixer, file); + _voice = new MP3Sound(_mixer, &file); } #endif if (_game == GAME_SIMON1TALKIE) { #ifdef USE_MAD - file2->open(gss->mp3_effects_filename, gameDataPath); - if (file2->isOpen() == false) { + file2.open(gss->mp3_effects_filename, gameDataPath); + if (file2.isOpen() == false) { #endif s = gss->voc_effects_filename; - file2->open(s, gameDataPath); - if (file2->isOpen() == false) { + file2.open(s, gameDataPath); + if (file2.isOpen() == false) { warning("Can't open effects file %s", s); } else { - _effects = new VocSound(_mixer, file2); + _effects = new VocSound(_mixer, &file2); } #ifdef USE_MAD } else { - _effects = new MP3Sound(_mixer, file2); + _effects = new MP3Sound(_mixer, &file2); } #endif } @@ -121,24 +121,24 @@ SimonSound::SimonSound(const byte game, const GameSpecificSettings *gss, const c void SimonSound::readSfxFile(const char *filename, const char *gameDataPath) { stopAll(); - File *file = new File(); - file->open(filename, gameDataPath); + File file; + file.open(filename, gameDataPath); - if (file->isOpen() == false) { + if (file.isOpen() == false) { char *filename2; filename2 = (char *)malloc(strlen(filename) + 2); strcpy(filename2, filename); strcat(filename2, "."); - file->open(filename2, gameDataPath); + file.open(filename2, gameDataPath); free(filename2); - if (file->isOpen() == false) { + if (file.isOpen() == false) { if (atoi(filename + 6) != 1 && atoi(filename + 6) != 30) warning("readSfxFile: Can't load sfx file %s", filename); return; } } - _effects = new WavSound(_mixer, file); + _effects = new WavSound(_mixer, &file); } void SimonSound::loadSfxTable(File *gameFile, uint32 base) { @@ -151,15 +151,15 @@ void SimonSound::loadSfxTable(File *gameFile, uint32 base) { } void SimonSound::playVoice(uint sound) { + File file; if (_game == GAME_SIMON2MAC && _filenums) { char filename[16]; sprintf(filename, "voices%d.dat", _filenums[sound]); - File *file = new File(); - file->open(filename, _gameDataPath); - if (file->isOpen() == false) { + file.open(filename, _gameDataPath); + if (file.isOpen() == false) { warning("Can't open voice file %s", filename); } else { - _voice = new WavSound(_mixer, file, _offsets); + _voice = new WavSound(_mixer, &file, _offsets); } } |