- added timeleft functionality to cstrike extension

- finalized timeleft api once again (i hope)
- added weapon slot definitions to cstrike.inc
- bumped timer API

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401465
This commit is contained in:
David Anderson
2007-09-23 19:33:19 +00:00
parent 980a8fba7b
commit 0f45f8b5ee
16 changed files with 400 additions and 49 deletions
+28 -18
View File
@@ -39,9 +39,10 @@ SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *
TimerSystem g_Timers;
float g_fUniversalTime = 0.0f;
float g_fMapStartTime = 0.0f;
float g_fGameStartTime = 0.0f; /* Game game start time, non-universal */
const float *g_pUniversalTime = &g_fUniversalTime;
ConVar *mp_timelimit = NULL;
int g_TimeLeftMode = 0;
ConVar sm_time_adjustment("sm_time_adjustment", "0", 0, "Adjusts the server time in seconds");
@@ -70,6 +71,11 @@ public:
m_bInUse = false;
}
void OnSourceModLevelChange(const char *mapName)
{
g_fGameStartTime = 0.0f;
}
int GetMapTimeLimit()
{
return mp_timelimit->GetInt();
@@ -88,18 +94,6 @@ public:
m_bInUse = enabled;
}
bool GetMapTimeLeft(int *time_left)
{
if (GetMapTimeLimit() == 0)
{
return false;
}
*time_left = (int)((g_fMapStartTime + mp_timelimit->GetInt() * 60.0f) - g_fUniversalTime);
return true;
}
void ExtendMapTimeLimit(int extra_time)
{
extra_time /= 60;
@@ -176,6 +170,7 @@ void TimerSystem::OnSourceModAllInitialized()
{
g_ShareSys.AddInterface(NULL, this);
m_pOnGameFrame = g_Forwards.CreateForward("OnGameFrame", ET_Ignore, 0, NULL);
m_pOnMapTimeLeftChanged = g_Forwards.CreateForward("OnMapTimeLeftChanged", ET_Ignore, 0, NULL);
}
void TimerSystem::OnSourceModGameInitialized()
@@ -192,6 +187,7 @@ void TimerSystem::OnSourceModShutdown()
{
SetMapTimer(NULL);
g_Forwards.ReleaseForward(m_pOnGameFrame);
g_Forwards.ReleaseForward(m_pOnMapTimeLeftChanged);
}
void TimerSystem::OnSourceModLevelChange(const char *mapName)
@@ -216,11 +212,7 @@ void TimerSystem::GameFrame(bool simulating)
}
m_fLastTickedTime = gpGlobals->curtime;
if (!m_bHasMapTickedYet)
{
g_fMapStartTime = g_fUniversalTime;
m_bHasMapTickedYet = true;
}
m_bHasMapTickedYet = true;
if (g_fUniversalTime - m_LastExecTime >= 0.1)
{
@@ -443,10 +435,28 @@ IMapTimer *TimerSystem::GetMapTimer()
void TimerSystem::MapTimeLeftChanged()
{
m_pOnMapTimeLeftChanged->Execute(NULL);
}
void TimerSystem::NotifyOfGameStart(float offset)
{
g_fGameStartTime = gpGlobals->curtime + offset;
}
float TimerSystem::GetTickedTime()
{
return g_fUniversalTime;
}
bool TimerSystem::GetMapTimeLeft(float *time_left)
{
int time_limit;
if (!m_pMapTimer || (time_limit = m_pMapTimer->GetMapTimeLimit()) < 1)
{
return false;
}
*time_left = (g_fGameStartTime + time_limit * 60.0f) - gpGlobals->curtime;
return true;
}
+4
View File
@@ -77,6 +77,8 @@ public: //ITimerSystem
void MapTimeLeftChanged();
IMapTimer *SetMapTimer(IMapTimer *pTimer);
float GetTickedTime();
void NotifyOfGameStart(float offset /* = 0.0f */);
bool GetMapTimeLeft(float *pTime);
public:
void RunFrame();
void MapChange(bool real_mapchange);
@@ -96,12 +98,14 @@ private:
*/
IForward *m_pOnGameFrame;
IForward *m_pOnMapTimeLeftChanged;
};
time_t GetAdjustedTime(time_t *buf = NULL);
extern const float *g_pUniversalTime;
extern TimerSystem g_Timers;
extern int g_TimeLeftMode;
#endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_
+18
View File
@@ -298,6 +298,24 @@
<File
RelativePath="..\Database.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ExpandAttributedSource="true"
AssemblerOutput="4"
/>
</FileConfiguration>
<FileConfiguration
Name="CrazyDebug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ExpandAttributedSource="false"
AssemblerOutput="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\DebugReporter.cpp"
+15 -11
View File
@@ -260,23 +260,21 @@ static cell_t smn_GetTickedTime(IPluginContext *pContext, const cell_t *params)
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))
float time_left;
int int_time;
if (!g_Timers.GetMapTimeLeft(&time_left))
{
time_left = -1;
int_time = -1;
}
else
{
int_time = (int)time_left;
}
*addr = time_left;
*addr = int_time;
return true;
}
@@ -312,6 +310,11 @@ static cell_t smn_ExtendMapTimeLimit(IPluginContext *pContext, const cell_t *par
return 1;
}
static cell_t smn_IsServerTicking(IPluginContext *pContext, const cell_t *params)
{
return (gpGlobals->frametime > 0.0f) ? 1 : 0;
}
REGISTER_NATIVES(timernatives)
{
{"CreateTimer", smn_CreateTimer},
@@ -321,5 +324,6 @@ REGISTER_NATIVES(timernatives)
{"GetMapTimeLeft", smn_GetMapTimeLeft},
{"GetMapTimeLimit", smn_GetMapTimeLimit},
{"ExtendMapTimeLimit", smn_ExtendMapTimeLimit},
{"IsServerTicking", smn_IsServerTicking},
{NULL, NULL}
};