Skip to content

Commit

Permalink
Merge pull request #6 from danielkempf/master
Browse files Browse the repository at this point in the history
Add Player Indicator
  • Loading branch information
sjrc6 authored Apr 27, 2022
2 parents c31829f + d2d4cf5 commit a49100e
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 209 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,8 @@ if(CLIENT)
components/nameplates.h
components/particles.cpp
components/particles.h
components/player_indicator.cpp
components/player_indicator.h
components/players.cpp
components/players.h
components/race_demo.cpp
Expand Down
477 changes: 286 additions & 191 deletions src/game/client/components/menus_settings.cpp

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions src/game/client/components/player_indicator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <engine/graphics.h>
#include <engine/shared/config.h>

#include <game/client/animstate.h>
#include <game/client/render.h>
#include <game/generated/client_data.h>
#include <game/generated/protocol.h>

#include <game/client/gameclient.h>

#include "player_indicator.h"

vec2 NormalizedDirection(vec2 src, vec2 dst)
{
return normalize(vec2(dst.x - src.x, dst.y - src.y));
}

float DistanceBetweenTwoPoints(vec2 src, vec2 dst)
{
return sqrt(pow(dst.x - src.x, 2) + pow(dst.y - src.y, 2));
}

void CPlayerIndicator::OnRender()
{
// Don't render if we can't find our own tee
if(m_pClient->m_Snap.m_LocalClientID == -1 || !m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_LocalClientID].m_Active)
return;

// Don't render if not race gamemode or in demo
if(!GameClient()->m_GameInfo.m_Race || Client()->State() == IClient::STATE_DEMOPLAYBACK)
return;

vec2 Position = m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_RenderPos;

if(g_Config.m_ClPlayerIndicator == 1)
{
Graphics()->TextureClear();
float CircleSize = 7.0f;
ColorRGBA col = ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f);
if(!(m_pClient->m_Teams.Team(m_pClient->m_Snap.m_LocalClientID) == 0 && g_Config.m_ClIndicatorTeamOnly))
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(!m_pClient->m_Snap.m_paPlayerInfos[i] || i == m_pClient->m_Snap.m_LocalClientID)
continue;

CGameClient::CClientData OtherTee = m_pClient->m_aClients[i];
if(
OtherTee.m_Team == m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_Team &&
!OtherTee.m_Paused &&
!OtherTee.m_Spec &&
m_pClient->m_Snap.m_aCharacters[i].m_Active)
{
if(g_Config.m_ClPlayerIndicatorFreeze && OtherTee.m_RenderCur.m_Weapon != WEAPON_NINJA)
continue;

vec2 norm = NormalizedDirection(m_pClient->m_aClients[i].m_RenderPos, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_RenderPos) * (-1);

float Offset = g_Config.m_ClIndicatorOffset;
if(g_Config.m_ClIndicatorVariableDistance)
{
Offset = mix((float)g_Config.m_ClIndicatorOffset, (float)g_Config.m_ClIndicatorOffsetMax,
std::min(DistanceBetweenTwoPoints(Position, OtherTee.m_RenderPos) / g_Config.m_ClIndicatorMaxDistance, 1.0f));
}

vec2 IndicatorPos(norm.x * Offset + Position.x, norm.y * Offset + Position.y);
CTeeRenderInfo TeeInfo = OtherTee.m_RenderInfo;
float Alpha = g_Config.m_ClIndicatorOpacity / 100.0f;
if(OtherTee.m_RenderCur.m_Weapon == WEAPON_NINJA)
{
col = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClIndicatorFreeze));
if(g_Config.m_ClIndicatorTees)
{
TeeInfo.m_ColorBody.r *= 0.4;
TeeInfo.m_ColorBody.g *= 0.4;
TeeInfo.m_ColorBody.b *= 0.4;
TeeInfo.m_ColorFeet.r *= 0.4;
TeeInfo.m_ColorFeet.g *= 0.4;
TeeInfo.m_ColorFeet.b *= 0.4;
Alpha *= 0.8;
}
}
else
{
col = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClIndicatorAlive));
}
col.a = Alpha;

CAnimState *pIdleState = CAnimState::GetIdle();
TeeInfo.m_Size = g_Config.m_ClIndicatorRadius * 4.f;

if(g_Config.m_ClIndicatorTees)
{
RenderTools()->RenderTee(CAnimState::GetIdle(), &TeeInfo, OtherTee.m_RenderCur.m_Emote, vec2(1.0f, 0.0f), IndicatorPos, col.a);
}
else
{
Graphics()->QuadsBegin();
Graphics()->SetColor(col);
RenderTools()->DrawCircle(IndicatorPos.x, IndicatorPos.y, g_Config.m_ClIndicatorRadius, 16);
Graphics()->QuadsEnd();
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions src/game/client/components/player_indicator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#ifndef GAME_CLIENT_COMPONENTS_PLAYER_INDICATOR_H
#define GAME_CLIENT_COMPONENTS_PLAYER_INDICATOR_H
#include <game/client/component.h>

class CPlayerIndicator : public CComponent
{
public:
virtual int Sizeof() const override { return sizeof(*this); }
virtual void OnRender() override;
};

#endif
34 changes: 17 additions & 17 deletions src/game/client/components/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ inline float AngularApproach(float Src, float Dst, float Amount)
return Dst;
return n;
}

