Team Fortress 2 Source Code as on 22/4/2020
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.

102 lines
2.8 KiB

  1. //========= Copyright 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 Term();
  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. // Runs until it hits a command that makes the script wait, like 'Test_Wait' or 'Test_StepTo'.
  42. void RunCommands();
  43. // Returns true if we're waiting for the timer.
  44. bool IsTimerWaiting() const;
  45. // Returns true if we're waiting for a checkpoint.
  46. bool IsCheckPointWaiting() const;
  47. void SetWaitTime( float flSeconds );
  48. CLoopInfo* FindLoop( const char *pLoopName );
  49. void StartLoop( const char *pLoopName );
  50. void LoopCount( const char *pLoopName, int nTimes );
  51. void LoopForNumSeconds( const char *pLoopName, double nSeconds );
  52. // Make sure the file is open. Error out if not.
  53. void ErrorIfNotInitted();
  54. private:
  55. FileHandle_t m_hFile;
  56. char m_NextCheckPoint[32]; // If this is > 0 length it will wait to run script until you hit
  57. // the next checkpoint with this name.
  58. double m_WaitUntil; // It waits to execute scripts until the time reaches here.
  59. CUtlLinkedList<CLoopInfo*,int> m_Loops;
  60. CUtlDict<int, int> m_CheckPointsHit; // Which checkpoints we've hit.
  61. // Console command handlers.
  62. friend void Test_Wait( const CCommand &args );
  63. friend void Test_RunFrame( const CCommand &args );
  64. friend void Test_StartLoop( const CCommand &args );
  65. friend void Test_LoopCount( const CCommand &args );
  66. friend void Test_Loop( const CCommand &args );
  67. friend void Test_LoopForNumSeconds( const CCommand &args );
  68. };
  69. inline CTestScriptMgr* GetTestScriptMgr()
  70. {
  71. extern CTestScriptMgr g_TestScriptMgr;
  72. return &g_TestScriptMgr;
  73. }
  74. #endif // TESTSCRIPTMGR_H