Merge pull request #10401 from tupaschoal/std-coords

Standardize Coords and TileCoords objects
This commit is contained in:
Duncan 2019-12-21 10:22:11 +00:00 committed by GitHub
commit 19f9fef532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 22 deletions

View File

@ -26,6 +26,7 @@
#include "../world/Banner.h" #include "../world/Banner.h"
#include "../world/Climate.h" #include "../world/Climate.h"
#include "../world/Footpath.h" #include "../world/Footpath.h"
#include "../world/Location.hpp"
#include "../world/Map.h" #include "../world/Map.h"
#include "../world/Park.h" #include "../world/Park.h"
#include "../world/Scenery.h" #include "../world/Scenery.h"

View File

@ -149,27 +149,38 @@ struct CoordsXY
{ {
return { floor2(x, 32), floor2(y, 32) }; return { floor2(x, 32), floor2(y, 32) };
} }
bool isNull() const
{
return x == COORDS_NULL;
};
}; };
struct TileCoordsXY struct TileCoordsXY
{ {
int32_t x = 0;
int32_t y = 0;
TileCoordsXY() = default; TileCoordsXY() = default;
constexpr TileCoordsXY(int32_t x_, int32_t y_) constexpr TileCoordsXY(int32_t x_, int32_t y_)
: x(x_) : x(x_)
, y(y_) , y(y_)
{ {
} }
explicit TileCoordsXY(CoordsXY c) explicit TileCoordsXY(CoordsXY c)
: x(c.x / 32) : x(c.x / 32)
, y(c.y / 32) , y(c.y / 32)
{ {
} }
TileCoordsXY& operator+=(const TileCoordsXY rhs) TileCoordsXY& operator+=(const TileCoordsXY rhs)
{ {
x += rhs.x; x += rhs.x;
y += rhs.y; y += rhs.y;
return *this; return *this;
} }
TileCoordsXY& operator-=(const TileCoordsXY rhs) TileCoordsXY& operator-=(const TileCoordsXY rhs)
{ {
x -= rhs.x; x -= rhs.x;
@ -209,7 +220,10 @@ struct TileCoordsXY
return rotatedCoords; return rotatedCoords;
} }
int32_t x = 0, y = 0; bool isNull() const
{
return x == COORDS_NULL;
};
}; };
struct CoordsXYZ : public CoordsXY struct CoordsXYZ : public CoordsXY
@ -250,27 +264,29 @@ struct CoordsXYZ : public CoordsXY
} }
}; };
struct TileCoordsXYZ struct TileCoordsXYZ : public TileCoordsXY
{ {
int32_t z = 0;
TileCoordsXYZ() = default; TileCoordsXYZ() = default;
TileCoordsXYZ(int32_t x_, int32_t y_, int32_t z_) constexpr TileCoordsXYZ(int32_t x_, int32_t y_, int32_t z_)
: x(x_) : TileCoordsXY(x_, y_)
, y(y_)
, z(z_) , z(z_)
{ {
} }
explicit TileCoordsXYZ(CoordsXY c, int32_t z_)
: x(c.x / 32) TileCoordsXYZ(CoordsXY c, int32_t z_)
, y(c.y / 32) : TileCoordsXY(c)
, z(z_) , z(z_)
{ {
} }
explicit TileCoordsXYZ(CoordsXYZ c) explicit TileCoordsXYZ(CoordsXYZ c)
: x(c.x / 32) : TileCoordsXY(c)
, y(c.y / 32)
, z(c.z / 8) , z(c.z / 8)
{ {
} }
TileCoordsXYZ& operator+=(const TileCoordsXY rhs) TileCoordsXYZ& operator+=(const TileCoordsXY rhs)
{ {
x += rhs.x; x += rhs.x;
@ -284,10 +300,12 @@ struct TileCoordsXYZ
y -= rhs.y; y -= rhs.y;
return *this; return *this;
} }
bool operator==(const TileCoordsXYZ& other) const bool operator==(const TileCoordsXYZ& other) const
{ {
return x == other.x && y == other.y && z == other.z; return x == other.x && y == other.y && z == other.z;
} }
bool operator!=(const TileCoordsXYZ& other) const bool operator!=(const TileCoordsXYZ& other) const
{ {
return !(*this == other); return !(*this == other);
@ -297,8 +315,6 @@ struct TileCoordsXYZ
{ {
return { x * 32, y * 32, z * 8 }; return { x * 32, y * 32, z * 8 };
} }
int32_t x = 0, y = 0, z = 0;
}; };
/** /**
@ -384,22 +400,30 @@ struct CoordsXYZD : public CoordsXYZ
{ {
return !(*this == other); return !(*this == other);
} }
bool isNull() const
{
return x == COORDS_NULL;
};
}; };
struct TileCoordsXYZD struct TileCoordsXYZD : public TileCoordsXYZ
{ {
int32_t x, y, z;
Direction direction; Direction direction;
bool isNull() const TileCoordsXYZD() = default;
constexpr TileCoordsXYZD(int32_t x_, int32_t y_, int32_t z_, Direction d_)
: TileCoordsXYZ(x_, y_, z_)
, direction(d_)
{ {
return x == COORDS_NULL; }
};
TileCoordsXYZD(CoordsXY c_, int32_t z_, Direction d_)
: TileCoordsXYZ(c_, z_)
, direction(d_)
{
}
TileCoordsXYZD(CoordsXYZ c_, Direction d_)
: TileCoordsXYZ(c_)
, direction(d_)
{
}
CoordsXYZD ToCoordsXYZD() const CoordsXYZD ToCoordsXYZD() const
{ {