spread avg/max velocity into as many places as possible

This commit is contained in:
Joe 2021-02-26 18:28:40 +00:00
parent 7b2fb3be65
commit 5351e49e76
3 changed files with 48 additions and 9 deletions

View File

@ -222,6 +222,8 @@ enum struct timer_snapshot_t
int iPerfectJumps; int iPerfectJumps;
float fTimeOffset[2]; float fTimeOffset[2];
float fDistanceOffset[2]; float fDistanceOffset[2];
float fAvgVelocity;
float fMaxVelocity;
} }
enum struct cp_cache_t enum struct cp_cache_t
@ -580,9 +582,11 @@ forward Action Shavit_OnFinishPre(int client, timer_snapshot_t snapshot);
* @param track Timer track. * @param track Timer track.
* @param oldtime The player's best time on the map before this finish. * @param oldtime The player's best time on the map before this finish.
* @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured. * @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured.
* @param avgvel Player's average velocity throughout the run.
* @param maxvel Player's highest reached velocity.
* @noreturn * @noreturn
*/ */
forward void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs); forward void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs, float avgvel, float maxvel);
/** /**
* Like Shavit_OnFinish, but after the insertion query was called. * Like Shavit_OnFinish, but after the insertion query was called.
@ -599,9 +603,11 @@ forward void Shavit_OnFinish(int client, int style, float time, int jumps, int s
* @param track Timer track. * @param track Timer track.
* @param oldtime The player's best time on the map before this finish. * @param oldtime The player's best time on the map before this finish.
* @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured. * @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured.
* @param avgvel Player's average velocity throughout the run.
* @param maxvel Player's highest reached velocity.
* @noreturn * @noreturn
*/ */
forward void Shavit_OnFinish_Post(int client, int style, float time, int jumps, int strafes, float sync, int rank, int overwrite, int track, float oldtime, float perfs); forward void Shavit_OnFinish_Post(int client, int style, float time, int jumps, int strafes, float sync, int rank, int overwrite, int track, float oldtime, float perfs, float avgvel, float maxvel);
/** /**
* Called when there's a new WR on the map. * Called when there's a new WR on the map.
@ -616,9 +622,11 @@ forward void Shavit_OnFinish_Post(int client, int style, float time, int jumps,
* @param oldwr Time of the old WR. 0.0 if there's none. * @param oldwr Time of the old WR. 0.0 if there's none.
* @param oldtime The player's best time on the map before this finish. * @param oldtime The player's best time on the map before this finish.
* @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured. * @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured.
* @param avgvel Player's average velocity throughout the run.
* @param maxvel Player's highest reached velocity.
* @noreturn * @noreturn
*/ */
forward void Shavit_OnWorldRecord(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldwr, float oldtime, float perfs); forward void Shavit_OnWorldRecord(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldwr, float oldtime, float perfs, float avgvel, float maxvel);
/** /**
* Called when an admin deletes a WR. * Called when an admin deletes a WR.
@ -773,9 +781,11 @@ forward Action Shavit_OnStageMessage(int client, int stageNumber, char[] message
* @param track Timer track. * @param track Timer track.
* @param oldtime The player's best time on the map before this finish. * @param oldtime The player's best time on the map before this finish.
* @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured. * @param perfs Perfect jump percentage (0.0 to 100.0) or 100.0 when not measured.
* @param avgvel Player's average velocity throughout the run.
* @param maxvel Player's highest reached velocity.
* @noreturn * @noreturn
*/ */
forward void Shavit_OnWorstRecord(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs); forward void Shavit_OnWorstRecord(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs, float avgvel, float maxvel);
/** /**
* Gets called when a map's tier is assigned. * Gets called when a map's tier is assigned.

View File

@ -1668,6 +1668,8 @@ public int Native_FinishMap(Handle handler, int numParams)
snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps; snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps;
snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; snapshot.fTimeOffset = gA_Timers[client].fTimeOffset;
snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset;
snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity;
snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity;
Action result = Plugin_Continue; Action result = Plugin_Continue;
Call_StartForward(gH_Forwards_FinishPre); Call_StartForward(gH_Forwards_FinishPre);
@ -1720,6 +1722,18 @@ public int Native_FinishMap(Handle handler, int numParams)
Call_PushCell(oldtime); Call_PushCell(oldtime);
Call_PushCell(perfs); Call_PushCell(perfs);
if(result == Plugin_Continue)
{
Call_PushCell(gA_Timers[client].fAvgVelocity);
Call_PushCell(gA_Timers[client].fMaxVelocity);
}
else
{
Call_PushCell(snapshot.fAvgVelocity);
Call_PushCell(snapshot.fMaxVelocity);
}
Call_Finish(); Call_Finish();
StopTimer(client); StopTimer(client);
@ -2010,6 +2024,8 @@ public int Native_SaveSnapshot(Handle handler, int numParams)
snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps; snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps;
snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; snapshot.fTimeOffset = gA_Timers[client].fTimeOffset;
snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset;
snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity;
snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity;
return SetNativeArray(2, snapshot, sizeof(timer_snapshot_t)); return SetNativeArray(2, snapshot, sizeof(timer_snapshot_t));
} }
@ -2050,6 +2066,8 @@ public int Native_LoadSnapshot(Handle handler, int numParams)
gA_Timers[client].iPerfectJumps = snapshot.iPerfectJumps; gA_Timers[client].iPerfectJumps = snapshot.iPerfectJumps;
gA_Timers[client].fTimeOffset = snapshot.fTimeOffset; gA_Timers[client].fTimeOffset = snapshot.fTimeOffset;
gA_Timers[client].fDistanceOffset = snapshot.fDistanceOffset; gA_Timers[client].fDistanceOffset = snapshot.fDistanceOffset;
gA_Timers[client].fAvgVelocity = snapshot.fAvgVelocity;
gA_Timers[client].fMaxVelocity = snapshot.fMaxVelocity;
return 0; return 0;
} }
@ -3328,6 +3346,8 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams)
snapshot.iTimerTrack = gA_Timers[client].iTrack; snapshot.iTimerTrack = gA_Timers[client].iTrack;
snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; snapshot.fTimeOffset = gA_Timers[client].fTimeOffset;
snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset;
snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity;
snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity;
Call_StartForward(gH_Forwards_OnTimerIncrement); Call_StartForward(gH_Forwards_OnTimerIncrement);
Call_PushCell(client); Call_PushCell(client);
@ -3781,13 +3801,16 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
if (GetTimerStatus(client) == view_as<int>(Timer_Running) && gA_Timers[client].fTimer != 0.0) if (GetTimerStatus(client) == view_as<int>(Timer_Running) && gA_Timers[client].fTimer != 0.0)
{ {
float frameCount = gB_Replay
? float(Shavit_GetClientFrameCount(client))
: (gA_Timers[client].fTimer / GetTickInterval());
float fAbsVelocity[3]; float fAbsVelocity[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fAbsVelocity); GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fAbsVelocity);
float curVel = SquareRoot(Pow(fAbsVelocity[0], 2.0) + Pow(fAbsVelocity[1], 2.0)); float curVel = SquareRoot(Pow(fAbsVelocity[0], 2.0) + Pow(fAbsVelocity[1], 2.0));
float maxVel = gA_Timers[client].fMaxVelocity; float maxVel = gA_Timers[client].fMaxVelocity;
gA_Timers[client].fMaxVelocity = (curVel > maxVel) ? curVel : maxVel; gA_Timers[client].fMaxVelocity = (curVel > maxVel) ? curVel : maxVel;
// STOLEN from Epic/Disrevoid. Thx :) // STOLEN from Epic/Disrevoid. Thx :)
gA_Timers[client].fAvgVelocity += (curVel - gA_Timers[client].fAvgVelocity) / Shavit_GetClientFrameCount(client); gA_Timers[client].fAvgVelocity += (curVel - gA_Timers[client].fAvgVelocity) / frameCount;
} }
gA_Timers[client].iLastButtons = iPButtons; gA_Timers[client].iLastButtons = iPButtons;

View File

@ -133,10 +133,10 @@ public void OnPluginStart()
#endif #endif
// forwards // forwards
gH_OnWorldRecord = CreateGlobalForward("Shavit_OnWorldRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell); gH_OnWorldRecord = CreateGlobalForward("Shavit_OnWorldRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_OnFinish_Post = CreateGlobalForward("Shavit_OnFinish_Post", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell); gH_OnFinish_Post = CreateGlobalForward("Shavit_OnFinish_Post", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_OnWRDeleted = CreateGlobalForward("Shavit_OnWRDeleted", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell); gH_OnWRDeleted = CreateGlobalForward("Shavit_OnWRDeleted", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_OnWorstRecord = CreateGlobalForward("Shavit_OnWorstRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell); gH_OnWorstRecord = CreateGlobalForward("Shavit_OnWorstRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_OnFinishMessage = CreateGlobalForward("Shavit_OnFinishMessage", ET_Event, Param_Cell, Param_CellByRef, Param_Array, Param_Cell, Param_Cell, Param_String, Param_Cell); gH_OnFinishMessage = CreateGlobalForward("Shavit_OnFinishMessage", ET_Event, Param_Cell, Param_CellByRef, Param_Array, Param_Cell, Param_Cell, Param_String, Param_Cell);
// player commands // player commands
@ -1978,7 +1978,7 @@ public void SQL_CreateTable_Callback(Database db, DBResultSet results, const cha
OnMapStart(); OnMapStart();
} }
public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs) public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs, float avgvel, float maxvel)
{ {
// do not risk overwriting the player's data if their PB isn't loaded to cache yet // do not risk overwriting the player's data if their PB isn't loaded to cache yet
if(!gA_WRCache[client].bLoadedCache) if(!gA_WRCache[client].bLoadedCache)
@ -2033,6 +2033,8 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st
Call_PushCell(fOldWR); Call_PushCell(fOldWR);
Call_PushCell(oldtime); Call_PushCell(oldtime);
Call_PushCell(perfs); Call_PushCell(perfs);
Call_PushCell(avgvel);
Call_PushCell(maxvel);
Call_Finish(); Call_Finish();
#if defined DEBUG #if defined DEBUG
@ -2054,6 +2056,8 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st
Call_PushCell(track); Call_PushCell(track);
Call_PushCell(oldtime); Call_PushCell(oldtime);
Call_PushCell(perfs); Call_PushCell(perfs);
Call_PushCell(avgvel);
Call_PushCell(maxvel);
Call_Finish(); Call_Finish();
} }
@ -2110,6 +2114,8 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st
Call_PushCell(track); Call_PushCell(track);
Call_PushCell(oldtime); Call_PushCell(oldtime);
Call_PushCell(perfs); Call_PushCell(perfs);
Call_PushCell(avgvel);
Call_PushCell(maxvel);
Call_Finish(); Call_Finish();
} }