Skip to content

Commit

Permalink
Merge branch 'sherlock' into sherlock2
Browse files Browse the repository at this point in the history
Conflicts:
	engines/sherlock/decompress.cpp
	engines/sherlock/objects.cpp
	engines/sherlock/objects.h
	engines/sherlock/scene.cpp
	engines/sherlock/scene.h
	engines/sherlock/sound.cpp
  • Loading branch information
dreammaster committed May 16, 2015
2 parents 4cbad28 + 96e929f commit d1d4d55
Show file tree
Hide file tree
Showing 26 changed files with 228 additions and 193 deletions.
36 changes: 0 additions & 36 deletions engines/sherlock/decompress.h

This file was deleted.

21 changes: 20 additions & 1 deletion engines/sherlock/detection.cpp
Expand Up @@ -25,6 +25,7 @@
#include "sherlock/scalpel/scalpel.h"
#include "sherlock/tattoo/tattoo.h"
#include "common/system.h"
#include "common/translation.h"
#include "engines/advancedDetector.h"

namespace Sherlock {
Expand Down Expand Up @@ -57,11 +58,29 @@ static const PlainGameDescriptor sherlockGames[] = {
{0, 0}
};


#define GAMEOPTION_ORIGINAL_SAVES GUIO_GAMEOPTIONS1

static const ADExtraGuiOptionsMap optionsList[] = {
{
GAMEOPTION_ORIGINAL_SAVES,
{
_s("Use original savegame dialog"),
_s("Files button in-game shows original savegame dialog rather than ScummVM menu"),
"originalsaveload",
false
}
},

AD_EXTRA_GUI_OPTIONS_TERMINATOR
};

#include "sherlock/detection_tables.h"

class SherlockMetaEngine : public AdvancedMetaEngine {
public:
SherlockMetaEngine() : AdvancedMetaEngine(Sherlock::gameDescriptions, sizeof(Sherlock::SherlockGameDescription), sherlockGames) {}
SherlockMetaEngine() : AdvancedMetaEngine(Sherlock::gameDescriptions, sizeof(Sherlock::SherlockGameDescription),
sherlockGames, optionsList) {}

virtual const char *getName() const {
return "Sherlock Engine";
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/detection_tables.h
Expand Up @@ -33,7 +33,7 @@ static const SherlockGameDescription gameDescriptions[] = {
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_UNSTABLE | ADGF_NO_FLAGS,
GUIO1(GUIO_NOSPEECH)
GUIO2(GUIO_NOSPEECH, GAMEOPTION_ORIGINAL_SAVES)
},
GType_SerratedScalpel,
},
Expand Down
5 changes: 0 additions & 5 deletions engines/sherlock/inventory.cpp
Expand Up @@ -49,8 +49,6 @@ Inventory::Inventory(SherlockEngine *vm) : Common::Array<InventoryItem>(), _vm(v
_invGraphicsLoaded = false;
_invIndex = 0;
_holdings = 0;
_oldFlag = 0;
_invFlag = 0;
_invMode = INVMODE_EXIT;
}

Expand Down Expand Up @@ -215,7 +213,6 @@ void Inventory::drawInventory(int flag) {
UserInterface &ui = *_vm->_ui;
int tempFlag = flag;

_oldFlag = 7;
loadInv();

if (flag == 128) {
Expand Down Expand Up @@ -257,10 +254,8 @@ void Inventory::drawInventory(int flag) {

if (flag) {
ui._oldKey = INVENTORY_COMMANDS[flag];
_oldFlag = flag;
} else {
ui._oldKey = -1;
_invFlag = 6;
}

invCommands(0);
Expand Down
2 changes: 0 additions & 2 deletions engines/sherlock/inventory.h
Expand Up @@ -75,8 +75,6 @@ class Inventory : public Common::Array<InventoryItem> {
int _holdings; // Used to hold number of visible items in active inventory.
// Since Inventory array also contains some special hidden items
void freeGraphics();
int _oldFlag;
int _invFlag;
public:
Inventory(SherlockEngine *vm);
~Inventory();
Expand Down
4 changes: 4 additions & 0 deletions engines/sherlock/map.cpp
Expand Up @@ -146,6 +146,10 @@ int Map::show() {
int oldFont = screen.fontNumber();
screen.setFont(0);

// Initial screen clear
screen._backBuffer1.clear();
screen.clear();

// Load the entire map
ImageFile bigMap("bigmap.vgs");
screen.setPalette(bigMap._palette);
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/map.h
Expand Up @@ -29,7 +29,7 @@
#include "common/serializer.h"
#include "common/str.h"
#include "common/str-array.h"
#include "sherlock/graphics.h"
#include "sherlock/surface.h"
#include "sherlock/objects.h"

namespace Sherlock {
Expand Down
3 changes: 1 addition & 2 deletions engines/sherlock/module.mk
Expand Up @@ -5,11 +5,9 @@ MODULE_OBJS = \
scalpel/scalpel.o \
tattoo/tattoo.o \
animation.o \
decompress.o \
debugger.o \
detection.o \
events.o \
graphics.o \
inventory.o \
journal.o \
map.o \
Expand All @@ -22,6 +20,7 @@ MODULE_OBJS = \
settings.o \
sherlock.o \
sound.o \
surface.o \
talk.o \
user_interface.o

Expand Down
90 changes: 78 additions & 12 deletions engines/sherlock/resources.cpp
Expand Up @@ -21,14 +21,14 @@
*/

#include "sherlock/resources.h"
#include "sherlock/decompress.h"
#include "sherlock/screen.h"
#include "sherlock/sherlock.h"
#include "common/debug.h"
#include "common/memstream.h"

namespace Sherlock {

Cache::Cache() {
Cache::Cache(SherlockEngine *vm): _vm(vm) {
}

/**
Expand Down Expand Up @@ -66,20 +66,17 @@ void Cache::load(const Common::String &name, Common::SeekableReadStream &stream)
if (_resources.contains(name))
return;

// Check whether the file is compressed
const char LZW_HEADER[5] = { "LZV\x1a" };
char header[5];
stream.read(header, 5);
bool isCompressed = !strncmp(header, LZW_HEADER, 5);
int32 signature = stream.readUint32BE();
stream.seek(0);

// Allocate a new cache entry
_resources[name] = CacheEntry();
CacheEntry &cacheEntry = _resources[name];

if (isCompressed) {
// Check whether the file is compressed
if (signature == MKTAG('L', 'Z', 'V', 26)) {
// It's compressed, so decompress the file and store it's data in the cache entry
Common::SeekableReadStream *decompressed = decompressLZ(stream);
Common::SeekableReadStream *decompressed = _vm->_res->decompressLZ(stream);
cacheEntry.resize(decompressed->size());
decompressed->read(&cacheEntry[0], decompressed->size());

Expand All @@ -102,7 +99,7 @@ Common::SeekableReadStream *Cache::get(const Common::String &filename) const {

/*----------------------------------------------------------------*/

Resources::Resources() {
Resources::Resources(SherlockEngine *vm): _vm(vm), _cache(vm) {
_resourceIndex = -1;

addToCache("vgs.lib");
Expand Down Expand Up @@ -169,8 +166,19 @@ Common::SeekableReadStream *Resources::load(const Common::String &filename) {
stream->seek(entry._offset);
Common::SeekableReadStream *resStream = stream->readStream(entry._size);

delete stream;
return resStream;
// Check whether the file is compressed
if (resStream->readUint32BE() == MKTAG('L', 'Z', 'V', 26)) {
resStream->seek(0);
// It's compressed, so decompress the sub-file and return it
Common::SeekableReadStream *decompressed = decompressLZ(*resStream);
delete stream;
delete resStream;
return decompressed;
} else {
resStream->seek(0);
delete stream;
return resStream;
}
}
}

Expand Down Expand Up @@ -402,4 +410,62 @@ void ImageFile::decompressFrame(ImageFrame &frame, const byte *src) {
}
}

/**
* Decompress an LZW compressed resource
*/
Common::SeekableReadStream *Resources::decompressLZ(Common::SeekableReadStream &source) {
if (_vm->getGameID() == GType_SerratedScalpel) {
uint32 id = source.readUint32BE();
assert(id == MKTAG('L', 'Z', 'V', 0x1A));
}

uint32 size = source.readUint32LE();
return decompressLZ(source, size);
}

/**
* Decompresses an LZW block of data with a specified output size
*/
Common::SeekableReadStream *Resources::decompressLZ(Common::SeekableReadStream &source, uint32 outSize) {
byte lzWindow[4096];
uint16 lzWindowPos;
uint16 cmd;

byte *outBuffer = (byte *)malloc(outSize);
byte *outBufferEnd = outBuffer + outSize;
Common::MemoryReadStream *outS = new Common::MemoryReadStream(outBuffer, outSize, DisposeAfterUse::YES);

memset(lzWindow, 0xFF, 0xFEE);
lzWindowPos = 0xFEE;
cmd = 0;

do {
cmd >>= 1;
if (!(cmd & 0x100))
cmd = source.readByte() | 0xFF00;

if (cmd & 1) {
byte literal = source.readByte();
*outBuffer++ = literal;
lzWindow[lzWindowPos] = literal;
lzWindowPos = (lzWindowPos + 1) & 0x0FFF;
} else {
int copyPos, copyLen;
copyPos = source.readByte();
copyLen = source.readByte();
copyPos = copyPos | ((copyLen & 0xF0) << 4);
copyLen = (copyLen & 0x0F) + 3;
while (copyLen--) {
byte literal = lzWindow[copyPos];
copyPos = (copyPos + 1) & 0x0FFF;
*outBuffer++ = literal;
lzWindow[lzWindowPos] = literal;
lzWindowPos = (lzWindowPos + 1) & 0x0FFF;
}
}
} while (outBuffer < outBufferEnd);

return outS;
}

} // End of namespace Sherlock
9 changes: 7 additions & 2 deletions engines/sherlock/resources.h
Expand Up @@ -52,9 +52,10 @@ class SherlockEngine;

class Cache {
private:
SherlockEngine *_vm;
CacheHash _resources;
public:
Cache();
Cache(SherlockEngine *_vm);

bool isCached(const Common::String &filename) const;

Expand All @@ -66,14 +67,15 @@ class Cache {

class Resources {
private:
SherlockEngine *_vm;
Cache _cache;
LibraryIndexes _indexes;
int _resourceIndex;

void loadLibraryIndex(const Common::String &libFilename, Common::SeekableReadStream *stream,
bool isNewStyle);
public:
Resources();
Resources(SherlockEngine *vm);

void addToCache(const Common::String &filename);
void addToCache(const Common::String &filename, const Common::String &libFilename);
Expand All @@ -87,6 +89,9 @@ class Resources {
bool exists(const Common::String &filename) const;

int resourceIndex() const;

static Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, uint32 outSize);
Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source);
};

struct ImageFrame {
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/saveload.cpp
Expand Up @@ -21,7 +21,7 @@
*/

#include "sherlock/saveload.h"
#include "sherlock/graphics.h"
#include "sherlock/surface.h"
#include "sherlock/sherlock.h"
#include "common/system.h"
#include "graphics/scaler.h"
Expand Down
3 changes: 2 additions & 1 deletion engines/sherlock/scalpel/scalpel.cpp
Expand Up @@ -255,8 +255,9 @@ void ScalpelEngine::initialize() {
_flags[39] = true; // Turn on Baker Street

// Add some more files to the cache
_res->addToCache("sequence.txt");
_res->addToCache("portrait.lib");
_res->addToCache("sequence.txt");
_res->addToCache("snd.snd");

// Load the map co-ordinates for each scene and sequence data
_map->loadPoints(NUM_PLACES, &MAP_X[0], &MAP_Y[0], &MAP_TRANSLATE[0]);
Expand Down

0 comments on commit d1d4d55

Please sign in to comment.