mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 10:28:26 +00:00
gimp Shavit_OnTimeIncrement and adjust tick->time stuff
This commit is contained in:
parent
39c9d96924
commit
a146b51fb1
@ -104,6 +104,7 @@ enum struct chatstrings_t
|
||||
enum struct timer_snapshot_t
|
||||
{
|
||||
bool bTimerEnabled;
|
||||
// fCurrentTime = (float(iFullTicks)+(iFractionalTicks/10000.0)+fZoneOffset[0])*GetTickInterval()
|
||||
float fCurrentTime;
|
||||
bool bClientPaused;
|
||||
int iJumps;
|
||||
@ -116,13 +117,16 @@ enum struct timer_snapshot_t
|
||||
int iTimerTrack;
|
||||
int iMeasuredJumps;
|
||||
int iPerfectJumps;
|
||||
// used as a "tick fraction" basically
|
||||
float fZoneOffset[2];
|
||||
float fDistanceOffset[2];
|
||||
float fAvgVelocity;
|
||||
float fMaxVelocity;
|
||||
float fTimescale;
|
||||
int iZoneIncrement; // convert to array for per zone offsets (?)
|
||||
float fTimescaledTicks;
|
||||
|
||||
int iFullTicks;
|
||||
int iFractionalTicks; // divide this by 10000.0 to get a fraction of a tick. whole ticks are moved to iFullTicks
|
||||
|
||||
bool bPracticeMode;
|
||||
|
||||
@ -528,8 +532,6 @@ forward Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
|
||||
|
||||
/**
|
||||
* Called just before shavit-core adds time to a player's timer.
|
||||
* This is the forward you should use to modify the player's timer smoothly.
|
||||
* A good example use case is timescaling.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param snapshot A snapshot with the player's current timer. You cannot manipulate it here.
|
||||
@ -1274,6 +1276,7 @@ native void Shavit_SetMaxVelocity(int client, float vel);
|
||||
/**
|
||||
* Sets the clients dynamic timescale. -1.0 to use the timescale of the client's style.
|
||||
* Note: Values above 1.0 won't scale into the replay bot.
|
||||
* Timescale is limited to four decimal places. 1.0 >= timescale >= 0.0001
|
||||
*
|
||||
* @param client Client index
|
||||
* @param scale New timescale
|
||||
|
||||
@ -1320,7 +1320,12 @@ void SaveCheckpointCache(int target, cp_cache_t cpcache, bool actually_a_checkpo
|
||||
snapshot.iSHSWCombination = -1;
|
||||
snapshot.iTimerTrack = Shavit_GetReplayBotTrack(target);
|
||||
snapshot.fTimescale = Shavit_GetStyleSettingFloat(snapshot.bsStyle, "timescale");
|
||||
snapshot.fTimescaledTicks = (Shavit_GetReplayBotCurrentFrame(target) - Shavit_GetReplayCachePreFrames(target)) * snapshot.fTimescale;
|
||||
|
||||
float ticks = (Shavit_GetReplayBotCurrentFrame(target) - Shavit_GetReplayCachePreFrames(target)) * snapshot.fTimescale;
|
||||
float fraction = FloatFraction(ticks);
|
||||
snapshot.iFullTicks = RoundFloat(ticks-fraction);
|
||||
snapshot.iFractionalTicks = RoundFloat(fraction * 10000.0);
|
||||
|
||||
cpcache.fSpeed = snapshot.fTimescale * Shavit_GetStyleSettingFloat(snapshot.bsStyle, "speed");
|
||||
ScaleVector(cpcache.fVelocity, 1 / cpcache.fSpeed);
|
||||
cpcache.fGravity = Shavit_GetStyleSettingFloat(target, "gravity");
|
||||
|
||||
@ -77,8 +77,8 @@ Handle gH_Forwards_OnStyleChanged = null;
|
||||
Handle gH_Forwards_OnTrackChanged = null;
|
||||
Handle gH_Forwards_OnChatConfigLoaded = null;
|
||||
Handle gH_Forwards_OnUserCmdPre = null;
|
||||
Handle gH_Forwards_OnTimerIncrement = null;
|
||||
Handle gH_Forwards_OnTimerIncrementPost = null;
|
||||
Handle gH_Forwards_OnTimeIncrement = null;
|
||||
Handle gH_Forwards_OnTimeIncrementPost = null;
|
||||
Handle gH_Forwards_OnTimescaleChanged = null;
|
||||
Handle gH_Forwards_OnTimeOffsetCalculated = null;
|
||||
Handle gH_Forwards_OnProcessMovement = null;
|
||||
@ -240,8 +240,8 @@ public void OnPluginStart()
|
||||
gH_Forwards_OnTrackChanged = CreateGlobalForward("Shavit_OnTrackChanged", ET_Event, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_Forwards_OnChatConfigLoaded = CreateGlobalForward("Shavit_OnChatConfigLoaded", ET_Event);
|
||||
gH_Forwards_OnUserCmdPre = CreateGlobalForward("Shavit_OnUserCmdPre", ET_Event, Param_Cell, Param_CellByRef, Param_CellByRef, Param_Array, Param_Array, Param_Cell, Param_Cell, Param_Cell, Param_Array, Param_Array);
|
||||
gH_Forwards_OnTimerIncrement = CreateGlobalForward("Shavit_OnTimeIncrement", ET_Event, Param_Cell, Param_Array, Param_CellByRef, Param_Array);
|
||||
gH_Forwards_OnTimerIncrementPost = CreateGlobalForward("Shavit_OnTimeIncrementPost", ET_Event, Param_Cell, Param_Cell, Param_Array);
|
||||
gH_Forwards_OnTimeIncrement = CreateGlobalForward("Shavit_OnTimeIncrement", ET_Event, Param_Cell, Param_Array, Param_CellByRef, Param_Array);
|
||||
gH_Forwards_OnTimeIncrementPost = CreateGlobalForward("Shavit_OnTimeIncrementPost", ET_Event, Param_Cell, Param_Cell, Param_Array);
|
||||
gH_Forwards_OnTimescaleChanged = CreateGlobalForward("Shavit_OnTimescaleChanged", ET_Event, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_Forwards_OnTimeOffsetCalculated = CreateGlobalForward("Shavit_OnTimeOffsetCalculated", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_Forwards_OnProcessMovement = CreateGlobalForward("Shavit_OnProcessMovement", ET_Event, Param_Cell);
|
||||
@ -1593,11 +1593,6 @@ public int Native_ChangeClientStyle(Handle handler, int numParams)
|
||||
|
||||
public Action Shavit_OnFinishPre(int client, timer_snapshot_t snapshot)
|
||||
{
|
||||
if (snapshot.fCurrentTime <= 0.0)
|
||||
{
|
||||
return Plugin_Stop;
|
||||
}
|
||||
|
||||
float minimum_time = GetStyleSettingFloat(snapshot.bsStyle, snapshot.iTimerTrack == Track_Main ? "minimum_time" : "minimum_time_bonus");
|
||||
|
||||
if (snapshot.fCurrentTime < minimum_time)
|
||||
@ -1609,11 +1604,29 @@ public Action Shavit_OnFinishPre(int client, timer_snapshot_t snapshot)
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
void CalculateRunTime(timer_snapshot_t s, bool include_end_offset)
|
||||
{
|
||||
float ticks = float(s.iFullTicks) + (s.iFractionalTicks / 10000.0);
|
||||
ticks += s.fZoneOffset[Zone_Start];
|
||||
|
||||
if (include_end_offset)
|
||||
{
|
||||
ticks -= (1.0 - s.fZoneOffset[Zone_End]);
|
||||
}
|
||||
|
||||
s.fCurrentTime = ticks * GetTickInterval();
|
||||
}
|
||||
|
||||
public int Native_FinishMap(Handle handler, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
int timestamp = GetTime();
|
||||
|
||||
if (!gA_Timers[client].iFullTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(gCV_UseOffsets.BoolValue)
|
||||
{
|
||||
CalculateTickIntervalOffset(client, Zone_End);
|
||||
@ -1628,7 +1641,12 @@ public int Native_FinishMap(Handle handler, int numParams)
|
||||
}
|
||||
}
|
||||
|
||||
gA_Timers[client].fCurrentTime = (gA_Timers[client].fTimescaledTicks + gA_Timers[client].fZoneOffset[Zone_Start] + gA_Timers[client].fZoneOffset[Zone_End]) * GetTickInterval();
|
||||
CalculateRunTime(gA_Timers[client], true);
|
||||
|
||||
if (gA_Timers[client].fCurrentTime <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer_snapshot_t snapshot;
|
||||
BuildSnapshot(client, snapshot);
|
||||
@ -1644,9 +1662,8 @@ public int Native_FinishMap(Handle handler, int numParams)
|
||||
return;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
float offset = (snapshot.fZoneOffset[Zone_Start] + snapshot.fZoneOffset[Zone_End]) * GetTickInterval();
|
||||
PrintToServer("0x%X %f -- ticks*interval -- offsettime=%f ticks=%.0f", snapshot.fCurrentTime, snapshot.fCurrentTime, offset, snapshot.fTimescaledTicks);
|
||||
#if 1
|
||||
PrintToServer("0x%X %f -- startoffset=%f endoffset=%f fullticks=%d fracticks=%d", snapshot.fCurrentTime, snapshot.fCurrentTime, snapshot.fZoneOffset[Zone_Start], snapshot.fZoneOffset[Zone_End], snapshot.iFullTicks, snapshot.iFractionalTicks);
|
||||
#endif
|
||||
|
||||
Call_StartForward(gH_Forwards_Finish);
|
||||
@ -1997,6 +2014,8 @@ public int Native_SetClientTimescale(Handle handler, int numParams)
|
||||
int client = GetNativeCell(1);
|
||||
float timescale = GetNativeCell(2);
|
||||
|
||||
timescale = float(RoundFloat((timescale * 10000.0)))/10000.0;
|
||||
|
||||
if (timescale != gA_Timers[client].fTimescale && timescale > 0.0)
|
||||
{
|
||||
CallOnTimescaleChanged(client, gA_Timers[client].fTimescale, timescale);
|
||||
@ -2087,7 +2106,8 @@ void StartTimer(int client, int track)
|
||||
}
|
||||
|
||||
gA_Timers[client].iZoneIncrement = 0;
|
||||
gA_Timers[client].fTimescaledTicks = 0.0;
|
||||
gA_Timers[client].iFullTicks = 0;
|
||||
gA_Timers[client].iFractionalTicks = 0;
|
||||
gA_Timers[client].bClientPaused = false;
|
||||
gA_Timers[client].iStrafes = 0;
|
||||
gA_Timers[client].iJumps = 0;
|
||||
@ -2246,7 +2266,8 @@ public void OnClientPutInServer(int client)
|
||||
gA_Timers[client].iTimerTrack = 0;
|
||||
gA_Timers[client].bsStyle = 0;
|
||||
gA_Timers[client].fTimescale = 1.0;
|
||||
gA_Timers[client].fTimescaledTicks = 0.0;
|
||||
gA_Timers[client].iFullTicks = 0;
|
||||
gA_Timers[client].iFractionalTicks = 0;
|
||||
gA_Timers[client].iZoneIncrement = 0;
|
||||
gS_DeleteMap[client][0] = 0;
|
||||
|
||||
@ -2637,31 +2658,26 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams)
|
||||
|
||||
float interval = GetTickInterval();
|
||||
float time = interval * gA_Timers[client].fTimescale;
|
||||
float timeOrig = time;
|
||||
|
||||
gA_Timers[client].iZoneIncrement++;
|
||||
|
||||
timer_snapshot_t snapshot;
|
||||
BuildSnapshot(client, snapshot);
|
||||
|
||||
Call_StartForward(gH_Forwards_OnTimerIncrement);
|
||||
Call_StartForward(gH_Forwards_OnTimeIncrement);
|
||||
Call_PushCell(client);
|
||||
Call_PushArray(snapshot, sizeof(timer_snapshot_t));
|
||||
Call_PushCellRef(time);
|
||||
Call_Finish();
|
||||
|
||||
if (time == timeOrig)
|
||||
{
|
||||
gA_Timers[client].fTimescaledTicks += gA_Timers[client].fTimescale;
|
||||
}
|
||||
else
|
||||
{
|
||||
gA_Timers[client].fTimescaledTicks += time / interval;
|
||||
}
|
||||
gA_Timers[client].iFractionalTicks += RoundFloat(gA_Timers[client].fTimescale * 10000.0);
|
||||
int whole_tick = gA_Timers[client].iFractionalTicks / 10000;
|
||||
gA_Timers[client].iFractionalTicks -= whole_tick * 10000;
|
||||
gA_Timers[client].iFullTicks += whole_tick;
|
||||
|
||||
gA_Timers[client].fCurrentTime = interval * gA_Timers[client].fTimescaledTicks;
|
||||
CalculateRunTime(gA_Timers[client], false);
|
||||
|
||||
Call_StartForward(gH_Forwards_OnTimerIncrementPost);
|
||||
Call_StartForward(gH_Forwards_OnTimeIncrementPost);
|
||||
Call_PushCell(client);
|
||||
Call_PushCell(time);
|
||||
Call_Finish();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user