void CPlayers::RenderHookCollLine(
const CNetObj_Character *pPrevChar,
const CNetObj_Character *pPlayerChar,
Expand Down Expand Up @@ -132,7 +133,7 @@ void CPlayers::RenderHookCollLine(
if(Local && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
ExDirection = normalize(vec2((int)m_pClient->m_Controls.m_MousePos[g_Config.m_ClDummy].x, (int)m_pClient->m_Controls.m_MousePos[g_Config.m_ClDummy].y));

if(!(int)m_pClient->m_Controls.m_MousePos[g_Config.m_ClDummy].x && !(int)m_pClient->m_Controls.m_MousePos[g_Config.m_ClDummy].y)
{
ExDirection = vec2(1, 0);
Expand Down Expand Up @@ -718,24 +719,24 @@ void CPlayers::OnRender()
m_aRenderInfo[i] = m_pClient->m_aClients[i].m_RenderInfo;
m_aRenderInfo[i].m_ShineDecoration = m_pClient->m_aClients[i].m_LiveFrozen;
if(m_pClient->m_Snap.m_aCharacters[i].m_Cur.m_Weapon == WEAPON_NINJA && g_Config.m_ClShowNinja || (g_Config.m_ClAmIFrozen && g_Config.m_ClFreezeUpdateFix && m_pClient->m_Snap.m_LocalClientID == i && g_Config.m_ClShowNinja))
{
// change the skin for the player to the ninja
int Skin = m_pClient->m_Skins.Find("x_ninja");
if(Skin != -1)
{
// change the skin for the player to the ninja
int Skin = m_pClient->m_Skins.Find("x_ninja");
if(Skin != -1)
const CSkin *pSkin = m_pClient->m_Skins.Get(Skin);
m_aRenderInfo[i].m_OriginalRenderSkin = pSkin->m_OriginalSkin;
m_aRenderInfo[i].m_ColorableRenderSkin = pSkin->m_ColorableSkin;
m_aRenderInfo[i].m_BloodColor = pSkin->m_BloodColor;
m_aRenderInfo[i].m_SkinMetrics = pSkin->m_Metrics;
m_aRenderInfo[i].m_CustomColoredSkin = IsTeamplay;
if(!IsTeamplay)
{
const CSkin *pSkin = m_pClient->m_Skins.Get(Skin);
m_aRenderInfo[i].m_OriginalRenderSkin = pSkin->m_OriginalSkin;
m_aRenderInfo[i].m_ColorableRenderSkin = pSkin->m_ColorableSkin;
m_aRenderInfo[i].m_BloodColor = pSkin->m_BloodColor;
m_aRenderInfo[i].m_SkinMetrics = pSkin->m_Metrics;
m_aRenderInfo[i].m_CustomColoredSkin = IsTeamplay;
if(!IsTeamplay)
{
m_aRenderInfo[i].m_ColorBody = ColorRGBA(1, 1, 1);
m_aRenderInfo[i].m_ColorFeet = ColorRGBA(1, 1, 1);
}
m_aRenderInfo[i].m_ColorBody = ColorRGBA(1, 1, 1);
m_aRenderInfo[i].m_ColorFeet = ColorRGBA(1, 1, 1);
}
}
}
}
int Skin = m_pClient->m_Skins.Find("x_spec");
const CSkin *pSkin = m_pClient->m_Skins.Get(Skin);
Expand Down Expand Up @@ -788,7 +789,7 @@ void CPlayers::OnRender()
{
continue;
}

vec2 Pos;
if(g_Config.m_ClFixKoGSpec)
Pos = m_aClient.m_RenderPos;
Expand All @@ -810,7 +811,6 @@ void CPlayers::OnRender()
continue;
}


RenderHookCollLine(&m_pClient->m_aClients[ClientID].m_RenderPrev, &m_pClient->m_aClients[ClientID].m_RenderCur, ClientID);

//don't render offscreen
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "components/motd.h"
#include "components/nameplates.h"
#include "components/particles.h"
#include "components/player_indicator.h"
#include "components/players.h"
#include "components/scoreboard.h"
#include "components/skins.h"
Expand Down Expand Up @@ -123,6 +124,7 @@ void CGameClient::OnConsoleInit()
m_All.Add(&m_Ghost);
m_All.Add(&m_MapLayersForeGround);
m_All.Add(&m_Particles.m_RenderExplosions);
m_All.Add(&m_PlayerIndicator);
m_All.Add(&m_NamePlates);
m_All.Add(&m_Particles.m_RenderGeneral);
m_All.Add(&m_DamageInd);
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/gameclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "components/motd.h"
#include "components/nameplates.h"
#include "components/particles.h"
#include "components/player_indicator.h"
#include "components/players.h"
#include "components/race_demo.h"
#include "components/scoreboard.h"
Expand Down Expand Up @@ -131,6 +132,7 @@ class CGameClient : public IGameClient
CSpectator m_Spectator;

CPlayers m_Players;
CPlayerIndicator m_PlayerIndicator;
CNamePlates m_NamePlates;
CItems m_Items;
CMapImages m_MapImages;
Expand Down
17 changes: 16 additions & 1 deletion src/game/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ MACRO_CONFIG_INT(ClShowCenterLines, tc_show_center, 0, 0, 1, CFGFLAG_CLIENT | CF

//MACRO_CONFIG_INT(ClFreeGhost, tc_freeghost, 0, 0, 1, CFGFLAG_CLIENT , "")

//Outline Variables
MACRO_CONFIG_INT(ClOutline, tc_outline, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Draws outlines")
MACRO_CONFIG_INT(ClOutlineFreeze, tc_outline_freeze, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Draws outline around freeze and deep")
MACRO_CONFIG_INT(ClOutlineUnFreeze, tc_outline_unfreeze, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Draws outline around unfreeze and undeep")
MACRO_CONFIG_INT(ClOutlineTele, tc_outline_tele, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Draws outline around teleporters")
MACRO_CONFIG_INT(ClOutlineSolid, tc_outline_solid, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Draws outline around hook and unhook")

MACRO_CONFIG_INT(ClOutlineWidth, tc_outline_width, 5, 1, 16, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(1-16) Width of freeze outline")
MACRO_CONFIG_INT(ClOutlineAlpha, tc_outline_alpha, 50, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(0-100) Outline alpha")
MACRO_CONFIG_INT(ClOutlineAlphaSolid, tc_outline_alpha_solid, 100, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(0-100) Outline solids alpha")
Expand All @@ -104,6 +104,21 @@ MACRO_CONFIG_COL(ClOutlineColorFreeze, tc_outline_color_freeze, 0, CFGFLAG_CLIEN
MACRO_CONFIG_COL(ClOutlineColorTele, tc_outline_color_tele, 0, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Tele outline color") //0 0 0
MACRO_CONFIG_COL(ClOutlineColorUnfreeze, tc_outline_color_unfreeze, 0, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Unfreeze outline color") //0 0 0

//Indicator Variables
MACRO_CONFIG_COL(ClIndicatorAlive, tc_indicator_alive, 255, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Color of alive tees in player indicator")
MACRO_CONFIG_COL(ClIndicatorFreeze, tc_indicator_freeze, 65407, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Color of frozen tees in player indicator")
MACRO_CONFIG_INT(ClIndicatorOffset, tc_indicator_offset, 42, 16, 200, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(16-128) Offset of indicator position")
MACRO_CONFIG_INT(ClIndicatorOffsetMax, tc_indicator_offset_max, 100, 16, 200, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(16-128) Max indicator offset for variable offset setting")
MACRO_CONFIG_INT(ClIndicatorVariableDistance, tc_indicator_variable_distance, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Indicator circles will be further away the further the tee is")
MACRO_CONFIG_INT(ClIndicatorMaxDistance, tc_indicator_variable_max_distance, 1000, 500, 7000, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Maximum tee distance for variable offset")
MACRO_CONFIG_INT(ClIndicatorRadius, tc_indicator_radius, 4, 1, 16, CFGFLAG_CLIENT | CFGFLAG_SAVE, "(1-16) indicator circle size")
MACRO_CONFIG_INT(ClIndicatorOpacity, tc_indicator_opacity, 50, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Opacity of indicator circles")
MACRO_CONFIG_INT(ClPlayerIndicator, tc_player_indicator, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show radial indicator of other tees")
MACRO_CONFIG_INT(ClPlayerIndicatorFreeze, tc_player_indicator_freeze, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Only show frozen tees in indicator")
MACRO_CONFIG_INT(ClIndicatorTeamOnly, tc_indicator_inteam, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Only show indicator while in team")
MACRO_CONFIG_INT(ClIndicatorTees, tc_indicator_tees, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show tees instead of circles")


MACRO_CONFIG_INT(ClWhiteFeet, tc_white_feet, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Render all feet as perfectly white base color")

MACRO_CONFIG_INT(ClMiniDebug, tc_mini_debug, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show position and angle")
Expand Down

0 comments on commit a49100e

Please sign in to comment.