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

This commit is contained in:
Matthew Jimenez
2020-08-14 11:57:52 -05:00
parent 5b96eb6bff
commit 6d68e93017
8 changed files with 33 additions and 53 deletions
@@ -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;
}
@@ -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;
}
+3 -1
View File
@@ -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());
@@ -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);
}
}
@@ -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());
}
+8 -39
View File
@@ -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 {
+2 -2
View File
@@ -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;
@@ -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;