diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/public/disp_vertindex.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/public/disp_vertindex.h')
| -rw-r--r-- | mp/src/public/disp_vertindex.h | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/mp/src/public/disp_vertindex.h b/mp/src/public/disp_vertindex.h new file mode 100644 index 00000000..42e26961 --- /dev/null +++ b/mp/src/public/disp_vertindex.h @@ -0,0 +1,150 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef DISP_VERTINDEX_H
+#define DISP_VERTINDEX_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+#include "tier0/dbg.h"
+
+
+// ------------------------------------------------------------------------ //
+// Helper class used for indexing vertices in the 2D grid.
+// ------------------------------------------------------------------------ //
+
+class CVertIndex
+{
+public:
+ CVertIndex();
+ CVertIndex( short ix, short iy );
+
+ void Init( short ix, short iy );
+
+ short& operator[]( short i );
+ short const& operator[]( short i ) const;
+ void operator+=( CVertIndex const &other );
+ void operator-=( CVertIndex const &other );
+ CVertIndex operator+( CVertIndex const &other ) const;
+ CVertIndex operator-( CVertIndex const &other ) const;
+ void operator<<=( int shift );
+ void operator>>=( int shift );
+ bool operator==( CVertIndex const &other ) const;
+ bool operator!=( CVertIndex const &other ) const;
+
+
+public:
+
+ short x, y;
+};
+
+
+// ------------------------------------------------------------------ //
+// Helper functions.
+// ------------------------------------------------------------------ //
+
+inline CVertIndex BuildOffsetVertIndex(
+ CVertIndex const &nodeIndex,
+ CVertIndex const &offset,
+ int mul )
+{
+ return CVertIndex( nodeIndex.x + offset.x * mul, nodeIndex.y + offset.y * mul );
+}
+
+
+// ------------------------------------------------------------------ //
+// CVertIndex inlines.
+// ------------------------------------------------------------------ //
+
+inline CVertIndex::CVertIndex()
+{
+}
+
+
+inline CVertIndex::CVertIndex( short ix, short iy )
+{
+ x = ix;
+ y = iy;
+}
+
+
+inline void CVertIndex::Init( short ix, short iy )
+{
+ x = ix;
+ y = iy;
+}
+
+
+inline short& CVertIndex::operator[]( short i )
+{
+ Assert( i >= 0 && i <= 1 );
+ return ((short*)this)[i];
+}
+
+
+inline short const& CVertIndex::operator[]( short i ) const
+{
+ Assert( i >= 0 && i <= 1 );
+ return ((short*)this)[i];
+}
+
+
+inline void CVertIndex::operator+=( CVertIndex const &other )
+{
+ x += other.x;
+ y += other.y;
+}
+
+
+inline void CVertIndex::operator-=( CVertIndex const &other )
+{
+ x -= other.x;
+ y -= other.y;
+}
+
+
+inline CVertIndex CVertIndex::operator+( CVertIndex const &other ) const
+{
+ return CVertIndex( x + other.x, y + other.y );
+}
+
+
+inline CVertIndex CVertIndex::operator-( CVertIndex const &other ) const
+{
+ return CVertIndex( x - other.x, y - other.y );
+}
+
+
+inline void CVertIndex::operator<<=( int shift )
+{
+ x <<= shift;
+ y <<= shift;
+}
+
+
+inline void CVertIndex::operator>>=( int shift )
+{
+ x >>= shift;
+ y >>= shift;
+}
+
+
+inline bool CVertIndex::operator==( CVertIndex const &other ) const
+{
+ return x==other.x && y==other.y;
+}
+
+
+inline bool CVertIndex::operator!=( CVertIndex const &other ) const
+{
+ return x!=other.x || y!=other.y;
+}
+
+
+#endif // DISP_VERTINDEX_H
|