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.

89 lines
2.6 KiB

  1. //========= Copyright 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 )
  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. // Set attributes
  44. assert( pfnCreate );
  45. m_pfnCreate = pfnCreate;
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose: Returns next object in list
  49. // Output : CHudElementHelper
  50. //-----------------------------------------------------------------------------
  51. CHudElementHelper *CHudElementHelper::GetNext( void )
  52. {
  53. return m_pNext;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Static class creation factory
  57. // Searches list of registered factories for a match and then instances the
  58. // requested technology by name
  59. // Input : *name -
  60. // Output : CBaseTFTechnology
  61. //-----------------------------------------------------------------------------
  62. void CHudElementHelper::CreateAllElements( void )
  63. {
  64. // Start of list
  65. CHudElementHelper *p = m_sHelpers;
  66. while ( p )
  67. {
  68. // Dispatch creation function directly
  69. CHudElement *( *fCreate )( void ) = p->m_pfnCreate;
  70. CHudElement *newElement = (fCreate)();
  71. if ( newElement )
  72. {
  73. gHUD.AddHudElement( newElement );
  74. }
  75. p = p->GetNext();
  76. }
  77. }