From 8bd294ae035afefa4c37763eb9bb7c284d7a64fd Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 26 Apr 2021 16:43:34 +0200 Subject: [PATCH] Small fix --- src/component/fps.cpp | 63 ++++++++++++++-------------------- src/component/game_console.cpp | 10 +++--- 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/src/component/fps.cpp b/src/component/fps.cpp index b7c880fe..c246f74b 100644 --- a/src/component/fps.cpp +++ b/src/component/fps.cpp @@ -49,58 +49,47 @@ namespace fps return total / history_count; } - void draw_fps() + void draw() { check_resize(); - const auto now = std::chrono::high_resolution_clock::now(); - const auto frametime = now - lastframe; - lastframe = now; - - const int fps = 1000000000 / frametime.count(); - - if (index >= history_count) + if (cg_drawfps->current.integer >= 1) { - index = 0; + const auto now = std::chrono::high_resolution_clock::now(); + const auto frametime = now - lastframe; + lastframe = now; + + const int fps = 1000000000 / frametime.count(); + + if (index >= history_count) + { + index = 0; + } + + history[index++] = fps; + + const auto fps_string = utils::string::va("%i", average_fps()); + const auto x = screen_max[0] - 15.f - game::R_TextWidth(fps_string, 0x7FFFFFFF, fps_font); + + game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, fps_font, x, 35.f, 1.0f, 1.0f, 0.0f, + fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad), 0); } - history[index++] = fps; - - const auto fps_string = utils::string::va("%i", average_fps()); - const auto x = screen_max[0] - 15.f - game::R_TextWidth(fps_string, 0x7FFFFFFF, fps_font); - - game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, fps_font, x, 35.f, 1.0f, 1.0f, 0.0f, - fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad), 0); - } - - void draw_pos() - { - if (game::CL_IsCgameInitialized() && game::g_entities[0].origin) + if (game::CL_IsCgameInitialized() && cg_drawfps->current.integer >= 2) { - const auto pos_string = utils::string::va("%f %f %f", + const auto font = fps_font; + + const auto pos_string = utils::string::va("%f %f %f", game::g_entities[0].origin[0], game::g_entities[0].origin[1], game::g_entities[0].origin[2]); - const auto x = screen_max[0] - 15.f - game::R_TextWidth(pos_string, 0x7FFFFFFF, fps_font); + const auto x = screen_max[0] - 15.f - game::R_TextWidth(pos_string, 0x7FFFFFFF, font); - game::R_AddCmdDrawText(pos_string, 0x7FFFFFFF, fps_font, x, + game::R_AddCmdDrawText(pos_string, 0x7FFFFFFF, font, x, 60.f, 1.0f, 1.0f, 0.0f, fps_color_ok, 0); } } - - void draw() - { - if (cg_drawfps->current.integer >= 1) - { - draw_fps(); - } - - if (cg_drawfps->current.integer >= 2) - { - draw_pos(); - } - } } class component final : public component_interface diff --git a/src/component/game_console.cpp b/src/component/game_console.cpp index efff02d0..f8d3a472 100644 --- a/src/component/game_console.cpp +++ b/src/component/game_console.cpp @@ -186,11 +186,6 @@ namespace game_console { input = utils::string::to_lower(input); - if (game::Dvar_FindVar(input.data())) - { - suggestions.push_back(input.data()); - } - for (const auto& dvar : dvars::dvar_list) { auto name = utils::string::to_lower(dvar); @@ -205,6 +200,11 @@ namespace game_console } } + if (suggestions.size() == 0 && game::Dvar_FindVar(input.data())) + { + suggestions.push_back(input.data()); + } + game::cmd_function_s* cmd = (*game::cmd_functions); while (cmd) {