Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TEXTSTATSMGR_H
  8. #define TEXTSTATSMGR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "filesystem.h"
  13. #include "utllinkedlist.h"
  14. // Text stats get to print their stuff by implementing this type of function.
  15. typedef void (*TextStatPrintFn)( IFileSystem *pFileSys, FileHandle_t hFile, void *pUserData );
  16. typedef void (*TextStatFileFn)();
  17. // The CTextStatsMgr is just a collection of CTextStat's that go into the same file.
  18. class CTextStatsMgr
  19. {
  20. public:
  21. CTextStatsMgr( void );
  22. // Write a file with all the registered stats.
  23. bool WriteFile( IFileSystem *pFileSystem, const char *pFilename = NULL );
  24. // Get the preset filename to write stats to, if none is specified when writing
  25. char *GetStatsFilename( void );
  26. // Set the filename to write stats to, if none is specified when writing
  27. void SetStatsFilename( char *sFilename );
  28. private:
  29. char m_szStatFilename[ MAX_PATH ];
  30. };
  31. // This is the default CTextStatsMgr, but there can be any number of them.
  32. extern CTextStatsMgr g_TextStatsMgr;
  33. // Make these to register text stat functions.
  34. class CTextStat
  35. {
  36. friend class CTextStatsMgr;
  37. public:
  38. CTextStat();
  39. CTextStat( TextStatPrintFn fn, void *pUserData, CTextStatsMgr *pMgr=&g_TextStatsMgr );
  40. ~CTextStat();
  41. // This can be called if you don't want to pass parameters into the constructor.
  42. void Init( TextStatPrintFn printFn, void *pUserData, CTextStatsMgr *pMgr=&g_TextStatsMgr );
  43. void Term();
  44. private:
  45. // Special constructor to just tie off the linked list.
  46. CTextStat( bool bGlobalListHead );
  47. // The global list of CTextStats.
  48. static CTextStat* GetTextStatsList();
  49. static void RemoveFn( void *pUserData );
  50. // Link it into the global list.
  51. CTextStat *m_pPrev;
  52. CTextStat *m_pNext;
  53. CTextStatsMgr *m_pMgr;
  54. TextStatPrintFn m_PrintFn;
  55. void *m_pUserData;
  56. };
  57. // This class registers like a ConVar and acts like an int. When the game is shutdown,
  58. // its value will be saved in the stats file along with its name.s
  59. class CTextStatInt
  60. {
  61. public:
  62. CTextStatInt( const char *pName, int initialValue=0, CTextStatsMgr *pMgr=&g_TextStatsMgr );
  63. operator int() const { return m_Value; }
  64. int operator=( int val ) { m_Value = val; return m_Value; }
  65. int operator++() { m_Value++; return m_Value; }
  66. int operator--() { m_Value--; return m_Value; }
  67. int operator+=( int val ) { m_Value += val; return m_Value; }
  68. int operator-=( int val ) { m_Value -= val; return m_Value; }
  69. int operator*=( int val ) { m_Value *= val; return m_Value; }
  70. int operator/=( int val ) { m_Value /= val; return m_Value; }
  71. private:
  72. static void PrintFn( IFileSystem *pFileSys, FileHandle_t hFile, void *pUserData );
  73. private:
  74. const char *m_pName;
  75. int m_Value;
  76. CTextStat m_Reg; // Use to register ourselves.
  77. };
  78. // This can be registered to get a callback when the text stats mgr is saving its files.
  79. // You can write data out to your own file in here.
  80. class CTextStatFile
  81. {
  82. public:
  83. CTextStatFile( TextStatFileFn fn );
  84. private:
  85. friend class CTextStatsMgr;
  86. static CTextStatFile *s_pHead;
  87. CTextStatFile *m_pNext;
  88. TextStatFileFn m_pFn;
  89. };
  90. #endif // TEXTSTATSMGR_H