summaryrefslogtreecommitdiff
path: root/game/shared/interval.cpp
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/shared/interval.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/shared/interval.cpp')
-rw-r--r--game/shared/interval.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/game/shared/interval.cpp b/game/shared/interval.cpp
new file mode 100644
index 0000000..38c9035
--- /dev/null
+++ b/game/shared/interval.cpp
@@ -0,0 +1,59 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "tier0/platform.h"
+#include "interval.h"
+#include "tier1/strtools.h"
+#include "vstdlib/random.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : *pString -
+// Output : interval_t
+//-----------------------------------------------------------------------------
+interval_t ReadInterval( const char *pString )
+{
+ interval_t tmp;
+
+ tmp.start = 0;
+ tmp.range = 0;
+
+ char tempString[128];
+ Q_strncpy( tempString, pString, sizeof(tempString) );
+
+ char *token = strtok( tempString, "," );
+ if ( token )
+ {
+ tmp.start = atof( token );
+ token = strtok( NULL, "," );
+ if ( token )
+ {
+ tmp.range = atof( token ) - tmp.start;
+ }
+ }
+
+ return tmp;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : &interval -
+// Output : float
+//-----------------------------------------------------------------------------
+float RandomInterval( const interval_t &interval )
+{
+ float out = interval.start;
+ if ( interval.range != 0 )
+ {
+ out += RandomFloat( 0, interval.range );
+ }
+
+ return out;
+}