finalized (i hope) new map timer api
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401421
This commit is contained in:
parent
6206027476
commit
c531ad8564
@ -120,7 +120,12 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_Timers.MapTimeLimitExtended(atoi(old_value) * 60, pVar->GetInt() * 60);
|
if (atoi(old_value) == pVar->GetInt())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_Timers.MapTimeLeftChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -436,10 +441,12 @@ IMapTimer *TimerSystem::GetMapTimer()
|
|||||||
return m_pMapTimer;
|
return m_pMapTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerSystem::MapTimeLimitExtended(int old_limit, int new_limit)
|
void TimerSystem::MapTimeLeftChanged()
|
||||||
{
|
{
|
||||||
if (old_limit == new_limit)
|
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
float TimerSystem::GetTickedTime()
|
||||||
|
{
|
||||||
|
return g_fUniversalTime;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,9 @@ public: //ITimerSystem
|
|||||||
ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
|
ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
|
||||||
void KillTimer(ITimer *pTimer);
|
void KillTimer(ITimer *pTimer);
|
||||||
void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
|
void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
|
||||||
void MapTimeLimitExtended(int old_limit, int new_limit);
|
void MapTimeLeftChanged();
|
||||||
IMapTimer *SetMapTimer(IMapTimer *pTimer);
|
IMapTimer *SetMapTimer(IMapTimer *pTimer);
|
||||||
|
float GetTickedTime();
|
||||||
public:
|
public:
|
||||||
void RunFrame();
|
void RunFrame();
|
||||||
void MapChange(bool real_mapchange);
|
void MapChange(bool real_mapchange);
|
||||||
|
@ -258,11 +258,68 @@ static cell_t smn_GetTickedTime(IPluginContext *pContext, const cell_t *params)
|
|||||||
return sp_ftoc(*g_pUniversalTime);
|
return sp_ftoc(*g_pUniversalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t smn_GetMapTimeLeft(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
IMapTimer *pMapTimer = g_Timers.GetMapTimer();
|
||||||
|
|
||||||
|
if (!pMapTimer)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t *addr;
|
||||||
|
pContext->LocalToPhysAddr(params[1], &addr);
|
||||||
|
|
||||||
|
int time_left;
|
||||||
|
if (!pMapTimer->GetMapTimeLeft(&time_left))
|
||||||
|
{
|
||||||
|
time_left = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*addr = time_left;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t smn_GetMapTimeLimit(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
IMapTimer *pMapTimer = g_Timers.GetMapTimer();
|
||||||
|
|
||||||
|
if (!pMapTimer)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t *addr;
|
||||||
|
pContext->LocalToPhysAddr(params[1], &addr);
|
||||||
|
|
||||||
|
*addr = pMapTimer->GetMapTimeLimit();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t smn_ExtendMapTimeLimit(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
IMapTimer *pMapTimer = g_Timers.GetMapTimer();
|
||||||
|
|
||||||
|
if (!pMapTimer)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pMapTimer->ExtendMapTimeLimit(params[1]);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
REGISTER_NATIVES(timernatives)
|
REGISTER_NATIVES(timernatives)
|
||||||
{
|
{
|
||||||
{"CreateTimer", smn_CreateTimer},
|
{"CreateTimer", smn_CreateTimer},
|
||||||
{"KillTimer", smn_KillTimer},
|
{"KillTimer", smn_KillTimer},
|
||||||
{"TriggerTimer", smn_TriggerTimer},
|
{"TriggerTimer", smn_TriggerTimer},
|
||||||
{"GetTickedTime", smn_GetTickedTime},
|
{"GetTickedTime", smn_GetTickedTime},
|
||||||
|
{"GetMapTimeLeft", smn_GetMapTimeLeft},
|
||||||
|
{"GetMapTimeLimit", smn_GetMapTimeLimit},
|
||||||
|
{"ExtendMapTimeLimit", smn_ExtendMapTimeLimit},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -120,6 +120,46 @@ native TriggerTimer(Handle:timer, bool:reset=false);
|
|||||||
*/
|
*/
|
||||||
native Float:GetTickedTime();
|
native Float:GetTickedTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an estimate of the time left before the map ends.
|
||||||
|
*
|
||||||
|
* @param timeleft Variable to store the time, in seconds. If the
|
||||||
|
* value is less than 0, the time limit is infinite.
|
||||||
|
* @return True if the operation is supported, false otherwise.
|
||||||
|
*/
|
||||||
|
native bool:GetMapTimeLeft(&timeleft);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current map time limit.
|
||||||
|
*
|
||||||
|
* @param time Set to the number of total seconds in the map time
|
||||||
|
* limit, or 0 if there is no time limit set.
|
||||||
|
* @return True on success, false if operation is not supported.
|
||||||
|
*/
|
||||||
|
native bool:GetMapTimeLimit(&time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the map time limit in a way that will notify all plugins.
|
||||||
|
*
|
||||||
|
* @param time Number of seconds to extend map time limit by.
|
||||||
|
* The number can be negative to decrease the time limit.
|
||||||
|
* If 0, the map will be set to have no time limit.
|
||||||
|
* @return True on success, false if operation is not supported.
|
||||||
|
*/
|
||||||
|
native bool:ExtendMapTimeLimit(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.
|
||||||
|
*
|
||||||
|
* Calling ExtendMapTimeLimit() from here, without proper precaution, will
|
||||||
|
* cause infinite recursion.
|
||||||
|
*
|
||||||
|
* If the operation is not supported, this will never be called.
|
||||||
|
*/
|
||||||
|
forward OnMapTimeLeftChanged();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a timer associated with a new data pack, and returns the datapack.
|
* Creates a timer associated with a new data pack, and returns the datapack.
|
||||||
* @note The datapack is automatically freed when the timer ends.
|
* @note The datapack is automatically freed when the timer ends.
|
||||||
|
@ -174,16 +174,27 @@ namespace SourceMod
|
|||||||
virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0;
|
virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Notifies the timer that the map timelimit has been extended.
|
* @brief Notification that the map's time left has changed
|
||||||
*
|
* via a change in the time limit or a change in the game rules (
|
||||||
* A time limit of 0 implies that there is no limit.
|
* such as mp_restartgame).
|
||||||
*
|
|
||||||
* @param old_limit Old limit, in seconds.
|
|
||||||
* @param new_limit New limit, in seconds.
|
|
||||||
*/
|
*/
|
||||||
virtual void MapTimeLimitExtended(int old_limit, int new_limit) =0;
|
virtual void MapTimeLeftChanged() =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the current universal tick time. This
|
||||||
|
* replacement for gpGlobals->curtime and engine->Time() correctly
|
||||||
|
* keeps track of ticks.
|
||||||
|
*
|
||||||
|
* During simulation, it is incremented by the difference between
|
||||||
|
* gpGlobals->curtime and the last simulated tick. Otherwise,
|
||||||
|
* it is incremented by the interval per tick.
|
||||||
|
*
|
||||||
|
* It is not reset past map changes.
|
||||||
|
*
|
||||||
|
* @return Universal ticked time.
|
||||||
|
*/
|
||||||
|
virtual float GetTickedTime() =0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
|
#endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user