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.

127 lines
3.8 KiB

  1. //===== Copyright � 1996-2006, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef COMMANDBUFFER_H
  10. #define COMMANDBUFFER_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier0/platform.h"
  15. #include "tier1/utllinkedlist.h"
  16. #include "tier1/convar.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class CUtlBuffer;
  21. //-----------------------------------------------------------------------------
  22. // Invalid command handle
  23. //-----------------------------------------------------------------------------
  24. typedef intp CommandHandle_t;
  25. enum
  26. {
  27. COMMAND_BUFFER_INVALID_COMMAND_HANDLE = 0
  28. };
  29. //-----------------------------------------------------------------------------
  30. // A command buffer class- a queue of argc/argv based commands associated
  31. // with a particular time
  32. //-----------------------------------------------------------------------------
  33. class CCommandBuffer
  34. {
  35. public:
  36. // Constructor, destructor
  37. CCommandBuffer( );
  38. ~CCommandBuffer();
  39. // Inserts text into the command buffer
  40. bool AddText( const char *pText, cmd_source_t cmdSource = kCommandSrcUserInput, int nTickDelay = 0 );
  41. // Used to iterate over all commands appropriate for the current time
  42. void BeginProcessingCommands( int nDeltaTicks );
  43. bool DequeueNextCommand( /*out*/ CCommand* pCommand );
  44. void EndProcessingCommands();
  45. // Are we in the middle of processing commands?
  46. bool IsProcessingCommands();
  47. // Delays all queued commands to execute at a later time
  48. void DelayAllQueuedCommands( int nTickDelay );
  49. // Indicates how long to delay when encoutering a 'wait' command
  50. void SetWaitDelayTime( int nTickDelay );
  51. // Returns a handle to the next command to process
  52. // (useful when inserting commands into the buffer during processing
  53. // of commands to force immediate execution of those commands,
  54. // most relevantly, to implement a feature where you stream a file
  55. // worth of commands into the buffer, where the file size is too large
  56. // to entirely contain in the buffer).
  57. CommandHandle_t GetNextCommandHandle();
  58. // Specifies a max limit of the args buffer. For unittesting. Size == 0 means use default
  59. void LimitArgumentBufferSize( int nSize );
  60. void SetWaitEnabled( bool bEnable ) { m_bWaitEnabled = bEnable; }
  61. bool IsWaitEnabled( void ) { return m_bWaitEnabled; }
  62. private:
  63. enum
  64. {
  65. ARGS_BUFFER_LENGTH = 8192,
  66. };
  67. struct Command_t
  68. {
  69. int m_nTick;
  70. int m_nFirstArgS;
  71. int m_nBufferSize;
  72. cmd_source_t m_source;
  73. };
  74. // Insert a command into the command queue at the appropriate time
  75. void InsertCommandAtAppropriateTime( intp hCommand );
  76. // Insert a command into the command queue
  77. // Only happens if it's inserted while processing other commands
  78. void InsertImmediateCommand( intp hCommand );
  79. // Insert a command into the command queue
  80. bool InsertCommand( const char *pArgS, int nCommandSize, int nTick, cmd_source_t cmdSource );
  81. // Returns the length of the next command, as well as the offset to the next command
  82. void GetNextCommandLength( const char *pText, int nMaxLen, int *pCommandLength, int *pNextCommandOffset );
  83. // Compacts the command buffer
  84. void Compact();
  85. // Parses argv0 out of the buffer
  86. bool ParseArgV0( CUtlBuffer &buf, char *pArgv0, int nMaxLen, const char **pArgs );
  87. char m_pArgSBuffer[ ARGS_BUFFER_LENGTH ];
  88. int m_nLastUsedArgSSize;
  89. int m_nArgSBufferSize;
  90. CUtlFixedLinkedList< Command_t > m_Commands;
  91. int m_nCurrentTick;
  92. int m_nLastTickToProcess;
  93. int m_nWaitDelayTicks;
  94. intp m_hNextCommand;
  95. int m_nMaxArgSBufferLength;
  96. bool m_bIsProcessingCommands;
  97. bool m_bWaitEnabled;
  98. };
  99. #endif // COMMANDBUFFER_H