diff options
author | Filippos Karapetis | 2019-06-10 01:52:35 +0300 |
---|---|---|
committer | Filippos Karapetis | 2019-06-11 00:48:16 +0300 |
commit | 709d606e016235b663e04b9abfa9d537bdc753f0 (patch) | |
tree | 0f7376571ed0d239e1bbc96d72b5a842caf55187 | |
parent | 3f7f1a24108b1333908e82fd01455ea4f863afd3 (diff) | |
download | scummvm-rg350-709d606e016235b663e04b9abfa9d537bdc753f0.tar.gz scummvm-rg350-709d606e016235b663e04b9abfa9d537bdc753f0.tar.bz2 scummvm-rg350-709d606e016235b663e04b9abfa9d537bdc753f0.zip |
STARTREK: Adapt many usages of Common::SharedPtr() to regular pointers
-rw-r--r-- | engines/startrek/actors.cpp | 8 | ||||
-rw-r--r-- | engines/startrek/awaymission.cpp | 2 | ||||
-rw-r--r-- | engines/startrek/bitmap.cpp | 11 | ||||
-rw-r--r-- | engines/startrek/bitmap.h | 1 | ||||
-rw-r--r-- | engines/startrek/font.cpp | 4 | ||||
-rw-r--r-- | engines/startrek/graphics.cpp | 20 | ||||
-rw-r--r-- | engines/startrek/graphics.h | 2 | ||||
-rw-r--r-- | engines/startrek/intro.cpp | 2 | ||||
-rw-r--r-- | engines/startrek/iwfile.cpp | 4 | ||||
-rw-r--r-- | engines/startrek/menu.cpp | 7 | ||||
-rw-r--r-- | engines/startrek/room.cpp | 5 | ||||
-rw-r--r-- | engines/startrek/saveload.cpp | 2 | ||||
-rw-r--r-- | engines/startrek/sound.cpp | 4 | ||||
-rw-r--r-- | engines/startrek/space.cpp | 8 | ||||
-rw-r--r-- | engines/startrek/startrek.cpp | 12 | ||||
-rw-r--r-- | engines/startrek/startrek.h | 7 |
16 files changed, 64 insertions, 35 deletions
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp index 1e0d8b6d2a..21b2892868 100644 --- a/engines/startrek/actors.cpp +++ b/engines/startrek/actors.cpp @@ -68,7 +68,7 @@ void StarTrekEngine::loadBanFile(const Common::String &name) { debugC(kDebugGeneral, 7, "Load BAN file: %s.ban", name.c_str()); for (int i = 0; i < MAX_BAN_FILES; i++) { if (!_banFiles[i]) { - _banFiles[i] = loadFile(name + ".ban"); + _banFiles[i] = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(name + ".ban")); _banFileOffsets[i] = 0; return; } @@ -435,7 +435,7 @@ void StarTrekEngine::drawActorToScreen(Actor *actor, const Common::String &_anim actor->animFilename = _animName; actor->animType = 2; - actor->animFile = loadFile(animFilename + ".anm"); + actor->animFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(animFilename + ".anm")); actor->numAnimFrames = actor->animFile->size() / 22; actor->animFrame = 0; actor->pos.x = x; @@ -764,7 +764,7 @@ SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filen } // Redraw face with xor file - FileStream xorFile = loadFile(filename + ".xor"); + Common::MemoryReadStreamEndian *xorFile = loadFile(filename + ".xor"); xorFile->seek(0, SEEK_SET); uint16 xoffset = bitmap->xoffset - xorFile->readUint16(); uint16 yoffset = bitmap->yoffset - xorFile->readUint16(); @@ -778,6 +778,8 @@ SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filen *dest++ ^= xorFile->readByte(); dest += (bitmap->width - xorWidth); } + + delete xorFile; } } } else { diff --git a/engines/startrek/awaymission.cpp b/engines/startrek/awaymission.cpp index 3f33d1f25d..ca1b3f0c79 100644 --- a/engines/startrek/awaymission.cpp +++ b/engines/startrek/awaymission.cpp @@ -468,7 +468,7 @@ void StarTrekEngine::unloadRoom() { // sub_2394b(); // TODO actorFunc1(); _room.reset(); - _mapFile.reset(); + delete _mapFile; } int StarTrekEngine::loadActorAnimWithRoomScaling(int actorIndex, const Common::String &animName, int16 x, int16 y) { diff --git a/engines/startrek/bitmap.cpp b/engines/startrek/bitmap.cpp index 2d2a223c80..9fa1d36f40 100644 --- a/engines/startrek/bitmap.cpp +++ b/engines/startrek/bitmap.cpp @@ -38,6 +38,17 @@ Bitmap::Bitmap(FileStream stream) { stream->read(pixels, width * height); } +Bitmap::Bitmap(Common::MemoryReadStreamEndian *stream) { + xoffset = stream->readUint16(); + yoffset = stream->readUint16(); + width = stream->readUint16(); + height = stream->readUint16(); + + pixelsArraySize = width * height; + pixels = new byte[pixelsArraySize]; + stream->read(pixels, width * height); +} + Bitmap::Bitmap(const Bitmap &bitmap) { xoffset = bitmap.xoffset; yoffset = bitmap.yoffset; diff --git a/engines/startrek/bitmap.h b/engines/startrek/bitmap.h index 8178f54e1a..6385d191fa 100644 --- a/engines/startrek/bitmap.h +++ b/engines/startrek/bitmap.h @@ -40,6 +40,7 @@ struct Bitmap { byte *pixels; Bitmap(FileStream stream); + Bitmap(Common::MemoryReadStreamEndian *stream); Bitmap(const Bitmap &bitmap); Bitmap(int w, int h); ~Bitmap(); diff --git a/engines/startrek/font.cpp b/engines/startrek/font.cpp index a5f12a5b27..b0875570f7 100644 --- a/engines/startrek/font.cpp +++ b/engines/startrek/font.cpp @@ -31,12 +31,14 @@ static const byte CHARACTER_COUNT = 0x80; static const byte CHARACTER_SIZE = 0x40; Font::Font(StarTrekEngine *vm) : _vm(vm) { - FileStream fontStream = _vm->loadFile("FONT.FNT"); + Common::MemoryReadStreamEndian *fontStream = _vm->loadFile("FONT.FNT"); _characters = new Character[CHARACTER_COUNT]; for (byte i = 0; i < CHARACTER_COUNT; i++) fontStream->read(_characters[i].data, CHARACTER_SIZE); + + delete fontStream; } Font::~Font() { diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp index bc82100bc1..02e778c2dc 100644 --- a/engines/startrek/graphics.cpp +++ b/engines/startrek/graphics.cpp @@ -83,7 +83,7 @@ void Graphics::setBackgroundImage(SharedPtr<Bitmap> bitmap) { _backgroundImage = SharedPtr<Bitmap>(new Bitmap(*bitmap)); } -void Graphics::drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, SharedPtr<Bitmap> bitmap) { +void Graphics::drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, Bitmap *bitmap) { byte *dest = _backgroundImage->pixels + drawRect.top * SCREEN_WIDTH + drawRect.left; byte *src = bitmap->pixels + (drawRect.left - origRect.left) + (drawRect.top - origRect.top) * bitmap->width; @@ -139,13 +139,14 @@ void Graphics::loadPalette(const Common::String &paletteName) { Common::String palFile = paletteName + ".PAL"; Common::String lutFile = paletteName + ".LUT"; - FileStream palStream = _vm->loadFile(palFile.c_str()); + Common::MemoryReadStreamEndian *palStream = _vm->loadFile(palFile.c_str()); palStream->read(_palData, 256 * 3); + delete palStream; // Load LUT file - FileStream lutStream = _vm->loadFile(lutFile.c_str()); - + Common::MemoryReadStreamEndian *lutStream = _vm->loadFile(lutFile.c_str()); lutStream->read(_lutData, 256); + delete lutStream; } void Graphics::copyRectBetweenBitmaps(Bitmap *destBitmap, int destX, int destY, Bitmap *srcBitmap, int srcX, int srcY, int width, int height) { @@ -220,8 +221,9 @@ void Graphics::decPaletteFadeLevel() { void Graphics::loadPri(const Common::String &priFile) { - FileStream priStream = _vm->loadFile(priFile + ".pri"); + Common::MemoryReadStream *priStream = _vm->loadFile(priFile + ".pri"); priStream->read(_priData, SCREEN_WIDTH * SCREEN_HEIGHT / 2); + delete priStream; } void Graphics::clearPri() { @@ -244,7 +246,7 @@ byte Graphics::getPriValue(int x, int y) { } SharedPtr<Bitmap> Graphics::loadBitmap(Common::String basename) { - return SharedPtr<Bitmap>(new Bitmap(_vm->loadFile(basename + ".BMP"))); + return SharedPtr<Bitmap>(new Bitmap(SharedPtr<Common::MemoryReadStreamEndian>(_vm->loadFile(basename + ".BMP")))); } Common::Point Graphics::getMousePos() { @@ -737,14 +739,15 @@ void Graphics::loadEGAData(const char *filename) { if (!_egaData) _egaData = new byte[256]; - FileStream egaStream = _vm->loadFile(filename); + Common::MemoryReadStreamEndian *egaStream = _vm->loadFile(filename); egaStream->read(_egaData, 256); + delete egaStream; } void Graphics::drawBackgroundImage(const char *filename) { // Draw an stjr BGD image (palette built-in) - FileStream imageStream = _vm->loadFile(filename); + Common::MemoryReadStreamEndian *imageStream = _vm->loadFile(filename); byte *palette = new byte[256 * 3]; imageStream->read(palette, 256 * 3); @@ -759,6 +762,7 @@ void Graphics::drawBackgroundImage(const char *filename) { byte *pixels = new byte[width * height]; imageStream->read(pixels, width * height); + delete imageStream; _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); _vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height); diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h index deca9e550d..3357931bb9 100644 --- a/engines/startrek/graphics.h +++ b/engines/startrek/graphics.h @@ -57,7 +57,7 @@ public: * whole bitmap, even if some is outside the drawable space) * @param drawRect The clipped rectangle to draw at (must be within the drawable space) */ - void drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, SharedPtr<Bitmap> bitmap); + void drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, Bitmap *bitmap); void fillBackgroundRect(const Common::Rect &rect, byte color); byte *getBackgroundPixels(); diff --git a/engines/startrek/intro.cpp b/engines/startrek/intro.cpp index 84a8208c34..ce77c974ef 100644 --- a/engines/startrek/intro.cpp +++ b/engines/startrek/intro.cpp @@ -152,7 +152,7 @@ void StarTrekEngine::playIntro() { loadSubtitleSprite(2, &subtitleSprite); planetR3.field22 = 2000; planetR3.field24 = 10000 / _starfieldPointDivisor; - planetR3.shpFile = loadFile("planet.shp"); + planetR3.shpFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile("planet.shp")); initIntroR3ObjectToMove(&planetR3, 6, 10000, 6, 10000, 0); addR3(&planetR3); initIntroR3ObjectToMove(&_enterpriseR3, -15, 250, 15, 500, 18); diff --git a/engines/startrek/iwfile.cpp b/engines/startrek/iwfile.cpp index 9f6eb44ebf..8a45248bca 100644 --- a/engines/startrek/iwfile.cpp +++ b/engines/startrek/iwfile.cpp @@ -29,7 +29,7 @@ IWFile::IWFile(StarTrekEngine *vm, const Common::String &filename) { _vm = vm; - FileStream file = _vm->loadFile(filename); + Common::MemoryReadStreamEndian *file = _vm->loadFile(filename); _numEntries = file->readUint16(); assert(_numEntries < MAX_KEY_POSITIONS); @@ -43,6 +43,8 @@ IWFile::IWFile(StarTrekEngine *vm, const Common::String &filename) { for (int i = 0; i < _numEntries; i++) { file->read(_iwEntries[i], _numEntries); } + + delete file; } // FIXME: same issue with sorting as with "compareSpritesByLayer" in graphics.cpp. diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp index 9aec7ccf93..85503e3534 100644 --- a/engines/startrek/menu.cpp +++ b/engines/startrek/menu.cpp @@ -504,10 +504,9 @@ void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) { _activeMenu = new Menu(); _activeMenu->nextMenu = oldMenu; - FileStream stream = loadFile(mnuFilename + ".MNU"); + Common::MemoryReadStreamEndian *stream = loadFile(mnuFilename + ".MNU"); - _activeMenu->menuFile = stream; - _activeMenu->numButtons = _activeMenu->menuFile->size() / 16; + _activeMenu->numButtons = stream->size() / 16; for (int i = 0; i < _activeMenu->numButtons; i++) { _activeMenu->sprites[i] = Sprite(); @@ -532,6 +531,8 @@ void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) { _activeMenu->sprites[i].drawPriority2 = 8; } + delete stream; + if (_activeMenu->retvals[_activeMenu->numButtons - 1] == 0) { // Set default retvals for buttons for (int i = 0; i < _activeMenu->numButtons; i++) diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp index d4f84d2b67..d3bf2d8f80 100644 --- a/engines/startrek/room.cpp +++ b/engines/startrek/room.cpp @@ -45,11 +45,12 @@ namespace StarTrek { Room::Room(StarTrekEngine *vm, const Common::String &name) : _vm(vm), _awayMission(&vm->_awayMission) { - FileStream rdfFile = _vm->loadFile(name + ".RDF"); + Common::MemoryReadStreamEndian *rdfFile = _vm->loadFile(name + ".RDF"); int size = rdfFile->size(); _rdfData = new byte[size]; rdfFile->read(_rdfData, size); + delete rdfFile; _roomIndex = name.lastChar() - '0'; @@ -436,7 +437,7 @@ void Room::walkCrewmanC(int actorIndex, int16 destX, int16 destY, void (Room::*f void Room::loadMapFile(const Common::String &name) { _vm->_mapFilename = name; _vm->_iwFile.reset(); - _vm->_mapFile.reset(); + delete _vm->_mapFile; _vm->_iwFile = SharedPtr<IWFile>(new IWFile(_vm, name + ".iw")); _vm->_mapFile = _vm->loadFile(name + ".map"); } diff --git a/engines/startrek/saveload.cpp b/engines/startrek/saveload.cpp index 362e0aa190..7c4516ec0b 100644 --- a/engines/startrek/saveload.cpp +++ b/engines/startrek/saveload.cpp @@ -148,7 +148,7 @@ bool StarTrekEngine::loadGame(int slot) { Actor *a = &_actorList[i]; if (a->spriteDrawn) { if (a->animType != 1) - a->animFile = loadFile(a->animFilename + ".anm"); + a->animFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(a->animFilename + ".anm")); _gfx->addSprite(&a->sprite); a->sprite.setBitmap(loadAnimationFrame(a->bitmapFilename, a->scale)); } diff --git a/engines/startrek/sound.cpp b/engines/startrek/sound.cpp index 3b77228324..c448126e08 100644 --- a/engines/startrek/sound.cpp +++ b/engines/startrek/sound.cpp @@ -346,7 +346,7 @@ void Sound::loadPCMusicFile(const Common::String &baseSoundName) { } debugC(5, kDebugSound, "Loading midi \'%s\'\n", soundName.c_str()); - FileStream soundStream = _vm->loadFile(soundName.c_str()); + Common::MemoryReadStreamEndian *soundStream = _vm->loadFile(soundName.c_str()); if (loadedSoundData != nullptr) delete[] loadedSoundData; @@ -355,6 +355,8 @@ void Sound::loadPCMusicFile(const Common::String &baseSoundName) { // FIXME: should music start playing when this is called? //_midiSlots[0].midiParser->loadMusic(loadedSoundData, soundStream->size()); + + delete soundStream; } void Sound::clearMidiSlot(int slot) { diff --git a/engines/startrek/space.cpp b/engines/startrek/space.cpp index 96a40da2ab..b9b0919738 100644 --- a/engines/startrek/space.cpp +++ b/engines/startrek/space.cpp @@ -81,7 +81,7 @@ void StarTrekEngine::drawStarfield() { int16 yvar = var2a / 2; int16 var8 = _starfieldPointDivisor << 3; - FileStream file = loadFile("stars.shp"); + Common::MemoryReadStreamEndian *file = loadFile("stars.shp"); for (int i = 0; i < NUM_STARS; i++) { Star *star = &_starList[i]; @@ -115,11 +115,11 @@ void StarTrekEngine::drawStarfield() { Common::Rect drawRect = _starfieldRect.findIntersectingRect(starRect); file->seek(fileOffset, SEEK_SET); - SharedPtr<Bitmap> bitmap = SharedPtr<Bitmap>(new Bitmap(file)); + Bitmap *bitmap = new Bitmap(file); if (!drawRect.isEmpty()) _gfx->drawBitmapToBackground(starRect, drawRect, bitmap); - bitmap.reset(); + delete bitmap; } else { star->active = false; @@ -128,6 +128,8 @@ void StarTrekEngine::drawStarfield() { file->seek(file->pos() + offset2, SEEK_SET); } } + + delete file; } /** diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index 6e197de15d..b01749525e 100644 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -394,7 +394,7 @@ void StarTrekEngine::stopPlayingSpeech() { * - This is supposed to read from a "patches" folder which overrides files in the * packed blob. */ -FileStream StarTrekEngine::loadFile(Common::String filename, int fileIndex) { +Common::MemoryReadStreamEndian *StarTrekEngine::loadFile(Common::String filename, int fileIndex) { filename.toUppercase(); Common::String basename, extension; @@ -429,7 +429,7 @@ FileStream StarTrekEngine::loadFile(Common::String filename, int fileIndex) { byte *data = (byte *)malloc(size); file->read(data, size); delete file; - return Common::SharedPtr<Common::MemoryReadStreamEndian>(new Common::MemoryReadStreamEndian(data, size, bigEndian)); + return new Common::MemoryReadStreamEndian(data, size, bigEndian); } Common::SeekableReadStream *indexFile = 0; @@ -559,10 +559,10 @@ FileStream StarTrekEngine::loadFile(Common::String filename, int fileIndex) { stream->read(data, size); delete stream; - return Common::SharedPtr<Common::MemoryReadStreamEndian>(new Common::MemoryReadStreamEndian(data, size, bigEndian)); + return new Common::MemoryReadStreamEndian(data, size, bigEndian); } -FileStream StarTrekEngine::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) { +Common::MemoryReadStreamEndian *StarTrekEngine::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) { return loadFile(filename); } @@ -618,7 +618,7 @@ uint16 StarTrekEngine::getRandomWord() { } Common::String StarTrekEngine::getLoadedText(int textIndex) { - FileStream txtFile = loadFile(_txtFilename + ".txt"); + Common::MemoryReadStreamEndian *txtFile = loadFile(_txtFilename + ".txt"); Common::String str; byte cur; @@ -631,6 +631,8 @@ Common::String StarTrekEngine::getLoadedText(int textIndex) { textIndex--; } + delete txtFile; + return str; } diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h index a47e0219b4..fadf295107 100644 --- a/engines/startrek/startrek.h +++ b/engines/startrek/startrek.h @@ -159,7 +159,6 @@ struct Menu { Sprite sprites[MAX_MENUBUTTONS]; uint16 retvals[MAX_MENUBUTTONS]; uint32 disabledButtons; - FileStream menuFile; uint16 numButtons; int16 selectedButton; Menu *nextMenu; @@ -247,11 +246,11 @@ public: void playSpeech(const Common::String &filename); void stopPlayingSpeech(); - FileStream loadFile(Common::String filename, int fileIndex = 0); + Common::MemoryReadStreamEndian *loadFile(Common::String filename, int fileIndex = 0); /** * TODO: Figure out what the extra parameters are, and if they're important. */ - FileStream loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3); + Common::MemoryReadStreamEndian *loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3); void playMovie(Common::String filename); void playMovieMac(Common::String filename); @@ -692,7 +691,7 @@ public: int _roomIndex; Common::String _screenName; // _screenName = _missionName + _roomIndex Common::String _mapFilename; // Similar to _screenName, but used for .map files? - FileStream _mapFile; + Common::MemoryReadStreamEndian *_mapFile; Fixed16 _playerActorScale; Common::String _txtFilename; |