Draw speed + graph
This commit is contained in:
parent
3692ef9eb6
commit
214226ad5a
@ -11,6 +11,8 @@
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
#define fps_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25)
|
||||
#define speed_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 50)
|
||||
#define material_white game::Material_RegisterHandle("white")
|
||||
|
||||
namespace fps
|
||||
{
|
||||
@ -20,11 +22,16 @@ namespace fps
|
||||
auto lastframe = std::chrono::high_resolution_clock::now();
|
||||
|
||||
game::dvar_t* cg_drawfps;
|
||||
game::dvar_t* cg_drawspeed;
|
||||
|
||||
float fps_color_good[4] = {0.6f, 1.0f, 0.0f, 1.0f};
|
||||
float fps_color_ok[4] = {1.0f, 0.7f, 0.3f, 1.0f};
|
||||
float fps_color_bad[4] = {1.0f, 0.3f, 0.3f, 1.0f};
|
||||
|
||||
float color_blue[4] = {0.12f, 0.77f, 1.f, 1.f};
|
||||
|
||||
float color_white[4] = {1.f, 1.f, 1.f, 1.f};
|
||||
|
||||
float screen_max[2];
|
||||
|
||||
int history_count = 20;
|
||||
@ -49,6 +56,63 @@ namespace fps
|
||||
return total / history_count;
|
||||
}
|
||||
|
||||
std::deque<float> speed_history;
|
||||
|
||||
void draw_line(float x, float y, float width, float height)
|
||||
{
|
||||
game::R_AddCmdDrawStretchPic(x, y, width, height, 0.0f, 0.0f, 0.0f, 0.0f, color_white, material_white);
|
||||
}
|
||||
|
||||
void draw_speed()
|
||||
{
|
||||
const auto speed = sqrt(pow(game::g_entities[0].client->velocity[0], 2) +
|
||||
pow(game::g_entities[0].client->velocity[1], 2) +
|
||||
pow(game::g_entities[0].client->velocity[2], 2));
|
||||
|
||||
if (cg_drawspeed->current.integer >= 1)
|
||||
{
|
||||
const auto font = speed_font;
|
||||
const auto speed_string = utils::string::va("%i\n", (int)speed);
|
||||
|
||||
const auto width = game::R_TextWidth(speed_string, 0x7FFFFFFF, font);
|
||||
|
||||
const auto x = (screen_max[0] / 2) - (width / 2);
|
||||
const auto y = screen_max[1] - 400.f;
|
||||
|
||||
const auto color = speed >= 300
|
||||
? color_blue
|
||||
: fps_color_bad;
|
||||
|
||||
game::R_AddCmdDrawText(speed_string, 0x7FFFFFFF, font, x,
|
||||
y, 1.0f, 1.0f, 0.0f, color, 0);
|
||||
}
|
||||
|
||||
if (cg_drawspeed->current.integer >= 2)
|
||||
{
|
||||
if (speed_history.size() > 400)
|
||||
{
|
||||
speed_history.pop_front();
|
||||
}
|
||||
|
||||
speed_history.push_back(speed);
|
||||
|
||||
const auto base_x = 80.f;
|
||||
const auto base_y = screen_max[1] - 400.f;
|
||||
|
||||
const auto width = 1.f;
|
||||
|
||||
for (auto i = 0; i < speed_history.size(); i++)
|
||||
{
|
||||
const auto height = std::min(std::max(speed_history[i] / 5.f, 1.f), 1000.f);
|
||||
|
||||
const auto x = base_x + (float)i * width;
|
||||
const auto y = base_y - height;
|
||||
|
||||
draw_line(x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
check_resize();
|
||||
@ -75,7 +139,12 @@ namespace fps
|
||||
fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad), 0);
|
||||
}
|
||||
|
||||
if (game::CL_IsCgameInitialized() && cg_drawfps->current.integer >= 2)
|
||||
if (!game::CL_IsCgameInitialized() || !game::g_entities[0].client)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cg_drawfps->current.integer >= 2)
|
||||
{
|
||||
const auto font = fps_font;
|
||||
|
||||
@ -89,6 +158,8 @@ namespace fps
|
||||
game::R_AddCmdDrawText(pos_string, 0x7FFFFFFF, font, x,
|
||||
60.f, 1.0f, 1.0f, 0.0f, fps_color_ok, 0);
|
||||
}
|
||||
|
||||
draw_speed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +168,8 @@ namespace fps
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
cg_drawfps = game::Dvar_RegisterInt(game::generateHashValue("cg_drawfps"), "", 0, 0, 4, game::DVAR_FLAG_SAVED);
|
||||
cg_drawspeed = dvars::register_int("cg_drawSpeed", 0, 0, 2, game::DVAR_FLAG_SAVED);
|
||||
cg_drawfps = dvars::register_int("cg_drawFPS", 0, 0, 4, game::DVAR_FLAG_SAVED);
|
||||
|
||||
scheduler::loop(draw, scheduler::pipeline::renderer);
|
||||
}
|
||||
|
@ -713,59 +713,59 @@ namespace game_console
|
||||
char a2[1] = {};
|
||||
|
||||
// add our dvars
|
||||
dvars::con_inputBoxColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputBoxColor"), a2,
|
||||
dvars::con_inputBoxColor = dvars::register_vec4(
|
||||
"con_inputBoxColor",
|
||||
0.2f, 0.2f, 0.2f, 0.9f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_inputHintBoxColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputHintBoxColor"), a2,
|
||||
dvars::con_inputHintBoxColor = dvars::register_vec4(
|
||||
"con_inputHintBoxColor",
|
||||
0.3f, 0.3f, 0.3f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_outputBarColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_outputBarColor"), a2,
|
||||
dvars::con_outputBarColor = dvars::register_vec4(
|
||||
"con_outputBarColor",
|
||||
0.5f, 0.5f, 0.5f, 0.6f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_outputSliderColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_outputSliderColor"), a2,
|
||||
dvars::con_outputSliderColor = dvars::register_vec4(
|
||||
"con_outputSliderColor",
|
||||
0.9f, 0.9f, 0.5f, 1.00f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_outputWindowColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_outputWindowColor"), a2,
|
||||
dvars::con_outputWindowColor = dvars::register_vec4(
|
||||
"con_outputWindowColor",
|
||||
0.25f, 0.25f, 0.25f, 0.85f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_inputDvarMatchColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputDvarMatchColor"), a2,
|
||||
dvars::con_inputDvarMatchColor = dvars::register_vec4(
|
||||
"con_inputDvarMatchColor",
|
||||
1.0f, 1.0f, 0.8f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_inputDvarValueColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputDvarValueColor"), a2,
|
||||
dvars::con_inputDvarValueColor = dvars::register_vec4(
|
||||
"con_inputDvarValueColor",
|
||||
1.0f, 1.0f, 0.8f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_inputDvarInactiveValueColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputDvarInactiveValueColor"), a2,
|
||||
dvars::con_inputDvarInactiveValueColor = dvars::register_vec4(
|
||||
"con_inputDvarInactiveValueColor",
|
||||
0.8f, 0.8f, 0.8f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
|
||||
dvars::con_inputCmdMatchColor = game::Dvar_RegisterVec4(
|
||||
game::generateHashValue("con_inputCmdMatchColor"), a2,
|
||||
dvars::con_inputCmdMatchColor = dvars::register_vec4(
|
||||
"con_inputCmdMatchColor",
|
||||
0.80f, 0.80f, 1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1);
|
||||
game::DVAR_FLAG_SAVED);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -15,23 +15,6 @@ namespace dvars
|
||||
game::dvar_t* con_inputDvarInactiveValueColor = nullptr;
|
||||
game::dvar_t* con_inputCmdMatchColor = nullptr;
|
||||
|
||||
game::dvar_t* g_playerEjection = nullptr;
|
||||
game::dvar_t* g_playerCollision = nullptr;
|
||||
game::dvar_t* g_gravity = nullptr;
|
||||
game::dvar_t* g_speed = nullptr;
|
||||
|
||||
game::dvar_t* pm_bouncing = nullptr;
|
||||
|
||||
game::dvar_t* jump_slowDownEnable = nullptr;
|
||||
game::dvar_t* jump_enableFallDamage = nullptr;
|
||||
game::dvar_t* jump_height = nullptr;
|
||||
game::dvar_t* jump_ladderPushVel = nullptr;
|
||||
|
||||
game::dvar_t* r_aspectRatioCustom = nullptr;
|
||||
game::dvar_t* r_fullbright = nullptr;
|
||||
|
||||
game::dvar_t* aimassist_enabled = nullptr;
|
||||
|
||||
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain)
|
||||
{
|
||||
if (domain.vector.min == -FLT_MAX)
|
||||
@ -134,7 +117,7 @@ namespace dvars
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const char*> dvar_list =
|
||||
std::vector<std::string> dvar_list =
|
||||
{
|
||||
"ai_corpseLimit",
|
||||
"band_12players",
|
||||
@ -1170,4 +1153,31 @@ namespace dvars
|
||||
"xblive_privatematch",
|
||||
"xblive_privatematch_solo"
|
||||
};
|
||||
|
||||
game::dvar_t* register_int(const std::string& name, int value, int min, int max, game::DvarFlags flags)
|
||||
{
|
||||
const auto hash = game::generateHashValue(name.data());
|
||||
|
||||
dvar_list.push_back(name);
|
||||
|
||||
return game::Dvar_RegisterInt(hash, "", value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags)
|
||||
{
|
||||
const auto hash = game::generateHashValue(name.data());
|
||||
|
||||
dvar_list.push_back(name);
|
||||
|
||||
return game::Dvar_RegisterFloat(hash, "", value, min, max, flags);
|
||||
}
|
||||
|
||||
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z, float w, float min, float max, game::DvarFlags flags)
|
||||
{
|
||||
const auto hash = game::generateHashValue(name.data());
|
||||
|
||||
dvar_list.push_back(name);
|
||||
|
||||
return game::Dvar_RegisterVec4(hash, "", x, y, z, w, min, max, flags);
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,12 @@ namespace dvars
|
||||
|
||||
extern game::dvar_t* aimassist_enabled;
|
||||
|
||||
extern std::vector<const char*> dvar_list;
|
||||
extern std::vector<std::string> dvar_list;
|
||||
|
||||
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain);
|
||||
std::string dvar_get_domain(const game::dvar_type type, const game::dvar_limits& domain);
|
||||
|
||||
game::dvar_t* register_int(const std::string& name, int value, int min, int max, game::DvarFlags flags);
|
||||
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags);
|
||||
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z, float w, float min, float max, game::DvarFlags flags);
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ namespace game
|
||||
|
||||
struct gclient_s
|
||||
{
|
||||
|
||||
char __pad0[0x8C];
|
||||
vec3_t velocity;
|
||||
};
|
||||
|
||||
struct client_t
|
||||
|
Loading…
Reference in New Issue
Block a user