Readd fidget spinner crosshair

This commit is contained in:
BenCat07 2018-04-02 10:31:32 +02:00
parent 39058d7066
commit 9525d26e02
7 changed files with 20 additions and 46 deletions

View File

@ -51,7 +51,7 @@ void draw_line(float x, float y, float dx, float dy, const rgba_t &rgba,
float thickness); float thickness);
void draw_rect_textured(float x, float y, float w, float h, const rgba_t &rgba, void draw_rect_textured(float x, float y, float w, float h, const rgba_t &rgba,
texture_handle_t texture, float u, float v, float s, texture_handle_t texture, float u, float v, float s,
float t); float t, float a);
void draw_circle(float x, float y, float radius, const rgba_t &rgba, void draw_circle(float x, float y, float radius, const rgba_t &rgba,
float thickness, int steps); float thickness, int steps);
void draw_string(float x, float y, const char *string, font_handle_t &font, void draw_string(float x, float y, const char *string, font_handle_t &font,

@ -1 +1 @@
Subproject commit 35e0841d5ee9d885013e47ce72e155bd22cf7a98 Subproject commit e3bdf1c994da95544b84896efe8de0099dffe023

View File

@ -6,12 +6,14 @@
*/ */
#include "fidgetspinner.hpp" #include "fidgetspinner.hpp"
#include "common.hpp"
#ifndef FEATURE_FIDGET_SPINNER_DISABLED #include <math.h>
#ifndef FEATURE_FIDGET_SPINNER_ENABLED
CatVar enable_spinner(CV_SWITCH, "fidgetspinner", "0", "Fidget Spinner", CatVar enable_spinner(CV_SWITCH, "fidgetspinner", "0", "Fidget Spinner",
"Part of Cathook Autism Awareness program"); "Part of Cathook Autism Awareness program");
std::vector<textures::AtlasTexture> spinner_states{};
float spinning_speed = 0.0f; float spinning_speed = 0.0f;
float angle = 0; float angle = 0;
@ -44,9 +46,6 @@ SpinnerListener listener;
void InitSpinner() void InitSpinner()
{ {
for (int i = 0; i < 4; i++)
spinner_states.emplace_back(i * 64, textures::atlas_height - 64 * 4, 64,
64);
g_IGameEventManager->AddListener(&listener, false); g_IGameEventManager->AddListener(&listener, false);
} }
@ -86,41 +85,16 @@ void DrawSpinner()
(speed_cap - 10) + 10 * ((spinning_speed - 750.0f) / 250.0f); (speed_cap - 10) + 10 * ((spinning_speed - 750.0f) / 250.0f);
const float speed_scale(spinner_speed_scale); const float speed_scale(spinner_speed_scale);
const float size(spinner_scale); const float size(spinner_scale);
ftgl::vec2 positions[4] = {
{ -size, -size }, { size, -size }, { size, size }, { -size, size }
};
angle += speed_scale * real_speed; angle += speed_scale * real_speed;
for (int i = 0; i < 4; i++) int state = min(3, int(spinning_speed / 250));
{
float x = positions[i].x;
float y = positions[i].y;
positions[i].x = x * cos(angle) - y * sin(angle);
positions[i].y = x * sin(angle) + y * cos(angle);
positions[i].x += draw::width / 2;
positions[i].y += draw::height / 2;
}
int state = min(3, spinning_speed / 250.0f);
// Paste from draw_api:: const glez_rgba_t color = glez_rgba(255, 255, 255, 255);
using namespace drawgl;
using namespace ftgl;
const auto &u1v1 = spinner_states[state].tex_coords[0];
const auto &u2v2 = spinner_states[state].tex_coords[1]; static glez_texture_t tex = glez_texture_load_png_rgba("/opt/cathook/data/res/atlas.png");
GLuint idx = buffer_triangles_textured->vertices->size; while (!tex)
GLuint indices[] = { idx, idx + 1, idx + 2, idx, idx + 2, idx + 3 }; tex = glez_texture_load_png_rgba("/opt/cathook/data/res/atlas.png");
vertex_v2t2c4_t vertices[] = { glez_rect_textured(draw::width / 2, draw::height / 2, size, size, color, tex, 0 + 64 * state, 3 * 64, 64, 64, angle);
{ vec2{ positions[0].x, positions[0].y }, vec2{ u1v1.x, u2v2.y },
*reinterpret_cast<const vec4 *>(&colors::white) },
{ vec2{ positions[1].x, positions[1].y }, vec2{ u2v2.x, u2v2.y },
*reinterpret_cast<const vec4 *>(&colors::white) },
{ vec2{ positions[2].x, positions[2].y }, vec2{ u2v2.x, u1v1.y },
*reinterpret_cast<const vec4 *>(&colors::white) },
{ vec2{ positions[3].x, positions[3].y }, vec2{ u1v1.x, u1v1.y },
*reinterpret_cast<const vec4 *>(&colors::white) }
};
vertex_buffer_push_back_indices(buffer_triangles_textured, indices, 6);
vertex_buffer_push_back_vertices(buffer_triangles_textured, vertices, 4);
if (angle > PI * 4) if (angle > PI * 4)
angle -= PI * 4; angle -= PI * 4;
} }

