diff options
author | Filippos Karapetis | 2019-12-27 14:27:49 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-12-27 16:54:57 +0200 |
commit | 9ebb737a06a1eb66d8106930b76c20958141d7ff (patch) | |
tree | bb218c4aba1d135069178fc20f98ce0c8ea97da5 /engines/startrek | |
parent | 454149c49d5897004c244f62b6325fc1b6c2829f (diff) | |
download | scummvm-rg350-9ebb737a06a1eb66d8106930b76c20958141d7ff.tar.gz scummvm-rg350-9ebb737a06a1eb66d8106930b76c20958141d7ff.tar.bz2 scummvm-rg350-9ebb737a06a1eb66d8106930b76c20958141d7ff.zip |
STARTREK: Simplify the BAN (misc animations) code
Diffstat (limited to 'engines/startrek')
-rw-r--r-- | engines/startrek/actors.cpp | 69 | ||||
-rw-r--r-- | engines/startrek/startrek.cpp | 3 | ||||
-rw-r--r-- | engines/startrek/startrek.h | 6 |
3 files changed, 45 insertions, 33 deletions
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp index b8d185e0fb..fa35468cd3 100644 --- a/engines/startrek/actors.cpp +++ b/engines/startrek/actors.cpp @@ -32,8 +32,11 @@ namespace StarTrek { void StarTrekEngine::initActors() { for (int i = 0; i < NUM_ACTORS; i++) _actorList[i] = Actor(); - for (int i = 0; i < MAX_BAN_FILES; i++) - _banFiles[i].reset(); + + for (int i = 0; i < MAX_BAN_FILES; i++) { + delete _banFiles[i]; + _banFiles[i] = nullptr; + } _kirkActor->animationString = "kstnd"; _spockActor->animationString = "sstnd"; @@ -68,7 +71,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] = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(name + ".ban")); + _banFiles[i] = loadFile(name + ".ban"); _banFileOffsets[i] = 0; return; } @@ -268,51 +271,58 @@ void StarTrekEngine::renderBanBelowSprites() { } int16 size = _banFiles[i]->readSint16(); - if (size != 0) { - _banFiles[i]->seek(_banFileOffsets[i], SEEK_SET); - renderBan(screenPixels, _banFiles[i]); - - _banFiles[i]->seek(_banFileOffsets[i], SEEK_SET); - renderBan(bgPixels, _banFiles[i]); - } - + if (size != 0) + renderBan(screenPixels, bgPixels, i); } _gfx->unlockScreenPixels(); } -void StarTrekEngine::renderBan(byte *destPixels, FileStream banFile) { +void StarTrekEngine::renderBan(byte *screenPixels, byte *bgPixels, int banFileIndex) { + Common::MemoryReadStreamEndian *banFile = _banFiles[banFileIndex]; + banFile->seek(_banFileOffsets[banFileIndex], SEEK_SET); + uint16 offset = banFile->readUint16(); int32 size = banFile->readUint16(); - byte *dest = destPixels + offset; + byte *dest1 = screenPixels + offset; + byte *dest2 = bgPixels + offset; // Skip 8 bytes (rectangle encompassing the area being drawn to) - banFile->readSint32(); - banFile->readSint32(); + banFile->skip(8); while (--size >= 0) { - assert(dest >= destPixels && dest < destPixels + SCREEN_WIDTH * SCREEN_HEIGHT); + assert(dest1 >= screenPixels && dest1 < screenPixels + SCREEN_WIDTH * SCREEN_HEIGHT); + assert(dest2 >= bgPixels && dest2 < bgPixels + SCREEN_WIDTH * SCREEN_HEIGHT); + int8 b = banFile->readByte(); - if (b == -128) // Add value to destination (usually jumping to next row) - dest += banFile->readUint16(); - else if (b < 0) { // Repeated byte + if (b == -128) { // Add value to destination (usually jumping to next row) + uint16 skip = banFile->readUint16(); + dest1 += skip; + dest2 += skip; + } else if (b < 0) { // Repeated byte byte c = banFile->readByte(); - if (c == 0) - dest += (-b) + 1; - else { - for (int j = 0; j < (-b) + 1; j++) - (*dest++) = c; + if (c == 0) { + dest1 += (-b) + 1; + dest2 += (-b) + 1; + } else { + for (int j = 0; j < (-b) + 1; j++) { + (*dest1++) = c; + (*dest2++) = c; + } } } else { // List of bytes b++; while (b-- != 0) { byte c = banFile->readByte(); - if (c == 0) - dest++; - else - *(dest++) = c; + if (c == 0) { + dest1++; + dest2++; + } else { + *(dest1++) = c; + *(dest2++) = c; + } } } } @@ -424,7 +434,8 @@ void StarTrekEngine::actorFunc1() { } for (int i = 0; i < MAX_BAN_FILES; i++) { - _banFiles[i].reset(); + delete _banFiles[i]; + _banFiles[i] = nullptr; } } diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index 580f604ddf..941052a65f 100644 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -105,6 +105,9 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam for (int i = 0; i < NUM_OBJECTS; i++) _itemList[i] = g_itemList[i]; + + for (int i = 0; i < MAX_BAN_FILES; i++) + _banFiles[i] = nullptr; } StarTrekEngine::~StarTrekEngine() { diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h index 3ccdfb5641..1c21201661 100644 --- a/engines/startrek/startrek.h +++ b/engines/startrek/startrek.h @@ -63,8 +63,6 @@ class Room; class Console; typedef String(StarTrekEngine::*TextGetterFunc)(int, uintptr, String *); -// FIXME: Eventually get rid of Common::SharedPtr and dispose of file streams properly -typedef Common::SharedPtr<Common::MemoryReadStreamEndian> FileStream; const int SAVEGAME_DESCRIPTION_LEN = 30; @@ -366,7 +364,7 @@ public: * "renderBanAboveSprites()" redraws sprites above them if necessary. */ void renderBanBelowSprites(); - void renderBan(byte *pixelDest, FileStream file); + void renderBan(byte *screenPixels, byte *bgPixels, int banFileIndex); void renderBanAboveSprites(); void removeActorFromScreen(int actorIndex); void actorFunc1(); @@ -706,7 +704,7 @@ public: // ".BAN" files provide extra miscellaneous animations in the room, ie. flashing // pixels on computer consoles, or fireflies in front of the screen. - FileStream _banFiles[MAX_BAN_FILES]; + Common::MemoryReadStreamEndian *_banFiles[MAX_BAN_FILES]; uint16 _banFileOffsets[MAX_BAN_FILES]; Sprite _inventoryIconSprite; |