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:
parent
997bab506c
commit
8bbbb57d8c
@ -152,6 +152,7 @@ TimerSystem::TimerSystem()
|
|||||||
{
|
{
|
||||||
m_pMapTimer = NULL;
|
m_pMapTimer = NULL;
|
||||||
m_bHasMapTickedYet = false;
|
m_bHasMapTickedYet = false;
|
||||||
|
m_bHasMapSimulatedYet = false;
|
||||||
m_fLastTickedTime = 0.0f;
|
m_fLastTickedTime = 0.0f;
|
||||||
m_LastExecTime = 0.0f;
|
m_LastExecTime = 0.0f;
|
||||||
}
|
}
|
||||||
@ -198,6 +199,7 @@ void TimerSystem::OnSourceModLevelChange(const char *mapName)
|
|||||||
void TimerSystem::OnSourceModLevelEnd()
|
void TimerSystem::OnSourceModLevelEnd()
|
||||||
{
|
{
|
||||||
m_bHasMapTickedYet = false;
|
m_bHasMapTickedYet = false;
|
||||||
|
m_bHasMapSimulatedYet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerSystem::GameFrame(bool simulating)
|
void TimerSystem::GameFrame(bool simulating)
|
||||||
@ -205,6 +207,11 @@ void TimerSystem::GameFrame(bool simulating)
|
|||||||
if (simulating && m_bHasMapTickedYet)
|
if (simulating && m_bHasMapTickedYet)
|
||||||
{
|
{
|
||||||
g_fUniversalTime += gpGlobals->curtime - m_fLastTickedTime;
|
g_fUniversalTime += gpGlobals->curtime - m_fLastTickedTime;
|
||||||
|
if (!m_bHasMapSimulatedYet)
|
||||||
|
{
|
||||||
|
m_bHasMapSimulatedYet = true;
|
||||||
|
MapTimeLeftChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -450,13 +457,21 @@ float TimerSystem::GetTickedTime()
|
|||||||
|
|
||||||
bool TimerSystem::GetMapTimeLeft(float *time_left)
|
bool TimerSystem::GetMapTimeLeft(float *time_left)
|
||||||
{
|
{
|
||||||
int time_limit;
|
if (!m_pMapTimer)
|
||||||
if (!m_pMapTimer || (time_limit = m_pMapTimer->GetMapTimeLimit()) < 1)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
*time_left = (g_fGameStartTime + time_limit * 60.0f) - gpGlobals->curtime;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ private:
|
|||||||
|
|
||||||
/* This is stuff for our manual ticking escapades. */
|
/* This is stuff for our manual ticking escapades. */
|
||||||
bool m_bHasMapTickedYet; /** Has the map ticked yet? */
|
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
|
float m_fLastTickedTime; /** Last time that the game currently gave
|
||||||
us while ticking.
|
us while ticking.
|
||||||
*/
|
*/
|
||||||
|
@ -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)
|
static cell_t smn_GetMapTimeLeft(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
cell_t *addr;
|
|
||||||
pContext->LocalToPhysAddr(params[1], &addr);
|
|
||||||
|
|
||||||
float time_left;
|
float time_left;
|
||||||
int int_time;
|
|
||||||
if (!g_Timers.GetMapTimeLeft(&time_left))
|
if (!g_Timers.GetMapTimeLeft(&time_left))
|
||||||
{
|
{
|
||||||
int_time = -1;
|
return 0;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int_time = (int)time_left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*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)
|
static cell_t smn_GetMapTimeLimit(IPluginContext *pContext, const cell_t *params)
|
||||||
@ -327,3 +321,4 @@ REGISTER_NATIVES(timernatives)
|
|||||||
{"IsServerProcessing", smn_IsServerProcessing},
|
{"IsServerProcessing", smn_IsServerProcessing},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,7 +121,9 @@ native TriggerTimer(Handle:timer, bool:reset=false);
|
|||||||
native Float:GetTickedTime();
|
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
|
* @param timeleft Variable to store the time, in seconds. If the
|
||||||
* value is less than 0, the time limit is infinite.
|
* value is less than 0, the time limit is infinite.
|
||||||
@ -130,7 +132,9 @@ native Float:GetTickedTime();
|
|||||||
native bool:GetMapTimeLeft(&timeleft);
|
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
|
* @param time Set to the number of total seconds in the map time
|
||||||
* limit, or 0 if there is no time limit set.
|
* limit, or 0 if there is no time limit set.
|
||||||
@ -157,6 +161,10 @@ native bool:ExtendMapTimeLimit(time);
|
|||||||
* cause infinite recursion.
|
* cause infinite recursion.
|
||||||
*
|
*
|
||||||
* If the operation is not supported, this will never be called.
|
* 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();
|
forward OnMapTimeLeftChanged();
|
||||||
|
|
||||||
@ -188,3 +196,4 @@ stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0)
|
|||||||
flags |= TIMER_HNDL_CLOSE;
|
flags |= TIMER_HNDL_CLOSE;
|
||||||
return CreateTimer(interval, func, data, flags);
|
return CreateTimer(interval, func, data, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,8 +198,9 @@ namespace SourceMod
|
|||||||
* @brief Returns the time left in the map.
|
* @brief Returns the time left in the map.
|
||||||
*
|
*
|
||||||
* @param pTime Pointer to store time left, in seconds.
|
* @param pTime Pointer to store time left, in seconds.
|
||||||
* @return True on success, false if there no time limit
|
* If there is no time limit, the number will
|
||||||
* or if the time limit could not be determined.
|
* be below 0.
|
||||||
|
* @return True on success, false if no support.
|
||||||
*/
|
*/
|
||||||
virtual bool GetMapTimeLeft(float *pTime) =0;
|
virtual bool GetMapTimeLeft(float *pTime) =0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user