clarified and fixed the meaning of timelimit/timeleft when no frames have been processed

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401468
This commit is contained in:
David Anderson 2007-09-23 20:11:48 +00:00
parent 997bab506c
commit 8bbbb57d8c
5 changed files with 40 additions and 19 deletions

View File

@ -152,6 +152,7 @@ TimerSystem::TimerSystem()
{
m_pMapTimer = NULL;
m_bHasMapTickedYet = false;
m_bHasMapSimulatedYet = false;
m_fLastTickedTime = 0.0f;
m_LastExecTime = 0.0f;
}
@ -198,6 +199,7 @@ void TimerSystem::OnSourceModLevelChange(const char *mapName)
void TimerSystem::OnSourceModLevelEnd()
{
m_bHasMapTickedYet = false;
m_bHasMapSimulatedYet = false;
}
void TimerSystem::GameFrame(bool simulating)
@ -205,6 +207,11 @@ void TimerSystem::GameFrame(bool simulating)
if (simulating && m_bHasMapTickedYet)
{
g_fUniversalTime += gpGlobals->curtime - m_fLastTickedTime;
if (!m_bHasMapSimulatedYet)
{
m_bHasMapSimulatedYet = true;
MapTimeLeftChanged();
}
}
else
{
@ -450,13 +457,21 @@ float TimerSystem::GetTickedTime()
bool TimerSystem::GetMapTimeLeft(float *time_left)
{
int time_limit;
if (!m_pMapTimer || (time_limit = m_pMapTimer->GetMapTimeLimit()) < 1)
if (!m_pMapTimer)
{
return false;
}
*time_left = (g_fGameStartTime + time_limit * 60.0f) - gpGlobals->curtime;
int time_limit;
if (!m_bHasMapSimulatedYet || (time_limit = m_pMapTimer->GetMapTimeLimit()) < 1)
{
*time_left = -1.0f;
}
else
{
*time_left = (g_fGameStartTime + time_limit * 60.0f) - gpGlobals->curtime;
}
return true;
}

View File

@ -93,6 +93,7 @@ private:
/* This is stuff for our manual ticking escapades. */
bool m_bHasMapTickedYet; /** Has the map ticked yet? */
bool m_bHasMapSimulatedYet; /** Has the map simulated yet? */
float m_fLastTickedTime; /** Last time that the game currently gave
us while ticking.
*/

View File

@ -260,23 +260,17 @@ static cell_t smn_GetTickedTime(IPluginContext *pContext, const cell_t *params)
static cell_t smn_GetMapTimeLeft(IPluginContext *pContext, const cell_t *params)
{
cell_t *addr;
pContext->LocalToPhysAddr(params[1], &addr);
float time_left;
int int_time;
if (!g_Timers.GetMapTimeLeft(&time_left))
{
int_time = -1;
}
else
{
int_time = (int)time_left;
return 0;
}
*addr = int_time;
cell_t *addr;
pContext->LocalToPhysAddr(params[1], &addr);
*addr = (int)time_left;
return true;
return 1;
}
static cell_t smn_GetMapTimeLimit(IPluginContext *pContext, const cell_t *params)
@ -327,3 +321,4 @@ REGISTER_NATIVES(timernatives)
{"IsServerProcessing", smn_IsServerProcessing},
{NULL, NULL}
};

View File

@ -121,7 +121,9 @@ native TriggerTimer(Handle:timer, bool:reset=false);
native Float:GetTickedTime();
/**
* Returns an estimate of the time left before the map ends.
* Returns an estimate of the time left before the map ends. If the server
* has not processed any frames yet (i.e. no players have joined the map yet),
* then the time left returned will always be infinite.
*
* @param timeleft Variable to store the time, in seconds. If the
* value is less than 0, the time limit is infinite.
@ -130,7 +132,9 @@ native Float:GetTickedTime();
native bool:GetMapTimeLeft(&timeleft);
/**
* Retrieves the current map time limit.
* Retrieves the current map time limit. If the server has not processed any
* frames yet (i.e. no players have joined the map yet), then the time limit
* returned will always be 0.
*
* @param time Set to the number of total seconds in the map time
* limit, or 0 if there is no time limit set.
@ -149,7 +153,7 @@ native bool:GetMapTimeLimit(&time);
native bool:ExtendMapTimeLimit(time);
/**
* Notification that the map's time left has changed via a change in the time
* Notification that the map's time left has changed via a change in the time
* limit or a change in the game rules (such as mp_restartgame). This is useful
* for plugins trying to create timers based on the time left in the map.
*
@ -157,6 +161,10 @@ native bool:ExtendMapTimeLimit(time);
* cause infinite recursion.
*
* If the operation is not supported, this will never be called.
* If the server has not yet processed any frames (i.e. no players have joined
* the map yet), then this will be called once the server begins ticking, even
* if there is no time limit set.
*/
forward OnMapTimeLeftChanged();
@ -188,3 +196,4 @@ stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0)
flags |= TIMER_HNDL_CLOSE;
return CreateTimer(interval, func, data, flags);
}

View File

@ -198,8 +198,9 @@ namespace SourceMod
* @brief Returns the time left in the map.
*
* @param pTime Pointer to store time left, in seconds.
* @return True on success, false if there no time limit
* or if the time limit could not be determined.
* If there is no time limit, the number will
* be below 0.
* @return True on success, false if no support.
*/
virtual bool GetMapTimeLeft(float *pTime) =0;
};