[Scummvm-git-logs] scummvm master -> a3833a98b98383cc59eb4d521d920238d2f7586c
OMGPizzaGuy
noreply at scummvm.org
Mon Sep 18 23:47:36 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:
a3833a98b9 ULTIMA8: Fix box isEmpty and add extend method.
Commit: a3833a98b98383cc59eb4d521d920238d2f7586c
https://github.com/scummvm/scummvm/commit/a3833a98b98383cc59eb4d521d920238d2f7586c
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-09-18T18:47:21-05:00
Commit Message:
ULTIMA8: Fix box isEmpty and add extend method.
Extend might be used to improve occlusion in item sorter by switching floor tiles together.
Changed paths:
engines/ultima/ultima8/misc/box.h
test/engines/ultima/ultima8/misc/box.h
diff --git a/engines/ultima/ultima8/misc/box.h b/engines/ultima/ultima8/misc/box.h
index 8216024a6ea..07f9b91ccf8 100644
--- a/engines/ultima/ultima8/misc/box.h
+++ b/engines/ultima/ultima8/misc/box.h
@@ -27,6 +27,12 @@
namespace Ultima {
namespace Ultima8 {
+/**
+ * Represents a worldspace bounding box and manipulation of those bounds.
+ * The box is build from a world point and positive dimensions
+ * The box has reversed coordinates for x and y, meaning those dimensions are
+ * subtracted from primary world point to calculate other points.
+ */
struct Box {
int32 _x, _y, _z;
int32 _xd, _yd, _zd;
@@ -37,7 +43,7 @@ struct Box {
// Check if the Box is empty (its width, height, or depth is 0) or invalid (its width, height, or depth are negative).
bool isEmpty() const {
- return _xd > 0 && _yd > 0 && _zd > 0;
+ return _xd <= 0 || _yd <= 0 || _zd <= 0;
}
// Check to see if a Box is 'valid'
@@ -73,12 +79,28 @@ struct Box {
}
bool overlaps(const Box &o) const {
- if (_x <= o._x - o._xd || o._x <= _x - _xd) return false;
- if (_y <= o._y - o._yd || o._y <= _y - _yd) return false;
- if (_z + _zd <= o._z || o._z + o._zd <= _z) return false;
+ if (_x <= o._x - o._xd || o._x <= _x - _xd)
+ return false;
+ if (_y <= o._y - o._yd || o._y <= _y - _yd)
+ return false;
+ if (_z + _zd <= o._z || o._z + o._zd <= _z)
+ return false;
return true;
}
+ void extend(const Box &o) {
+ int32 x2 = MIN(_x - _xd, o._x - o._xd);
+ int32 y2 = MIN(_y - _yd, o._y - o._yd);
+ int32 z2 = MAX(_z + _zd, o._z + o._zd);
+
+ _x = MAX(_x, o._x);
+ _y = MAX(_y, o._y);
+ _z = MIN(_z, o._z);
+ _xd = _x - x2;
+ _yd = _y - y2;
+ _zd = z2 - _z;
+ }
+
bool operator==(const Box &rhs) const { return equals(rhs); }
bool operator!=(const Box &rhs) const { return !equals(rhs); }
diff --git a/test/engines/ultima/ultima8/misc/box.h b/test/engines/ultima/ultima8/misc/box.h
index 8d2e2f661bd..210301097b1 100644
--- a/test/engines/ultima/ultima8/misc/box.h
+++ b/test/engines/ultima/ultima8/misc/box.h
@@ -10,24 +10,35 @@ class U8BoxTestSuite : public CxxTest::TestSuite {
}
void test_simple_box() {
+ // Note: These tests expect Box has reversed coordinates in x and y.
Ultima::Ultima8::Box box;
- TS_ASSERT(!box.contains(0,0,1));
- TS_ASSERT(!box.contains(0, 1, 0));
- TS_ASSERT(!box.contains(1, 0, 0));
+ TS_ASSERT(box.isEmpty());
+ TS_ASSERT(box.isValid());
+ TS_ASSERT(!box.overlaps(box));
+ TS_ASSERT(box == box);
+ TS_ASSERT(!box.contains(0, 0, 0));
+ TS_ASSERT(!box.contains(0, 0, 1));
+ TS_ASSERT(!box.contains(0, -1, 0));
+ TS_ASSERT(!box.contains(-1, 0, 0));
+
box.resize(1, 1, 1);
+ TS_ASSERT(!box.isEmpty());
+ TS_ASSERT(box.isValid());
+ TS_ASSERT(box.contains(0, 0, 0));
TS_ASSERT(!box.contains(-1, 0, 0));
TS_ASSERT(!box.contains(0, -1, 0));
- TS_ASSERT(!box.contains(0, 0, -1));
+ TS_ASSERT(!box.contains(0, 0, 1));
TS_ASSERT(box.overlaps(box));
TS_ASSERT(box == box);
+
box.resize(2, 2, 2);
+ TS_ASSERT(!box.isEmpty());
TS_ASSERT(box.isValid());
TS_ASSERT(box.overlaps(box));
TS_ASSERT(box == box);
-
- // Note: These tests expect Box has reversed coordinates in x and y.
TS_ASSERT(box.contains(-1, -1, 1));
TS_ASSERT(box.contains(-1, -1, 0));
+
box.moveTo(0, 0, 1);
TS_ASSERT(!box.contains(-1, -1, 0));
TS_ASSERT(box.contains(-1, -1, 2));
@@ -44,6 +55,17 @@ class U8BoxTestSuite : public CxxTest::TestSuite {
TS_ASSERT(box3.overlaps(box2));
box3.resize(1, 1, 1);
TS_ASSERT(!box3.overlaps(box2));
+
+ box3.moveTo(2, 2, 2);
+ box.extend(box3);
+ TS_ASSERT(!box.isEmpty());
+ TS_ASSERT(box.isValid());
+ TS_ASSERT(box._x == 2);
+ TS_ASSERT(box._y == 2);
+ TS_ASSERT(box._z == 1);
+ TS_ASSERT(box._xd == 4);
+ TS_ASSERT(box._yd == 4);
+ TS_ASSERT(box._zd == 2);
}
};
More information about the Scummvm-git-logs
mailing list