[Scummvm-git-logs] scummvm master -> 6e9d0fafb561cda74b61a2fba642a04da07a7b7d
sluicebox
22204938+sluicebox at users.noreply.github.com
Wed Feb 12 17:08:14 UTC 2020
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:
6e9d0fafb5 SCI32: Use Mac cursor palettes
Commit: 6e9d0fafb561cda74b61a2fba642a04da07a7b7d
https://github.com/scummvm/scummvm/commit/6e9d0fafb561cda74b61a2fba642a04da07a7b7d
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2020-02-12T09:04:57-08:00
Commit Message:
SCI32: Use Mac cursor palettes
Fixes cursor colors in SCI32 Mac games that use native cursor resources.
Changed paths:
A engines/sci/graphics/maccursor32.cpp
A engines/sci/graphics/maccursor32.h
engines/sci/graphics/cursor32.cpp
engines/sci/graphics/cursor32.h
engines/sci/module.mk
engines/sci/resource.cpp
engines/sci/resource.h
engines/sci/sci.cpp
diff --git a/engines/sci/graphics/cursor32.cpp b/engines/sci/graphics/cursor32.cpp
index 8ba35e1..7a655a5 100644
--- a/engines/sci/graphics/cursor32.cpp
+++ b/engines/sci/graphics/cursor32.cpp
@@ -196,48 +196,7 @@ void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const
_cursorInfo.loopNo = loopNo;
_cursorInfo.celNo = celNo;
- if (!_macCursorRemap.empty() && viewId != -1) {
- // Mac cursor handling
- GuiResourceId viewNum = viewId;
-
- // Remap cursor view based on what the scripts have given us.
- for (uint32 i = 0; i < _macCursorRemap.size(); i++) {
- if (viewNum == _macCursorRemap[i]) {
- viewNum = (i + 1) * 0x100 + loopNo * 0x10 + celNo;
- break;
- }
- }
-
- _cursorInfo.resourceId = viewNum;
-
- Resource *resource = g_sci->getResMan()->findResource(ResourceId(kResourceTypeCursor, viewNum), false);
-
- if (!resource) {
- // The cursor resources often don't exist, this is normal behavior
- debug(0, "Mac cursor %d not found", viewNum);
- return;
- }
- Common::MemoryReadStream resStream(resource->toStream());
- Graphics::MacCursor *macCursor = new Graphics::MacCursor();
-
- if (!macCursor->readFromStream(resStream)) {
- warning("Failed to load Mac cursor %d", viewNum);
- delete macCursor;
- return;
- }
-
- _hotSpot = Common::Point(macCursor->getHotspotX(), macCursor->getHotspotY());
- _width = macCursor->getWidth();
- _height = macCursor->getHeight();
-
- _cursor.data = (byte *)realloc(_cursor.data, _width * _height);
- memcpy(_cursor.data, macCursor->getSurface(), _width * _height);
- _cursor.rect = Common::Rect(_width, _height);
- _cursor.skipColor = macCursor->getKeyColor();
-
- // The cursor will be drawn on next refresh
- delete macCursor;
- } else if (viewId != -1) {
+ if (viewId != -1) {
CelObjView view(viewId, loopNo, celNo);
_hotSpot = view._origin;
@@ -443,9 +402,4 @@ void GfxCursor32::move() {
}
}
-void GfxCursor32::setMacCursorRemapList(int cursorCount, reg_t *cursors) {
- for (int i = 0; i < cursorCount; i++)
- _macCursorRemap.push_back(cursors[i].toUint16());
-}
-
} // End of namespace Sci
diff --git a/engines/sci/graphics/cursor32.h b/engines/sci/graphics/cursor32.h
index b8ac6da..7cb328e 100644
--- a/engines/sci/graphics/cursor32.h
+++ b/engines/sci/graphics/cursor32.h
@@ -52,39 +52,39 @@ public:
* Called by GfxFrameout once for each show rectangle that is going to be
* drawn to hardware.
*/
- void gonnaPaint(Common::Rect paintRect);
+ virtual void gonnaPaint(Common::Rect paintRect);
/**
* Called by GfxFrameout when the rendering to hardware begins.
*/
- void paintStarting();
+ virtual void paintStarting();
/**
* Called by GfxFrameout when the output buffer has finished rendering to
* hardware.
*/
- void donePainting();
+ virtual void donePainting();
/**
* Hides the cursor. Each call to `hide` will increment a hide counter,
* which must be returned to 0 before the cursor will be shown again.
*/
- void hide();
+ virtual void hide();
/**
* Shows the cursor, if the hide counter is returned to 0.
*/
- void unhide();
+ virtual void unhide();
/**
* Shows the cursor regardless of the state of the hide counter.
*/
- void show();
+ virtual void show();
/**
* Sets the view used to render the cursor.
*/
- void setView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo);
+ virtual void setView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo);
/**
* Explicitly sets the position of the cursor, in game script coordinates.
@@ -103,6 +103,18 @@ public:
void saveLoadWithSerializer(Common::Serializer &ser) override;
+protected:
+ /**
+ * Information about the current cursor. Used to restore cursor when loading
+ * a savegame.
+ */
+ CelInfo32 _cursorInfo;
+
+ /**
+ * The number of times the cursor has been hidden.
+ */
+ int _hideCount;
+
private:
struct DrawRegion {
Common::Rect rect;
@@ -113,12 +125,6 @@ private:
};
/**
- * Information about the current cursor. Used to restore cursor when loading
- * a savegame.
- */
- CelInfo32 _cursorInfo;
-
- /**
* The content of the frame buffer which was behind the cursor prior to its
* being drawn.
*/
@@ -161,11 +167,6 @@ private:
Buffer _screen;
/**
- * The number of times the cursor has been hidden.
- */
- int _hideCount;
-
- /**
* The rendered position of the cursor, in screen coordinates.
*/
Common::Point _position;
@@ -217,14 +218,10 @@ private:
/**
* Renders the cursor at its new location.
*/
- void move();
+ virtual void move();
public:
- void setMacCursorRemapList(int cursorCount, reg_t *cursors);
-
-private:
- // Mac versions of games use a remap list to remap their cursors
- Common::Array<uint16> _macCursorRemap;
+ virtual void setMacCursorRemapList(int cursorCount, reg_t *cursors) {}
};
} // End of namespace Sci
diff --git a/engines/sci/graphics/maccursor32.cpp b/engines/sci/graphics/maccursor32.cpp
new file mode 100644
index 0000000..d17b381
--- /dev/null
+++ b/engines/sci/graphics/maccursor32.cpp
@@ -0,0 +1,102 @@
+/* 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/system.h" // for OSystem, g_system
+#include "graphics/cursorman.h" // for CursorMan
+#include "graphics/maccursor.h" // for MacCursor
+#include "sci/graphics/maccursor32.h"
+
+namespace Sci {
+
+void GfxMacCursor32::setMacCursorRemapList(int cursorCount, reg_t *cursors) {
+ for (int i = 0; i < cursorCount; i++) {
+ _macCursorRemap.push_back(cursors[i].toUint16());
+ }
+}
+
+void GfxMacCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo) {
+ hide();
+
+ _cursorInfo.resourceId = viewId;
+ _cursorInfo.loopNo = loopNo;
+ _cursorInfo.celNo = celNo;
+
+ GuiResourceId viewNum = viewId;
+
+ // Remap cursor view based on what the scripts have given us.
+ for (uint32 i = 0; i < _macCursorRemap.size(); i++) {
+ if (viewNum == _macCursorRemap[i]) {
+ viewNum = (i + 1) * 0x100 + loopNo * 0x10 + celNo;
+ break;
+ }
+ }
+
+ _cursorInfo.resourceId = viewNum;
+
+ Resource *resource = g_sci->getResMan()->findResource(ResourceId(kResourceTypeCursor, viewNum), false);
+
+ if (!resource) {
+ // The cursor resources often don't exist, this is normal behavior
+ debug(0, "Mac cursor %d not found", viewNum);
+ return;
+ }
+ Common::MemoryReadStream resStream(resource->toStream());
+ Graphics::MacCursor *macCursor = new Graphics::MacCursor();
+
+ if (!macCursor->readFromStream(resStream)) {
+ warning("Failed to load Mac cursor %d", viewNum);
+ delete macCursor;
+ return;
+ }
+
+ CursorMan.disableCursorPalette(false);
+ CursorMan.replaceCursor(macCursor);
+
+ delete macCursor;
+
+ unhide();
+}
+
+void GfxMacCursor32::hide() {
+ if (_hideCount++) {
+ return;
+ }
+
+ g_system->showMouse(false);
+}
+
+void GfxMacCursor32::unhide() {
+ if (_hideCount == 0 || --_hideCount) {
+ return;
+ }
+
+ g_system->showMouse(true);
+}
+
+void GfxMacCursor32::show() {
+ if (_hideCount) {
+ g_system->showMouse(true);
+ _hideCount = 0;
+ }
+}
+
+} // End of namespace Sci
diff --git a/engines/sci/graphics/maccursor32.h b/engines/sci/graphics/maccursor32.h
new file mode 100644
index 0000000..906c1c1
--- /dev/null
+++ b/engines/sci/graphics/maccursor32.h
@@ -0,0 +1,104 @@
+/* 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 SCI_GRAPHICS_MACCURSOR32_H
+#define SCI_GRAPHICS_MACCURSOR32_H
+
+#include "common/array.h" // for Array
+#include "common/rect.h" // for Point, Rect
+#include "common/scummsys.h" // for int16, byte, uint8
+#include "sci/graphics/cursor32.h" // for GfxCursor32
+#include "sci/graphics/helpers.h" // for GuiResourceId
+
+namespace Sci {
+
+/**
+ * GfxMacCursor32 handles SCI32 games with native Mac cursor resources.
+ *
+ * GfxCursor32 was modeled after the PC SSCI structure in which cursors are
+ * views that use the game's palette. It draws the cursor directly to the
+ * game's frame. Mac cursors have their own individual palettes and are drawn
+ * independent of the rest of the game. GfxMacCursor32 uses CursorManager to
+ * handle this, since it supports cursor palettes, and disables the GfxCursor32
+ * functionality which CursorManager handles.
+ */
+class GfxMacCursor32 : public GfxCursor32 {
+public:
+ GfxMacCursor32() : GfxCursor32() {}
+
+ /**
+ * Sets the remap list used to map views to native Mac cursor resources.
+ */
+ void setMacCursorRemapList(int cursorCount, reg_t *cursors) override;
+
+ /**
+ * Sets the view used to render the cursor.
+ */
+ void setView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo) override;
+
+ /**
+ * Hides the cursor. Each call to `hide` will increment a hide counter,
+ * which must be returned to 0 before the cursor will be shown again.
+ */
+ void hide() override;
+
+ /**
+ * Shows the cursor, if the hide counter is returned to 0.
+ */
+ void unhide() override;
+
+ /**
+ * Shows the cursor regardless of the state of the hide counter.
+ */
+ void show() override;
+
+ /**
+ * Called by GfxFrameout, ignored since CursorManager handles Mac cursors.
+ */
+ void gonnaPaint(Common::Rect paintRect) override {}
+
+ /**
+ * Called by GfxFrameout, ignored since CursorManager handles Mac cursors.
+ */
+ void paintStarting() override {}
+
+ /**
+ * Called by GfxFrameout, ignored since CursorManager handles Mac cursors.
+ */
+ void donePainting() override {}
+
+private:
+ /**
+ * Renders the cursor at its new location, but ignored since CursorManager
+ * handles Mac cursors.
+ */
+ void move() override {}
+
+ /**
+ * Remap list of views to native Mac cursor resources.
+ */
+ Common::Array<uint16> _macCursorRemap;
+};
+
+} // End of namespace Sci
+
+#endif
diff --git a/engines/sci/module.mk b/engines/sci/module.mk
index 174bd8d..8004131 100644
--- a/engines/sci/module.mk
+++ b/engines/sci/module.mk
@@ -98,6 +98,7 @@ MODULE_OBJS += \
graphics/transitions32.o \
graphics/video32.o \
graphics/cursor32.o \
+ graphics/maccursor32.o \
sound/audio32.o \
sound/decoders/sol.o \
video/robot_decoder.o
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index d3f3d98..1f74139 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -1151,6 +1151,17 @@ Common::List<ResourceId> ResourceManager::listResources(ResourceType type, int m
return resources;
}
+bool ResourceManager::hasResourceType(ResourceType type) {
+ ResourceMap::iterator itr = _resMap.begin();
+ while (itr != _resMap.end()) {
+ if (itr->_value->getType() == type) {
+ return true;
+ }
+ ++itr;
+ }
+ return false;
+}
+
Resource *ResourceManager::findResource(ResourceId id, bool lock) {
// remap known incorrect audio36 and sync36 resource ids
if (id.getType() == kResourceTypeAudio36) {
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 5268e7a..783a574 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -391,6 +391,11 @@ public:
*/
Common::List<ResourceId> listResources(ResourceType type, int mapNumber = -1);
+ /**
+ * Returns if there are any resources of the specified type.
+ */
+ bool hasResourceType(ResourceType type);
+
void setAudioLanguage(int language);
int getAudioLanguage() const;
void changeAudioDirectory(Common::String path);
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index eac8022..c72e268 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -70,6 +70,7 @@
#include "sci/graphics/controls32.h"
#include "sci/graphics/cursor32.h"
#include "sci/graphics/frameout.h"
+#include "sci/graphics/maccursor32.h"
#include "sci/graphics/palette32.h"
#include "sci/graphics/remap32.h"
#include "sci/graphics/text32.h"
@@ -636,7 +637,11 @@ void SciEngine::initGraphics() {
#ifdef ENABLE_SCI32
if (getSciVersion() >= SCI_VERSION_2) {
// SCI32 graphic objects creation
- _gfxCursor32 = new GfxCursor32();
+ if (g_sci->getPlatform() == Common::kPlatformMacintosh && _resMan->hasResourceType(kResourceTypeCursor)) {
+ _gfxCursor32 = new GfxMacCursor32();
+ } else {
+ _gfxCursor32 = new GfxCursor32();
+ }
_gfxCompare = new GfxCompare(_gamestate->_segMan, _gfxCache, nullptr, _gfxCoordAdjuster);
_gfxPaint32 = new GfxPaint32(_gamestate->_segMan);
_gfxTransitions32 = new GfxTransitions32(_gamestate->_segMan);
More information about the Scummvm-git-logs
mailing list