[Scummvm-git-logs] scummvm master -> 2e11704ed9001721ccef7eb4038f8bcb8a631473

OMGPizzaGuy noreply at scummvm.org
Thu Jan 19 03:55:05 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:
2e11704ed9 ULTIMA8: Update box struct better match rect methods


Commit: 2e11704ed9001721ccef7eb4038f8bcb8a631473
    https://github.com/scummvm/scummvm/commit/2e11704ed9001721ccef7eb4038f8bcb8a631473
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-01-18T21:54:41-06:00

Commit Message:
ULTIMA8: Update box struct better match rect methods

Changed paths:
    engines/ultima/ultima8/misc/box.h
    engines/ultima/ultima8/world/actors/animation_tracker.cpp
    test/engines/ultima/ultima8/misc/box.h


diff --git a/engines/ultima/ultima8/misc/box.h b/engines/ultima/ultima8/misc/box.h
index aeb891c41d4..8216024a6ea 100644
--- a/engines/ultima/ultima8/misc/box.h
+++ b/engines/ultima/ultima8/misc/box.h
@@ -35,65 +35,54 @@ struct Box {
 	Box(int nx, int ny, int nz, int nxd, int nyd, int nzd)
 		: _x(nx), _y(ny), _z(nz), _xd(nxd), _yd(nyd), _zd(nzd) {}
 
-	void    Set(int nx, int ny, int nz, int nxd, int nyd, int nzd) {
-		_x = nx;
-		_y = ny;
-		_z = nz;
-		_xd = nxd;
-		_yd = nyd;
-		_zd = nzd;
-	}
-	void    Set(Box &o) {
-		*this = o;
+	// 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;
 	}
 
 	// Check to see if a Box is 'valid'
-	bool    IsValid() const {
-		return _xd > 0 && _yd > 0 && _zd > 0;
+	bool isValid() const {
+		return _xd >= 0 && _yd >= 0 && _zd >= 0;
 	}
 
 	// Check to see if a point is within the Box
-	bool    InBox(int px, int py, int pz) const {
+	bool contains(int px, int py, int pz) const {
 		return (px > (_x - _xd) && py > (_y - _yd) && pz >= _z &&
 		        px <= _x && py <= _y && pz < (_z + _zd));
 	}
 
 	// Move the Box (Relative)
-	void    MoveRel(int32 dx, int32 dy, int32 dz) {
+	void translate(int32 dx, int32 dy, int32 dz) {
 		_x += dx;
 		_y += dy;
 		_z += dz;
 	}
 
 	// Move the Box (Absolute)
-	void    MoveAbs(int32 nx, int32 ny, int32 nz) {
+	void moveTo(int32 nx, int32 ny, int32 nz) {
 		_x = nx;
 		_y = ny;
 		_z = nz;
 	}
 
-	// Resize the Box (Relative)
-	void    ResizeRel(int32 dxd, int32 dyd, int32 dzd) {
-		_xd += dxd;
-		_yd += dyd;
-		_zd += dzd;
-	}
-
 	// Resize the Box (Absolute)
-	void    ResizeAbs(int32 nxd, int32 nyd, int32 nzd) {
+	void resize(int32 nxd, int32 nyd, int32 nzd) {
 		_xd = nxd;
 		_yd = nyd;
 		_zd = nzd;
 	}
 
-	bool    Overlaps(const Box &o) const {
+	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;
 		return true;
 	}
 
-	bool operator == (const Box &o) const {
+	bool operator==(const Box &rhs) const { return equals(rhs); }
+	bool operator!=(const Box &rhs) const { return !equals(rhs); }
+
+	bool equals(const Box &o) const {
 		return (_x == o._x && _y == o._y && _z == o._z &&
 		        _xd == o._xd && _yd == o._yd && _zd == o._zd);
 	}
diff --git a/engines/ultima/ultima8/world/actors/animation_tracker.cpp b/engines/ultima/ultima8/world/actors/animation_tracker.cpp
index 62d18cbb8f8..5462a168b42 100644
--- a/engines/ultima/ultima8/world/actors/animation_tracker.cpp
+++ b/engines/ultima/ultima8/world/actors/animation_tracker.cpp
@@ -462,8 +462,8 @@ void AnimationTracker::checkWeaponHit() {
 
 
 	Box abox = a->getWorldBox();
-	abox.MoveAbs(_x, _y, _z);
-	abox.MoveRel(Direction_XFactor(_dir) * 32 * range, Direction_YFactor(_dir) * 32 * range, 0);
+	abox.moveTo(_x, _y, _z);
+	abox.translate(Direction_XFactor(_dir) * 32 * range, Direction_YFactor(_dir) * 32 * range, 0);
 
 #ifdef WATCHACTOR
 	if (a->getObjId() == watchactor) {
@@ -489,7 +489,7 @@ void AnimationTracker::checkWeaponHit() {
 
 		Box ibox = item->getWorldBox();
 
-		if (abox.Overlaps(ibox)) {
+		if (abox.overlaps(ibox)) {
 			hit = itemid;
 #ifdef WATCHACTOR
 			if (a->getObjId() == watchactor) {
diff --git a/test/engines/ultima/ultima8/misc/box.h b/test/engines/ultima/ultima8/misc/box.h
index 96367eb67b0..8d2e2f661bd 100644
--- a/test/engines/ultima/ultima8/misc/box.h
+++ b/test/engines/ultima/ultima8/misc/box.h
@@ -11,39 +11,39 @@ class U8BoxTestSuite : public CxxTest::TestSuite {
 
 	void test_simple_box() {
 		Ultima::Ultima8::Box box;
-		TS_ASSERT(!box.InBox(0,0,1));
-		TS_ASSERT(!box.InBox(0,1,0));
-		TS_ASSERT(!box.InBox(1,0,0));
-		box.ResizeRel(1,1,1);
-		TS_ASSERT(!box.InBox(-1,0,0));
-		TS_ASSERT(!box.InBox(0,-1,0));
-		TS_ASSERT(!box.InBox(0,0,-1));
-		TS_ASSERT(box.Overlaps(box));
+		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.contains(-1, 0, 0));
+		TS_ASSERT(!box.contains(0, -1, 0));
+		TS_ASSERT(!box.contains(0, 0, -1));
+		TS_ASSERT(box.overlaps(box));
 		TS_ASSERT(box == box);
-		box.ResizeRel(1,1,1);
-		TS_ASSERT(box.IsValid());
-		TS_ASSERT(box.Overlaps(box));
+		box.resize(2, 2, 2);
+		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.InBox(-1,-1,1));
-		TS_ASSERT(box.InBox(-1,-1,0));
-		box.MoveRel(0, 0, 1);
-		TS_ASSERT(!box.InBox(-1,-1,0));
-		TS_ASSERT(box.InBox(-1,-1,2));
+		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));
 
 		Ultima::Ultima8::Box box2(box);
 		TS_ASSERT(box == box2);
-		TS_ASSERT(box.Overlaps(box2));
+		TS_ASSERT(box.overlaps(box2));
 		TS_ASSERT(box2 == box);
-		TS_ASSERT(box2.Overlaps(box));
+		TS_ASSERT(box2.overlaps(box));
 
 		Ultima::Ultima8::Box box3(0, 0, 0, 2, 2, 3);
-		TS_ASSERT(!(box2 == box3));
-		TS_ASSERT(box2.Overlaps(box3));
-		TS_ASSERT(box3.Overlaps(box2));
-		box3.ResizeAbs(1,1,1);
-		TS_ASSERT(!box3.Overlaps(box2));
+		TS_ASSERT(box2 != box3);
+		TS_ASSERT(box2.overlaps(box3));
+		TS_ASSERT(box3.overlaps(box2));
+		box3.resize(1, 1, 1);
+		TS_ASSERT(!box3.overlaps(box2));
 	}
 
 };




More information about the Scummvm-git-logs mailing list