summaryrefslogtreecommitdiff
path: root/game/server/variant_t.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/variant_t.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/variant_t.h')
-rw-r--r--game/server/variant_t.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/game/server/variant_t.h b/game/server/variant_t.h
new file mode 100644
index 0000000..d5e93ea
--- /dev/null
+++ b/game/server/variant_t.h
@@ -0,0 +1,122 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef VARIANT_T_H
+#define VARIANT_T_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+#include "ehandle.h"
+#include "mathlib/vmatrix.h"
+
+class CBaseEntity;
+
+
+//
+// A variant class for passing data in entity input/output connections.
+//
+class variant_t
+{
+ union
+ {
+ bool bVal;
+ string_t iszVal;
+ int iVal;
+ float flVal;
+ float vecVal[3];
+ color32 rgbaVal;
+ };
+ CHandle<CBaseEntity> eVal; // this can't be in the union because it has a constructor.
+
+ fieldtype_t fieldType;
+
+public:
+
+ // constructor
+ variant_t() : fieldType(FIELD_VOID), iVal(0) {}
+
+ inline bool Bool( void ) const { return( fieldType == FIELD_BOOLEAN ) ? bVal : false; }
+ inline const char *String( void ) const { return( fieldType == FIELD_STRING ) ? STRING(iszVal) : ToString(); }
+ inline string_t StringID( void ) const { return( fieldType == FIELD_STRING ) ? iszVal : NULL_STRING; }
+ inline int Int( void ) const { return( fieldType == FIELD_INTEGER ) ? iVal : 0; }
+ inline float Float( void ) const { return( fieldType == FIELD_FLOAT ) ? flVal : 0; }
+ inline const CHandle<CBaseEntity> &Entity(void) const;
+ inline color32 Color32(void) const { return rgbaVal; }
+ inline void Vector3D(Vector &vec) const;
+
+ fieldtype_t FieldType( void ) { return fieldType; }
+
+ void SetBool( bool b ) { bVal = b; fieldType = FIELD_BOOLEAN; }
+ void SetString( string_t str ) { iszVal = str, fieldType = FIELD_STRING; }
+ void SetInt( int val ) { iVal = val, fieldType = FIELD_INTEGER; }
+ void SetFloat( float val ) { flVal = val, fieldType = FIELD_FLOAT; }
+ void SetEntity( CBaseEntity *val );
+ void SetVector3D( const Vector &val ) { vecVal[0] = val[0]; vecVal[1] = val[1]; vecVal[2] = val[2]; fieldType = FIELD_VECTOR; }
+ void SetPositionVector3D( const Vector &val ) { vecVal[0] = val[0]; vecVal[1] = val[1]; vecVal[2] = val[2]; fieldType = FIELD_POSITION_VECTOR; }
+ void SetColor32( color32 val ) { rgbaVal = val; fieldType = FIELD_COLOR32; }
+ void SetColor32( int r, int g, int b, int a ) { rgbaVal.r = r; rgbaVal.g = g; rgbaVal.b = b; rgbaVal.a = a; fieldType = FIELD_COLOR32; }
+ void Set( fieldtype_t ftype, void *data );
+ void SetOther( void *data );
+ bool Convert( fieldtype_t newType );
+
+ static typedescription_t m_SaveBool[];
+ static typedescription_t m_SaveInt[];
+ static typedescription_t m_SaveFloat[];
+ static typedescription_t m_SaveEHandle[];
+ static typedescription_t m_SaveString[];
+ static typedescription_t m_SaveColor[];
+ static typedescription_t m_SaveVector[];
+ static typedescription_t m_SavePositionVector[];
+ static typedescription_t m_SaveVMatrix[];
+ static typedescription_t m_SaveVMatrixWorldspace[];
+ static typedescription_t m_SaveMatrix3x4Worldspace[];
+
+protected:
+
+ //
+ // Returns a string representation of the value without modifying the variant.
+ //
+ const char *ToString( void ) const;
+
+ friend class CVariantSaveDataOps;
+};
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns this variant as a vector.
+//-----------------------------------------------------------------------------
+inline void variant_t::Vector3D(Vector &vec) const
+{
+ if (( fieldType == FIELD_VECTOR ) || ( fieldType == FIELD_POSITION_VECTOR ))
+ {
+ vec[0] = vecVal[0];
+ vec[1] = vecVal[1];
+ vec[2] = vecVal[2];
+ }
+ else
+ {
+ vec = vec3_origin;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns this variant as an EHANDLE.
+//-----------------------------------------------------------------------------
+inline const CHandle<CBaseEntity> &variant_t::Entity(void) const
+{
+ if ( fieldType == FIELD_EHANDLE )
+ return eVal;
+
+ static CHandle<CBaseEntity> hNull;
+ hNull.Set(NULL);
+ return(hNull);
+}
+
+
+#endif // VARIANT_T_H