Update fps component

This commit is contained in:
Federico Cecchetto 2021-04-24 16:22:43 +02:00
parent 11d6098c69
commit f48bd18653
2 changed files with 34 additions and 6 deletions

View File

@ -25,12 +25,28 @@ namespace fps
float screen_max[2]; float screen_max[2];
int history_count = 20;
int history[20] = { 0 };
int index;
void check_resize() void check_resize()
{ {
screen_max[0] = game::ScrPlace_GetViewPlacement()->realViewportSize[0]; screen_max[0] = game::ScrPlace_GetViewPlacement()->realViewportSize[0];
screen_max[1] = game::ScrPlace_GetViewPlacement()->realViewportSize[1]; screen_max[1] = game::ScrPlace_GetViewPlacement()->realViewportSize[1];
} }
int average_fps()
{
auto total = 0;
for (auto i = 0; i < history_count; i++)
{
total += history[i];
}
return total / history_count;
}
void draw_fps() void draw_fps()
{ {
check_resize(); check_resize();
@ -41,7 +57,14 @@ namespace fps
const int fps = 1000000000 / frametime.count(); const int fps = 1000000000 / frametime.count();
const auto fps_string = utils::string::va("%i", fps); 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); 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, 25.f, 1.0f, 1.0f, 0.0f, game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, fps_font, x, 25.f, 1.0f, 1.0f, 0.0f,

View File

@ -518,12 +518,17 @@ namespace game_console
void execute(const char* cmd) void execute(const char* cmd)
{ {
scripting::event e; const auto sv_running = game::Dvar_FindVar("sv_running")->current.enabled;
e.name = "console_command";
e.arguments.push_back(cmd);
e.entity = *game::levelEntityId;
scripting::lua::engine::notify(e); if (sv_running)
{
std::string command = cmd;
scheduler::once([command]()
{
scripting::notify(*game::levelEntityId, "console_command", {command});
}, scheduler::pipeline::server);
}
game::Cbuf_AddText(0, utils::string::va("%s \n", cmd)); game::Cbuf_AddText(0, utils::string::va("%s \n", cmd));
} }