summaryrefslogtreecommitdiff
path: root/replay/basethinker.cpp
blob: 108a345f9857502ee8399789ca25d7a43cd04b2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//

#include "basethinker.h"
#include "ithinkmanager.h"
#include "replay/ienginereplay.h"
#include "dbg.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//----------------------------------------------------------------------------------------

extern IThinkManager *g_pThinkManager;
extern IEngineReplay *g_pEngine;

//----------------------------------------------------------------------------------------

CBaseThinker::CBaseThinker()
:	m_flNextThinkTime( 0.0f )
{
	g_pThinkManager->AddThinker( this );
}

CBaseThinker::~CBaseThinker()
{
	g_pThinkManager->RemoveThinker( this );
}

void CBaseThinker::Think()
{
	AssertMsg( ShouldThink(), "Thinking before ready - Think() being called explicitly?  Let the think manager call Think()." );
}

bool CBaseThinker::ShouldThink() const
{
	const float flHostTime = g_pEngine->GetHostTime();
	return m_flNextThinkTime >= 0.0f && flHostTime >= m_flNextThinkTime;
}

void CBaseThinker::PostThink()
{
	m_flNextThinkTime = GetNextThinkTime();
}

//----------------------------------------------------------------------------------------