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.

233 lines
9.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef IENGINETOOL_H
  7. #define IENGINETOOL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "interface.h"
  12. #include "soundflags.h"
  13. #include "video/ivideoservices.h"
  14. #include "ispatialpartition.h"
  15. class CViewSetup;
  16. class IToolSystem;
  17. class KeyValues;
  18. class ITraceFilter;
  19. class CBaseTrace;
  20. struct dlight_t;
  21. struct Ray_t;
  22. struct AudioState_t;
  23. typedef bool (*FnQuitHandler)( void *pvUserData );
  24. #ifndef MAX_DLIGHTS
  25. #define MAX_DLIGHTS 32
  26. #endif
  27. // Exposed from engine to all tools, simplest interface
  28. class IEngineToolFramework : public IBaseInterface
  29. {
  30. public:
  31. // Input system overrides TBD
  32. // Something like this
  33. //virtual void AddMessageHandler( int wm_message, bool (*pfnCallback)( int wm_message, int wParam, int lParam ) ) = 0;
  34. //virtual void RemoveMessageHanlder( int wm_message, bool (*pfnCallbackToRemove)( int wm_message, int wParam, int lParam ) ) = 0;
  35. // Helpers for implementing a tool switching UI
  36. virtual int GetToolCount() const = 0;
  37. virtual char const *GetToolName( int index ) const = 0;
  38. virtual void SwitchToTool( int index ) = 0;
  39. virtual bool IsTopmostTool( const IToolSystem *sys ) const = 0;
  40. virtual const IToolSystem *GetToolSystem( int index ) const = 0;
  41. virtual IToolSystem *GetTopmostTool() = 0;
  42. // Take over input
  43. virtual void ShowCursor( bool show ) = 0;
  44. virtual bool IsCursorVisible() const = 0;
  45. };
  46. #define VENGINETOOLFRAMEWORK_INTERFACE_VERSION "VENGINETOOLFRAMEWORK003"
  47. struct model_t;
  48. struct studiohdr_t;
  49. #include "toolframework/itoolentity.h"
  50. // Exposed from engine to tools via, more involved version of above
  51. class IEngineTool : public IEngineToolFramework
  52. {
  53. public:
  54. virtual void GetServerFactory( CreateInterfaceFn& factory ) = 0;
  55. virtual void GetClientFactory( CreateInterfaceFn& factory ) = 0;
  56. virtual float GetSoundDuration( const char *pszName ) = 0;
  57. virtual bool IsSoundStillPlaying( int guid ) = 0;
  58. // Returns the guid of the sound
  59. virtual int StartSound(
  60. int iUserData,
  61. bool staticsound,
  62. int iEntIndex,
  63. int iChannel,
  64. const char *pSample,
  65. float flVolume,
  66. soundlevel_t iSoundlevel,
  67. const Vector& origin,
  68. const Vector& direction,
  69. int iFlags = 0,
  70. int iPitch = PITCH_NORM,
  71. bool bUpdatePositions = true,
  72. float delay = 0.0f,
  73. int speakerentity = -1 ) = 0;
  74. virtual void StopSoundByGuid( int guid ) = 0;
  75. // Returns how long the sound is
  76. virtual float GetSoundDuration( int guid ) = 0;
  77. // Returns if the sound is looping
  78. virtual bool IsLoopingSound( int guid ) = 0;
  79. virtual void ReloadSound( const char *pSample ) = 0;
  80. virtual void StopAllSounds( ) = 0;
  81. virtual float GetMono16Samples( const char *pszName, CUtlVector< short >& sampleList ) = 0;
  82. virtual void SetAudioState( const AudioState_t &audioState ) = 0;
  83. // Issue a console command
  84. virtual void Command( char const *cmd ) = 0;
  85. // Flush console command buffer right away
  86. virtual void Execute() = 0;
  87. virtual char const *GetCurrentMap() = 0;
  88. virtual void ChangeToMap( char const *mapname ) = 0;
  89. virtual bool IsMapValid( char const *mapname ) = 0;
  90. // Method for causing engine to call client to render scene with no view model or overlays
  91. // See cdll_int.h for enum RenderViewInfo_t for specifying whatToRender
  92. virtual void RenderView( CViewSetup &view, int nFlags, int whatToRender ) = 0;
  93. // Returns true if the player is fully connected and active in game (i.e, not still loading)
  94. virtual bool IsInGame() = 0;
  95. // Returns true if the player is connected, but not necessarily active in game (could still be loading)
  96. virtual bool IsConnected() = 0;
  97. virtual int GetMaxClients() = 0; // Tools might want to ensure single player, e.g.
  98. virtual bool IsGamePaused() = 0;
  99. virtual void SetGamePaused( bool paused ) = 0;
  100. virtual float GetTimescale() = 0; // Could do this via ConVar system, too
  101. virtual void SetTimescale( float scale ) = 0;
  102. // Real time is unscaled, but is updated once per frame
  103. virtual float GetRealTime() = 0;
  104. virtual float GetRealFrameTime() = 0; // unscaled
  105. // Get high precision timer (for profiling?)
  106. virtual float Time() = 0;
  107. // Host time is scaled
  108. virtual float HostFrameTime() = 0; // host_frametime
  109. virtual float HostTime() = 0; // host_time
  110. virtual int HostTick() = 0; // host_tickcount
  111. virtual int HostFrameCount() = 0; // total famecount
  112. virtual float ServerTime() = 0; // gpGlobals->curtime on server
  113. virtual float ServerFrameTime() = 0; // gpGlobals->frametime on server
  114. virtual int ServerTick() = 0; // gpGlobals->tickcount on server
  115. virtual float ServerTickInterval() = 0; // tick interval on server
  116. virtual float ClientTime() = 0; // gpGlobals->curtime on client
  117. virtual float ClientFrameTime() = 0; // gpGlobals->frametime on client
  118. virtual int ClientTick() = 0; // gpGlobals->tickcount on client
  119. virtual void SetClientFrameTime( float frametime ) = 0; // gpGlobals->frametime on client
  120. // Currently the engine doesn't like to do networking when it's paused, but if a tool changes entity state, it can be useful to force
  121. // a network update to get that state over to the client
  122. virtual void ForceUpdateDuringPause() = 0;
  123. // Maybe through modelcache???
  124. virtual model_t *GetModel( HTOOLHANDLE hEntity ) = 0;
  125. // Get the .mdl file used by entity (if it's a cbaseanimating)
  126. virtual studiohdr_t *GetStudioModel( HTOOLHANDLE hEntity ) = 0;
  127. // SINGLE PLAYER/LISTEN SERVER ONLY (just matching the client .dll api for this)
  128. // Prints the formatted string to the notification area of the screen ( down the right hand edge
  129. // numbered lines starting at position 0
  130. virtual void Con_NPrintf( int pos, PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
  131. // SINGLE PLAYER/LISTEN SERVER ONLY(just matching the client .dll api for this)
  132. // Similar to Con_NPrintf, but allows specifying custom text color and duration information
  133. virtual void Con_NXPrintf( const struct con_nprint_s *info, PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
  134. // Get the current game directory (hl2, tf2, hl1, cstrike, etc.)
  135. virtual void GetGameDir( char *szGetGameDir, int maxlength ) = 0;
  136. // Do we need separate rects for the 3d "viewport" vs. the tools surface??? and can we control viewports from
  137. virtual void GetScreenSize( int& width, int &height ) = 0;
  138. // GetRootPanel(VPANEL)
  139. // Sets the location of the main view
  140. virtual void SetMainView( const Vector &vecOrigin, const QAngle &angles ) = 0;
  141. // Gets the player view
  142. virtual bool GetPlayerView( CViewSetup &playerView, int x, int y, int w, int h ) = 0;
  143. // From a location on the screen, figure out the vector into the world
  144. virtual void CreatePickingRay( const CViewSetup &viewSetup, int x, int y, Vector& org, Vector& forward ) = 0;
  145. // precache methods
  146. virtual bool PrecacheSound( const char *pName, bool bPreload = false ) = 0;
  147. virtual bool PrecacheModel( const char *pName, bool bPreload = false ) = 0;
  148. virtual void InstallQuitHandler( void *pvUserData, FnQuitHandler func ) = 0;
  149. virtual void TakeTGAScreenShot( char const *filename, int width, int height ) = 0;
  150. // Even if game is paused, force networking to update to get new server state down to client
  151. virtual void ForceSend() = 0;
  152. virtual bool IsRecordingMovie() = 0;
  153. // NOTE: Params can contain file name, frame rate, output avi, output raw, and duration
  154. virtual void StartMovieRecording( KeyValues *pMovieParams ) = 0;
  155. virtual void EndMovieRecording() = 0;
  156. virtual void CancelMovieRecording() = 0;
  157. virtual IVideoRecorder *GetActiveVideoRecorder() = 0;
  158. virtual void StartRecordingVoiceToFile( char const *filename, char const *pPathID = 0 ) = 0;
  159. virtual void StopRecordingVoiceToFile() = 0;
  160. virtual bool IsVoiceRecording() = 0;
  161. // A version that simply accepts a ray (can work as a traceline or tracehull)
  162. virtual void TraceRay( const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, CBaseTrace *pTrace ) = 0; // client version
  163. virtual void TraceRayServer( const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, CBaseTrace *pTrace ) = 0;
  164. virtual bool IsConsoleVisible() = 0;
  165. virtual int GetPointContents( const Vector &vecPosition ) = 0;
  166. virtual int GetActiveDLights( dlight_t *pList[MAX_DLIGHTS] ) = 0;
  167. virtual int GetLightingConditions( const Vector &vecPosition, Vector *pColors, int nMaxLocalLights, LightDesc_t *pLocalLights ) = 0;
  168. virtual void GetWorldToScreenMatrixForView( const CViewSetup &view, VMatrix *pVMatrix ) = 0;
  169. // Collision support
  170. virtual SpatialPartitionHandle_t CreatePartitionHandle( IHandleEntity *pEntity,
  171. SpatialPartitionListMask_t listMask, const Vector& mins, const Vector& maxs ) = 0;
  172. virtual void DestroyPartitionHandle( SpatialPartitionHandle_t hPartition ) = 0;
  173. virtual void InstallPartitionQueryCallback( IPartitionQueryCallback *pQuery ) = 0;
  174. virtual void RemovePartitionQueryCallback( IPartitionQueryCallback *pQuery ) = 0;
  175. virtual void ElementMoved( SpatialPartitionHandle_t handle,
  176. const Vector& mins, const Vector& maxs ) = 0;
  177. };
  178. #define VENGINETOOL_INTERFACE_VERSION "VENGINETOOL003"
  179. #endif // IENGINETOOL_H