Merge branch 'wolf-operator-best-practices' of https://github.com/wolfman2000/stepmania

This commit is contained in:
Kyzentun
2014-12-01 15:46:19 -07:00
10 changed files with 218 additions and 97 deletions
+21 -6
View File
@@ -51,14 +51,29 @@ struct DeviceButtonPair
InputDevice device;
DeviceButton button;
DeviceButtonPair( InputDevice d, DeviceButton b ): device(d), button(b){ }
bool operator<( const DeviceButtonPair &other ) const
{
if( device != other.device )
return device < other.device;
return button < other.button;
}
};
inline bool operator<(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
if (lhs.device != rhs.device)
{
return lhs.device < rhs.device;
}
return lhs.button < rhs.button;
}
inline bool operator>(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return !operator<(lhs, rhs);
}
namespace
{
/* Maintain a set of all interesting buttons: buttons which are being held
+33 -10
View File
@@ -136,18 +136,41 @@ struct BMSObject
float position;
bool flag;
RString value;
bool operator<(const BMSObject &other) const
{
if( measure < other.measure ) return true;
if( measure > other.measure ) return false;
if( position < other.position ) return true;
if( position > other.position ) return false;
if( channel == 1 ) return false;
if( other.channel == 1 ) return true;
return channel < other.channel;
}
};
inline bool operator<(BMSObject const &lhs, BMSObject const &rhs)
{
if (lhs.measure != rhs.measure)
{
return lhs.measure < rhs.measure;
}
if (lhs.position != rhs.position)
{
return lhs.position < rhs.position;
}
if (lhs.channel == 1)
{
return false;
}
if (rhs.channel == 1)
{
return true;
}
return lhs.channel < rhs.channel;
}
inline bool operator>(BMSObject const &lhs, BMSObject const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(BMSObject const &lhs, BMSObject const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(BMSObject const &lhs, BMSObject const &rhs)
{
return !operator<(lhs, rhs);
}
struct BMSMeasure
{
float size;
+44 -25
View File
@@ -66,14 +66,18 @@ struct InputDeviceInfo
InputDevice id;
RString sDesc;
bool operator==( const InputDeviceInfo &other ) const
{
return id == other.id &&
sDesc == other.sDesc;
}
};
inline bool operator==(InputDeviceInfo const &lhs, InputDeviceInfo const &rhs)
{
return lhs.id == rhs.id && lhs.sDesc == rhs.sDesc;
}
inline bool operator!=(InputDeviceInfo const &lhs, InputDeviceInfo const &rhs)
{
return !operator==(lhs, rhs);
}
enum InputDeviceState
{
InputDeviceState_Connected, // has an InputHandler and controller is plugged in
@@ -336,25 +340,6 @@ public:
DeviceInput( InputDevice d, DeviceButton b, const RageTimer &t, int zVal=0 ):
device(d), button(b), level(0), z(zVal), bDown(false), ts(t) { }
bool operator==( const DeviceInput &other ) const
{
/* Return true if we represent the same button on the same device.
* Don't compare level or ts. */
return device == other.device && button == other.button;
}
bool operator!=( const DeviceInput &other ) const
{
return ! operator==( other );
}
bool operator<( const DeviceInput &other ) const
{
/* Return true if we represent the same button on the same device.
* Don't compare level or ts. */
if( device != other.device )
return device < other.device;
return button < other.button;
}
RString ToString() const;
bool FromString( const RString &s );
@@ -365,6 +350,40 @@ public:
bool IsMouse() const { return ::IsMouse(device); }
};
inline bool operator==(DeviceInput const &lhs, DeviceInput const &rhs)
{
/* Return true if we represent the same button on the same device.
* Don't compare level or ts. */
return lhs.device == rhs.device &&
lhs.button == rhs.button;
}
inline bool operator!=(DeviceInput const &lhs, DeviceInput const &rhs)
{
return !operator==(lhs, rhs);
}
inline bool operator<(DeviceInput const &lhs, DeviceInput const &rhs)
{
/* Only the devices and buttons matter here. */
if ( lhs.device != rhs.device)
{
return lhs.device < rhs.device;
}
return lhs.button < rhs.button;
}
inline bool operator>(DeviceInput const &lhs, DeviceInput const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(DeviceInput const &lhs, DeviceInput const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(DeviceInput const &lhs, DeviceInput const &rhs)
{
return !operator<(lhs, rhs);
}
typedef vector<DeviceInput> DeviceInputList;
#endif
-4
View File
@@ -4,10 +4,6 @@
#include <limits.h>
bool RageSurfaceColor::operator== ( const RageSurfaceColor &rhs ) const
{
return rhs.r == r && rhs.g == g && rhs.b == b && rhs.a == a;
}
int32_t RageSurfacePalette::FindColor( const RageSurfaceColor &color ) const
{
+14 -2
View File
@@ -10,10 +10,22 @@ struct RageSurfaceColor
RageSurfaceColor(): r(0), g(0), b(0), a(0) { }
RageSurfaceColor( uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ ):
r(r_), g(g_), b(b_), a(a_) { }
bool operator== ( const RageSurfaceColor &rhs ) const;
};
inline bool operator==(RageSurfaceColor const &lhs, RageSurfaceColor const &rhs)
{
return
lhs.r == rhs.r &&
lhs.g == rhs.g &&
lhs.b == rhs.b &&
lhs.a == rhs.a;
}
inline bool operator!=(RageSurfaceColor const &lhs, RageSurfaceColor const &rhs)
{
return !operator==(lhs, rhs);
}
struct RageSurfacePalette
{
RageSurfaceColor colors[256];
-35
View File
@@ -17,41 +17,6 @@ void RageTextureID::Init()
Policy = TEXTUREMAN->GetDefaultTexturePolicy();
}
bool RageTextureID::operator<(const RageTextureID &rhs) const
{
#define COMP(a) if(a<rhs.a) return true; if(a>rhs.a) return false;
COMP(filename);
COMP(iMaxSize);
COMP(bMipMaps);
COMP(iAlphaBits);
COMP(iGrayscaleBits);
COMP(iColorDepth);
COMP(bDither);
COMP(bStretch);
COMP(bHotPinkColorKey);
COMP(AdditionalTextureHints);
// COMP(Policy); // don't do this
#undef COMP
return false;
}
bool RageTextureID::operator==(const RageTextureID &rhs) const
{
#define EQUAL(a) (a==rhs.a)
return
EQUAL(filename) &&
EQUAL(iMaxSize) &&
EQUAL(bMipMaps) &&
EQUAL(iAlphaBits) &&
EQUAL(iGrayscaleBits) &&
EQUAL(iColorDepth) &&
EQUAL(bDither) &&
EQUAL(bStretch) &&
EQUAL(bHotPinkColorKey) &&
EQUAL(AdditionalTextureHints);
// EQUAL(Policy); // don't do this
}
void RageTextureID::SetFilename( const RString &fn )
{
filename = fn;
+54 -3
View File
@@ -48,9 +48,6 @@ struct RageTextureID
// These hints will be used in addition to any in the filename.
RString AdditionalTextureHints;
bool operator< (const RageTextureID &rhs) const;
bool operator== (const RageTextureID &rhs) const;
/* Used by RageTextureManager. Order is important; see RageTextureManager.cpp.
* Note that this property is not considered for ordering/equality. Loading
* a texture with a different loading policy will reuse the same texture with
@@ -71,6 +68,60 @@ struct RageTextureID
void SetFilename( const RString &fn );
};
inline bool operator==(RageTextureID const &lhs, RageTextureID const &rhs)
{
#define EQUAL(a) (lhs.a==rhs.a)
return
EQUAL(filename) &&
EQUAL(iMaxSize) &&
EQUAL(bMipMaps) &&
EQUAL(iAlphaBits) &&
EQUAL(iGrayscaleBits) &&
EQUAL(iColorDepth) &&
EQUAL(bDither) &&
EQUAL(bStretch) &&
EQUAL(bHotPinkColorKey) &&
EQUAL(AdditionalTextureHints);
// EQUAL(Policy); // don't do this
#undef EQUAL
}
inline bool operator!=(RageTextureID const &lhs, RageTextureID const &rhs)
{
return !operator==(lhs, rhs);
}
inline bool operator<(RageTextureID const &lhs, RageTextureID const &rhs)
{
#define COMP(a) if(lhs.a<rhs.a) return true; if(lhs.a>rhs.a) return false;
COMP(filename);
COMP(iMaxSize);
COMP(bMipMaps);
COMP(iAlphaBits);
COMP(iGrayscaleBits);
COMP(iColorDepth);
COMP(bDither);
COMP(bStretch);
COMP(bHotPinkColorKey);
COMP(AdditionalTextureHints);
// COMP(Policy); // don't do this
#undef COMP
return false;
}
inline bool operator>(RageTextureID const &lhs, RageTextureID const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(RageTextureID const &lhs, RageTextureID const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(RageTextureID const &lhs, RageTextureID const &rhs)
{
return !operator<(lhs, rhs);
}
#endif
/*
+9 -1
View File
@@ -40,7 +40,6 @@ struct File
dir=false; size=-1; hash=-1; priv=NULL; dirp=NULL;
}
bool operator== (const File &rhs) const { return lname==rhs.lname; }
bool operator< (const File &rhs) const { return lname<rhs.lname; }
bool equal(const File &rhs) const { return lname == rhs.lname; }
@@ -52,6 +51,15 @@ struct File
}
};
inline bool operator==(File const &lhs, File const &rhs)
{
return lhs.lname == rhs.lname;
}
inline bool operator!=(File const &lhs, File const &rhs)
{
return !operator==(lhs, rhs);
}
/** @brief This represents a directory. */
struct FileSet
{
+10 -1
View File
@@ -27,8 +27,17 @@ struct StepsTypeAndDifficulty
Difficulty cd;
StepsTypeAndDifficulty( const StepsType &s, const Difficulty &d ) : st( s ), cd( d ) { }
bool operator==( const StepsTypeAndDifficulty &stad ) const { return st == stad.st && cd == stad.cd; }
};
inline bool operator==(StepsTypeAndDifficulty const &lhs, StepsTypeAndDifficulty const &rhs)
{
return lhs.st == rhs.st && lhs.cd == rhs.cd;
}
inline bool operator!=(StepsTypeAndDifficulty const &lhs, StepsTypeAndDifficulty const &rhs)
{
return !operator==(lhs,rhs);
}
static void SetNextCombination()
{
vector<StepsTypeAndDifficulty> v;
+33 -10
View File
@@ -514,22 +514,45 @@ struct res_t
int w, h;
res_t(): w(0), h(0) { }
res_t( int w_, int h_ ): w(w_), h(h_) { }
res_t operator-( const res_t &rhs ) const
{
return res_t( w-rhs.w, h-rhs.h );
}
bool operator<( const res_t &rhs ) const
{
if( w != rhs.w )
return w < rhs.w;
return h < rhs.h;
res_t& operator-=( res_t const &rhs) {
w -= rhs.w;
h -= rhs.h;
return *this;
}
// Ugly: allow convert to a float for FindClosestEntry.
operator float() const { return w * 5000.0f + h; }
};
inline bool operator<(res_t const &lhs, res_t const &rhs)
{
if( lhs.w != rhs.w )
{
return lhs.w < rhs.w;
}
return lhs.h < rhs.h;
}
inline bool operator>(res_t const &lhs, res_t const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(res_t const &lhs, res_t const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(res_t const &lhs, res_t const &rhs)
{
return !operator<(lhs, rhs);
}
inline res_t operator-(res_t lhs, res_t const &rhs)
{
lhs -= rhs;
return lhs;
}
static void DisplayResolutionM( int &sel, bool ToSel, const ConfOption *pConfOption )
{
vector<res_t> v;