[Scummvm-git-logs] scummvm master -> d64c94c6dd7b8794a44d4f49dab39def0d67af04

fracturehill noreply at scummvm.org
Fri Nov 24 22:09:38 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8add576cbc NANCY: Further optimize decompressor
d64c94c6dd NANCY: Stop multiple keys at the same time in PianoPuzzle


Commit: 8add576cbcb9918b7e2e4d47f9accf2a11919254
    https://github.com/scummvm/scummvm/commit/8add576cbcb9918b7e2e4d47f9accf2a11919254
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-11-25T00:09:19+02:00

Commit Message:
NANCY: Further optimize decompressor

Modified the Decompressor class so it no longer keeps
a ReadStream for its input data. This helps us avoid doing
a vtable lookup for every byte read, and halves the time
needed to decompress.

Changed paths:
    engines/nancy/cif.cpp
    engines/nancy/decompress.cpp
    engines/nancy/decompress.h


diff --git a/engines/nancy/cif.cpp b/engines/nancy/cif.cpp
index 961b367c50d..3a6dc13fb26 100644
--- a/engines/nancy/cif.cpp
+++ b/engines/nancy/cif.cpp
@@ -113,7 +113,7 @@ Common::SeekableReadStream *CifFile::createReadStream() const {
 		// Decompress the data into the buffer
 		if (_stream->seek(_info.dataOffset)) {
 			Common::MemoryWriteStream write(buf, _info.size);
-			Common::SubReadStream read(_stream, _info.compressedSize);
+			Common::SeekableSubReadStream read(_stream, _info.dataOffset, _info.dataOffset + _info.compressedSize);
 			Decompressor dec;
 			success = dec.decompress(read, write);
 		} else {
@@ -223,7 +223,7 @@ Common::SeekableReadStream *CifTree::createReadStreamForMember(const Common::Pat
 		// Decompress the data into the buffer
 		if (_stream->seek(info.dataOffset)) {
 			Common::MemoryWriteStream write(buf, info.size);
-			Common::SubReadStream read(_stream, info.compressedSize);
+			Common::SeekableSubReadStream read(_stream, info.dataOffset, info.dataOffset + info.compressedSize);
 			Decompressor dec;
 			success = dec.decompress(read, write);
 		} else {
diff --git a/engines/nancy/decompress.cpp b/engines/nancy/decompress.cpp
index 1468da88c62..f0afb20a6dd 100644
--- a/engines/nancy/decompress.cpp
+++ b/engines/nancy/decompress.cpp
@@ -26,18 +26,39 @@
 
 namespace Nancy {
 
-void Decompressor::init(Common::ReadStream &input, Common::WriteStream &output) {
+Decompressor::Decompressor() :
+	_bufpos(0),
+	_err(false),
+	_val(0),
+	_output(nullptr),
+	_input(nullptr),
+	_pos(nullptr),
+	_end(nullptr) {}
+
+Decompressor::~Decompressor() {
+	delete[] _input;
+}
+
+void Decompressor::init(Common::SeekableReadStream &input, Common::WriteStream &output) {
 	memset(_buf, ' ', kBufSize);
 	_bufpos = kBufStart;
 	_err = false;
 	_val = 0;
-	_input = &input;
+
+	// We store the input data in a raw buffer, since we need to check if we're at the end of the
+	// stream on _every_ read byte. This way we avoid doing a vtable lookup per byte, which makes
+	// decompression roughly twice as fast
+	delete[] _input;
+	_input = new byte[input.size()];
+	input.read(_input, input.size());
+	_pos = _input;
+	_end = _input + input.size();
 	_output = &output;
 }
 
 bool Decompressor::readByte(byte &b) {
-	b = _input->readByte() - _val++;
-	return !_input->eos();
+	b = *_pos++ - _val++;
+	return _pos <= _end;
 }
 
 bool Decompressor::writeByte(byte b) {
@@ -47,10 +68,15 @@ bool Decompressor::writeByte(byte b) {
 	return true;
 }
 
-bool Decompressor::decompress(Common::ReadStream &input, Common::MemoryWriteStream &output) {
+bool Decompressor::decompress(Common::SeekableReadStream &input, Common::MemoryWriteStream &output) {
 	init(input, output);
 	uint16 bits = 0;
 
+	if (input.err()) {
+		warning("Failed to decompress resource");
+		return false;
+	}
+
 	while (1) {
 		byte b;
 
@@ -83,7 +109,7 @@ bool Decompressor::decompress(Common::ReadStream &input, Common::MemoryWriteStre
 		}
 	}
 
-	if (input.err() || output.err() || output.pos() != output.size()) {
+	if (output.err() || output.pos() != output.size()) {
 		// Workaround for nancy3 file "SLN RollPanOpn.avf", which outputs 2 bytes less than it should
 		if (output.size() - output.pos() <= 2) {
 			return true;
diff --git a/engines/nancy/decompress.h b/engines/nancy/decompress.h
index aaa70803a70..236a72618ae 100644
--- a/engines/nancy/decompress.h
+++ b/engines/nancy/decompress.h
@@ -34,9 +34,12 @@ namespace Nancy {
 
 class Decompressor {
 public:
+	Decompressor();
+	~Decompressor();
+
 	// Decompresses data from input until the end of the stream
 	// The output stream must have the right size for the decompressed data
-	bool decompress(Common::ReadStream &input, Common::MemoryWriteStream &output);
+	bool decompress(Common::SeekableReadStream &input, Common::MemoryWriteStream &output);
 
 private:
 	enum {
@@ -44,7 +47,7 @@ private:
 		kBufStart = 4078
 	};
 
-	void init(Common::ReadStream &input, Common::WriteStream &output);
+	void init(Common::SeekableReadStream &input, Common::WriteStream &output);
 	bool readByte(byte &b);
 	bool writeByte(byte b);
 
@@ -52,8 +55,11 @@ private:
 	uint _bufpos;
 	bool _err;
 	byte _val;
-	Common::ReadStream *_input;
 	Common::WriteStream *_output;
+
+	byte *_input;
+	byte *_pos;
+	byte *_end;
 };
 
 } // End of namespace Nancy


Commit: d64c94c6dd7b8794a44d4f49dab39def0d67af04
    https://github.com/scummvm/scummvm/commit/d64c94c6dd7b8794a44d4f49dab39def0d67af04
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-11-25T00:09:19+02:00

Commit Message:
NANCY: Stop multiple keys at the same time in PianoPuzzle

This fixes an issue in PianoPuzzle that could produce
graphical glitches when clicking adjacent keys

Changed paths:
    engines/nancy/action/puzzle/orderingpuzzle.cpp


diff --git a/engines/nancy/action/puzzle/orderingpuzzle.cpp b/engines/nancy/action/puzzle/orderingpuzzle.cpp
index 3b64ad2b9c0..d7d03214e03 100644
--- a/engines/nancy/action/puzzle/orderingpuzzle.cpp
+++ b/engines/nancy/action/puzzle/orderingpuzzle.cpp
@@ -432,7 +432,7 @@ void OrderingPuzzle::handleInput(NancyInput &input) {
 	}
 
 	bool canClick = true;
-	if (_itemsStayDown && g_nancy->_sound->isSoundPlaying(_pushDownSound)) {
+	if ((_itemsStayDown || _puzzleType == kPiano) && g_nancy->_sound->isSoundPlaying(_pushDownSound)) {
 		canClick = false;
 	}
 




More information about the Scummvm-git-logs mailing list