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.

191 lines
7.4 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #if !defined( CDLL_UTIL_H )
  10. #define CDLL_UTIL_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include <soundflags.h>
  15. #include "mathlib/vector.h"
  16. #include <shareddefs.h>
  17. #include "color.h"
  18. #include "shake.h"
  19. #include "bitmap/imageformat.h"
  20. #include "ispatialpartition.h"
  21. #include "materialsystem/MaterialSystemUtil.h"
  22. class Vector;
  23. class QAngle;
  24. class IMaterial;
  25. class ITexture;
  26. class IClientEntity;
  27. class CHudTexture;
  28. class CGameTrace;
  29. class C_BaseEntity;
  30. class C_BasePlayer;
  31. struct Ray_t;
  32. struct client_textmessage_t;
  33. typedef CGameTrace trace_t;
  34. namespace vgui
  35. {
  36. typedef unsigned long HFont;
  37. class EditablePanel;
  38. };
  39. extern bool g_MakingDevShots;
  40. // ScreenHeight returns the height of the screen, in pixels
  41. int ScreenHeight( void );
  42. // ScreenWidth returns the width of the screen, in pixels
  43. int ScreenWidth( void );
  44. inline void ConvertNormalizedScreenSpaceToPixelScreenSpace( Vector &in )
  45. {
  46. in.x = ( ( 1.0f + in.x ) * 0.5f ) * ScreenWidth();
  47. in.y = ScreenHeight() - ( ( ( 1.0f + in.y ) * 0.5f ) * ScreenHeight() );
  48. }
  49. #define XRES(x) ( x * ( ( float )ScreenWidth() / 640.0 ) )
  50. #define YRES(y) ( y * ( ( float )ScreenHeight() / 480.0 ) )
  51. int UTIL_ComputeStringWidth( vgui::HFont& font, const char *str );
  52. int UTIL_ComputeStringWidth( vgui::HFont& font, const wchar_t *str );
  53. float UTIL_AngleDiff( float destAngle, float srcAngle );
  54. void UTIL_Bubbles( const Vector& mins, const Vector& maxs, int count );
  55. void UTIL_Smoke( const Vector &origin, const float scale, const float framerate );
  56. void UTIL_ImpactTrace( trace_t *pTrace, int iDamageType, char *pCustomImpactName = NULL );
  57. int UTIL_PrecacheDecal( const char *name, bool preload = false );
  58. void UTIL_EmitAmbientSound( C_BaseEntity *entity, const Vector &vecOrigin, const char *samp, float vol, soundlevel_t soundlevel, int fFlags, int pitch );
  59. void UTIL_SetOrigin( C_BaseEntity *entity, const Vector &vecOrigin );
  60. void UTIL_ScreenShake( const Vector &center, float amplitude, float frequency, float duration, float radius, ShakeCommand_t eCommand, bool bAirShake=false );
  61. byte *UTIL_LoadFileForMe( const char *filename, int *pLength );
  62. void UTIL_FreeFile( byte *buffer );
  63. void UTIL_MakeSafeName( const char *oldName, char *newName, int newNameBufSize ); ///< Cleans up player names for putting in vgui controls (cleaned names can be up to original*2+1 in length)
  64. const char *UTIL_SafeName( const char *oldName ); ///< Wraps UTIL_MakeSafeName, and returns a static buffer
  65. void UTIL_ReplaceKeyBindings( const wchar_t *inbuf, int inbufsizebytes, OUT_Z_BYTECAP(outbufsizebytes) wchar_t *outbuf, int outbufsizebytes );
  66. void UTIL_SetControlStringWithKeybindings( vgui::EditablePanel *panel, const char *controlName, const char *str );
  67. void UTIL_MessageText( C_BasePlayer *player, const char *text, Color color = Color( 0, 0, 0, 0 ) );
  68. // Fade out an entity based on distance fades
  69. unsigned char UTIL_ComputeEntityFade( C_BaseEntity *pEntity, float flMinDist, float flMaxDist, float flFadeScale );
  70. client_textmessage_t *TextMessageGet( const char *pName );
  71. char *VarArgs( PRINTF_FORMAT_STRING const char *format, ... );
  72. // Get the entity the local player is spectating (can be a player or a ragdoll entity).
  73. int GetSpectatorTarget();
  74. bool CanControlSpectatedTarget( void );
  75. bool CanSeeSpectatorOnlyTools( void );
  76. bool CanToggleXRayView( void );
  77. int GetSpectatorMode( void );
  78. bool IsPlayerIndex( int index );
  79. int GetLocalPlayerIndex( void );
  80. int GetLocalPlayerTeam( void );
  81. bool IsLocalPlayerSpectator( void );
  82. void NormalizeAngles( QAngle& angles );
  83. void InterpolateAngles( const QAngle& start, const QAngle& end, QAngle& output, float frac );
  84. void InterpolateVector( float frac, const Vector& src, const Vector& dest, Vector& output );
  85. const char *nexttoken(char *token, const char *str, char sep);
  86. void UTIL_PrecacheOther( const char *szClassname );
  87. void UTIL_SetTrace(trace_t& tr, const Ray_t& ray, C_BaseEntity *edict, float fraction, int hitgroup, unsigned int contents, const Vector& normal, float intercept );
  88. bool GetVectorInScreenSpace( Vector pos, int& iX, int& iY, Vector *vecOffset = NULL );
  89. bool GetTargetInScreenSpace( C_BaseEntity *pTargetEntity, int& iX, int& iY, Vector *vecOffset = NULL );
  90. // prints messages through the HUD (stub in client .dll right now )
  91. class C_BasePlayer;
  92. void ClientPrint( C_BasePlayer *player, int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
  93. C_BasePlayer* UTIL_PlayerByUserId( int userID );
  94. C_BaseEntity* UTIL_EntityFromUserMessageEHandle( long nEncodedEHandle );
  95. // Pass in an array of pointers and an array size, it fills the array and returns the number inserted
  96. int UTIL_EntitiesInBox( C_BaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask, int partitionMask = PARTITION_CLIENT_NON_STATIC_EDICTS );
  97. int UTIL_EntitiesInSphere( C_BaseEntity **pList, int listMax, const Vector &center, float radius, int flagMask, int partitionMask = PARTITION_CLIENT_NON_STATIC_EDICTS );
  98. int UTIL_RenderablesInBox( C_BaseEntity** pList, int listMax, const Vector &mins, const Vector &maxs );
  99. // make this a fixed size so it just sits on the stack
  100. #define MAX_SPHERE_QUERY 256
  101. class CEntitySphereQuery
  102. {
  103. public:
  104. // currently this builds the list in the constructor
  105. // UNDONE: make an iterative query of ISpatialPartition so we could
  106. // make queries like this optimal
  107. CEntitySphereQuery( const Vector &center, float radius, int flagMask=0, int partitionMask = PARTITION_CLIENT_NON_STATIC_EDICTS );
  108. C_BaseEntity *GetCurrentEntity();
  109. inline void NextEntity() { m_listIndex++; }
  110. private:
  111. int m_listIndex;
  112. int m_listCount;
  113. C_BaseEntity *m_pList[MAX_SPHERE_QUERY];
  114. };
  115. C_BaseEntity *CreateEntityByName( const char *className );
  116. // creates an entity by name, and ensure it's correctness
  117. // does not spawn the entity
  118. // use the CREATE_ENTITY() macro which wraps this, instead of using it directly
  119. template< class T >
  120. T *_CreateEntity( T *newClass, const char *className )
  121. {
  122. T *newEnt = dynamic_cast<T*>( CreateEntityByName(className) );
  123. if ( !newEnt )
  124. {
  125. Warning( "classname %s used to create wrong class type\n", className );
  126. Assert(0);
  127. }
  128. return newEnt;
  129. }
  130. #define CREATE_ENTITY( newClass, className ) _CreateEntity( (newClass*)NULL, className )
  131. #define CREATE_UNSAVED_ENTITY( newClass, className ) _CreateEntityTemplate( (newClass*)NULL, className )
  132. // Misc useful
  133. inline bool FStrEq(const char *sz1, const char *sz2)
  134. {
  135. return(stricmp(sz1, sz2) == 0);
  136. }
  137. // Given a vector, clamps the scalar axes to MAX_COORD_FLOAT ranges from worldsize.h
  138. void UTIL_BoundToWorldSize( Vector *pVecPos );
  139. void UTIL_ApproachTarget( float target, float increaseSpeed, float decreaseSpeed, float *val );
  140. void UTIL_ApproachTarget( const Vector &target, float increaseSpeed, float decreaseSpeed, Vector *val );
  141. // Returns true if the user has loaded any maps, false otherwise.
  142. bool UTIL_HasLoadedAnyMap();
  143. wchar_t *UTIL_GetLocalizedKeyString( const char *command, const char *fmt, const wchar_t *arg1 = NULL, const wchar_t *arg2 = NULL, const wchar_t *arg3 = NULL );
  144. void UTIL_GetClientStatusText( char *buffer, int bufsize );
  145. class CGameTrace;
  146. typedef CGameTrace trace_t;
  147. void UTIL_ClearTrace ( trace_t &trace );
  148. #endif // !CDLL_UTIL_H