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.

96 lines
2.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hud_element_helper.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // Start with empty list
  12. CHudElementHelper *CHudElementHelper::m_sHelpers = NULL;
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Constructs a technology factory
  15. // Input : pfnCreate - fn Ptr to the constructor for this element
  16. // depth - determines position in the creation list, 100 is farthest into the screen
  17. // 0 is nearest, default is 50
  18. //
  19. //-----------------------------------------------------------------------------
  20. CHudElementHelper::CHudElementHelper( CHudElement *( *pfnCreate )( void ), int depth, int flags /* = 0 */ )
  21. {
  22. //Insert into the list based on depth
  23. //List is empty, or element belongs at front, insert here
  24. if( m_sHelpers == NULL || depth >= m_sHelpers->m_iDepth )
  25. {
  26. m_pNext = m_sHelpers;
  27. m_sHelpers = this;
  28. }
  29. else
  30. {
  31. //Scan to insert in decreasing depth order
  32. CHudElementHelper *pPrev = m_sHelpers;
  33. CHudElementHelper *pCurrent = m_sHelpers->m_pNext;
  34. while( pCurrent != NULL && depth < pCurrent->m_iDepth )
  35. {
  36. pPrev = pCurrent;
  37. pCurrent = pCurrent->m_pNext;
  38. }
  39. pPrev->m_pNext = this;
  40. m_pNext = pCurrent;
  41. }
  42. m_iDepth = depth;
  43. m_iFlags = flags;
  44. // Set attributes
  45. assert( pfnCreate );
  46. m_pfnCreate = pfnCreate;
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Returns next object in list
  50. // Output : CHudElementHelper
  51. //-----------------------------------------------------------------------------
  52. CHudElementHelper *CHudElementHelper::GetNext( void )
  53. {
  54. return m_pNext;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Static class creation factory
  58. // Searches list of registered factories for a match and then instances the
  59. // requested technology by name
  60. // Input : *name -
  61. // Output : CBaseTFTechnology
  62. //-----------------------------------------------------------------------------
  63. void CHudElementHelper::CreateAllElements( void )
  64. {
  65. // Start of list
  66. CHudElementHelper *p = m_sHelpers;
  67. while ( p )
  68. {
  69. // only create this element in slot 0
  70. if ( ( p->m_iFlags & HUDELEMENT_SS_FULLSCREEN_ONLY ) && ( GET_ACTIVE_SPLITSCREEN_SLOT() != 0 ) )
  71. {
  72. p = p->m_pNext;
  73. continue;
  74. }
  75. // Dispatch creation function directly
  76. CHudElement *( *fCreate )( void ) = p->m_pfnCreate;
  77. CHudElement *newElement = (fCreate)();
  78. if ( newElement )
  79. {
  80. GetHud().AddHudElement( newElement );
  81. }
  82. p = p->GetNext();
  83. }
  84. }