Further improve warp and make it use all 24 ticks

This commit is contained in:
BenCat07 2020-05-18 13:53:01 +02:00
parent c8b3d3fdb7
commit f5b6c9457b
2 changed files with 26 additions and 17 deletions

View File

@ -59,7 +59,7 @@
<Box padding="12 6 6 6" width="content" height="content" name="Warp" x="370" y="65"> <Box padding="12 6 6 6" width="content" height="content" name="Warp" x="370" y="65">
<List width="180"> <List width="180">
<AutoVariable width="fill" target="warp.enabled" label="Enable Warp" tooltip="Allows you to charge a burst of speed"/> <AutoVariable width="fill" target="warp.enabled" label="Enable Warp" tooltip="Allows you to charge a burst of speed"/>
<AutoVariable width="fill" target="warp.speed" label="Warp speed" tooltip="The Discharge speed (0.5 = +50%, 2 = +200%, +1000% is the maximum possible)"/> <AutoVariable width="fill" target="warp.speed" label="Warp speed" tooltip="The Discharge speed (0.5 = +50%, 2 = +200%, +2300% is the maximum possible)"/>
<AutoVariable width="fill" target="warp.key" label="Warp Key" tooltip="Pressing this key will use all stored ticks to accelerate you"/> <AutoVariable width="fill" target="warp.key" label="Warp Key" tooltip="Pressing this key will use all stored ticks to accelerate you"/>
<AutoVariable width="fill" target="warp.draw" label="Draw Warp" tooltip="Draws a bar indicating your warp readyness"/> <AutoVariable width="fill" target="warp.draw" label="Draw Warp" tooltip="Draws a bar indicating your warp readyness"/>
<AutoVariable width="fill" target="warp.bar-size" label="Bar Size"/> <AutoVariable width="fill" target="warp.bar-size" label="Bar Size"/>

View File

@ -16,7 +16,7 @@
namespace hacks::tf2::warp namespace hacks::tf2::warp
{ {
static settings::Boolean enabled{ "warp.enabled", "false" }; static settings::Boolean enabled{ "warp.enabled", "false" };
static settings::Float speed{ "warp.speed", "10" }; static settings::Float speed{ "warp.speed", "23" };
static settings::Boolean draw{ "warp.draw", "false" }; static settings::Boolean draw{ "warp.draw", "false" };
static settings::Button warp_key{ "warp.key", "<null>" }; static settings::Button warp_key{ "warp.key", "<null>" };
static settings::Boolean charge_passively{ "warp.charge-passively", "true" }; static settings::Boolean charge_passively{ "warp.charge-passively", "true" };
@ -31,6 +31,9 @@ static settings::Boolean warp_backwards{ "warp.on-hit.backwards", "false" };
static settings::Boolean warp_left{ "warp.on-hit.left", "true" }; static settings::Boolean warp_left{ "warp.on-hit.left", "true" };
static settings::Boolean warp_right{ "warp.on-hit.right", "true" }; static settings::Boolean warp_right{ "warp.on-hit.right", "true" };
// Hidden control rvars for communtiy servers
static settings::Int maxusrcmdprocessticks("warp.maxusrcmdprocessticks", "24");
// Draw control // Draw control
static settings::Int size{ "warp.bar-size", "100" }; static settings::Int size{ "warp.bar-size", "100" };
static settings::Int bar_x{ "warp.bar-x", "50" }; static settings::Int bar_x{ "warp.bar-x", "50" };
@ -44,21 +47,27 @@ static bool charged = false;
// How many ticks of excess we have (for decimal speeds) // How many ticks of excess we have (for decimal speeds)
float excess_ticks = 0.0f; float excess_ticks = 0.0f;
int GetWarpAmount() int GetWarpAmount(bool finalTick)
{ {
static auto sv_max_dropped_packets_to_process = g_ICvar->FindVar("sv_max_dropped_packets_to_process"); int max_extra_ticks = *maxusrcmdprocessticks - 1;
float warp_amount_preprocessed = std::max(*speed, 0.05f); // No limit set
// Store excess if (!*maxusrcmdprocessticks)
excess_ticks += warp_amount_preprocessed - std::floor(warp_amount_preprocessed); max_extra_ticks = INT_MAX;
float warp_amount_preprocessed = std::max(*speed, 0.05f);
// How many ticks to warp, add excess too // How many ticks to warp, add excess too
int warp_amount_processed = std::floor(warp_amount_preprocessed) + std::floor(excess_ticks); int warp_amount_processed = std::floor(warp_amount_preprocessed) + std::floor(excess_ticks);
// Remove the used amount from excess // Remove the used amount from excess
excess_ticks -= std::floor(excess_ticks); if (finalTick)
excess_ticks -= std::floor(excess_ticks);
// Store excess
if (finalTick)
excess_ticks += warp_amount_preprocessed - std::floor(warp_amount_preprocessed);
// Return smallest of the two // Return smallest of the two
return std::min(warp_amount_processed, sv_max_dropped_packets_to_process->GetInt()); return std::min(warp_amount_processed, max_extra_ticks);
} }
static bool should_warp = true; static bool should_warp = true;
@ -87,10 +96,11 @@ void Warp(float accumulated_extra_samples, bool finalTick)
CL_Move_t original = (CL_Move_t) cl_move_detour.GetOriginalFunc(); CL_Move_t original = (CL_Move_t) cl_move_detour.GetOriginalFunc();
// Call CL_Move once for every warp tick // Call CL_Move once for every warp tick
int warp_amnt = GetWarpAmount(); int warp_amnt = GetWarpAmount(finalTick);
if (warp_amnt) if (warp_amnt)
{ {
for (int i = 0; i <= std::min(warp_ticks, warp_amnt); i++) int calls = std::min(warp_ticks, warp_amnt);
for (int i = 0; i < calls; i++)
{ {
original(accumulated_extra_samples, finalTick); original(accumulated_extra_samples, finalTick);
// Only decrease ticks for the final CL_Move tick // Only decrease ticks for the final CL_Move tick
@ -117,8 +127,7 @@ void Warp(float accumulated_extra_samples, bool finalTick)
int GetMaxWarpTicks() int GetMaxWarpTicks()
{ {
static auto usercmd_cvar = g_ICvar->FindVar("sv_maxusrcmdprocessticks"); int ticks = *maxusrcmdprocessticks;
int ticks = usercmd_cvar->GetInt();
// No limit set // No limit set
if (!ticks) if (!ticks)
ticks = INT_MAX; ticks = INT_MAX;
@ -333,8 +342,8 @@ void CreateMove()
else else
{ {
charge_ticks = std::clamp(charge_ticks, 0, warp_amount); charge_ticks = std::clamp(charge_ticks, 0, warp_amount);
// For every started 10 ticks We can subtract 1 because we'll get an extra CreateMove call. // For every started batch We can subtract 1 because we'll get an extra CreateMove call.
charge_ticks -= std::ceil(charge_ticks / 10.0f); charge_ticks -= std::ceil(charge_ticks / *speed);
should_melee = true; should_melee = true;
} }
// Use these ticks // Use these ticks
@ -419,8 +428,8 @@ void CreateMove()
} }
case MOVE_TOWARDS: case MOVE_TOWARDS:
{ {
// Just wait until we used about half of our warp, then we can start going back // Just wait until we used about a third of our warp, the rest has to be used for moving back
if (warp_amount <= charge_at_start / 2.0f) if (warp_amount <= charge_at_start * (2.0f / 3.0f))
current_peek_state = MOVE_BACK; current_peek_state = MOVE_BACK;
break; break;
} }