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.

104 lines
2.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef TESTSCRIPTMGR_H
  8. #define TESTSCRIPTMGR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "filesystem.h"
  13. #include "tier1/utllinkedlist.h"
  14. #include "tier1/utldict.h"
  15. class CCommand;
  16. // This represents a loop structure.
  17. class CLoopInfo
  18. {
  19. public:
  20. int m_nCount; // How many times we've hit the loop.
  21. double m_flStartTime; // What time the loop started at.
  22. char m_Name[64];
  23. unsigned long m_iNextCommandPos; // Position in the file of the next command.
  24. int m_ListIndex; // Index into CTestScriptMgr::m_Loops.
  25. };
  26. class CTestScriptMgr
  27. {
  28. public:
  29. CTestScriptMgr();
  30. virtual ~CTestScriptMgr();
  31. bool StartTestScript( const char *pFilename );
  32. void StopTestScript( void);
  33. bool IsInitted() const;
  34. // The engine calls this when it gets to certain points during execution. The 'Test_StepTo' command
  35. // stops executing scripts until it reaches a checkpoint with a matching names.
  36. void CheckPoint( const char *pName );
  37. // This pauses the script until execution reaches the specified checkpoint.
  38. // If bOnce is true, then it won't start waiting if the specified checkpoint was already hit.
  39. void SetWaitCheckPoint( const char *pCheckPointName, bool bOnce=false );
  40. private:
  41. void Term( void );
  42. // Runs until it hits a command that makes the script wait, like 'Test_Wait' or 'Test_StepTo'.
  43. void RunCommands();
  44. // Returns true if we're waiting for the timer.
  45. bool IsTimerWaiting() const;
  46. // Returns true if we're waiting for a checkpoint.
  47. bool IsCheckPointWaiting() const;
  48. void SetWaitTime( float flSeconds );
  49. CLoopInfo* FindLoop( const char *pLoopName );
  50. void StartLoop( const char *pLoopName );
  51. void LoopCount( const char *pLoopName, int nTimes );
  52. void LoopForNumSeconds( const char *pLoopName, double nSeconds );
  53. // Make sure the file is open. Error out if not.
  54. void ErrorIfNotInitted();
  55. private:
  56. FileHandle_t m_hFile;
  57. char m_NextCheckPoint[32]; // If this is > 0 length it will wait to run script until you hit
  58. // the next checkpoint with this name.
  59. double m_WaitUntil; // It waits to execute scripts until the time reaches here.
  60. CUtlLinkedList<CLoopInfo*,int> m_Loops;
  61. CUtlDict<int, int> m_CheckPointsHit; // Which checkpoints we've hit.
  62. // Console command handlers.
  63. friend void Test_Wait( const CCommand &args );
  64. friend void Test_RunFrame( const CCommand &args );
  65. friend void Test_StartLoop( const CCommand &args );
  66. friend void Test_LoopCount( const CCommand &args );
  67. friend void Test_Loop( const CCommand &args );
  68. friend void Test_LoopForNumSeconds( const CCommand &args );
  69. };
  70. inline CTestScriptMgr* GetTestScriptMgr()
  71. {
  72. extern CTestScriptMgr g_TestScriptMgr;
  73. return &g_TestScriptMgr;
  74. }
  75. #endif // TESTSCRIPTMGR_H