[Scummvm-git-logs] scummvm master -> 39022664601a805b48e5830a314c14b63551ecec

bluegr noreply at scummvm.org
Thu Nov 7 16:05:23 UTC 2024


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:
a5d3e07533 HYPNO: Cache Smacker cursors, hopefully improving performance (bug #15347)
3902266460 HYPNO: Fix mismatched malloc()/free()


Commit: a5d3e075331619255539f6864c9da37c0181dc02
    https://github.com/scummvm/scummvm/commit/a5d3e075331619255539f6864c9da37c0181dc02
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2024-11-07T18:05:18+02:00

Commit Message:
HYPNO: Cache Smacker cursors, hopefully improving performance (bug #15347)

At least in Spider Man: Sinister Six the cursor is constantly being
changed to the current cursor, and since that involves decoding a
Smacker file it is apparently quite slow on Android. Possibly on other
systems as well.

The cursor doesn't actually change, though - it is not animated - so by
remembering the previously decoded cursor we can cut down on unnecessary
file access.

Changed paths:
    engines/hypno/cursors.cpp
    engines/hypno/hypno.cpp
    engines/hypno/hypno.h


diff --git a/engines/hypno/cursors.cpp b/engines/hypno/cursors.cpp
index 22bec92e9b4..80fc968c281 100644
--- a/engines/hypno/cursors.cpp
+++ b/engines/hypno/cursors.cpp
@@ -148,16 +148,35 @@ void HypnoEngine::changeCursor(const Common::String &cursor) {
 	CursorMan.showMouse(true);
 }
 
+Graphics::Surface *CursorCache::getCursor(const Common::String &cursor, uint32 n, byte **palette) {
+	if (cursor == _filename && n == _frame) {
+		*palette = _palette;
+		return _surface;
+	}
+
+	delete(_palette);
+	_palette = nullptr;
+
+	if (_surface) {
+		_surface->free();
+		delete _surface;
+		_surface = nullptr;
+	}
+
+	_filename = cursor;
+	_frame = n;
+	_surface = _vm->decodeFrame(cursor, n, &_palette);
+	*palette = _palette;
+	return _surface;
+}
+
 void HypnoEngine::changeCursor(const Common::String &cursor, uint32 n, bool centerCursor) {
 	byte *palette;
-	Graphics::Surface *entry = decodeFrame(cursor, n, &palette);
+	Graphics::Surface *entry = _cursorCache->getCursor(cursor, n, &palette);
 	uint32 hotspotX = centerCursor ? entry->w / 2 : 0;
 	uint32 hotspotY = centerCursor ? entry->h / 2 : 0;
 	CursorMan.replaceCursor(*entry, hotspotX, hotspotY, 0, false);
 	CursorMan.replaceCursorPalette(palette, 0, 256);
-	entry->free();
-	delete entry;
-	free(palette);
 	CursorMan.showMouse(true);
 }
 
diff --git a/engines/hypno/hypno.cpp b/engines/hypno/hypno.cpp
index 197011da306..edb006f319e 100644
--- a/engines/hypno/hypno.cpp
+++ b/engines/hypno/hypno.cpp
@@ -63,6 +63,8 @@ HypnoEngine::HypnoEngine(OSystem *syst, const ADGameDescription *gd)
 	_rnd = new Common::RandomSource("hypno");
 	_checkpoint = "";
 
+	_cursorCache = new CursorCache(this);
+
 	if (gd->extra)
 		_variant = gd->extra;
 	else
@@ -109,6 +111,7 @@ HypnoEngine::~HypnoEngine() {
 	// }
 
 	delete _rnd;
+	delete _cursorCache;
 	_compositeSurface->free();
 	delete _compositeSurface;
 
diff --git a/engines/hypno/hypno.h b/engines/hypno/hypno.h
index b587b45fb8e..a227d0eaa03 100644
--- a/engines/hypno/hypno.h
+++ b/engines/hypno/hypno.h
@@ -78,6 +78,29 @@ enum SpiderColors {
 	kSpiderColorBlue = 252,
 };
 
+class HypnoEngine;
+
+class CursorCache {
+private:
+	HypnoEngine *_vm;
+	Common::String _filename;
+	uint32 _frame;
+	byte *_palette;
+	Graphics::Surface *_surface;
+
+public:
+	CursorCache(HypnoEngine *vm) : _vm(vm), _filename(""), _frame(0), _palette(nullptr), _surface(nullptr) {}
+
+	~CursorCache() {
+		if (_surface) {
+			_surface->free();
+			delete _surface;
+		}
+		free(_palette);
+	}
+
+	Graphics::Surface *getCursor(const Common::String &cursor, uint32 n, byte **palette);
+};
 
 class HypnoEngine : public Engine {
 private:
@@ -164,6 +187,7 @@ public:
 	// Cursors
 	Common::String _defaultCursor;
 	uint32 _defaultCursorIdx;
+	CursorCache *_cursorCache;
 	void disableCursor();
 	void defaultCursor();
 	virtual void changeCursor(const Common::String &cursor, uint32 n, bool centerCursor = false);


Commit: 39022664601a805b48e5830a314c14b63551ecec
    https://github.com/scummvm/scummvm/commit/39022664601a805b48e5830a314c14b63551ecec
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-11-07T18:05:18+02:00

Commit Message:
HYPNO: Fix mismatched malloc()/free()

Changed paths:
    engines/hypno/cursors.cpp


diff --git a/engines/hypno/cursors.cpp b/engines/hypno/cursors.cpp
index 80fc968c281..83e9ee33f10 100644
--- a/engines/hypno/cursors.cpp
+++ b/engines/hypno/cursors.cpp
@@ -154,7 +154,7 @@ Graphics::Surface *CursorCache::getCursor(const Common::String &cursor, uint32 n
 		return _surface;
 	}
 
-	delete(_palette);
+	free(_palette);
 	_palette = nullptr;
 
 	if (_surface) {




More information about the Scummvm-git-logs mailing list