[Scummvm-git-logs] scummvm master -> 00583aa7f5baffd65cbde03455c90728db2dd1a1

OMGPizzaGuy noreply at scummvm.org
Wed Jan 18 05:20:14 UTC 2023


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:
00583aa7f5 ULTIMA8: Add basic test for sort item occludes


Commit: 00583aa7f5baffd65cbde03455c90728db2dd1a1
    https://github.com/scummvm/scummvm/commit/00583aa7f5baffd65cbde03455c90728db2dd1a1
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-17T23:19:09-06:00

Commit Message:
ULTIMA8: Add basic test for sort item occludes

Changed paths:
    engines/ultima/ultima8/world/item_sorter.cpp
    engines/ultima/ultima8/world/sort_item.h
    test/engines/ultima/ultima8/world/sort_item.h


diff --git a/engines/ultima/ultima8/world/item_sorter.cpp b/engines/ultima/ultima8/world/item_sorter.cpp
index 079ee409fe9..8fbf42c7c7e 100644
--- a/engines/ultima/ultima8/world/item_sorter.cpp
+++ b/engines/ultima/ultima8/world/item_sorter.cpp
@@ -128,20 +128,7 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
 	si->_yFar = si->_y - yd;
 	si->_zTop = si->_z + zd;
 
-	// Screenspace bounding box left extent    (LNT x coord)
-	si->_sxLeft = (si->_xLeft - si->_y) / 4 - _camSx;
-	// Screenspace bounding box right extent   (RFT x coord)
-	si->_sxRight = (si->_x - si->_yFar) / 4 - _camSx;
-
-	// Screenspace bounding box top x coord    (LFT x coord)
-	si->_sxTop = (si->_xLeft - si->_yFar) / 4 - _camSx;
-	// Screenspace bounding box top extent     (LFT y coord)
-	si->_syTop = (si->_xLeft + si->_yFar) / 8 - si->_zTop - _camSy;
-
-	// Screenspace bounding box bottom x coord (RNB x coord)
-	si->_sxBot = (si->_x - si->_y) / 4 - _camSx;
-	// Screenspace bounding box bottom extent  (RNB y coord)
-	si->_syBot = (si->_x + si->_y) / 8 - si->_z - _camSy;
+	si->calculateBoxBounds(_camSx, _camSy);
 
 	// Real Screenspace coords
 	si->_sx = si->_sxBot - frame->_xoff;   // Left
@@ -420,7 +407,8 @@ uint16 ItemSorter::Trace(int32 x, int32 y, HitFace *face, bool item_highlight) {
 	// We then check to see if the item has a point where the trace goes.
 	// Finally we then set the selected SortItem if it's '_order' is highest
 
-	if (!selected) for (it = _items; it != nullptr; it = it->_next) {
+	if (!selected) {
+		for (it = _items; it != nullptr; it = it->_next) {
 			if (!it->_itemNum) continue;
 
 			// Doesn't Overlap
@@ -440,6 +428,7 @@ uint16 ItemSorter::Trace(int32 x, int32 y, HitFace *face, bool item_highlight) {
 			// Ok now check against selected
 			if (!selected || (it->_order > selected->_order)) selected = it;
 		}
+	}
 
 	if (selected) {
 
diff --git a/engines/ultima/ultima8/world/sort_item.h b/engines/ultima/ultima8/world/sort_item.h
index d538ace0bd2..76e95e55ffa 100644
--- a/engines/ultima/ultima8/world/sort_item.h
+++ b/engines/ultima/ultima8/world/sort_item.h
@@ -217,6 +217,9 @@ struct SortItem {
 
 	// Functions
 
+	// Calculate screenspace box bounds at center point from worldspace bounds
+	inline void calculateBoxBounds(int32 sx, int32 sy);
+
 	// Screenspace check to see if this overlaps si2
 	inline bool overlap(const SortItem &si2) const;
 
@@ -234,6 +237,23 @@ struct SortItem {
 	Common::String dumpInfo() const;
 };
 
+inline void SortItem::calculateBoxBounds(int32 sx, int32 sy) {
+	// Screenspace bounding box left extent    (LNT x coord)
+	_sxLeft = (_xLeft - _y) / 4 - sx;
+	// Screenspace bounding box right extent   (RFT x coord)
+	_sxRight = (_x - _yFar) / 4 - sx;
+
+	// Screenspace bounding box top x coord    (LFT x coord)
+	_sxTop = (_xLeft - _yFar) / 4 - sx;
+	// Screenspace bounding box top extent     (LFT y coord)
+	_syTop = (_xLeft + _yFar) / 8 - _zTop - sy;
+
+	// Screenspace bounding box bottom x coord (RNB x coord)
+	_sxBot = (_x - _y) / 4 - sx;
+	// Screenspace bounding box bottom extent  (RNB y coord)
+	_syBot = (_x + _y) / 8 - _z - sy;
+}
+
 inline bool SortItem::overlap(const SortItem &si2) const {
 	const int point_top_diff[2] = { _sxTop - si2._sxBot, _syTop - si2._syBot };
 	const int point_bot_diff[2] = { _sxBot - si2._sxTop, _syBot - si2._syTop };
diff --git a/test/engines/ultima/ultima8/world/sort_item.h b/test/engines/ultima/ultima8/world/sort_item.h
index 9ef0eb2dae2..4c4d02e8ed5 100644
--- a/test/engines/ultima/ultima8/world/sort_item.h
+++ b/test/engines/ultima/ultima8/world/sort_item.h
@@ -154,4 +154,23 @@ class U8SortItemTestSuite : public CxxTest::TestSuite {
 		TS_ASSERT(si1.below(si2));
 		TS_ASSERT(!si2.below(si1));
 	}
+
+	/* Overlapping non-flat occludes flat */
+	void test_basic_occludes() {
+		Ultima::Ultima8::SortItem si1(nullptr);
+		Ultima::Ultima8::SortItem si2(nullptr);
+
+		si1._xLeft = si2._xLeft = 0;
+		si1._yFar = si2._yFar = 0;
+		si1._z = si2._z = 0;
+		si1._y = si2._y = 128;
+		si1._x = si2._x = 128;
+		si1._zTop = 16;
+		si2._zTop = 0;
+		si1.calculateBoxBounds(0, 0);
+		si2.calculateBoxBounds(0, 0);
+
+		TS_ASSERT(si1.occludes(si2));
+		TS_ASSERT(!si2.occludes(si1));
+	}
 };




More information about the Scummvm-git-logs mailing list