mess around with the timer starting & restarting code

This commit is contained in:
rtldg 2021-12-30 08:49:42 +00:00
parent 01a2e616a6
commit 0a99f06ff4
4 changed files with 44 additions and 66 deletions

View File

@ -856,9 +856,10 @@ native void Shavit_StartTimer(int client, int track);
*
* @param client Client index.
* @param track Timer track.
* @noreturn
* @param force True to force the player to restart. False to call into Shavit_OnRestartPre and Shavit_OnStopPre first.
* @return True on restart and False if a callback blocked the restart.
*/
native void Shavit_RestartTimer(int client, int track);
native bool Shavit_RestartTimer(int client, int track, bool force=true);
/**
* Stops the timer for a player.

View File

@ -625,26 +625,7 @@ public Action Command_StartTimer(int client, int args)
return Plugin_Handled;
}
Action result = Plugin_Continue;
Call_StartForward(gH_Forwards_OnRestartPre);
Call_PushCell(client);
Call_PushCell(track);
Call_Finish(result);
if (result > Plugin_Continue)
{
return Plugin_Handled;
}
if (!Shavit_StopTimer(client, false))
{
return Plugin_Handled;
}
Call_StartForward(gH_Forwards_OnRestart);
Call_PushCell(client);
Call_PushCell(track);
Call_Finish();
Shavit_RestartTimer(client, track);
return Plugin_Handled;
}
@ -1459,11 +1440,7 @@ void ChangeClientStyle(int client, int style, bool manual)
if (gB_Zones && (Shavit_ZoneExists(Zone_Start, gA_Timers[client].iTimerTrack) || gB_KZMap[gA_Timers[client].iTimerTrack]))
{
Shavit_StopTimer(client, true);
Call_StartForward(gH_Forwards_OnRestart);
Call_PushCell(client);
Call_PushCell(gA_Timers[client].iTimerTrack);
Call_Finish();
Shavit_RestartTimer(client, gA_Timers[client].iTimerTrack, true);
}
char sStyle[4];
@ -1999,18 +1976,40 @@ public int Native_RestartTimer(Handle handler, int numParams)
{
int client = GetNativeCell(1);
int track = GetNativeCell(2);
bool force = (numParams < 3) || GetNativeCell(3);
Shavit_StopTimer(client, true);
if (!force)
{
Action result = Plugin_Continue;
Call_StartForward(gH_Forwards_OnRestartPre);
Call_PushCell(client);
Call_PushCell(track);
Call_Finish(result);
if (result > Plugin_Continue)
{
return 0;
}
}
if (!Shavit_StopTimer(client, force))
{
return 0;
}
if (gA_Timers[client].iTimerTrack != track)
{
CallOnTrackChanged(client, gA_Timers[client].iTimerTrack, track);
}
gA_Timers[client].iTimerTrack = track;
Call_StartForward(gH_Forwards_OnRestart);
Call_PushCell(client);
Call_PushCell(track);
Call_Finish();
if (!gB_Zones)
{
StartTimer(client, track);
}
return 1;
}
float CalcPerfs(timer_snapshot_t s)

View File

@ -2241,21 +2241,13 @@ public Action Respawn(Handle timer, any data)
if(gCV_RespawnOnRestart.BoolValue)
{
RestartTimer(client, Track_Main);
Shavit_RestartTimer(client, Shavit_GetClientTrack(client));
}
}
return Plugin_Handled;
}
void RestartTimer(int client, int track)
{
if ((gB_Zones && Shavit_ZoneExists(Zone_Start, track)) || Shavit_IsKZMap(track))
{
Shavit_RestartTimer(client, track);
}
}
public void Player_Spawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
@ -2271,7 +2263,7 @@ public void Player_Spawn(Event event, const char[] name, bool dontBroadcast)
if (gCV_StartOnSpawn.BoolValue && !(gB_Checkpoints && Shavit_HasSavestate(client)))
{
RestartTimer(client, Track_Main);
Shavit_RestartTimer(client, Shavit_GetClientTrack(client));
}
if(gCV_Scoreboard.BoolValue)

View File

@ -3648,54 +3648,46 @@ public void Shavit_OnRestart(int client, int track)
if(gCV_TeleportToStart.BoolValue)
{
bool use_CustomStart_over_CustomSpawn = (iIndex != -1) && gB_HasSetStart[client][track] && !gB_StartAnglesOnly[client][track];
bool bCustomStart = gB_HasSetStart[client][track] && !gB_StartAnglesOnly[client][track];
bool use_CustomStart_over_CustomSpawn = (iIndex != -1) && bCustomStart;
// custom spawns
if (!use_CustomStart_over_CustomSpawn && !EmptyVector(gF_CustomSpawn[track]))
{
TeleportEntity(client, gF_CustomSpawn[track], NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0}));
}
// standard zoning
else if (iIndex != -1)
{
float bmin[3], bmax[3];
bool bCustomStart = false;
float fCenter[3];
fCenter[0] = gV_ZoneCenter[iIndex][0];
fCenter[1] = gV_ZoneCenter[iIndex][1];
fCenter[2] = gV_MapZones[iIndex][0][2] + gCV_ExtraSpawnHeight.FloatValue;
if (gB_HasSetStart[client][track] && !gB_StartAnglesOnly[client][track])
if (bCustomStart)
{
FillBoxMinMax(gV_MapZones[iIndex][0], gV_MapZones[iIndex][1], bmin, bmax);
bmin[2] -= 0.01; // help fix some slight float accuracy loss for things like bhop_pisjapahnetribkoj
fCenter = gF_StartPos[client][track];
bCustomStart = true;
}
fCenter[2] += 1.0;
if (bCustomStart && !PointInBox(fCenter, bmin, bmax))
{
Shavit_StopTimer(client);
}
TeleportEntity(client, fCenter, gB_HasSetStart[client][track] ? gF_StartAng[client][track] : NULL_VECTOR, view_as<float>({0.0, 0.0, 0.0}));
// I would like to put MaybeDoPhysicsUntouch() here but then it doesn't retrigger the zone's starttouch until next frame so the hud can show the wrong thing if I spam !r since the player isn't "in-the-zone"... TODO maybe...
if (gB_ReplayRecorder && gB_HasSetStart[client][track])
{
Shavit_HijackAngles(client, gF_StartAng[client][track][0], gF_StartAng[client][track][1], -1, true);
}
}
if (!gB_HasSetStart[client][track] || gB_StartAnglesOnly[client][track])
{
// normally StartTimer will happen on zone-touch BUT we have this here for zones that are in the air
Shavit_StartTimer(client, track);
}
}
// kz buttons
else if (Shavit_IsKZMap(track))
{
Shavit_StopTimer(client);
if (EmptyVector(gF_ClimbButtonCache[client][track][0]) || EmptyVector(gF_ClimbButtonCache[client][track][1]))
{
return;
@ -3705,12 +3697,6 @@ public void Shavit_OnRestart(int client, int track)
return;
}
// Just let TouchPost/TouchPost_Trigger handle it so setstarts outside of a start zone don't start.
if (!gB_HasSetStart[client][track] || gB_StartAnglesOnly[client][track])
{
Shavit_StartTimer(client, track);
}
}
if (iIndex != -1)