core/TimerSys.cpp
changeset 1459 8132c2259758
parent 1415 edf4efe5707c
child 1462 c5feb60740cf
     1.1 --- a/core/TimerSys.cpp	Sun Sep 23 16:01:12 2007 +0000
     1.2 +++ b/core/TimerSys.cpp	Sun Sep 23 19:33:19 2007 +0000
     1.3 @@ -39,9 +39,10 @@
     1.4  
     1.5  TimerSystem g_Timers;
     1.6  float g_fUniversalTime = 0.0f;
     1.7 -float g_fMapStartTime = 0.0f;
     1.8 +float g_fGameStartTime = 0.0f;	/* Game game start time, non-universal */
     1.9  const float *g_pUniversalTime = &g_fUniversalTime;
    1.10  ConVar *mp_timelimit = NULL;
    1.11 +int g_TimeLeftMode = 0;
    1.12  
    1.13  ConVar sm_time_adjustment("sm_time_adjustment", "0", 0, "Adjusts the server time in seconds");
    1.14  
    1.15 @@ -70,6 +71,11 @@
    1.16  		m_bInUse = false;
    1.17  	}
    1.18  
    1.19 +	void OnSourceModLevelChange(const char *mapName)
    1.20 +	{
    1.21 +		g_fGameStartTime = 0.0f;
    1.22 +	}
    1.23 +
    1.24  	int GetMapTimeLimit()
    1.25  	{
    1.26  		return mp_timelimit->GetInt();
    1.27 @@ -88,18 +94,6 @@
    1.28  		m_bInUse = enabled;
    1.29  	}
    1.30  
    1.31 -	 bool GetMapTimeLeft(int *time_left)
    1.32 -	{
    1.33 -		if (GetMapTimeLimit() == 0)
    1.34 -		{
    1.35 -			return false;
    1.36 -		}
    1.37 -
    1.38 -		*time_left = (int)((g_fMapStartTime + mp_timelimit->GetInt() * 60.0f) - g_fUniversalTime);
    1.39 -
    1.40 -		return true;
    1.41 -	}
    1.42 -
    1.43  	void ExtendMapTimeLimit(int extra_time)
    1.44  	{
    1.45  		extra_time /= 60;
    1.46 @@ -176,6 +170,7 @@
    1.47  {
    1.48  	g_ShareSys.AddInterface(NULL, this);
    1.49  	m_pOnGameFrame = g_Forwards.CreateForward("OnGameFrame", ET_Ignore, 0, NULL);
    1.50 +	m_pOnMapTimeLeftChanged = g_Forwards.CreateForward("OnMapTimeLeftChanged", ET_Ignore, 0, NULL);
    1.51  }
    1.52  
    1.53  void TimerSystem::OnSourceModGameInitialized()
    1.54 @@ -192,6 +187,7 @@
    1.55  {
    1.56  	SetMapTimer(NULL);
    1.57  	g_Forwards.ReleaseForward(m_pOnGameFrame);
    1.58 +	g_Forwards.ReleaseForward(m_pOnMapTimeLeftChanged);
    1.59  }
    1.60  
    1.61  void TimerSystem::OnSourceModLevelChange(const char *mapName)
    1.62 @@ -216,11 +212,7 @@
    1.63  	}
    1.64  
    1.65  	m_fLastTickedTime = gpGlobals->curtime;
    1.66 -	if (!m_bHasMapTickedYet)
    1.67 -	{
    1.68 -		g_fMapStartTime = g_fUniversalTime;
    1.69 -		m_bHasMapTickedYet = true;
    1.70 -	}
    1.71 +	m_bHasMapTickedYet = true;
    1.72  
    1.73  	if (g_fUniversalTime - m_LastExecTime >= 0.1)
    1.74  	{
    1.75 @@ -443,10 +435,28 @@
    1.76  
    1.77  void TimerSystem::MapTimeLeftChanged()
    1.78  {
    1.79 +	m_pOnMapTimeLeftChanged->Execute(NULL);
    1.80 +}
    1.81  
    1.82 +void TimerSystem::NotifyOfGameStart(float offset)
    1.83 +{
    1.84 +	g_fGameStartTime = gpGlobals->curtime + offset;
    1.85  }
    1.86  
    1.87  float TimerSystem::GetTickedTime()
    1.88  {
    1.89  	return g_fUniversalTime;
    1.90  }
    1.91 +
    1.92 +bool TimerSystem::GetMapTimeLeft(float *time_left)
    1.93 +{
    1.94 +	int time_limit;
    1.95 +	if (!m_pMapTimer || (time_limit = m_pMapTimer->GetMapTimeLimit()) < 1)
    1.96 +	{
    1.97 +		return false;
    1.98 +	}
    1.99 +
   1.100 +	*time_left = (g_fGameStartTime + time_limit * 60.0f) - gpGlobals->curtime;
   1.101 +
   1.102 +	return true;
   1.103 +}