[Scummvm-git-logs] scummvm master -> 6d68e93017656908e0071fff62c18e7a224d1a1f

OMGPizzaGuy 48367439+OMGPizzaGuy at users.noreply.github.com
Fri Aug 14 16:59:58 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:
6d68e93017 ULTIMA8: Rename methods in Ultima8::Rect to match Common::Rect and remove unused methods.


Commit: 6d68e93017656908e0071fff62c18e7a224d1a1f
    https://github.com/scummvm/scummvm/commit/6d68e93017656908e0071fff62c18e7a224d1a1f
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2020-08-14T11:57:52-05:00

Commit Message:
ULTIMA8: Rename methods in Ultima8::Rect to match Common::Rect and remove unused methods.

Changed paths:
    engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
    engines/ultima/ultima8/gumps/container_gump.cpp
    engines/ultima/ultima8/gumps/gump.cpp
    engines/ultima/ultima8/gumps/paperdoll_gump.cpp
    engines/ultima/ultima8/gumps/widgets/text_widget.cpp
    engines/ultima/ultima8/misc/rect.h
    engines/ultima/ultima8/world/current_map.cpp
    engines/ultima/ultima8/world/snap_process.cpp


diff --git a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp b/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
index d6b8bee248..9c8ad628da 100644
--- a/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
+++ b/engines/ultima/ultima8/graphics/base_soft_render_surface.cpp
@@ -46,7 +46,8 @@ BaseSoftRenderSurface::BaseSoftRenderSurface(Graphics::ManagedSurface *s) :
 	_ox(0), _oy(0), _width(0), _height(0), _pitch(0), _zPitch(0),
 	_flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
 	_surface(s), _rttTex(nullptr) {
-	_clipWindow.ResizeAbs(_width = _surface->w, _height = _surface->h);
+	_clipWindow.setWidth(_width = _surface->w);
+	_clipWindow.setHeight(_height = _surface->h);
 	_pitch = _surface->pitch;
 	_bitsPerPixel = _surface->format.bpp();
 	_bytesPerPixel = _surface->format.bytesPerPixel;
@@ -122,7 +123,8 @@ BaseSoftRenderSurface::BaseSoftRenderSurface(int w, int h, int bpp,
 	_ox(0), _oy(0), _width(0), _height(0), _pitch(0), _zPitch(0),
 	_flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0), _surface(nullptr),
 	_rttTex(nullptr) {
-	_clipWindow.ResizeAbs(_width = w, _height = h);
+	_clipWindow.setWidth(_width = w);
+	_clipWindow.setHeight(_height = h);
 
 	switch (bpp) {
 	case 15:
@@ -184,7 +186,8 @@ BaseSoftRenderSurface::BaseSoftRenderSurface(int w, int h, uint8 *buf) :
 	_ox(0), _oy(0), _width(0), _height(0), _pitch(0), _zPitch(0),
 	_flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0),
 	_surface(nullptr), _rttTex(nullptr) {
-	_clipWindow.ResizeAbs(_width = w, _height = h);
+	_clipWindow.setWidth(_width = w);
+	_clipWindow.setHeight(_height = h);
 
 	int bpp = RenderSurface::_format.bpp();
 
@@ -207,7 +210,8 @@ BaseSoftRenderSurface::BaseSoftRenderSurface(int w, int h) :
 	_ox(0), _oy(0), _width(0), _height(0), _pitch(0), _zPitch(0),
 	_flipped(false), _clipWindow(0, 0, 0, 0), _lockCount(0), _surface(nullptr),
 	_rttTex(nullptr) {
-	_clipWindow.ResizeAbs(_width = w, _height = h);
+	_clipWindow.setWidth(_width = w);
+	_clipWindow.setHeight(_height = h);
 
 	int bpp = RenderSurface::_format.bpp();
 
@@ -411,7 +415,9 @@ void BaseSoftRenderSurface::CreateNativePalette(Palette *palette, int maxindex)
 // r: Rect object to fill
 //
 void BaseSoftRenderSurface::GetSurfaceDims(Rect &r) const {
-	r.Set(_ox, _oy, _width, _height);
+	r.moveTo(_ox, _oy);
+	r.setWidth(_width);
+	r.setHeight(_height);
 }
 
 //
@@ -477,7 +483,8 @@ int16 BaseSoftRenderSurface::CheckClipped(const Rect &c) const {
 	r.clip(_clipWindow);
 
 	// Clipped away to the void
-	if (!r.IsValid()) return -1;
+	if (!r.isValidRect())
+		return -1;
 	else if (r == c) return 0;
 	else return 1;
 }
diff --git a/engines/ultima/ultima8/gumps/container_gump.cpp b/engines/ultima/ultima8/gumps/container_gump.cpp
index 4feebf7301..cd9145371b 100644
--- a/engines/ultima/ultima8/gumps/container_gump.cpp
+++ b/engines/ultima/ultima8/gumps/container_gump.cpp
@@ -550,7 +550,9 @@ bool ContainerGump::loadData(Common::ReadStream *rs, uint32 version) {
 	int32 iay = static_cast<int32>(rs->readUint32LE());
 	int32 iaw = static_cast<int32>(rs->readUint32LE());
 	int32 iah = static_cast<int32>(rs->readUint32LE());
-	_itemArea.Set(iax, iay, iaw, iah);
+	_itemArea.moveTo(iax, iay);
+	_itemArea.setWidth(iaw);
+	_itemArea.setHeight(iah);
 
 	return true;
 }
diff --git a/engines/ultima/ultima8/gumps/gump.cpp b/engines/ultima/ultima8/gumps/gump.cpp
index 332af08c12..009b715549 100644
--- a/engines/ultima/ultima8/gumps/gump.cpp
+++ b/engines/ultima/ultima8/gumps/gump.cpp
@@ -836,7 +836,9 @@ bool Gump::loadData(Common::ReadStream *rs, uint32 version) {
 	int dy = static_cast<int32>(rs->readUint32LE());
 	int dw = static_cast<int32>(rs->readUint32LE());
 	int dh = static_cast<int32>(rs->readUint32LE());
-	_dims.Set(dx, dy, dw, dh);
+	_dims.moveTo(dx, dy);
+	_dims.setWidth(dw);
+	_dims.setHeight(dh);
 
 	_flags = rs->readUint32LE();
 	_layer = static_cast<int32>(rs->readUint32LE());
diff --git a/engines/ultima/ultima8/gumps/paperdoll_gump.cpp b/engines/ultima/ultima8/gumps/paperdoll_gump.cpp
index eae4c79fe2..03083b861e 100644
--- a/engines/ultima/ultima8/gumps/paperdoll_gump.cpp
+++ b/engines/ultima/ultima8/gumps/paperdoll_gump.cpp
@@ -399,7 +399,7 @@ void PaperdollGump::ChildNotify(Gump *child, uint32 message) {
 			statsgump->GetDims(sr);
 			sr.grow(-2);
 			statsgump->GumpRectToScreenSpace(sr);
-			if (!sr.Overlaps(rect))
+			if (!sr.intersects(rect))
 				statsgump->setRelativePosition(BOTTOM_RIGHT, -5, -5);
 		}
 	}
diff --git a/engines/ultima/ultima8/gumps/widgets/text_widget.cpp b/engines/ultima/ultima8/gumps/widgets/text_widget.cpp
index b7c5363694..3c4a6f1590 100644
--- a/engines/ultima/ultima8/gumps/widgets/text_widget.cpp
+++ b/engines/ultima/ultima8/gumps/widgets/text_widget.cpp
@@ -134,7 +134,7 @@ bool TextWidget::setupNextText() {
 			_dims.setWidth(sr.width());
 			_dims.setHeight(sr.height());
 
-			sr.Set(0, 0, 0, _dims.top);
+			sr = Rect(0, 0, 0, _dims.top);
 			ScreenSpaceToGumpRect(sr, ROUND_OUTSIDE);
 			_dims.moveTo(_dims.left, sr.height());
 		}
diff --git a/engines/ultima/ultima8/misc/rect.h b/engines/ultima/ultima8/misc/rect.h
index 418c506b97..f8cd2d0395 100644
--- a/engines/ultima/ultima8/misc/rect.h
+++ b/engines/ultima/ultima8/misc/rect.h
@@ -26,6 +26,10 @@
 namespace Ultima {
 namespace Ultima8 {
 
+// TODO: Replace Ultima8::Rect with Common::Rect
+// The key difference between Ultima8::Rect and Common::Rect is the use of int32 for variables.
+// Attempts to change this may cause the game to be unstable.
+
 struct Rect {
 	int32 left, top;
 	int32 right, bottom;
@@ -54,16 +58,9 @@ struct Rect {
 		bottom += offset;
 	}
 
-	void    Set(int nx, int ny, int nw, int nh) {
-		left = nx;
-		top = ny;
-		right = nx + nw;
-		bottom = ny + nh;
-	}
-
 	// Check to see if a Rectangle is 'valid'
-	bool    IsValid() const {
-		return right > left && bottom > top;
+	bool isValidRect() const {
+		return (left <= right && top <= bottom);
 	}
 
 	// Check to see if a point is within the Rectangle
@@ -87,12 +84,6 @@ struct Rect {
 		left = x;
 	}
 
-	// Resize the Rect (Absolute)
-	void    ResizeAbs(int32 nw, int32 nh) {
-		right = left + nw;
-		bottom = top + nh;
-	}
-
 	void clip(const Rect &r) {
 		if (top < r.top) top = r.top;
 		else if (top > r.bottom) top = r.bottom;
@@ -107,30 +98,8 @@ struct Rect {
 		else if (right > r.right) right = r.right;
 	}
 
-	// Union/Add this rect with another
-	void    Union(int ox, int oy, int ow, int oh) {
-		int x2 = right,     y2 = bottom;
-		int ox2 = ox + ow,  oy2 = oy + oh;
-
-		if (ox < left) left = ox;
-		else if (ox2 > x2) x2 = ox2;
-
-		if (oy < top) top = ox;
-		else if (oy2 > y2) y2 = ox2;
-
-		right = x2;
-		bottom = y2;
-	}
-
-	// Union/Add this rect with another
-	void    Union(const Rect &o) {
-		Union(o.left, o.top, o.width(), o.height());
-	}
-
-	bool    Overlaps(const Rect &o) const {
-		if (right <= o.left || o.right <= left) return false;
-		if (bottom <= o.top || o.bottom <= top) return false;
-		return true;
+	bool intersects(const Rect &r) const {
+		return (left < r.right) && (r.left < right) && (top < r.bottom) && (r.top < bottom);
 	}
 
 	bool equals(const Rect &o) const {
diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp
index e8817298bb..79d54158f5 100644
--- a/engines/ultima/ultima8/world/current_map.cpp
+++ b/engines/ultima/ultima8/world/current_map.cpp
@@ -551,7 +551,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
 
 				const Rect itemrect(ix - ixd, iy - iyd, ix, iy);
 
-				if (!itemrect.Overlaps(searchrange))
+				if (!itemrect.intersects(searchrange))
 					continue;
 
 				// check item against loopscript
@@ -621,7 +621,7 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
 
 				const Rect itemrect(ix - ixd, iy - iyd, ix, iy);
 
-				if (!itemrect.Overlaps(searchrange))
+				if (!itemrect.intersects(searchrange))
 					continue;
 
 				bool ok = false;
diff --git a/engines/ultima/ultima8/world/snap_process.cpp b/engines/ultima/ultima8/world/snap_process.cpp
index 83b1a3e258..2d76785556 100644
--- a/engines/ultima/ultima8/world/snap_process.cpp
+++ b/engines/ultima/ultima8/world/snap_process.cpp
@@ -76,7 +76,7 @@ void SnapProcess::updateCurrentEgg() {
 		Rect r;
 		egg->getLocation(x, y, z);
 		getSnapEggRange(egg, r);
-		if (r.Overlaps(arect) && (az < z + 0x30 && az > z - 0x30)) {
+		if (r.intersects(arect) && (az < z + 0x30 && az > z - 0x30)) {
 			_currentSnapEgg = *iter;
 			_currentSnapEggRange = r;
 			CameraProcess::SetCameraProcess(new CameraProcess(_currentSnapEgg));
@@ -116,7 +116,7 @@ bool SnapProcess::isNpcInRangeOfCurrentEgg() const {
 
 	Rect arect(ax, ay, ax + axd, ay + ayd);
 
-	if (!_currentSnapEggRange.Overlaps(arect))
+	if (!_currentSnapEggRange.intersects(arect))
 		return false;
 	if (az > z + 0x30 || az < z - 0x30)
 		return false;




More information about the Scummvm-git-logs mailing list