summaryrefslogtreecommitdiff
path: root/gcsdk/jobtime.cpp
blob: c2dd0397386aa0be35c2486bf76d56c7270e70da (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Encapsultes the job system's version of time (which is != to wall clock time)
//
//=============================================================================

#include "stdafx.h"

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

namespace GCSDK
{

uint64 CJobTime::sm_lTimeCur = 0;

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CJobTime::CJobTime() 
{ 
	m_lTime = sm_lTimeCur; 
}


//----------------------------------------------------------------------------
// Purpose: Sets our value to the current time
//-----------------------------------------------------------------------------
void CJobTime::SetToJobTime()
{
	m_lTime = sm_lTimeCur;
}


//-----------------------------------------------------------------------------
// Purpose: Sets our value as an offset from the current time
//-----------------------------------------------------------------------------
void CJobTime::SetFromJobTime( int64 dMicroSecOffset )
{
	m_lTime = sm_lTimeCur + dMicroSecOffset;
}


//-----------------------------------------------------------------------------
// Purpose: Returns the amount of time that's passed between our time and the
//			current time.
// Output:	Time that's passed between our time and the current time
//-----------------------------------------------------------------------------
int64 CJobTime::CServerMicroSecsPassed() const
{
	return( sm_lTimeCur - m_lTime );
}


//-----------------------------------------------------------------------------
// Purpose: Updates our current time value.  We only
//			update the time once per frame-- the rest of the time, we just
//			access a cached copy of the time.  On the server, we use an arbitrary
//			time value beginning at 0, and incremented by 50 milliseconds every
//			frame.  
//			NOTE: This should only be called once per frame.
//-----------------------------------------------------------------------------
void CJobTime::UpdateJobTime( int cMicroSecPerShellFrame )
{
	sm_lTimeCur += cMicroSecPerShellFrame; // force a 50 msec clock
}


//-----------------------------------------------------------------------------
// Purpose: Stomps the current clock with the specified time
// Input  : lCurrentTime - new current time
//-----------------------------------------------------------------------------
void CJobTime::SetCurrentJobTime( uint64 lCurrentTime )
{
	sm_lTimeCur = lCurrentTime;
}

} // namespace GCSDK