- disable implicit conversions from float to TAngle

This commit is contained in:
Christoph Oelckers 2022-08-26 00:56:53 +02:00
commit f0fbdba593
66 changed files with 425 additions and 374 deletions

View file

@ -15,7 +15,9 @@ enum
struct FRemapTable
{
FRemapTable(int count = 256) { NumEntries = count; }
FRemapTable(const FRemapTable& o) = default;
FRemapTable& operator=(const FRemapTable& o) = default;
bool operator==(const FRemapTable& o);
void MakeIdentity();

View file

@ -317,7 +317,7 @@ FVoxelDef *R_LoadVoxelDef(int lumpnum, int spin)
voxdef->Voxel = vox;
voxdef->Scale = 1.;
voxdef->DroppedSpin = voxdef->PlacedSpin = spin;
voxdef->AngleOffset = 90.;
voxdef->AngleOffset = DAngle::fromDeg(90.);
Voxels.Push(vox);
VoxelDefs.Push(voxdef);

View file

@ -147,10 +147,10 @@ FSkyVertexBuffer::~FSkyVertexBuffer()
void FSkyVertexBuffer::SkyVertexDoom(int r, int c, bool zflip)
{
static const FAngle maxSideAngle = 60.f;
static const FAngle maxSideAngle = FAngle::fromDeg(60.f);
static const float scale = 10000.;
FAngle topAngle = (c / (float)mColumns * 360.f);
FAngle topAngle = FAngle::fromDeg((c / (float)mColumns * 360.f));
FAngle sideAngle = maxSideAngle * float(mRows - r) / float(mRows);
float height = sideAngle.Sin();
float realRadius = scale * sideAngle.Cos();
@ -190,10 +190,10 @@ void FSkyVertexBuffer::SkyVertexDoom(int r, int c, bool zflip)
void FSkyVertexBuffer::SkyVertexBuild(int r, int c, bool zflip)
{
static const FAngle maxSideAngle = 60.f;
static const FAngle maxSideAngle = FAngle::fromDeg(60.f);
static const float scale = 10000.;
FAngle topAngle = (c / (float)mColumns * 360.f);
FAngle topAngle = FAngle::fromDeg((c / (float)mColumns * 360.f));
FVector2 pos = topAngle.ToVector(scale);
float z = (!zflip) ? (mRows - r) * 4000.f : -(mRows - r) * 4000.f;

View file

@ -511,7 +511,8 @@ bool AssertObject(void * ob);
#define PARAM_SOUND_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); FSoundID x = param[p].i;
#define PARAM_COLOR_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); PalEntry x; x.d = param[p].i;
#define PARAM_FLOAT_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); double x = param[p].f;
#define PARAM_ANGLE_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); DAngle x = param[p].f;
#define PARAM_ANGLE_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); DAngle x = DAngle::fromDeg(param[p].f);
#define PARAM_FANGLE_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); FAngle x = FAngle::fromDeg(param[p].f);
#define PARAM_STRING_VAL_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_STRING); FString x = param[p].s();
#define PARAM_STRING_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_STRING); const FString &x = param[p].s();
#define PARAM_STATELABEL_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); int x = param[p].i;
@ -538,6 +539,7 @@ bool AssertObject(void * ob);
#define PARAM_COLOR(x) ++paramnum; PARAM_COLOR_AT(paramnum,x)
#define PARAM_FLOAT(x) ++paramnum; PARAM_FLOAT_AT(paramnum,x)
#define PARAM_ANGLE(x) ++paramnum; PARAM_ANGLE_AT(paramnum,x)
#define PARAM_FANGLE(x) ++paramnum; PARAM_FANGLE_AT(paramnum,x)
#define PARAM_STRING(x) ++paramnum; PARAM_STRING_AT(paramnum,x)
#define PARAM_STRING_VAL(x) ++paramnum; PARAM_STRING_VAL_AT(paramnum,x)
#define PARAM_STATELABEL(x) ++paramnum; PARAM_STATELABEL_AT(paramnum,x)

View file

@ -40,20 +40,9 @@ inline unsigned FloatToAngle(double f)
return xs_CRoundToInt((f)* (0x40000000 / 90.));
}
inline constexpr double AngleToFloat(unsigned f)
{
return f * (90. / 0x40000000);
}
inline constexpr double AngleToFloat(int f)
{
return f * (90. / 0x40000000);
}
#define FLOAT2FIXED(f) FloatToFixed(f)
#define FIXED2FLOAT(f) float(FixedToFloat(f))
#define FIXED2DBL(f) FixedToFloat(f)
#define ANGLE2DBL(f) AngleToFloat(f)
#endif

View file

@ -1158,40 +1158,85 @@ struct TAngle
TAngle() = default;
TAngle (vec_t amt)
: Degrees(amt)
private:
// Both constructors are needed to avoid unnecessary conversions when assigning to FAngle.
constexpr TAngle (float amt)
: Degrees((vec_t)amt)
{
}
constexpr TAngle (double amt)
: Degrees((vec_t)amt)
{
}
public:
static constexpr TAngle fromDeg(float deg)
{
return TAngle(deg);
}
static constexpr TAngle fromDeg(double deg)
{
return TAngle(deg);
}
static constexpr TAngle fromDeg(int deg)
{
return TAngle((vec_t)deg);
}
static constexpr TAngle fromDeg(unsigned deg)
{
return TAngle((vec_t)deg);
}
static constexpr TAngle fromRad(float rad)
{
return TAngle(float(rad * (180.0f / pi::pif())));
}
static constexpr TAngle fromRad(double rad)
{
return TAngle(double(rad * (180.0 / pi::pi())));
}
static constexpr TAngle fromBam(int f)
{
return TAngle(f * (90. / 0x40000000));
}
static constexpr TAngle fromBam(unsigned f)
{
return TAngle(f * (90. / 0x40000000));
}
TAngle(const TAngle &other) = default;
TAngle &operator= (const TAngle &other) = default;
/*
TAngle &operator= (double other)
{
Degrees = (decltype(Degrees))other;
return *this;
}
*/
// intentionally disabled so that common math functions cannot be accidentally called with a TAngle.
//operator vec_t() const { return Degrees; }
TAngle operator- () const
constexpr TAngle operator- () const
{
return TAngle(-Degrees);
}
TAngle &operator+= (TAngle other)
constexpr TAngle &operator+= (TAngle other)
{
Degrees += other.Degrees;
return *this;
}
TAngle &operator-= (TAngle other)
constexpr TAngle &operator-= (TAngle other)
{
Degrees -= other.Degrees;
return *this;
}
/*
TAngle &operator*= (TAngle other)
{
Degrees *= other.Degrees;
@ -1203,27 +1248,29 @@ struct TAngle
Degrees /= other.Degrees;
return *this;
}
*/
TAngle operator+ (TAngle other) const
constexpr TAngle operator+ (TAngle other) const
{
return Degrees + other.Degrees;
}
TAngle operator- (TAngle other) const
constexpr TAngle operator- (TAngle other) const
{
return Degrees - other.Degrees;
}
TAngle operator* (TAngle other) const
constexpr TAngle operator* (TAngle other) const
{
return Degrees * other.Degrees;
}
TAngle operator/ (TAngle other) const
constexpr TAngle operator/ (TAngle other) const
{
return Degrees / other.Degrees;
}
/*
TAngle &operator+= (vec_t other)
{
Degrees = Degrees + other;
@ -1235,19 +1282,21 @@ struct TAngle
Degrees = Degrees - other;
return *this;
}
*/
TAngle &operator*= (vec_t other)
constexpr TAngle &operator*= (vec_t other)
{
Degrees = Degrees * other;
return *this;
}
TAngle &operator/= (vec_t other)
constexpr TAngle &operator/= (vec_t other)
{
Degrees = Degrees / other;
return *this;
}
/*
TAngle operator+ (vec_t other) const
{
return Degrees + other;
@ -1257,79 +1306,82 @@ struct TAngle
{
return Degrees - other;
}
*/
/*
friend TAngle operator- (vec_t o1, TAngle o2)
{
return TAngle(o1 - o2.Degrees);
}
*/
TAngle operator* (vec_t other) const
constexpr TAngle operator* (vec_t other) const
{
return Degrees * other;
}
TAngle operator/ (vec_t other) const
constexpr TAngle operator/ (vec_t other) const
{
return Degrees / other;
}
// Should the comparisons consider an epsilon value?
bool operator< (TAngle other) const
constexpr bool operator< (TAngle other) const
{
return Degrees < other.Degrees;
}
bool operator> (TAngle other) const
constexpr bool operator> (TAngle other) const
{
return Degrees > other.Degrees;
}
bool operator<= (TAngle other) const
constexpr bool operator<= (TAngle other) const
{
return Degrees <= other.Degrees;
}
bool operator>= (TAngle other) const
constexpr bool operator>= (TAngle other) const
{
return Degrees >= other.Degrees;
}
bool operator== (TAngle other) const
constexpr bool operator== (TAngle other) const
{
return Degrees == other.Degrees;
}
bool operator!= (TAngle other) const
constexpr bool operator!= (TAngle other) const
{
return Degrees != other.Degrees;
}
bool operator< (vec_t other) const
constexpr bool operator< (vec_t other) const
{
return Degrees < other;
}
bool operator> (vec_t other) const
constexpr bool operator> (vec_t other) const
{
return Degrees > other;
}
bool operator<= (vec_t other) const
constexpr bool operator<= (vec_t other) const
{
return Degrees <= other;
}
bool operator>= (vec_t other) const
constexpr bool operator>= (vec_t other) const
{
return Degrees >= other;
}
bool operator== (vec_t other) const
constexpr bool operator== (vec_t other) const
{
return Degrees == other;
}
bool operator!= (vec_t other) const
constexpr bool operator!= (vec_t other) const
{
return Degrees != other;
}
@ -1348,7 +1400,7 @@ struct TAngle
return (vec_t)(BAM_FACTOR * (signed int)BAMs());
}
vec_t Radians() const
constexpr vec_t Radians() const
{
return vec_t(Degrees * (pi::pi() / 180.0));
}
@ -1394,13 +1446,13 @@ struct TAngle
// Emulates the old floatbob offset table with direct calls to trig functions.
inline double BobSin(double fb)
{
return TAngle<double>(double(fb * (180.0 / 32))).Sin() * 8;
return g_sindeg(double(fb * (180.0 / 32))) * 8;
}
template<class T>
inline TAngle<T> fabs (const TAngle<T> &deg)
{
return TAngle<T>(fabs(deg.Degrees));
return TAngle<T>::fromDeg(fabs(deg.Degrees));
}
template<class T>
@ -1409,6 +1461,7 @@ inline TAngle<T> deltaangle(const TAngle<T> &a1, const TAngle<T> &a2)
return (a2 - a1).Normalized180();
}
/*
template<class T>
inline TAngle<T> deltaangle(const TAngle<T> &a1, double a2)
{
@ -1420,6 +1473,7 @@ inline TAngle<T> deltaangle(double a1, const TAngle<T> &a2)
{
return (a2 - a1).Normalized180();
}
*/
template<class T>
inline TAngle<T> absangle(const TAngle<T> &a1, const TAngle<T> &a2)
@ -1427,27 +1481,29 @@ inline TAngle<T> absangle(const TAngle<T> &a1, const TAngle<T> &a2)
return fabs((a1 - a2).Normalized180());
}
/*
template<class T>
inline TAngle<T> absangle(const TAngle<T> &a1, double a2)
{
return fabs((a1 - a2).Normalized180());
}
*/
inline TAngle<double> VecToAngle(double x, double y)
{
return g_atan2(y, x) * (180.0 / pi::pi());
return TAngle<double>::fromDeg(g_atan2(y, x) * (180.0 / pi::pi()));
}
template<class T>
inline TAngle<T> VecToAngle (const TVector2<T> &vec)
{
return (T)g_atan2(vec.Y, vec.X) * (180.0 / pi::pi());
return TAngle<T>::fromDeg(g_atan2(vec.Y, vec.X) * (180.0 / pi::pi()));
}
template<class T>
inline TAngle<T> VecToAngle (const TVector3<T> &vec)
{
return (T)g_atan2(vec.Y, vec.X) * (180.0 / pi::pi());
return TAngle<T>::fromDeg(g_atan2(vec.Y, vec.X) * (180.0 / pi::pi()));
}
template<class T>
@ -1651,6 +1707,8 @@ typedef TRotator<double> DRotator;
typedef TMatrix3x3<double> DMatrix3x3;
typedef TAngle<double> DAngle;
constexpr DAngle nullAngle = DAngle::fromDeg(0.);
constexpr FAngle nullFAngle = FAngle::fromDeg(0.);
class Plane
{