Skip to content

Commit

Permalink
trail speed coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Jan 3, 2025
1 parent 8c6ef8c commit a89f5b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/engine/shared/tater_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ MACRO_CONFIG_INT(ClTeeTrailUseTeeColor, tc_tee_trail_use_tee_color, 1, 0, 1, CFG
MACRO_CONFIG_INT(ClTeeTrailTaper, tc_tee_trail_taper, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Taper tee trail over length")
MACRO_CONFIG_INT(ClTeeTrailFade, tc_tee_trail_fade, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Fade trail alpha over length")
MACRO_CONFIG_INT(ClTeeTrailRainbow, tc_tee_trail_rainbow, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Rainbow tee trails")
MACRO_CONFIG_INT(ClTeeTrailSpeed, tc_tee_trail_speed, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Speed color tee trails")



Expand Down
24 changes: 18 additions & 6 deletions src/game/client/components/tclient/trails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,8 @@ void CTrails::OnRender()

vec2 CurServerPos = vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_Y);
vec2 PrevServerPos = vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_Y);
m_PositionHistory[ClientId][GameTick % 200] = mix(PrevServerPos, CurServerPos, Client()->IntraGameTick(g_Config.m_ClDummy));
m_PositionTick[ClientId][GameTick % 200] = GameTick;

// Slightly messy way to make the position of our player accurate without ugly logic in the loop
vec2 SavedTempPredPos = GameClient()->m_aClients[ClientId].m_aPredPos[PredTick % 200];
GameClient()->m_aClients[ClientId].m_aPredPos[PredTick % 200] = GameClient()->m_aClients[ClientId].m_RenderPos;

IGraphics::CLineItem LineItem;
bool LineMode = g_Config.m_ClTeeTrailWidth == 0;

Expand Down Expand Up @@ -152,6 +147,8 @@ void CTrails::OnRender()
continue;
Part.Pos = m_PositionHistory[ClientId][PosTick % 200];
}
Part.Tick = PosTick;
Part.UnMovedPos = Part.Pos;
Trail.push_back(Part);
}

Expand All @@ -166,6 +163,11 @@ void CTrails::OnRender()
if((int)Trail.size() < 3)
continue;

if(PredictPlayer)
Trail.at(0).Pos = GameClient()->m_aClients[ClientId].m_RenderPos;
else
Trail.at(0).Pos = mix(PrevServerPos, CurServerPos, Client()->IntraGameTick(g_Config.m_ClDummy));

Trail.at(Trail.size() - 1).Pos = mix(Trail.at(Trail.size() - 1).Pos, Trail.at(Trail.size() - 2).Pos, std::fmod(IntraTick, 1.0f));

// Set progress
Expand All @@ -188,6 +190,17 @@ void CTrails::OnRender()
float Hue = std::fmod(((StartTick - i + 6361 * ClientId) % 1000000) * Cycle, 1.0f);
Part.Col = color_cast<ColorRGBA>(ColorHSLA(Hue, 1.0f, 0.5f));
}
if(g_Config.m_ClTeeTrailSpeed)
{
float Speed = 0.0f;
if(i == 0)
Speed = distance(Trail.at(i + 1).UnMovedPos, Trail.at(i).UnMovedPos) / std::abs(Trail.at(i + 1).Tick - Trail.at(i).Tick);
else
Speed = distance(Part.UnMovedPos, Trail.at(i - 1).UnMovedPos) / std::abs(Part.Tick - Trail.at(i - 1).Tick);
float Hue = std::fmod(Speed * 0.05f, 1.0f);
Part.Col = color_cast<ColorRGBA>(ColorHSLA(Hue, 1.0f, 0.5f));
Part.Col = color_cast<ColorRGBA>(ColorHSLA(65280 * ((int)(Speed * 4.0f) + 1)).UnclampLighting(ColorHSLA::DARKEST_LGT));
}

Part.Width = g_Config.m_ClTeeTrailWidth;
if(g_Config.m_ClTeeTrailTaper)
Expand Down Expand Up @@ -329,7 +342,6 @@ void CTrails::OnRender()
else
Graphics()->TrianglesEnd();

GameClient()->m_aClients[ClientId].m_aPredPos[PredTick % 200] = SavedTempPredPos;
m_PositionHistory[ClientId][GameTick % 200] = CurServerPos;
}
}
3 changes: 2 additions & 1 deletion src/game/client/components/tclient/trails.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
struct STrailPart
{
vec2 Pos = vec2(0, 0);
vec2 UnMovedPos = vec2(0, 0);
ColorRGBA Col = {};
float Alpha = 1.0f;
float Width = 0.0f;
Expand All @@ -13,7 +14,7 @@ struct STrailPart
vec2 Bot = vec2(0, 0);
bool Flip = false;
float Progress = 1.0f;

int Tick = -1;

bool operator==(const STrailPart &Other) const
{
Expand Down

0 comments on commit a89f5b9

Please sign in to comment.