[Scummvm-git-logs] scummvm branch-2-9 -> f4567290f67aae57e7df9a9ab6c50baec11c6c55

eriktorbjorn noreply at scummvm.org
Thu Nov 21 18:51:06 UTC 2024


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

Summary:
f4567290f6 SCUMM: MACGUI: Optimize Mac palette handling (bug #15492)


Commit: f4567290f67aae57e7df9a9ab6c50baec11c6c55
    https://github.com/scummvm/scummvm/commit/f4567290f67aae57e7df9a9ab6c50baec11c6c55
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2024-11-21T19:50:05+01:00

Commit Message:
SCUMM: MACGUI: Optimize Mac palette handling (bug #15492)

Previously, every palette change in a game get passed on to the Mac
Window Manager, which would then have to look up new colors for drawing
Mac GUI stuff. This was fine for some games, but later ones do a lot of
palette animations, which could slow things down.

Now the Mac Window Manager gets the new palette only when it's about to
draw the Mac menu, or when it's about to draw a dialog (since those can
be triggered outside of the menu).

Additionally, the Mac Window Manager now triggers the auto-opening of
the menu in the event handler, not in the drawing code. Otherwise the
menu would be drawn once before the SCUMM Mac GUI could notice that the
menu was visible, causing an ugly color glitch.

Changed paths:
    engines/scumm/macgui/macgui.cpp
    engines/scumm/macgui/macgui.h
    engines/scumm/macgui/macgui_dialogwindow.cpp
    engines/scumm/macgui/macgui_impl.cpp
    engines/scumm/macgui/macgui_impl.h
    engines/scumm/palette.cpp
    graphics/macgui/macwindowmanager.cpp


diff --git a/engines/scumm/macgui/macgui.cpp b/engines/scumm/macgui/macgui.cpp
index ae3a0eac1e8..8ecbbffffa3 100644
--- a/engines/scumm/macgui/macgui.cpp
+++ b/engines/scumm/macgui/macgui.cpp
@@ -88,8 +88,8 @@ void MacGui::setupCursor(int &width, int &height, int &hotspotX, int &hotspotY,
 	_impl->setupCursor(width, height, hotspotX, hotspotY, animate);
 }
 
-void MacGui::setPalette(const byte *palette, uint size) {
-	_impl->setPalette(palette, size);
+void MacGui::setPaletteDirty() {
+	_impl->setPaletteDirty();
 }
 
 const Graphics::Font *MacGui::getFontByScummId(int32 id) {
diff --git a/engines/scumm/macgui/macgui.h b/engines/scumm/macgui/macgui.h
index 76ab676778c..726ea2a9a92 100644
--- a/engines/scumm/macgui/macgui.h
+++ b/engines/scumm/macgui/macgui.h
@@ -58,7 +58,7 @@ public:
 
 	void setupCursor(int &width, int &height, int &hotspotX, int &hotspotY, int &animate);
 
-	void setPalette(const byte *palette, uint size);
+	void setPaletteDirty();
 
 	const Graphics::Font *getFontByScummId(int32 id);
 
diff --git a/engines/scumm/macgui/macgui_dialogwindow.cpp b/engines/scumm/macgui/macgui_dialogwindow.cpp
index d7a9390b320..8130b7df3a9 100644
--- a/engines/scumm/macgui/macgui_dialogwindow.cpp
+++ b/engines/scumm/macgui/macgui_dialogwindow.cpp
@@ -40,6 +40,8 @@ namespace Scumm {
 // ---------------------------------------------------------------------------
 
 MacGuiImpl::MacDialogWindow::MacDialogWindow(MacGuiImpl *gui, OSystem *system, Graphics::Surface *from, Common::Rect bounds, MacDialogWindowStyle windowStyle, MacDialogMenuStyle menuStyle) : _gui(gui), _system(system), _from(from), _bounds(bounds) {
+	_gui->updatePalette();
+
 	// Only apply menu style if the menu is open.
 	Graphics::MacMenu *menu = _gui->_windowManager->getMenu();
 
diff --git a/engines/scumm/macgui/macgui_impl.cpp b/engines/scumm/macgui/macgui_impl.cpp
index 6cf3298ebc6..5c584153f05 100644
--- a/engines/scumm/macgui/macgui_impl.cpp
+++ b/engines/scumm/macgui/macgui_impl.cpp
@@ -92,8 +92,15 @@ int MacGuiImpl::toMacRoman(int unicode) const {
 	return macRoman;
 }
 
-void MacGuiImpl::setPalette(const byte *palette, uint size) {
-	_windowManager->passPalette(palette, size);
+void MacGuiImpl::setPaletteDirty() {
+	_paletteDirty = true;
+}
+
+void MacGuiImpl::updatePalette() {
+	if (_paletteDirty) {
+		_paletteDirty = false;
+		_windowManager->passPalette(_vm->_currentPalette, getNumColors());
+	}
 }
 
 bool MacGuiImpl::handleEvent(Common::Event event) {
@@ -495,6 +502,10 @@ void MacGuiImpl::updateWindowManager() {
 	}
 
 	_menuIsActive = isActive;
+
+	if (menu->isVisible())
+		updatePalette();
+
 	_windowManager->draw();
 }
 
diff --git a/engines/scumm/macgui/macgui_impl.h b/engines/scumm/macgui/macgui_impl.h
index 71fd9fc5031..59e8c1ef704 100644
--- a/engines/scumm/macgui/macgui_impl.h
+++ b/engines/scumm/macgui/macgui_impl.h
@@ -140,6 +140,8 @@ protected:
 
 	Common::Path _resourceFile;
 
+	bool _paletteDirty = false;
+
 	bool _menuIsActive = false;
 	bool _cursorWasVisible = false;
 
@@ -704,7 +706,9 @@ public:
 
 	int toMacRoman(int unicode) const;
 
-	void setPalette(const byte *palette, uint size);
+	void setPaletteDirty();
+	void updatePalette();
+
 	virtual bool handleEvent(Common::Event event);
 
 	static void menuCallback(int id, Common::String &name, void *data);
diff --git a/engines/scumm/palette.cpp b/engines/scumm/palette.cpp
index ae1e949c12c..586cf9757f5 100644
--- a/engines/scumm/palette.cpp
+++ b/engines/scumm/palette.cpp
@@ -1734,7 +1734,7 @@ void ScummEngine::updatePalette() {
 	_system->getPaletteManager()->setPalette(paletteColors, first, num);
 
 	if (_macGui)
-		_macGui->setPalette(_currentPalette, _macGui->getNumColors());
+		_macGui->setPaletteDirty();
 }
 
 } // End of namespace Scumm
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 947aa904113..c342c41cae3 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -994,14 +994,6 @@ void MacWindowManager::draw() {
 		}
 	}
 
-	if (_menuTimer && g_system->getMillis() >= _menuTimer) {
-		if (_menuHotzone.contains(_lastMousePos)) {
-			activateMenu();
-		}
-
-		_menuTimer = 0;
-	}
-
 	// Menu is drawn on top of everything and always
 	if (_menu && !(_mode & kWMModeFullscreen)) {
 		if (_fullRefresh)
@@ -1044,6 +1036,14 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 				_menuTimer = g_system->getMillis() + _menuDelay;
 			}
 		}
+
+		if (_menuTimer && g_system->getMillis() >= _menuTimer) {
+			if (_menuHotzone.contains(_lastMousePos)) {
+				activateMenu();
+			}
+
+			_menuTimer = 0;
+		}
 	}
 
 	// Menu gets events first for shortcuts and menu bar




More information about the Scummvm-git-logs mailing list