summaryrefslogtreecommitdiff
path: root/engine/traceinit.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 /engine/traceinit.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'engine/traceinit.cpp')
-rw-r--r--engine/traceinit.cpp177
1 files changed, 177 insertions, 0 deletions
diff --git a/engine/traceinit.cpp b/engine/traceinit.cpp
new file mode 100644
index 0000000..c3a26e5
--- /dev/null
+++ b/engine/traceinit.cpp
@@ -0,0 +1,177 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+
+#include "basetypes.h"
+#include "traceinit.h"
+#include "utlvector.h"
+#include "sys.h"
+#include "common.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+class CInitTracker
+{
+public:
+ enum
+ {
+ NUM_LISTS = 4,
+ };
+
+ //-----------------------------------------------------------------------------
+ // Purpose:
+ //-----------------------------------------------------------------------------
+ class InitFunc
+ {
+ public:
+ const char *initname;
+ const char *shutdownname;
+ int referencecount;
+ int sequence;
+ bool warningprinted;
+ // Profiling data
+ float inittime;
+ float shutdowntime;
+ };
+
+ CInitTracker( void );
+ ~CInitTracker( void );
+
+ void Init( const char *init, const char *shutdown, int listnum );
+ void Shutdown( const char *shutdown, int listnum );
+
+private:
+ int m_nNumFuncs[ NUM_LISTS ];
+ CUtlVector < InitFunc * > m_Funcs[ NUM_LISTS ];
+};
+
+static CInitTracker g_InitTracker;
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CInitTracker::CInitTracker( void )
+{
+ for ( int l = 0; l < NUM_LISTS; l++ )
+ {
+ m_nNumFuncs[ l ] = 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CInitTracker::~CInitTracker( void )
+{
+ for ( int l = 0; l < NUM_LISTS; l++ )
+ {
+ //assert( m_nNumFuncs[l] == 0 );
+ for ( int i = 0; i < m_nNumFuncs[l]; i++ )
+ {
+ InitFunc *f = m_Funcs[ l ][ i ];
+ if ( f->referencecount )
+ {
+ Msg( "Missing shutdown function for %s : %s\n", f->initname, f->shutdownname );
+ }
+ delete f;
+ }
+ m_Funcs[ l ].RemoveAll();
+ m_nNumFuncs[ l ] = 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : *init -
+// *shutdown -
+//-----------------------------------------------------------------------------
+void CInitTracker::Init( const char *init, const char *shutdown, int listnum )
+{
+ InitFunc *f = new InitFunc;
+ Assert( f );
+ f->initname = init;
+ f->shutdownname = shutdown;
+ f->sequence = m_nNumFuncs[ listnum ];
+ f->referencecount = 1;
+ f->warningprinted = false;
+ f->inittime = 0.0; //Sys_FloatTime();
+ f->shutdowntime = 0.0;
+
+ m_Funcs[ listnum ].AddToHead( f );
+ m_nNumFuncs[ listnum ]++;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : *shutdown -
+//-----------------------------------------------------------------------------
+void CInitTracker::Shutdown( const char *shutdown, int listnum )
+{
+ if( !m_nNumFuncs[ listnum ] )
+ {
+ Msg( "Mismatched shutdown function %s\n", shutdown );
+ return;
+ }
+
+ int i = 0;
+ InitFunc *f = NULL;
+ for ( i = 0; i < m_nNumFuncs[ listnum ]; i++ )
+ {
+ f = m_Funcs[ listnum ][ i ];
+ if ( f->referencecount )
+ break;
+ }
+
+ if ( f && f->referencecount && stricmp( f->shutdownname, shutdown ) )
+ {
+ if ( !f->warningprinted )
+ {
+ f->warningprinted = true;
+ //Msg( "Shutdown function %s called out of order, expecting %s\n", shutdown, f->shutdownname );
+ }
+ }
+
+ for ( i = 0; i < m_nNumFuncs[ listnum ]; i++ )
+ {
+ f = m_Funcs[ listnum ][ i ];
+
+ if ( !stricmp( f->shutdownname, shutdown ) )
+ {
+ Assert( f->referencecount );
+ //f->shutdowntime = Sys_FloatTime();
+ f->referencecount--;
+ return;
+ }
+ }
+
+ Msg( "Shutdown function %s not in list!!!\n", shutdown );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : *i -
+// *s -
+//-----------------------------------------------------------------------------
+void TraceInit( const char *i, const char *s, int listnum )
+{
+ g_InitTracker.Init( i, s, listnum );
+
+ COM_TimestampedLog( "%s", i );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Input : *s -
+//-----------------------------------------------------------------------------
+void TraceShutdown( const char *s, int listnum )
+{
+ g_InitTracker.Shutdown( s, listnum );
+} \ No newline at end of file