[Scummvm-git-logs] scummvm master -> ffb0b2b743ee347822902eb4031efa2b37edf771
bluegr
bluegr at gmail.com
Wed Sep 9 19:36:47 UTC 2020
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
df536ad6f8 STARTREK: Reduce usage of SharedPtr in sprites
40bfdb8d7a STARTREK: Plug memory leaks
ed24377900 STARTREK: Move resource-related functions into a separate class
ffb0b2b743 STARTREK: Fix typo
Commit: df536ad6f8823145bd97a2913624a952706db587
https://github.com/scummvm/scummvm/commit/df536ad6f8823145bd97a2913624a952706db587
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2020-09-09T22:36:10+03:00
Commit Message:
STARTREK: Reduce usage of SharedPtr in sprites
Changed paths:
engines/startrek/actors.cpp
engines/startrek/menu.cpp
engines/startrek/rooms/demon4.cpp
engines/startrek/rooms/demon6.cpp
engines/startrek/sprite.cpp
engines/startrek/sprite.h
engines/startrek/textbox.cpp
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp
index 80704d7ac3..8f9eb68d4f 100644
--- a/engines/startrek/actors.cpp
+++ b/engines/startrek/actors.cpp
@@ -206,7 +206,8 @@ void StarTrekEngine::updateActorAnimations() {
Fixed16 newX = actor->granularPosX + actor->speedX;
Fixed16 newY = actor->granularPosY + actor->speedY;
if ((actor->field90 & 3) == 0) {
- sprite->bitmap.reset();
+ delete sprite->bitmap;
+ sprite->bitmap = nullptr;
updateActorPositionWhileWalking(actor, (newX + 0.5).toInt(), (newY + 0.5).toInt());
actor->field92++;
}
@@ -222,7 +223,8 @@ void StarTrekEngine::updateActorAnimations() {
addAction(ACTION_FINISHED_WALKING, actor->finishedAnimActionParam & 0xff, 0, 0);
}
- actor->sprite.bitmap.reset();
+ delete actor->sprite.bitmap;
+ actor->sprite.bitmap = nullptr;
updateActorPositionWhileWalking(actor, (actor->granularPosX + 0.5).toInt(), (actor->granularPosY + 0.5).toInt());
initStandAnim(i);
} else { // actor->iwSrcPosition != -1
@@ -487,11 +489,11 @@ void StarTrekEngine::releaseAnim(Actor *actor) {
switch (actor->animType) {
case 0:
case 2:
- actor->sprite.bitmap.reset();
actor->animFile.reset();
- break;
+ // Fall through
case 1:
- actor->sprite.bitmap.reset();
+ delete actor->sprite.bitmap;
+ actor->sprite.bitmap = nullptr;
break;
default:
error("Invalid anim type");
@@ -791,6 +793,7 @@ Bitmap *StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed
}
delete xorFile;
+ delete bitmap;
}
}
} else {
@@ -1075,13 +1078,15 @@ void StarTrekEngine::hideInventoryIcons() {
if (_itemIconSprite.drawMode == 2) {
_gfx->delSprite(&_itemIconSprite);
_itemIconSprite.drawMode = 0;
- _itemIconSprite.bitmap.reset();
+ delete _itemIconSprite.bitmap;
+ _itemIconSprite.bitmap = nullptr;
}
if (_inventoryIconSprite.drawMode == 2) {
_gfx->delSprite(&_inventoryIconSprite);
_inventoryIconSprite.drawMode = 0;
- _inventoryIconSprite.bitmap.reset();
+ delete _inventoryIconSprite.bitmap;
+ _inventoryIconSprite.bitmap = nullptr;
}
}
@@ -1183,11 +1188,11 @@ int StarTrekEngine::showInventoryMenu(int x, int y, bool restoreMouse) {
itemIndex = getMenuButtonAt(itemSprites, numItems, mousePos.x, mousePos.y);
if (itemIndex != lastItemIndex) {
if (lastItemIndex != -1) {
- drawMenuButtonOutline(itemSprites[lastItemIndex].bitmap.get(), 0);
+ drawMenuButtonOutline(itemSprites[lastItemIndex].bitmap, 0);
itemSprites[lastItemIndex].bitmapChanged = true;
}
if (itemIndex != -1) {
- drawMenuButtonOutline(itemSprites[itemIndex].bitmap.get(), 15);
+ drawMenuButtonOutline(itemSprites[itemIndex].bitmap, 15);
itemSprites[itemIndex].bitmapChanged = true;
}
lastItemIndex = itemIndex;
@@ -1266,7 +1271,7 @@ exitWithoutSelection:
_sound->playSoundEffectIndex(0x10);
if (lastItemIndex >= 0)
- drawMenuButtonOutline(itemSprites[lastItemIndex].bitmap.get(), 0);
+ drawMenuButtonOutline(itemSprites[lastItemIndex].bitmap, 0);
for (int i = 0; i < numItems; i++)
itemSprites[i].dontDrawNextFrame();
@@ -1274,7 +1279,8 @@ exitWithoutSelection:
_gfx->drawAllSprites();
for (int i = 0; i < numItems; i++) {
- itemSprites[i].bitmap.reset();
+ delete itemSprites[i].bitmap;
+ itemSprites[i].bitmap = nullptr;
_gfx->delSprite(&itemSprites[i]);
}
diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp
index cb1c290cc8..0abef6a3a6 100644
--- a/engines/startrek/menu.cpp
+++ b/engines/startrek/menu.cpp
@@ -555,7 +555,7 @@ void StarTrekEngine::setVisibleMenuButtons(uint32 bits) {
if ((bits & spriteBitmask) == 0 || sprite->drawMode != 0) {
if ((bits & spriteBitmask) == 0 && sprite->drawMode == 2) {
if (i == _activeMenu->selectedButton) {
- drawMenuButtonOutline(sprite->bitmap.get(), 0x00);
+ drawMenuButtonOutline(sprite->bitmap, 0x00);
_activeMenu->selectedButton = -1;
}
@@ -592,7 +592,7 @@ void StarTrekEngine::disableMenuButtons(uint32 bits) {
if (_activeMenu->selectedButton != -1
&& (_activeMenu->disabledButtons & (1 << _activeMenu->selectedButton))) {
Sprite *sprite = &_activeMenu->sprites[_activeMenu->selectedButton];
- drawMenuButtonOutline(sprite->bitmap.get(), 0x00);
+ drawMenuButtonOutline(sprite->bitmap, 0x00);
sprite->bitmapChanged = true;
_activeMenu->selectedButton = -1;
@@ -622,12 +622,12 @@ int StarTrekEngine::handleMenuEvents(uint32 ticksUntilClickingEnabled, bool inTe
if (buttonIndex != _activeMenu->selectedButton) {
if (_activeMenu->selectedButton != -1) {
Sprite &spr = _activeMenu->sprites[_activeMenu->selectedButton];
- drawMenuButtonOutline(spr.bitmap.get(), 0x00);
+ drawMenuButtonOutline(spr.bitmap, 0x00);
spr.bitmapChanged = true;
}
if (buttonIndex != -1) {
Sprite &spr = _activeMenu->sprites[buttonIndex];
- drawMenuButtonOutline(spr.bitmap.get(), 0xda);
+ drawMenuButtonOutline(spr.bitmap, 0xda);
spr.bitmapChanged = true;
}
_activeMenu->selectedButton = buttonIndex;
@@ -835,7 +835,7 @@ rclick:
void StarTrekEngine::unloadMenuButtons() {
if (_activeMenu->selectedButton != -1)
- drawMenuButtonOutline(_activeMenu->sprites[_activeMenu->selectedButton].bitmap.get(), 0x00);
+ drawMenuButtonOutline(_activeMenu->sprites[_activeMenu->selectedButton].bitmap, 0x00);
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
@@ -849,7 +849,8 @@ void StarTrekEngine::unloadMenuButtons() {
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
- sprite->bitmap.reset();
+ delete sprite->bitmap;
+ sprite->bitmap = nullptr;
if (sprite->drawMode == 2)
_gfx->delSprite(sprite);
}
@@ -1142,7 +1143,8 @@ lclick:
someSprite.dontDrawNextFrame();
_gfx->drawAllSprites();
_gfx->delSprite(&someSprite);
- someSprite.bitmap.reset();
+ delete someSprite.bitmap;
+ someSprite.bitmap = nullptr;
spriteLoaded = false;
}
}
@@ -1167,7 +1169,8 @@ lclick:
}
_gfx->fadeoutScreen();
- someSprite.bitmap.reset();
+ delete someSprite.bitmap;
+ someSprite.bitmap = nullptr;
_gfx->popSprites();
_gfx->loadPri(getScreenName());
diff --git a/engines/startrek/rooms/demon4.cpp b/engines/startrek/rooms/demon4.cpp
index 0028ad7a18..16fd78bef7 100644
--- a/engines/startrek/rooms/demon4.cpp
+++ b/engines/startrek/rooms/demon4.cpp
@@ -73,9 +73,9 @@ void Room::demon4FinishedAnimation2() {
void Room::demon4FinishedAnimation3() {
showText(TX_SPEAKER_NAUIAN, 34, true);
- showText(TX_SPEAKER_KIRK, 10, true);
+ showText(TX_SPEAKER_KIRK, 10, true);
showText(TX_SPEAKER_NAUIAN, 35, true);
- showText(TX_SPEAKER_SPOCK, 30, true);
+ showText(TX_SPEAKER_SPOCK, 30, true);
_awayMission->disableInput = true;
_awayMission->demon.missionScore += 5;
@@ -186,7 +186,7 @@ void Room::demon4UseSkullOnNauian() {
void Room::demon4KirkReachedNauianWithSkull() {
showText(TX_SPEAKER_NAUIAN, 36, true);
- const TextRef choices[] = { TX_SPEAKER_KIRK, 6, 3, 5, TX_BLANK };
+ const TextRef choices[] = {TX_SPEAKER_KIRK, 6, 3, 5, TX_BLANK};
int choice = showMultipleTexts(choices, true);
switch (choice) {
@@ -227,7 +227,7 @@ void Room::demon4TalkToNauian() {
_awayMission->demon.metNauian = true;
showText(TX_SPEAKER_NAUIAN, 44, true);
- const TextRef choices[] = { TX_SPEAKER_KIRK, 2, 4, 9, TX_BLANK };
+ const TextRef choices[] = {TX_SPEAKER_KIRK, 2, 4, 9, TX_BLANK};
int choice = showMultipleTexts(choices, true);
switch (choice) {
@@ -250,7 +250,7 @@ void Room::demon4TalkToNauian() {
showText(TX_SPEAKER_NAUIAN, 43, true);
- const TextRef choices2[] = { TX_SPEAKER_KIRK, 8, 7, TX_BLANK };
+ const TextRef choices2[] = {TX_SPEAKER_KIRK, 8, 7, TX_BLANK};
choice = showMultipleTexts(choices2, true);
switch (choice) {
@@ -272,9 +272,9 @@ void Room::demon4TalkToNauian() {
// BUGFIX: Originally all of these used no audio, despite the files existing
// (being used elsewhere).
- showText(TX_SPEAKER_KIRK, 10, true);
+ showText(TX_SPEAKER_KIRK, 10, true);
showText(TX_SPEAKER_NAUIAN, 35, true);
- showText(TX_SPEAKER_SPOCK, 30, true);
+ showText(TX_SPEAKER_SPOCK, 30, true);
_awayMission->disableInput = true;
_awayMission->demon.missionScore += 5;
@@ -427,43 +427,43 @@ bool Room::demon4ShowSunPuzzle() {
sprites[1].setXYAndPriority(0xa8, sliderR + 0x75, 14);
sprites[2].setXYAndPriority(0xb0, sliderB + 0x75, 14);
- int var56 = 0x82;
- int var58 = 0x83;
- int var5a = 3;
+ int y = 0x82;
+ int x = 0x83;
+ int start = 3;
int numSprites = abs(sliderY) / 3;
for (int i = 0; i < 6; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
+ sprites[i + start].setXYAndPriority(x, y, 14);
}
- var56 -= 6;
+ y -= 6;
for (int i = 0; i < numSprites; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
- var56 -= 6;
+ sprites[i + start].setXYAndPriority(x, y, 14);
+ y -= 6;
}
- var56 = 0x82;
- var58 = 0x8b;
- var5a = 9;
+ y = 0x82;
+ x = 0x8b;
+ start = 9;
numSprites = abs(sliderR) / 3;
for (int i = 0; i < 6; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
+ sprites[i + start].setXYAndPriority(x, y, 14);
}
- var56 -= 6;
+ y -= 6;
for (int i = 0; i < numSprites; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
- var56 -= 6;
+ sprites[i + start].setXYAndPriority(x, y, 14);
+ y -= 6;
}
- var56 = 0x82;
- var58 = 0x93;
- var5a = 15;
+ y = 0x82;
+ x = 0x93;
+ start = 15;
numSprites = abs(sliderB) / 3;
for (int i = 0; i < 6; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
+ sprites[i + start].setXYAndPriority(x, y, 14);
}
- var56 -= 6;
+ y -= 6;
for (int i = 0; i < numSprites; i++) {
- sprites[i + var5a].setXYAndPriority(var58, var56, 14);
- var56 -= 6;
+ sprites[i + start].setXYAndPriority(x, y, 14);
+ y -= 6;
}
sliderChanged = false;
@@ -475,7 +475,7 @@ bool Room::demon4ShowSunPuzzle() {
switch (event.type) {
case TREKEVENT_LBUTTONDOWN: {
-lclick:
+ lclick:
Common::Point mousePos = _vm->_gfx->getMousePos();
if (_vm->_gfx->getSpriteAt(mousePos) == &doneButtonSprite)
goto done;
@@ -494,7 +494,7 @@ lclick:
}
case TREKEVENT_RBUTTONDOWN:
-done:
+ done:
if (abs(sliderY) <= 2 && abs(sliderR) <= 2 && abs(sliderB) <= 2)
solved = true;
else
@@ -532,6 +532,10 @@ done:
_vm->_gfx->copyBackgroundScreen();
_vm->_gfx->forceDrawAllSprites();
+ for (int i = 0; i < 21; i++) {
+ sprites[i].bitmap = nullptr;
+ }
+
delete lightbBitmap;
delete lightrBitmap;
delete lightyBitmap;
@@ -629,4 +633,4 @@ void Room::demon4UseMTricorderOnSecurityEquipment() {
showText(TX_SPEAKER_SPOCK, 26, true); // BUG: Uses spock's voice (speaker says "Spock" too)
}
-}
+} // namespace StarTrek
diff --git a/engines/startrek/rooms/demon6.cpp b/engines/startrek/rooms/demon6.cpp
index 038f66dea8..920b4934a6 100644
--- a/engines/startrek/rooms/demon6.cpp
+++ b/engines/startrek/rooms/demon6.cpp
@@ -578,7 +578,8 @@ int Room::demon6ShowCaseProcessSelection(Sprite *sprites, Sprite *clickedSprite,
clickedSprite->dontDrawNextFrame();
_vm->_gfx->drawAllSprites();
_vm->_gfx->delSprite(clickedSprite);
- clickedSprite->bitmap.reset();
+ delete clickedSprite->bitmap;
+ clickedSprite->bitmap = nullptr;
visible ^= (0x10 >> (clickedSprite - sprites));
return visible;
diff --git a/engines/startrek/sprite.cpp b/engines/startrek/sprite.cpp
index 51a97ee89f..1ab6292017 100644
--- a/engines/startrek/sprite.cpp
+++ b/engines/startrek/sprite.cpp
@@ -27,19 +27,25 @@ namespace StarTrek {
Sprite::Sprite() :
pos(), drawPriority(0), drawPriority2(0), field8(""),
- bitmap(), drawMode(0), textColor(0), bitmapChanged(false),
+ bitmap(nullptr), drawMode(0), textColor(0), bitmapChanged(false),
rect2Valid(false), isOnScreen(false), field16(false), lastDrawRect(),
drawRect(), rectangle2(), drawX(0), drawY(0)
{}
+Sprite::~Sprite() {
+ delete bitmap;
+ bitmap = nullptr;
+}
+
void Sprite::setBitmap(Bitmap *b) {
- bitmap = SharedPtr<Bitmap>(b);
+ if (bitmap)
+ delete bitmap;
+ bitmap = b;
bitmapChanged = true;
}
void Sprite::setBitmap(Common::MemoryReadStreamEndian *stream) {
- bitmap = SharedPtr<Bitmap>(new Bitmap(stream));
- bitmapChanged = true;
+ setBitmap(new Bitmap(stream));
}
void Sprite::setXYAndPriority(int16 x, int16 y, int16 priority) {
diff --git a/engines/startrek/sprite.h b/engines/startrek/sprite.h
index b5dba1c20d..b89efa633f 100644
--- a/engines/startrek/sprite.h
+++ b/engines/startrek/sprite.h
@@ -42,12 +42,13 @@ namespace StarTrek {
// the rectangle, but ScummVM rects are not. Functions from Trek have been adapted to use
// ScummVM's rect format. Be wary of off-by-1 errors...
-struct Sprite : Common::Serializable {
+class Sprite : Common::Serializable {
+public:
Common::Point pos;
uint16 drawPriority;
uint16 drawPriority2; // If two sprites' drawPriorities are equal, this is checked.
Common::String field8;
- SharedPtr<Bitmap> bitmap;
+ Bitmap *bitmap;
uint16 drawMode;
uint16 textColor;
bool bitmapChanged;
@@ -60,6 +61,7 @@ struct Sprite : Common::Serializable {
int16 drawX, drawY;
Sprite();
+ virtual ~Sprite();
void setBitmap(Bitmap *b);
void setBitmap(Common::MemoryReadStreamEndian *stream);
diff --git a/engines/startrek/textbox.cpp b/engines/startrek/textbox.cpp
index 3ececac636..474af78cb6 100644
--- a/engines/startrek/textbox.cpp
+++ b/engines/startrek/textbox.cpp
@@ -457,7 +457,8 @@ readjustScroll:
textboxSprite.dontDrawNextFrame();
_gfx->drawAllSprites();
//delete textBitmap;
- textboxSprite.bitmap.reset();
+ delete textboxSprite.bitmap;
+ textboxSprite.bitmap = nullptr;
_gfx->delSprite(&textboxSprite);
}
@@ -517,7 +518,7 @@ TextBitmap *StarTrekEngine::initTextSprite(int *xoffsetPtr, int *yoffsetPtr, byt
*sprite = Sprite();
sprite->drawPriority = 15;
sprite->drawPriority2 = 8;
- sprite->bitmap = SharedPtr<TextBitmap>(bitmap); // This is deallocated explicitly at the end of showText()
+ sprite->bitmap = bitmap; // This is deallocated explicitly at the end of showText()
sprite->textColor = textColor;
memset(bitmap->pixels, ' ', textHeight * TEXTBOX_WIDTH);
@@ -684,7 +685,7 @@ void StarTrekEngine::redrawTextInput() {
if (_textInputCursorChar != 0)
buf[_textInputCursorPos] = _textInputCursorChar;
- drawTextLineToBitmap(buf, MAX_TEXT_INPUT_LEN, 4, 12, _textInputSprite.bitmap.get());
+ drawTextLineToBitmap(buf, MAX_TEXT_INPUT_LEN, 4, 12, _textInputSprite.bitmap);
_textInputSprite.bitmapChanged = true;
_gfx->drawAllSprites();
}
@@ -849,7 +850,7 @@ void StarTrekEngine::initTextInputSprite(int16 textboxX, int16 textboxY, const C
const int16 height = row * 8 + 8;
- _textInputSprite.bitmap = SharedPtr<Bitmap>(new Bitmap(width, height));
+ _textInputSprite.bitmap = new Bitmap(width, height);
_textInputSprite.bitmap->xoffset = width / 2;
if (textboxX + width / 2 >= SCREEN_WIDTH)
@@ -876,7 +877,7 @@ void StarTrekEngine::initTextInputSprite(int16 textboxX, int16 textboxY, const C
// Draw header text
for (int r = 0; r < row; r++) {
char *text = textBuf + r * TEXTBOX_WIDTH;
- drawTextLineToBitmap(text, strlen(text), 4, r * 8 + 4, _textInputSprite.bitmap.get());
+ drawTextLineToBitmap(text, strlen(text), 4, r * 8 + 4, _textInputSprite.bitmap);
}
_textInputSprite.drawMode = 2;
@@ -892,7 +893,8 @@ void StarTrekEngine::cleanupTextInputSprite() {
_gfx->drawAllSprites();
_gfx->delSprite(&_textInputSprite);
- _textInputSprite.bitmap.reset();
+ delete _textInputSprite.bitmap;
+ _textInputSprite.bitmap = nullptr;
}
} // End of namespace StarTrek
Commit: 40bfdb8d7ae9a6af7fb5f4ec9d110bc2681f4dc6
https://github.com/scummvm/scummvm/commit/40bfdb8d7ae9a6af7fb5f4ec9d110bc2681f4dc6
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2020-09-09T22:36:10+03:00
Commit Message:
STARTREK: Plug memory leaks
Changed paths:
engines/startrek/startrek.cpp
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 6bbc3c1b0c..7acb1214a9 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -378,7 +378,7 @@ Common::MemoryReadStreamEndian *StarTrekEngine::loadFile(Common::String filename
byte *data = (byte *)malloc(size);
file->read(data, size);
delete file;
- return new Common::MemoryReadStreamEndian(data, size, bigEndian);
+ return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
}
Common::SeekableReadStream *indexFile = 0;
@@ -508,7 +508,7 @@ Common::MemoryReadStreamEndian *StarTrekEngine::loadFile(Common::String filename
stream->read(data, size);
delete stream;
- return new Common::MemoryReadStreamEndian(data, size, bigEndian);
+ return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
}
Common::MemoryReadStreamEndian *StarTrekEngine::loadBitmapFile(Common::String baseName) {
Commit: ed243779004c5afff7a994cde89bff05bf9ae8c9
https://github.com/scummvm/scummvm/commit/ed243779004c5afff7a994cde89bff05bf9ae8c9
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2020-09-09T22:36:11+03:00
Commit Message:
STARTREK: Move resource-related functions into a separate class
Changed paths:
A engines/startrek/resource.cpp
A engines/startrek/resource.h
engines/startrek/actors.cpp
engines/startrek/awaymission.cpp
engines/startrek/console.cpp
engines/startrek/font.cpp
engines/startrek/graphics.cpp
engines/startrek/intro.cpp
engines/startrek/iwfile.cpp
engines/startrek/menu.cpp
engines/startrek/module.mk
engines/startrek/room.cpp
engines/startrek/room.h
engines/startrek/rooms/demon4.cpp
engines/startrek/rooms/demon6.cpp
engines/startrek/saveload.cpp
engines/startrek/sound.cpp
engines/startrek/space.cpp
engines/startrek/startrek.cpp
engines/startrek/startrek.h
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp
index 8f9eb68d4f..42a32df73e 100644
--- a/engines/startrek/actors.cpp
+++ b/engines/startrek/actors.cpp
@@ -24,6 +24,7 @@
#include "common/memstream.h"
#include "startrek/iwfile.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -71,7 +72,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] = _resource->loadFile(name + ".ban");
_banFileOffsets[i] = 0;
return;
}
@@ -448,7 +449,7 @@ void StarTrekEngine::drawActorToScreen(Actor *actor, const Common::String &_anim
actor->animFilename = _animName;
actor->animType = 2;
- actor->animFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(animFilename + ".anm"));
+ actor->animFile = SharedPtr<Common::MemoryReadStreamEndian>(_resource->loadFile(animFilename + ".anm"));
actor->numAnimFrames = actor->animFile->size() / 22;
actor->animFrame = 0;
actor->pos.x = x;
@@ -719,7 +720,7 @@ Bitmap *StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed
&& (c == 'm' || c == 's' || c == 'k' || c == 'r')) {
if (c == 'm') {
// Mccoy has the "base" animations for all crewmen
- bitmapToReturn = new Bitmap(loadBitmapFile(filename));
+ bitmapToReturn = new Bitmap(_resource->loadBitmapFile(filename));
} else {
// All crewman other than mccoy copy the animation frames from mccoy, change
// the colors of the uniforms, and load an "xor" file to redraw the face.
@@ -731,7 +732,7 @@ Bitmap *StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed
if (bitmapToReturn == nullptr) {
Common::String mccoyFilename = filename;
mccoyFilename.setChar('m', 0);
- Bitmap *bitmap = new Bitmap(loadBitmapFile(mccoyFilename));
+ Bitmap *bitmap = new Bitmap(_resource->loadBitmapFile(mccoyFilename));
uint16 width = bitmap->width;
uint16 height = bitmap->height;
@@ -777,7 +778,7 @@ Bitmap *StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed
}
// Redraw face with xor file
- Common::MemoryReadStreamEndian *xorFile = loadFile(filename + ".xor");
+ Common::MemoryReadStreamEndian *xorFile = _resource->loadFile(filename + ".xor");
xorFile->seek(0, SEEK_SET);
uint16 xoffset = bitmap->xoffset - xorFile->readUint16();
uint16 yoffset = bitmap->yoffset - xorFile->readUint16();
@@ -799,7 +800,7 @@ Bitmap *StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed
} else {
// TODO: when loading a bitmap, it passes a different argument than is standard to
// the "file loading with cache" function...
- bitmapToReturn = new Bitmap(loadBitmapFile(filename));
+ bitmapToReturn = new Bitmap(_resource->loadBitmapFile(filename));
}
if (scale != 1.0) {
@@ -1038,7 +1039,7 @@ void StarTrekEngine::showInventoryIcons(bool showItem) {
_itemIconSprite.pos.y = 10;
_itemIconSprite.drawPriority = 15;
_itemIconSprite.drawPriority2 = 8;
- _itemIconSprite.setBitmap(loadBitmapFile(itemFilename));
+ _itemIconSprite.setBitmap(_resource->loadBitmapFile(itemFilename));
_inventoryIconSprite.pos.x = 46;
}
@@ -1049,7 +1050,7 @@ void StarTrekEngine::showInventoryIcons(bool showItem) {
_inventoryIconSprite.drawMode = 2;
_inventoryIconSprite.drawPriority = 15;
_inventoryIconSprite.drawPriority2 = 8;
- _inventoryIconSprite.setBitmap(loadBitmapFile("inv00"));
+ _inventoryIconSprite.setBitmap(_resource->loadBitmapFile("inv00"));
}
bool StarTrekEngine::isObjectUnusable(int object, int action) {
@@ -1168,7 +1169,7 @@ int StarTrekEngine::showInventoryMenu(int x, int y, bool restoreMouse) {
itemSprites[i].pos.y = itemPositions[i].y;
itemSprites[i].drawPriority = 15;
itemSprites[i].drawPriority2 = 8;
- itemSprites[i].setBitmap(loadBitmapFile(itemNames[i]));
+ itemSprites[i].setBitmap(_resource->loadBitmapFile(itemNames[i]));
}
chooseMousePositionFromSprites(itemSprites, numItems, -1, 4);
diff --git a/engines/startrek/awaymission.cpp b/engines/startrek/awaymission.cpp
index 3d3a273754..16af10c152 100644
--- a/engines/startrek/awaymission.cpp
+++ b/engines/startrek/awaymission.cpp
@@ -21,6 +21,7 @@
*/
#include "startrek/iwfile.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -31,8 +32,7 @@ void StarTrekEngine::initAwayMission() {
// memset(bitmapBuffer->pixels, 0, 0xfa00);
- _txtFilename = "ground";
- _loadedText = "";
+ _resource->setTxtFileName("ground");
// sub_23a60(); // TODO
_sound->loadMusicFile("ground");
@@ -545,7 +545,7 @@ void StarTrekEngine::handleAwayMissionAction() {
// BUGFIX: Don't allow the "use" action to bypass the "disableWalking" variable
if (!(!_awayMission.disableWalking && _room->handleAction(ACTION_WALK, action.passiveObject(), 0, 0))
&& !_room->handleAction(ACTION_GET, action.passiveObject(), 0, 0)) {
- showTextbox("Capt. Kirk", getLoadedText(GROUNDTX_KIRK_USE), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("Capt. Kirk", _resource->getLoadedText(GROUNDTX_KIRK_USE), 20, 20, TEXTCOLOR_YELLOW, 0);
}
break;
@@ -554,7 +554,7 @@ void StarTrekEngine::handleAwayMissionAction() {
// BUGFIX: Original game has just "Spock" instead of "Mr. Spock" as the
// speaker. That's inconsistent.
// Same applies to other parts of this function.
- showTextbox("Mr. Spock", getLoadedText(GROUNDTX_SPOCK_USE), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Mr. Spock", _resource->getLoadedText(GROUNDTX_SPOCK_USE), 20, 20, TEXTCOLOR_BLUE, 0);
}
break;
@@ -562,24 +562,24 @@ void StarTrekEngine::handleAwayMissionAction() {
if (!_room->handleAction(ACTION_USE, OBJECT_IMEDKIT, action.passiveObject(), 0)
&& !_room->handleAction(ACTION_USE, OBJECT_IMTRICOR, action.passiveObject(), 0)) {
// BUGFIX: Original game has just "McCoy" instead of "Dr. McCoy".
- showTextbox("Dr. McCoy", getLoadedText(GROUNDTX_MCCOY_USE), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Dr. McCoy", _resource->getLoadedText(GROUNDTX_MCCOY_USE), 20, 20, TEXTCOLOR_BLUE, 0);
}
break;
case OBJECT_REDSHIRT:
- showTextbox(NULL, getLoadedText(GROUNDTX_REDSHIRT_USE), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox(NULL, _resource->getLoadedText(GROUNDTX_REDSHIRT_USE), 20, 20, TEXTCOLOR_YELLOW, 0);
break;
case OBJECT_IPHASERS:
case OBJECT_IPHASERK:
if (action.passiveObject() == OBJECT_SPOCK) {
int text = GROUNDTX_PHASER_ON_SPOCK + getRandomWord() % 8;
- showTextbox("Mr. Spock", getLoadedText(text), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Mr. Spock", _resource->getLoadedText(text), 20, 20, TEXTCOLOR_BLUE, 0);
} else if (action.passiveObject() == OBJECT_MCCOY) {
int text = GROUNDTX_PHASER_ON_MCCOY + getRandomWord() % 8;
- showTextbox("Dr. McCoy", getLoadedText(text), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Dr. McCoy", _resource->getLoadedText(text), 20, 20, TEXTCOLOR_BLUE, 0);
} else if (action.passiveObject() == OBJECT_REDSHIRT) {
- Common::String text = getLoadedText(GROUNDTX_PHASER_ON_REDSHIRT + getRandomWord() % 8);
+ Common::String text = _resource->getLoadedText(GROUNDTX_PHASER_ON_REDSHIRT + getRandomWord() % 8);
// Replace audio filename with start of mission name (to load the
// audio for the crewman specific to the mission))
text.setChar(_missionName[0], 6);
@@ -591,60 +591,60 @@ void StarTrekEngine::handleAwayMissionAction() {
} else if (!_room->handleActionWithBitmask(action)) {
int index = getRandomWord() % 7;
if (index & 1)
- showTextbox("Dr. McCoy", getLoadedText(GROUNDTX_PHASER_ANYWHERE + index), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Dr. McCoy", _resource->getLoadedText(GROUNDTX_PHASER_ANYWHERE + index), 20, 20, TEXTCOLOR_BLUE, 0);
else
- showTextbox("Mr. Spock", getLoadedText(GROUNDTX_PHASER_ANYWHERE + index), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Mr. Spock", _resource->getLoadedText(GROUNDTX_PHASER_ANYWHERE + index), 20, 20, TEXTCOLOR_BLUE, 0);
}
break;
case OBJECT_ISTRICOR:
- showTextbox("Mr. Spock", getLoadedText(GROUNDTX_SPOCK_SCAN), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Mr. Spock", _resource->getLoadedText(GROUNDTX_SPOCK_SCAN), 20, 20, TEXTCOLOR_BLUE, 0);
break;
case OBJECT_IMTRICOR:
- showTextbox("Dr. McCoy", getLoadedText(GROUNDTX_MCCOY_SCAN), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Dr. McCoy", _resource->getLoadedText(GROUNDTX_MCCOY_SCAN), 20, 20, TEXTCOLOR_BLUE, 0);
break;
case OBJECT_ICOMM:
if (!_room->handleAction(ACTION_USE, OBJECT_ICOMM, 0xff, 0))
- showTextbox("Lt. Uhura", getLoadedText(GROUNDTX_USE_COMMUNICATOR), 20, 20, TEXTCOLOR_RED, 0);
+ showTextbox("Lt. Uhura", _resource->getLoadedText(GROUNDTX_USE_COMMUNICATOR), 20, 20, TEXTCOLOR_RED, 0);
break;
case OBJECT_IMEDKIT:
- showTextbox("Dr. McCoy", getLoadedText(GROUNDTX_USE_MEDKIT), 20, 20, TEXTCOLOR_BLUE, 0);
+ showTextbox("Dr. McCoy", _resource->getLoadedText(GROUNDTX_USE_MEDKIT), 20, 20, TEXTCOLOR_BLUE, 0);
break;
default:
if (!_room->handleActionWithBitmask(action.type, action.b1, action.b2, action.b3))
- showTextbox("", getLoadedText(GROUNDTX_NOTHING_HAPPENS), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_NOTHING_HAPPENS), 20, 20, TEXTCOLOR_YELLOW, 0);
}
}
break;
case ACTION_GET:
if (!_room->handleActionWithBitmask(action.type, action.b1, action.b2, action.b3))
- showTextbox("", getLoadedText(GROUNDTX_FAIL_TO_OBTAIN_ANYTHING), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_FAIL_TO_OBTAIN_ANYTHING), 20, 20, TEXTCOLOR_YELLOW, 0);
break;
case ACTION_LOOK:
if (action.activeObject() >= ITEMS_START && action.activeObject() < ITEMS_END) {
int i = action.activeObject() - ITEMS_START;
- Common::String text = getLoadedText(_itemList[i].textIndex);
+ Common::String text = _resource->getLoadedText(_itemList[i].textIndex);
showTextbox("", text, 20, 20, TEXTCOLOR_YELLOW, 0);
} else if (action.activeObject() == OBJECT_KIRK)
- showTextbox("", getLoadedText(GROUNDTX_LOOK_KIRK), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_LOOK_KIRK), 20, 20, TEXTCOLOR_YELLOW, 0);
else if (action.activeObject() == OBJECT_SPOCK)
- showTextbox("", getLoadedText(GROUNDTX_LOOK_SPOCK), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_LOOK_SPOCK), 20, 20, TEXTCOLOR_YELLOW, 0);
else if (action.activeObject() == OBJECT_MCCOY)
- showTextbox("", getLoadedText(GROUNDTX_LOOK_MCCOY), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_LOOK_MCCOY), 20, 20, TEXTCOLOR_YELLOW, 0);
else if (action.activeObject() == OBJECT_REDSHIRT)
- showTextbox("", getLoadedText(GROUNDTX_LOOK_REDSHIRT), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_LOOK_REDSHIRT), 20, 20, TEXTCOLOR_YELLOW, 0);
else
// Show generic "nothing of note" text.
// BUGFIX: originally this was shown after the redshirt's text as well.
// Though, the original game may not have used this default implementation
// anywhere...
- showTextbox("", getLoadedText(GROUNDTX_LOOK_ANYWHERE), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_LOOK_ANYWHERE), 20, 20, TEXTCOLOR_YELLOW, 0);
break;
case ACTION_TALK:
@@ -653,11 +653,11 @@ void StarTrekEngine::handleAwayMissionAction() {
case OBJECT_SPOCK:
case OBJECT_MCCOY:
case OBJECT_REDSHIRT:
- showTextbox("", getLoadedText(GROUNDTX_TALK_TO_CREWMAN), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_TALK_TO_CREWMAN), 20, 20, TEXTCOLOR_YELLOW, 0);
break;
default:
- showTextbox("", getLoadedText(GROUNDTX_NO_RESPONSE), 20, 20, TEXTCOLOR_YELLOW, 0);
+ showTextbox("", _resource->getLoadedText(GROUNDTX_NO_RESPONSE), 20, 20, TEXTCOLOR_YELLOW, 0);
break;
}
break;
diff --git a/engines/startrek/console.cpp b/engines/startrek/console.cpp
index d3f012d4d1..87d26f5d85 100644
--- a/engines/startrek/console.cpp
+++ b/engines/startrek/console.cpp
@@ -22,6 +22,7 @@
#include "startrek/console.h"
#include "gui/debugger.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -63,7 +64,7 @@ bool Console::Cmd_Actions(int argc, const char **argv) {
screenName = missionName + (char)(roomIndex + '0');
}
- Common::MemoryReadStreamEndian *rdfFile = _vm->loadFile(screenName + ".RDF");
+ Common::MemoryReadStreamEndian *rdfFile = _vm->_resource->loadFile(screenName + ".RDF");
rdfFile->seek(14);
uint16 startOffset = rdfFile->readUint16LE();
diff --git a/engines/startrek/font.cpp b/engines/startrek/font.cpp
index b0875570f7..2a6a80569f 100644
--- a/engines/startrek/font.cpp
+++ b/engines/startrek/font.cpp
@@ -20,10 +20,11 @@
*
*/
-#include "common/stream.h"
#include "common/memstream.h"
+#include "common/stream.h"
#include "startrek/font.h"
+#include "startrek/resource.h"
namespace StarTrek {
@@ -31,7 +32,7 @@ static const byte CHARACTER_COUNT = 0x80;
static const byte CHARACTER_SIZE = 0x40;
Font::Font(StarTrekEngine *vm) : _vm(vm) {
- Common::MemoryReadStreamEndian *fontStream = _vm->loadFile("FONT.FNT");
+ Common::MemoryReadStreamEndian *fontStream = _vm->_resource->loadFile("FONT.FNT");
_characters = new Character[CHARACTER_COUNT];
@@ -54,7 +55,6 @@ bool Font::isDisplayableCharacter(char c) {
return _fontProperties[c & 0xff] & 0x57;
}
-
// Bit 0 set for lowercase characters;
// Bit 1 set for uppercase characters;
// Bit 2 set for digits;
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp
index 8a70908cac..ce26a29660 100644
--- a/engines/startrek/graphics.cpp
+++ b/engines/startrek/graphics.cpp
@@ -22,6 +22,7 @@
#include "startrek/common.h"
#include "startrek/console.h"
#include "startrek/graphics.h"
+#include "startrek/resource.h"
#include "common/algorithm.h"
#include "common/config-manager.h"
@@ -76,7 +77,7 @@ Graphics::~Graphics() {
void Graphics::setBackgroundImage(Common::String imageName) {
delete _backgroundImage;
- _backgroundImage = new Bitmap(_vm->loadBitmapFile(imageName));
+ _backgroundImage = new Bitmap(_vm->_resource->loadBitmapFile(imageName));
}
void Graphics::drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, Bitmap *bitmap) {
@@ -135,12 +136,12 @@ void Graphics::loadPalette(const Common::String &paletteName) {
Common::String palFile = paletteName + ".PAL";
Common::String lutFile = paletteName + ".LUT";
- Common::MemoryReadStreamEndian *palStream = _vm->loadFile(palFile.c_str());
+ Common::MemoryReadStreamEndian *palStream = _vm->_resource->loadFile(palFile.c_str());
palStream->read(_palData, 256 * 3);
delete palStream;
// Load LUT file
- Common::MemoryReadStreamEndian *lutStream = _vm->loadFile(lutFile.c_str());
+ Common::MemoryReadStreamEndian *lutStream = _vm->_resource->loadFile(lutFile.c_str());
lutStream->read(_lutData, 256);
delete lutStream;
}
@@ -217,7 +218,7 @@ void Graphics::decPaletteFadeLevel() {
void Graphics::loadPri(const Common::String &priFile) {
- Common::MemoryReadStream *priStream = _vm->loadFile(priFile + ".pri");
+ Common::MemoryReadStream *priStream = _vm->_resource->loadFile(priFile + ".pri");
priStream->read(_priData, SCREEN_WIDTH * SCREEN_HEIGHT / 2);
delete priStream;
}
@@ -246,7 +247,7 @@ Common::Point Graphics::getMousePos() {
}
void Graphics::setMouseBitmap(Common::String bitmapName) {
- Bitmap *bitmap = new Bitmap(_vm->loadBitmapFile(bitmapName));
+ Bitmap *bitmap = new Bitmap(_vm->_resource->loadBitmapFile(bitmapName));
CursorMan.pushCursor(
bitmap->pixels,
@@ -693,7 +694,7 @@ void Graphics::loadEGAData(const char *filename) {
if (!_egaData)
_egaData = new byte[256];
- Common::MemoryReadStreamEndian *egaStream = _vm->loadFile(filename);
+ Common::MemoryReadStreamEndian *egaStream = _vm->_resource->loadFile(filename);
egaStream->read(_egaData, 256);
delete egaStream;
}
@@ -701,7 +702,7 @@ void Graphics::loadEGAData(const char *filename) {
void Graphics::drawBackgroundImage(const char *filename) {
// Draw an stjr BGD image (palette built-in)
- Common::MemoryReadStreamEndian *imageStream = _vm->loadFile(filename);
+ Common::MemoryReadStreamEndian *imageStream = _vm->_resource->loadFile(filename);
byte *palette = new byte[256 * 3];
imageStream->read(palette, 256 * 3);
diff --git a/engines/startrek/intro.cpp b/engines/startrek/intro.cpp
index 14c2d556f8..64e462e574 100644
--- a/engines/startrek/intro.cpp
+++ b/engines/startrek/intro.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "startrek/resource.h"
#include "startrek/startrek.h"
namespace StarTrek {
@@ -56,7 +57,7 @@ void StarTrekEngine::playIntro() {
Sprite subtitleSprite;
_gfx->addSprite(&subtitleSprite);
subtitleSprite.setXYAndPriority(0, 0, 12);
- subtitleSprite.setBitmap(loadBitmapFile("blank"));
+ subtitleSprite.setBitmap(_resource->loadBitmapFile("blank"));
subtitleSprite.drawPriority2 = 16;
int index = 12;
@@ -151,7 +152,7 @@ void StarTrekEngine::playIntro() {
loadSubtitleSprite(2, &subtitleSprite);
planetR3.field22 = 2000;
planetR3.field24 = 10000 / _starfieldPointDivisor;
- planetR3.bitmap = new Bitmap(loadFile("planet.shp"));
+ planetR3.bitmap = new Bitmap(_resource->loadFile("planet.shp"));
initIntroR3ObjectToMove(&planetR3, 6, 10000, 6, 10000, 0);
addR3(&planetR3);
initIntroR3ObjectToMove(&_enterpriseR3, -15, 250, 15, 500, 18);
@@ -313,7 +314,7 @@ void StarTrekEngine::showCreditsScreen(R3 *creditsBuffer, int index, bool delete
if (deletePrevious) {
delR3(creditsBuffer);
}
- creditsBuffer->bitmap = new Bitmap(loadFile(Common::String::format("credit%02d.shp", index)));
+ creditsBuffer->bitmap = new Bitmap(_resource->loadFile(Common::String::format("credit%02d.shp", index)));
creditsBuffer->field1e = 3;
creditsBuffer->field22 = 1;
creditsBuffer->field24 = 1;
@@ -351,10 +352,10 @@ void StarTrekEngine::initIntroR3ObjectToMove(R3 *r3, int16 srcAngle, int16 srcDe
void StarTrekEngine::loadSubtitleSprite(int index, Sprite *sprite) {
if (_showSubtitles) {
if (index == -1)
- sprite->setBitmap(loadBitmapFile("blank"));
+ sprite->setBitmap(_resource->loadBitmapFile("blank"));
else {
Common::String file = Common::String::format("tittxt%02d", index);
- sprite->setBitmap(loadBitmapFile(file));
+ sprite->setBitmap(_resource->loadBitmapFile(file));
}
}
}
diff --git a/engines/startrek/iwfile.cpp b/engines/startrek/iwfile.cpp
index 8a45248bca..9a9798dba0 100644
--- a/engines/startrek/iwfile.cpp
+++ b/engines/startrek/iwfile.cpp
@@ -21,6 +21,7 @@
*/
#include "startrek/iwfile.h"
+#include "startrek/resource.h"
namespace StarTrek {
@@ -29,7 +30,7 @@ IWFile::IWFile(StarTrekEngine *vm, const Common::String &filename) {
_vm = vm;
- Common::MemoryReadStreamEndian *file = _vm->loadFile(filename);
+ Common::MemoryReadStreamEndian *file = _vm->_resource->loadFile(filename);
_numEntries = file->readUint16();
assert(_numEntries < MAX_KEY_POSITIONS);
diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp
index 0abef6a3a6..95fd921476 100644
--- a/engines/startrek/menu.cpp
+++ b/engines/startrek/menu.cpp
@@ -25,6 +25,7 @@
#include "graphics/cursorman.h"
#include "startrek/graphics.h"
+#include "startrek/resource.h"
namespace StarTrek {
@@ -307,7 +308,7 @@ int StarTrekEngine::showActionMenu() {
bool addEventBack = false;
int action = ACTION_WALK;
- menuSprite.setBitmap(loadBitmapFile("action"));
+ menuSprite.setBitmap(_resource->loadBitmapFile("action"));
int menuWidth = menuSprite.bitmap->width;
int menuHeight = menuSprite.bitmap->height;
@@ -505,7 +506,7 @@ void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_activeMenu = new Menu();
_activeMenu->nextMenu = oldMenu;
- Common::MemoryReadStreamEndian *stream = loadFile(mnuFilename + ".MNU");
+ Common::MemoryReadStreamEndian *stream = _resource->loadFile(mnuFilename + ".MNU");
_activeMenu->numButtons = stream->size() / 16;
@@ -523,7 +524,7 @@ void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
}
bitmapBasename[10] = '\0';
- _activeMenu->sprites[i].setBitmap(loadBitmapFile(bitmapBasename));
+ _activeMenu->sprites[i].setBitmap(_resource->loadBitmapFile(bitmapBasename));
_activeMenu->sprites[i].pos.x = stream->readUint16() + xpos;
_activeMenu->sprites[i].pos.y = stream->readUint16() + ypos;
_activeMenu->retvals[i] = stream->readUint16();
@@ -1135,7 +1136,7 @@ lclick:
if (!spriteLoaded) {
_gfx->addSprite(&someSprite);
someSprite.setXYAndPriority(3, 168, 15);
- someSprite.setBitmap(loadBitmapFile(Common::String::format("turbo%d", clickedArea)));
+ someSprite.setBitmap(_resource->loadBitmapFile(Common::String::format("turbo%d", clickedArea)));
spriteLoaded = true;
}
} else {
diff --git a/engines/startrek/module.mk b/engines/startrek/module.mk
index a86d7efd0a..1de7872aa9 100644
--- a/engines/startrek/module.mk
+++ b/engines/startrek/module.mk
@@ -14,6 +14,7 @@ MODULE_OBJS = \
iwfile.o \
lzss.o \
menu.o \
+ resource.o \
room.o \
saveload.o \
sound.o \
diff --git a/engines/startrek/resource.cpp b/engines/startrek/resource.cpp
new file mode 100644
index 0000000000..782afc1acb
--- /dev/null
+++ b/engines/startrek/resource.cpp
@@ -0,0 +1,261 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+
+#include "common/file.h"
+#include "common/macresman.h"
+
+#include "engines/util.h"
+#include "video/qt_decoder.h"
+
+#include "startrek/iwfile.h"
+#include "startrek/lzss.h"
+#include "startrek/resource.h"
+
+namespace StarTrek {
+
+Resource::Resource(Common::Platform platform, bool isDemo) : _platform(platform), _isDemo(isDemo), _macResFork(nullptr) {
+ if (_platform == Common::kPlatformMacintosh) {
+ _macResFork = new Common::MacResManager();
+ if (!_macResFork->open("Star Trek Data"))
+ error("Could not load Star Trek Data");
+ assert(_macResFork->hasDataFork() && _macResFork->hasResFork());
+ }
+}
+
+Resource::~Resource() {
+ delete _macResFork;
+}
+
+/**
+ * TODO:
+ * - Should return nullptr on failure to open a file?
+ * - This is supposed to cache results, return same FileStream on multiple accesses.
+ * - This is supposed to read from a "patches" folder which overrides files in the
+ * packed blob.
+ */
+Common::MemoryReadStreamEndian *Resource::loadFile(Common::String filename, int fileIndex) {
+ filename.toUppercase();
+
+ Common::String basename, extension;
+
+ bool bigEndian = _platform == Common::kPlatformAmiga;
+
+ for (int i = filename.size() - 1; ; i--) {
+ if (filename[i] == '.') {
+ basename = filename;
+ extension = filename;
+ basename.replace(i, filename.size() - i, "");
+ extension.replace(0, i + 1, "");
+ break;
+ }
+ }
+
+ // FIXME: don't know if this is right, or if it goes here
+ while (!basename.empty() && basename.lastChar() == ' ') {
+ basename.erase(basename.size() - 1, 1);
+ }
+
+ filename = basename + '.' + extension;
+
+ // TODO: Re-enable this when more work has been done on the demo
+ /*
+ // The Judgment Rites demo has its files not in the standard archive
+ if (getGameType() == GType_STJR && _isDemo) {
+ Common::File *file = new Common::File();
+ if (!file->open(filename.c_str())) {
+ delete file;
+ error("Could not find file \'%s\'", filename.c_str());
+ }
+ int32 size = file->size();
+ byte *data = (byte *)malloc(size);
+ file->read(data, size);
+ delete file;
+ return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
+ }
+ */
+
+ Common::SeekableReadStream *indexFile = 0;
+
+ if (_platform == Common::kPlatformAmiga) {
+ indexFile = SearchMan.createReadStreamForMember("data000.dir");
+ if (!indexFile)
+ error("Could not open data000.dir");
+ } else if (_platform == Common::kPlatformMacintosh) {
+ indexFile = _macResFork->getResource("Directory");
+ if (!indexFile)
+ error("Could not find 'Directory' resource in 'Star Trek Data'");
+ } else {
+ indexFile = SearchMan.createReadStreamForMember("data.dir");
+ if (!indexFile)
+ error("Could not open data.dir");
+ }
+
+ uint32 indexOffset = 0;
+ bool foundData = false;
+ uint16 fileCount = 1;
+ uint16 uncompressedSize = 0;
+
+ while (!indexFile->eos() && !indexFile->err()) {
+ Common::String testfile;
+ for (byte i = 0; i < 8; i++) {
+ char c = indexFile->readByte();
+ if (c)
+ testfile += c;
+ }
+ testfile += '.';
+
+ for (byte i = 0; i < 3; i++)
+ testfile += indexFile->readByte();
+
+ if (_isDemo && _platform == Common::kPlatformDOS) {
+ indexFile->readByte(); // Always 0?
+ fileCount = indexFile->readUint16LE(); // Always 1
+ indexOffset = indexFile->readUint32LE();
+ uncompressedSize = indexFile->readUint16LE();
+ } else {
+ if (_platform == Common::kPlatformAmiga)
+ indexOffset = (indexFile->readByte() << 16) + (indexFile->readByte() << 8) + indexFile->readByte();
+ else
+ indexOffset = indexFile->readByte() + (indexFile->readByte() << 8) + (indexFile->readByte() << 16);
+
+ if (indexOffset & (1 << 23)) {
+ fileCount = (indexOffset >> 16) & 0x7F;
+ indexOffset = indexOffset & 0xFFFF;
+ assert(fileCount > 1);
+ } else {
+ fileCount = 1;
+ }
+ }
+
+ if (filename.matchString(testfile)) {
+ foundData = true;
+ break;
+ }
+ }
+
+ delete indexFile;
+
+ if (!foundData) {
+ // Files can be accessed "sequentially" if their filenames are the same except for
+ // the last character being incremented by one.
+ if ((basename.lastChar() >= '1' && basename.lastChar() <= '9') ||
+ (basename.lastChar() >= 'B' && basename.lastChar() <= 'Z')) {
+ basename.setChar(basename.lastChar() - 1, basename.size() - 1);
+ return loadFile(basename + "." + extension, fileIndex + 1);
+ } else
+ error("Could not find file \'%s\'", filename.c_str());
+ }
+
+ if (fileIndex >= fileCount)
+ error("Tried to access file index %d for file '%s' which doesn't exist.", fileIndex, filename.c_str());
+
+ Common::SeekableReadStream *dataFile = 0;
+ Common::SeekableReadStream *dataRunFile = 0; // FIXME: Amiga & Mac need this implemented
+
+ if (_platform == Common::kPlatformAmiga) {
+ dataFile = SearchMan.createReadStreamForMember("data.000");
+ if (!dataFile)
+ error("Could not open data.000");
+ } else if (_platform == Common::kPlatformMacintosh) {
+ dataFile = _macResFork->getDataFork();
+ if (!dataFile)
+ error("Could not get 'Star Trek Data' data fork");
+ } else {
+ dataFile = SearchMan.createReadStreamForMember("data.001");
+ if (!dataFile)
+ error("Could not open data.001");
+ dataRunFile = SearchMan.createReadStreamForMember("data.run");
+ if (!dataFile)
+ error("Could not open data.run");
+ }
+
+ Common::SeekableReadStream *stream;
+ if (_isDemo && _platform == Common::kPlatformDOS) {
+ assert(fileCount == 1); // Sanity check...
+ stream = dataFile->readStream(uncompressedSize);
+ } else {
+ if (fileCount != 1) {
+ dataRunFile->seek(indexOffset);
+
+ indexOffset = dataRunFile->readByte() + (dataRunFile->readByte() << 8) + (dataRunFile->readByte() << 16);
+ //indexOffset &= 0xFFFFFE;
+
+ for (uint16 i = 0; i < fileIndex; i++) {
+ uint16 size = dataRunFile->readUint16LE();
+ indexOffset += size;
+ }
+ }
+ dataFile->seek(indexOffset);
+
+ uncompressedSize = (_platform == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE();
+ uint16 compressedSize = (_platform == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE();
+
+ stream = decodeLZSS(dataFile->readStream(compressedSize), uncompressedSize);
+ }
+
+ delete dataFile;
+ delete dataRunFile;
+
+ int32 size = stream->size();
+ byte *data = (byte *)malloc(size);
+ stream->read(data, size);
+ delete stream;
+
+ return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
+}
+
+Common::MemoryReadStreamEndian *Resource::loadBitmapFile(Common::String baseName) {
+ return loadFile(baseName + ".BMP");
+}
+
+Common::MemoryReadStreamEndian *Resource::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) {
+ return loadFile(filename);
+}
+
+Common::String Resource::getLoadedText(int textIndex) {
+ Common::MemoryReadStreamEndian *txtFile = loadFile(_txtFilename + ".txt");
+
+ Common::String str;
+ byte cur;
+ int curIndex = 0;
+
+ while (!txtFile->eos()) {
+ do {
+ cur = txtFile->readByte();
+ str += cur;
+ } while (cur != '\0');
+
+ if (curIndex == textIndex) {
+ delete txtFile;
+ return str;
+ }
+
+ curIndex++;
+ str = "";
+ }
+
+ delete txtFile;
+ return "";
+}
+
+} // End of namespace StarTrek
diff --git a/engines/startrek/resource.h b/engines/startrek/resource.h
new file mode 100644
index 0000000000..751630cc3d
--- /dev/null
+++ b/engines/startrek/resource.h
@@ -0,0 +1,72 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef RESOURCE_H
+#define RESOURCE_H
+
+#include "common/memstream.h"
+#include "common/platform.h"
+#include "common/str.h"
+#include "common/stream.h"
+
+#include "startrek/iwfile.h"
+
+namespace Common {
+class MacResManager;
+}
+
+namespace StarTrek {
+
+class Resource {
+public:
+ Resource(Common::Platform platform, bool isDemo);
+ virtual ~Resource();
+
+ Common::MemoryReadStreamEndian *loadFile(Common::String filename, int fileIndex = 0);
+ Common::MemoryReadStreamEndian *loadBitmapFile(Common::String baseName);
+
+ /**
+ * TODO: Figure out what the extra parameters are, and if they're important.
+ */
+ Common::MemoryReadStreamEndian *loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3);
+
+ /**
+ * ".txt" files are just lists of strings. This traverses the file to get a particular
+ * string index.
+ */
+ Common::String getLoadedText(int textIndex);
+
+ void setTxtFileName(Common::String txtFileName) {
+ _txtFilename = txtFileName;
+ }
+
+private:
+ IWFile *_iwFile;
+ Common::MacResManager *_macResFork;
+ Common::Platform _platform;
+ bool _isDemo;
+ Common::String _txtFilename;
+};
+
+} // End of namespace StarTrek
+
+#endif
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp
index 48c75e78b7..6f64ae4e07 100644
--- a/engines/startrek/room.cpp
+++ b/engines/startrek/room.cpp
@@ -21,6 +21,7 @@
*/
#include "startrek/iwfile.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -45,7 +46,7 @@
namespace StarTrek {
Room::Room(StarTrekEngine *vm, const Common::String &name) : _vm(vm), _awayMission(&vm->_awayMission) {
- Common::MemoryReadStreamEndian *rdfFile = _vm->loadFile(name + ".RDF");
+ Common::MemoryReadStreamEndian *rdfFile = _vm->_resource->loadFile(name + ".RDF");
int size = rdfFile->size();
_rdfData = new byte[size];
@@ -588,12 +589,20 @@ void Room::walkCrewmanC(int actorIndex, int16 destX, int16 destY, void (Room::*f
void Room::loadMapFile(const Common::String &name) {
delete _vm->_mapFile;
- _vm->_mapFile = _vm->loadFile(name + ".map");
+ _vm->_mapFile = _vm->_resource->loadFile(name + ".map");
delete _vm->_iwFile;
_vm->_iwFile = new IWFile(_vm, name + ".iw");
}
+Common::MemoryReadStreamEndian *Room::loadBitmapFile(Common::String baseName) {
+ return _vm->_resource->loadFile(baseName);
+}
+
+Common::MemoryReadStreamEndian *Room::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) {
+ return _vm->_resource->loadFileWithParams(filename, unk1, unk2, unk3);
+}
+
void Room::showBitmapFor5Ticks(const Common::String &bmpName, int priority) {
if (priority < 0 || priority > 15)
priority = 5;
@@ -601,7 +610,7 @@ void Room::showBitmapFor5Ticks(const Common::String &bmpName, int priority) {
Sprite sprite;
_vm->_gfx->addSprite(&sprite);
sprite.setXYAndPriority(0, 0, priority);
- sprite.setBitmap(_vm->loadBitmapFile(bmpName));
+ sprite.setBitmap(_vm->_resource->loadBitmapFile(bmpName));
_vm->_gfx->drawAllSprites();
diff --git a/engines/startrek/room.h b/engines/startrek/room.h
index b3ae3e00d1..929638785d 100644
--- a/engines/startrek/room.h
+++ b/engines/startrek/room.h
@@ -180,6 +180,9 @@ private:
void loadRoomMessage(const char *text);
Common::String patchRoomMessage(const char *text);
+ Common::MemoryReadStreamEndian *loadBitmapFile(Common::String baseName);
+ Common::MemoryReadStreamEndian *loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3);
+
int findFunctionPointer(int action, void (Room::*funcPtr)());
diff --git a/engines/startrek/rooms/demon4.cpp b/engines/startrek/rooms/demon4.cpp
index 16fd78bef7..fa976229dd 100644
--- a/engines/startrek/rooms/demon4.cpp
+++ b/engines/startrek/rooms/demon4.cpp
@@ -393,13 +393,13 @@ bool Room::demon4ShowSunPuzzle() {
_vm->_gfx->addSprite(&sprites[i]);
}
- sprites[0].setBitmap(_vm->loadBitmapFile("levery"));
- sprites[1].setBitmap(_vm->loadBitmapFile("leverr"));
- sprites[2].setBitmap(_vm->loadBitmapFile("leverb"));
+ sprites[0].setBitmap(loadBitmapFile("levery"));
+ sprites[1].setBitmap(loadBitmapFile("leverr"));
+ sprites[2].setBitmap(loadBitmapFile("leverb"));
- Bitmap *lightyBitmap = new Bitmap(_vm->loadBitmapFile("lighty"));
- Bitmap *lightrBitmap = new Bitmap(_vm->loadBitmapFile("lightr"));
- Bitmap *lightbBitmap = new Bitmap(_vm->loadBitmapFile("lightb"));
+ Bitmap *lightyBitmap = new Bitmap(loadBitmapFile("lighty"));
+ Bitmap *lightrBitmap = new Bitmap(loadBitmapFile("lightr"));
+ Bitmap *lightbBitmap = new Bitmap(loadBitmapFile("lightb"));
for (int i = 3; i < 9; i++)
sprites[i].setBitmap(lightyBitmap);
@@ -411,7 +411,7 @@ bool Room::demon4ShowSunPuzzle() {
Sprite doneButtonSprite;
_vm->_gfx->addSprite(&doneButtonSprite);
doneButtonSprite.setXYAndPriority(0x104, 0x64, 2);
- doneButtonSprite.setBitmap(_vm->loadBitmapFile("donebutt"));
+ doneButtonSprite.setBitmap(loadBitmapFile("donebutt"));
// BUGFIX: use draw mode 2 so the entire button is clickable (not just non-transparent
// pixels)
doneButtonSprite.drawMode = 2;
diff --git a/engines/startrek/rooms/demon6.cpp b/engines/startrek/rooms/demon6.cpp
index 920b4934a6..22eaf3244b 100644
--- a/engines/startrek/rooms/demon6.cpp
+++ b/engines/startrek/rooms/demon6.cpp
@@ -466,7 +466,7 @@ int Room::demon6ShowCase(int visible) {
sprites[i].pos.y = spritePositions[i].y;
sprites[i].drawPriority = 2;
sprites[i].bitmapChanged = true;
- sprites[i].setBitmap(_vm->loadBitmapFile(Common::String::format("stlitem%d", i)));
+ sprites[i].setBitmap(loadBitmapFile(Common::String::format("stlitem%d", i)));
}
Sprite buttonSprite;
@@ -478,7 +478,7 @@ int Room::demon6ShowCase(int visible) {
buttonSprite.pos.y = 0x19;
buttonSprite.drawPriority = 2;
buttonSprite.bitmapChanged = true;
- buttonSprite.setBitmap(_vm->loadBitmapFile("donebutt"));
+ buttonSprite.setBitmap(loadBitmapFile("donebutt"));
_vm->_gfx->addSprite(&buttonSprite);
_vm->_gfx->forceDrawAllSprites();
diff --git a/engines/startrek/saveload.cpp b/engines/startrek/saveload.cpp
index 89d272ccc2..436eb9c2bb 100644
--- a/engines/startrek/saveload.cpp
+++ b/engines/startrek/saveload.cpp
@@ -29,6 +29,7 @@
#include "common/serializer.h"
#include "common/translation.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -148,7 +149,7 @@ bool StarTrekEngine::loadGame(int slot) {
Actor *a = &_actorList[i];
if (a->spriteDrawn) {
if (a->animType != 1)
- a->animFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile(a->animFilename + ".anm"));
+ a->animFile = SharedPtr<Common::MemoryReadStreamEndian>(_resource->loadFile(a->animFilename + ".anm"));
_gfx->addSprite(&a->sprite);
a->sprite.setBitmap(loadAnimationFrame(a->bitmapFilename, a->scale));
}
@@ -158,7 +159,7 @@ bool StarTrekEngine::loadGame(int slot) {
_lastGameMode = GAMEMODE_BRIDGE;
// TODO: mode change
} else {
- _txtFilename = _missionToLoad;
+ _resource->setTxtFileName(_missionToLoad);
initBridge(false);
// TODO: mode change
}
@@ -227,7 +228,7 @@ bool StarTrekEngine::saveOrLoadGameData(Common::SeekableReadStream *in, Common::
if (ser.isLoading()) {
_gfx->fadeoutScreen();
- _txtFilename = "ground";
+ _resource->setTxtFileName("ground");
// This must be done before loading the actor variables, since this clears
// them.
diff --git a/engines/startrek/sound.cpp b/engines/startrek/sound.cpp
index 794a42db39..8fec588a17 100644
--- a/engines/startrek/sound.cpp
+++ b/engines/startrek/sound.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "startrek/resource.h"
#include "startrek/sound.h"
#include "common/file.h"
@@ -403,7 +404,7 @@ void Sound::loadPCMusicFile(const Common::String &baseSoundName) {
}
debugC(5, kDebugSound, "Loading midi \'%s\'\n", soundName.c_str());
- Common::MemoryReadStreamEndian *soundStream = _vm->loadFile(soundName.c_str());
+ Common::MemoryReadStreamEndian *soundStream = _vm->_resource->loadFile(soundName.c_str());
if (loadedSoundData != nullptr)
delete[] loadedSoundData;
diff --git a/engines/startrek/space.cpp b/engines/startrek/space.cpp
index 21942113af..4f64e47cb5 100644
--- a/engines/startrek/space.cpp
+++ b/engines/startrek/space.cpp
@@ -20,7 +20,7 @@
*
*/
-
+#include "startrek/resource.h"
#include "startrek/startrek.h"
namespace StarTrek {
@@ -84,7 +84,7 @@ void StarTrekEngine::drawStarfield() {
int16 yvar = var2a / 2;
int16 var8 = _starfieldPointDivisor << 3;
- Common::MemoryReadStreamEndian *file = loadFile("stars.shp");
+ Common::MemoryReadStreamEndian *file = _resource->loadFile("stars.shp");
for (int i = 0; i < NUM_STARS; i++) {
Star *star = &_starList[i];
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 7acb1214a9..56e471aaae 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -40,6 +40,7 @@
#include "startrek/console.h"
#include "startrek/iwfile.h"
#include "startrek/lzss.h"
+#include "startrek/resource.h"
#include "startrek/room.h"
#include "startrek/startrek.h"
@@ -70,8 +71,8 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam
_gfx = nullptr;
_activeMenu = nullptr;
_sound = nullptr;
- _macResFork = nullptr;
_room = nullptr;
+ _resource = nullptr;
memset(_actionOnWalkCompletionInUse, 0, sizeof(_actionOnWalkCompletionInUse));
@@ -117,21 +118,15 @@ StarTrekEngine::~StarTrekEngine() {
delete _gfx;
delete _sound;
- delete _macResFork;
+ delete _resource;
}
Common::Error StarTrekEngine::run() {
+ _resource = new Resource(getPlatform(), getFeatures() & GF_DEMO);
_gfx = new Graphics(this);
_sound = new Sound(this);
setDebugger(new Console(this));
- if (getPlatform() == Common::kPlatformMacintosh) {
- _macResFork = new Common::MacResManager();
- if (!_macResFork->open("Star Trek Data"))
- error("Could not load Star Trek Data");
- assert(_macResFork->hasDataFork() && _macResFork->hasResFork());
- }
-
initGraphics(SCREEN_WIDTH, SCREEN_HEIGHT);
initializeEventsAndMouse();
@@ -336,189 +331,6 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
initActors();
}
-/**
- * TODO:
- * - Should return nullptr on failure to open a file?
- * - This is supposed to cache results, return same FileStream on multiple accesses.
- * - This is supposed to read from a "patches" folder which overrides files in the
- * packed blob.
- */
-Common::MemoryReadStreamEndian *StarTrekEngine::loadFile(Common::String filename, int fileIndex) {
- filename.toUppercase();
-
- Common::String basename, extension;
-
- bool bigEndian = getPlatform() == Common::kPlatformAmiga;
-
- for (int i = filename.size() - 1; ; i--) {
- if (filename[i] == '.') {
- basename = filename;
- extension = filename;
- basename.replace(i, filename.size() - i, "");
- extension.replace(0, i + 1, "");
- break;
- }
- }
-
- // FIXME: don't know if this is right, or if it goes here
- while (!basename.empty() && basename.lastChar() == ' ') {
- basename.erase(basename.size() - 1, 1);
- }
-
- filename = basename + '.' + extension;
-
- // The Judgment Rites demo has its files not in the standard archive
- if (getGameType() == GType_STJR && (getFeatures() & GF_DEMO)) {
- Common::File *file = new Common::File();
- if (!file->open(filename.c_str())) {
- delete file;
- error("Could not find file \'%s\'", filename.c_str());
- }
- int32 size = file->size();
- byte *data = (byte *)malloc(size);
- file->read(data, size);
- delete file;
- return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
- }
-
- Common::SeekableReadStream *indexFile = 0;
-
- if (getPlatform() == Common::kPlatformAmiga) {
- indexFile = SearchMan.createReadStreamForMember("data000.dir");
- if (!indexFile)
- error("Could not open data000.dir");
- } else if (getPlatform() == Common::kPlatformMacintosh) {
- indexFile = _macResFork->getResource("Directory");
- if (!indexFile)
- error("Could not find 'Directory' resource in 'Star Trek Data'");
- } else {
- indexFile = SearchMan.createReadStreamForMember("data.dir");
- if (!indexFile)
- error("Could not open data.dir");
- }
-
- uint32 indexOffset = 0;
- bool foundData = false;
- uint16 fileCount = 1;
- uint16 uncompressedSize = 0;
-
- while (!indexFile->eos() && !indexFile->err()) {
- Common::String testfile;
- for (byte i = 0; i < 8; i++) {
- char c = indexFile->readByte();
- if (c)
- testfile += c;
- }
- testfile += '.';
-
- for (byte i = 0; i < 3; i++)
- testfile += indexFile->readByte();
-
- if (getFeatures() & GF_DEMO && getPlatform() == Common::kPlatformDOS) {
- indexFile->readByte(); // Always 0?
- fileCount = indexFile->readUint16LE(); // Always 1
- indexOffset = indexFile->readUint32LE();
- uncompressedSize = indexFile->readUint16LE();
- } else {
- if (getPlatform() == Common::kPlatformAmiga)
- indexOffset = (indexFile->readByte() << 16) + (indexFile->readByte() << 8) + indexFile->readByte();
- else
- indexOffset = indexFile->readByte() + (indexFile->readByte() << 8) + (indexFile->readByte() << 16);
-
- if (indexOffset & (1 << 23)) {
- fileCount = (indexOffset >> 16) & 0x7F;
- indexOffset = indexOffset & 0xFFFF;
- assert(fileCount > 1);
- } else {
- fileCount = 1;
- }
- }
-
- if (filename.matchString(testfile)) {
- foundData = true;
- break;
- }
- }
-
- delete indexFile;
-
- if (!foundData) {
- // Files can be accessed "sequentially" if their filenames are the same except for
- // the last character being incremented by one.
- if ((basename.lastChar() >= '1' && basename.lastChar() <= '9') ||
- (basename.lastChar() >= 'B' && basename.lastChar() <= 'Z')) {
- basename.setChar(basename.lastChar() - 1, basename.size() - 1);
- return loadFile(basename + "." + extension, fileIndex + 1);
- } else
- error("Could not find file \'%s\'", filename.c_str());
- }
-
- if (fileIndex >= fileCount)
- error("Tried to access file index %d for file '%s' which doesn't exist.", fileIndex, filename.c_str());
-
- Common::SeekableReadStream *dataFile = 0;
- Common::SeekableReadStream *dataRunFile = 0; // FIXME: Amiga & Mac need this implemented
-
- if (getPlatform() == Common::kPlatformAmiga) {
- dataFile = SearchMan.createReadStreamForMember("data.000");
- if (!dataFile)
- error("Could not open data.000");
- } else if (getPlatform() == Common::kPlatformMacintosh) {
- dataFile = _macResFork->getDataFork();
- if (!dataFile)
- error("Could not get 'Star Trek Data' data fork");
- } else {
- dataFile = SearchMan.createReadStreamForMember("data.001");
- if (!dataFile)
- error("Could not open data.001");
- dataRunFile = SearchMan.createReadStreamForMember("data.run");
- if (!dataFile)
- error("Could not open data.run");
- }
-
- Common::SeekableReadStream *stream;
- if (getFeatures() & GF_DEMO && getPlatform() == Common::kPlatformDOS) {
- assert(fileCount == 1); // Sanity check...
- stream = dataFile->readStream(uncompressedSize);
- } else {
- if (fileCount != 1) {
- dataRunFile->seek(indexOffset);
-
- indexOffset = dataRunFile->readByte() + (dataRunFile->readByte() << 8) + (dataRunFile->readByte() << 16);
- //indexOffset &= 0xFFFFFE;
-
- for (uint16 i = 0; i < fileIndex; i++) {
- uint16 size = dataRunFile->readUint16LE();
- indexOffset += size;
- }
- }
- dataFile->seek(indexOffset);
-
- uncompressedSize = (getPlatform() == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE();
- uint16 compressedSize = (getPlatform() == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE();
-
- stream = decodeLZSS(dataFile->readStream(compressedSize), uncompressedSize);
- }
-
- delete dataFile;
- delete dataRunFile;
-
- int32 size = stream->size();
- byte *data = (byte *)malloc(size);
- stream->read(data, size);
- delete stream;
-
- return new Common::MemoryReadStreamEndian(data, size, bigEndian, DisposeAfterUse::YES);
-}
-
-Common::MemoryReadStreamEndian *StarTrekEngine::loadBitmapFile(Common::String baseName) {
- return loadFile(baseName + ".BMP");
-}
-
-Common::MemoryReadStreamEndian *StarTrekEngine::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) {
- return loadFile(filename);
-}
-
void StarTrekEngine::playMovie(Common::String filename) {
if (getPlatform() == Common::kPlatformMacintosh)
playMovieMac(filename);
@@ -570,30 +382,4 @@ uint16 StarTrekEngine::getRandomWord() {
return _randomSource.getRandomNumber(0xffff);
}
-Common::String StarTrekEngine::getLoadedText(int textIndex) {
- Common::MemoryReadStreamEndian *txtFile = loadFile(_txtFilename + ".txt");
-
- Common::String str;
- byte cur;
- int curIndex = 0;
-
- while (!txtFile->eos()) {
- do {
- cur = txtFile->readByte();
- str += cur;
- } while (cur != '\0');
-
- if (curIndex == textIndex) {
- delete txtFile;
- return str;
- }
-
- curIndex++;
- str = "";
- }
-
- delete txtFile;
- return "";
-}
-
} // End of namespace StarTrek
diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h
index d9e7a77b1b..939e53adc3 100644
--- a/engines/startrek/startrek.h
+++ b/engines/startrek/startrek.h
@@ -62,6 +62,7 @@ namespace StarTrek {
class StarTrekEngine;
class Room;
class Console;
+class Resource;
typedef String(StarTrekEngine::*TextGetterFunc)(int, uintptr, String *);
@@ -242,23 +243,10 @@ public:
void initBridge(bool b) {}; // TODO
void cleanupBridge() {}; // TODO
- Common::MemoryReadStreamEndian *loadFile(Common::String filename, int fileIndex = 0);
- Common::MemoryReadStreamEndian *loadBitmapFile(Common::String baseName);
-
- /**
- * TODO: Figure out what the extra parameters are, and if they're important.
- */
- Common::MemoryReadStreamEndian *loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3);
-
void playMovie(Common::String filename);
void playMovieMac(Common::String filename);
uint16 getRandomWord();
- /**
- * ".txt" files are just lists of strings. This traverses the file to get a particular
- * string index.
- */
- Common::String getLoadedText(int textIndex);
// awaymission.cpp
void initAwayMission();
@@ -439,13 +427,6 @@ public:
void removeNextEvent();
bool popNextEvent(TrekEvent *e, bool poll = true);
void addEventToQueue(const TrekEvent &e);
- void clearEventBuffer();
- void updateEvents();
- void updateTimerEvent();
- void updateMouseEvents();
- void updateKeyboardEvents();
- void updateClockTicks();
- bool checkKeyPressed();
Common::EventManager *getEventMan() {
return _eventMan;
@@ -479,7 +460,6 @@ public:
* "readTextFromArrayWithChoices" replaces this.
*/
String readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput);
- String readTextFromBuffer(int choiceIndex, uintptr data, String *headerTextOutput);
/**
* Shows text with the given header and main text.
@@ -674,9 +654,6 @@ public:
Common::MemoryReadStreamEndian *_mapFile;
Fixed16 _playerActorScale;
- Common::String _txtFilename;
- Common::String _loadedText; // TODO: might be OK to delete this
-
// Queue of "actions" (ie. next frame, clicked on object) for away mission or bridge
Common::Queue<Action> _actionQueue;
@@ -756,13 +733,13 @@ public:
Graphics *_gfx;
Sound *_sound;
IWFile *_iwFile;
+ Resource *_resource;
private:
Common::RandomSource _randomSource;
Common::SineTable _sineTable;
Common::CosineTable _cosineTable;
Room *_room;
- Common::MacResManager *_macResFork;
};
// Static function
Commit: ffb0b2b743ee347822902eb4031efa2b37edf771
https://github.com/scummvm/scummvm/commit/ffb0b2b743ee347822902eb4031efa2b37edf771
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2020-09-09T22:36:11+03:00
Commit Message:
STARTREK: Fix typo
Changed paths:
engines/startrek/room.cpp
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp
index 6f64ae4e07..9e7d2e9bc7 100644
--- a/engines/startrek/room.cpp
+++ b/engines/startrek/room.cpp
@@ -596,7 +596,7 @@ void Room::loadMapFile(const Common::String &name) {
}
Common::MemoryReadStreamEndian *Room::loadBitmapFile(Common::String baseName) {
- return _vm->_resource->loadFile(baseName);
+ return _vm->_resource->loadBitmapFile(baseName);
}
Common::MemoryReadStreamEndian *Room::loadFileWithParams(Common::String filename, bool unk1, bool unk2, bool unk3) {
More information about the Scummvm-git-logs
mailing list