aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/graphics/screen_item32.h
diff options
context:
space:
mode:
authorColin Snover2016-12-18 22:47:57 -0600
committerColin Snover2016-12-19 14:46:58 -0600
commitba619a08dd5a2076c361155690736043f01b4703 (patch)
tree76e8bc802662ea2eee1d972d90585362c86635dc /engines/sci/graphics/screen_item32.h
parent6412b323860e9eb351efd46c57ea65ebd56b2823 (diff)
downloadscummvm-rg350-ba619a08dd5a2076c361155690736043f01b4703.tar.gz
scummvm-rg350-ba619a08dd5a2076c361155690736043f01b4703.tar.bz2
scummvm-rg350-ba619a08dd5a2076c361155690736043f01b4703.zip
SCI32: Change plane and screen item sorting algorithm
SSCI's last resort comparison here was to compare the object IDs of planes & screen items, but this randomly breaks (at least) the "you have died" dialog at the end of Phant1, and text & buttons in Hoyle5, even in SSCI itself. This commit changes last resort comparison to use a monotonically increasing ID instead, which keeps objects with identical priority & z-index in creation order when compared. Fixes Trac#9585.
Diffstat (limited to 'engines/sci/graphics/screen_item32.h')
-rw-r--r--engines/sci/graphics/screen_item32.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/engines/sci/graphics/screen_item32.h b/engines/sci/graphics/screen_item32.h
index 009b608f18..c2c4e43358 100644
--- a/engines/sci/graphics/screen_item32.h
+++ b/engines/sci/graphics/screen_item32.h
@@ -61,6 +61,13 @@ private:
*/
static uint16 _nextObjectId;
+ /**
+ * A serial used to identify the creation order of
+ * screen items, to ensure a stable sort order for
+ * screen items with identical priorities and z-indexes.
+ */
+ static uint32 _nextCreationId;
+
public:
/**
* The parent plane of this screen item.
@@ -120,6 +127,13 @@ private:
public:
/**
+ * The creation order number, which ensures a stable
+ * sort when screen items with identical priorities and
+ * z-indexes are added to the screen item list.
+ */
+ uint32 _creationId;
+
+ /**
* A descriptor for the cel object represented by the
* screen item.
*/
@@ -242,7 +256,26 @@ public:
}
if (_position.y + _z == other._position.y + other._z) {
- return _object < other._object;
+ // SSCI's last resort comparison here is to compare the _object
+ // IDs, but this is wrong and randomly breaks (at least):
+ //
+ // (1) the death dialog at the end of Phant1, where the ID of
+ // the text is often higher than the ID of the border;
+ // (2) text-based buttons and dialogues in Hoyle5, where the ID
+ // of the text is often lower than the ID of the
+ // button/dialogue background.
+ //
+ // This occurs because object IDs (in both ScummVM and SSCI) are
+ // reused, so objects created later may receive a lower ID,
+ // which makes them sort lower when the programmer intended them
+ // to sort higher.
+ //
+ // To fix this problem, we give each ScreenItem a monotonically
+ // increasing insertion ID at construction time, and compare
+ // these insertion IDs instead. They are more stable and cause
+ // objects with identical priority and z-index to be rendered in
+ // the order that they were created.
+ return _creationId < other._creationId;
}
}
@@ -260,7 +293,9 @@ public:
}
if (_position.y + _z == other._position.y + other._z) {
- return _object > other._object;
+ // This is different than SSCI; see ScreenItem::operator< for an
+ // explanation
+ return _creationId > other._creationId;
}
}