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.

47 lines
1.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "basethinker.h"
  5. #include "ithinkmanager.h"
  6. #include "replay/ienginereplay.h"
  7. #include "dbg.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //----------------------------------------------------------------------------------------
  11. extern IThinkManager *g_pThinkManager;
  12. extern IEngineReplay *g_pEngine;
  13. //----------------------------------------------------------------------------------------
  14. CBaseThinker::CBaseThinker()
  15. : m_flNextThinkTime( 0.0f )
  16. {
  17. g_pThinkManager->AddThinker( this );
  18. }
  19. CBaseThinker::~CBaseThinker()
  20. {
  21. g_pThinkManager->RemoveThinker( this );
  22. }
  23. void CBaseThinker::Think()
  24. {
  25. AssertMsg( ShouldThink(), "Thinking before ready - Think() being called explicitly? Let the think manager call Think()." );
  26. }
  27. bool CBaseThinker::ShouldThink() const
  28. {
  29. const float flHostTime = g_pEngine->GetHostTime();
  30. return m_flNextThinkTime >= 0.0f && flHostTime >= m_flNextThinkTime;
  31. }
  32. void CBaseThinker::PostThink()
  33. {
  34. m_flNextThinkTime = GetNextThinkTime();
  35. }
  36. //----------------------------------------------------------------------------------------