View File

@ -369,7 +369,7 @@ free(logname);*/
hacks::tf2::healarrow::Init(); hacks::tf2::healarrow::Init();
#if ENABLE_VISUALS == 1 #if ENABLE_VISUALS == 1
#ifndef FEATURE_FIDGET_SPINNER_DISABLED #ifndef FEATURE_FIDGET_SPINNER_ENABLED
InitSpinner(); InitSpinner();
logging::Info("Initialized Fidget Spinner"); logging::Info("Initialized Fidget Spinner");
#endif #endif

View File

@ -395,10 +395,10 @@ void CreateMove()
} }
if (instant_weapon_switch && not HasCondition<TFCond_Cloaked>(LOCAL_E)) if (instant_weapon_switch && not HasCondition<TFCond_Cloaked>(LOCAL_E))
{ {
if (lastwep != g_pLocalPlayer->weapon()->m_IDX) if (lastwep != g_pLocalPlayer->weapon()->m_iClassID)
{ {
amount = 2 * 90; amount = 2 * 90;
lastwep = g_pLocalPlayer->weapon()->m_IDX; lastwep = g_pLocalPlayer->weapon()->m_iClassID;
} }
} }
// SHOUTOUTS TO BLACKFIRE // SHOUTOUTS TO BLACKFIRE
@ -408,7 +408,7 @@ void CreateMove()
servertime = servertime =
(float) (CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * (float) (CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) *
g_GlobalVars->interval_per_tick; g_GlobalVars->interval_per_tick;
if (!nextattack || !i || g_pLocalPlayer->weapon()->m_IDX != lastwep) if (!nextattack || !i || g_pLocalPlayer->weapon()->m_iClassID != lastwep)
nextattack = nextattack =
CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack); CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack);
if (servertime - nextattack > 30.0f) if (servertime - nextattack > 30.0f)
@ -441,7 +441,7 @@ void CreateMove()
} }
if (i) if (i)
i--; i--;
lastwep = g_pLocalPlayer->weapon()->m_IDX; lastwep = g_pLocalPlayer->weapon()->m_iClassID;
} }
if (!amount) if (!amount)
return; return;

View File

@ -22,7 +22,7 @@ void sprite::draw(float scrx, float scry, float scrw, float scrh,
const rgba_t &rgba) const const rgba_t &rgba) const
{ {
draw_api::draw_rect_textured(scrx, scry, scrw, scrh, rgba, atlas.texture, draw_api::draw_rect_textured(scrx, scry, scrw, scrh, rgba, atlas.texture,
nx, ny, nw, nh); nx, ny, nw, nh, 0);
} }
texture_atlas::texture_atlas(std::string filename, float width, float height) texture_atlas::texture_atlas(std::string filename, float width, float height)

View File

@ -150,7 +150,7 @@ void DrawCheatVisuals()
{ {
criticals::draw(); criticals::draw();
} }
#ifndef FEATURE_FIDGET_SPINNER_DISABLED #ifndef FEATURE_FIDGET_SPINNER_ENABLED
DrawSpinner(); DrawSpinner();
#endif #endif
Prediction_PaintTraverse(); Prediction_PaintTraverse();