Skip to content

Commit

Permalink
feat: `sar_velocitygraph_show_line (#276)
Browse files Browse the repository at this point in the history
Added "sar_velocitygraph_show_line" which when set to 0 (1 by default), keeps only the speedometer from the velocity graph giving us a speedometer like in Half-Life 1.

This displays our velocity separate from the HUD in the bottom middle of our screen nicely, so we can more easily see it whilst bunnyhopping.
  • Loading branch information
kipod8 authored and ThisAMJ committed Sep 2, 2024
1 parent 78e5e34 commit 873ce81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
|sar_velocitygraph|0|Shows velocity graph.|
|sar_velocitygraph_background|0|Background of velocity graph.|
|sar_velocitygraph_font_index|21|Font index of velocity graph.|
|sar_velocitygraph_show_line|1|Shows line for velocity graph.|
|sar_velocitygraph_rainbow|0|Rainbow mode of velocity graph text.|
|sar_velocitygraph_show_speed_on_graph|1|Show speed between jumps.|
|sar_velocitygraph_x|-250|Velocity graph x axis offset.|
Expand Down
38 changes: 20 additions & 18 deletions src/Features/Hud/VelocityGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

Variable sar_velocitygraph("sar_velocitygraph", "0", "Shows velocity graph.\n");
Variable sar_velocitygraph_font_index("sar_velocitygraph_font_index", "21", 0, "Font index of velocity graph.\n"); // 21 looks pretty good
Variable sar_velocitygraph_show_line("sar_velocitygraph_show_line", "1", "Shows line for velocity graph.\n");
Variable sar_velocitygraph_x("sar_velocitygraph_x", "-250", "Velocity graph x axis offset.\n");
Variable sar_velocitygraph_y("sar_velocitygraph_y", "-175", "Velocity graph y axis offset.\n");
Variable sar_velocitygraph_background("sar_velocitygraph_background", "0", "Background of velocity graph.\n"); // imo this should be off by default
Expand Down Expand Up @@ -81,8 +82,23 @@ void VelocityGraph::Paint(int slot) {
const Vector2<int> graphPos = Vector2<int>(x / 2, y) +
Vector2<int>(sar_velocitygraph_x.GetInt(), sar_velocitygraph_y.GetInt());

if (sar_velocitygraph_background.GetBool())
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
Color c = Color(30, 255, 109);
if (sar_velocitygraph_rainbow.GetBool()) {
c = Utils::HSVToRGB(speed, 100, 100);
} else if (std::abs(speed - recentSpeed) < 5) {
c = Color(255, 199, 89);
} else if (speed < recentSpeed + 5) {
c = Color(255, 119, 119);
}

auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

if (!sar_velocitygraph_show_line.GetBool()) return;

for (int i = 1; i < velocityStamps[slot].size - 1; i++) {
const auto current = velocityStamps[slot][i];
Expand All @@ -102,28 +118,14 @@ void VelocityGraph::Paint(int slot) {
Color(255, 255, 255), std::to_string(next.speed).c_str());
}
}

surface->DrawColoredLine(
graphPos + Vector2<int>(i - 1, -current_speed),
graphPos + Vector2<int>(i, -next_speed),
Color(255, 255, 255));
}

bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
Color c = Color(30, 255, 109);
if (sar_velocitygraph_rainbow.GetBool()) {
c = Utils::HSVToRGB(speed, 100, 100);
} else if (std::abs(speed - recentSpeed) < 5) {
c = Color(255, 199, 89);
} else if (speed < recentSpeed + 5) {
c = Color(255, 119, 119);
}

auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
if (sar_velocitygraph_background.GetBool())
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
}
bool VelocityGraph::GetCurrentSize(int &xSize, int &ySize) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/Features/Hud/VelocityGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern VelocityGraph *velocityGraph;

extern Variable sar_velocitygraph;
extern Variable sar_velocitygraph_font_index;
extern Variable sar_velocitygraph_show_line;
extern Variable sar_velocitygraph_x;
extern Variable sar_velocitygraph_y;
extern Variable sar_velocitygraph_background;
Expand Down

0 comments on commit 873ce81

Please sign in to comment.