Make spec character rendering a bit cleaner

This commit is contained in:
heinrich5991 2020-06-25 14:56:23 +02:00
parent f93561758b
commit 8c095b2727
9 changed files with 80 additions and 123 deletions

View file

@ -270,13 +270,9 @@ Objects = [
NetIntAny("m_Test"),
]),
NetObjectEx("SpecChar", "spec-char-2@netobj.ddnet.tw", [
NetObjectEx("SpecChar", "spec-char@netobj.ddnet.tw", [
NetIntAny("m_X"),
NetIntAny("m_Y"),
NetIntAny("m_HookState"),
NetIntAny("m_HookedPlayer"),
NetIntAny("m_HookX"),
NetIntAny("m_HookY"),
]),
]

View file

@ -339,8 +339,8 @@ void CGhost::OnRender()
Player.m_AttackTick += Client()->GameTick(g_Config.m_ClDummy) - GhostTick;
m_pClient->m_pPlayers->RenderHook(&Prev, &Player, &pGhost->m_RenderInfo , -2, false, IntraTick);
m_pClient->m_pPlayers->RenderPlayer(&Prev, &Player, &pGhost->m_RenderInfo, -2, false, IntraTick);
m_pClient->m_pPlayers->RenderHook(&Prev, &Player, &pGhost->m_RenderInfo , -2, IntraTick);
m_pClient->m_pPlayers->RenderPlayer(&Prev, &Player, &pGhost->m_RenderInfo, -2, IntraTick);
}
}

View file

@ -35,11 +35,12 @@ void CNamePlates::RenderNameplate(
else
Position = mix(vec2(pPrevChar->m_X, pPrevChar->m_Y), vec2(pPlayerChar->m_X, pPlayerChar->m_Y), Client()->IntraGameTick(g_Config.m_ClDummy));
if(m_pClient->m_aClients[ClientID].m_Spec)
{
Position.x = m_pClient->m_aClients[ClientID].m_SpecChar.m_X;
Position.y = m_pClient->m_aClients[ClientID].m_SpecChar.m_Y;
}
RenderNameplatePos(Position, pPlayerInfo, 1.0f);
}
void CNamePlates::RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pPlayerInfo, float Alpha)
{
int ClientID = pPlayerInfo->m_ClientID;
bool OtherTeam = m_pClient->IsOtherTeam(ClientID);
@ -120,16 +121,8 @@ void CNamePlates::RenderNameplate(
}
else
{
if(m_pClient->m_aClients[ClientID].m_Spec)
{
TOutlineColor.Set(0.0f, 0.0f, 0.0f, 0.2f * g_Config.m_ClShowOthersAlpha / 100.0f);
TColor.Set(rgb.r, rgb.g, rgb.b, g_Config.m_ClShowOthersAlpha / 100.0f);
}
else
{
TOutlineColor.Set(0.0f, 0.0f, 0.0f, 0.5f*a);
TColor.Set(rgb.r, rgb.g, rgb.b, a);
}
TOutlineColor.Set(0.0f, 0.0f, 0.0f, 0.5f*a);
TColor.Set(rgb.r, rgb.g, rgb.b, a);
}
if(g_Config.m_ClNameplatesTeamcolors && m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS)
{
@ -139,6 +132,9 @@ void CNamePlates::RenderNameplate(
TColor.Set(0.7f, 0.7f, 1.0f, a);
}
TOutlineColor.m_A *= Alpha;
TColor.m_A *= Alpha;
if(m_aNamePlates[ClientID].m_NameTextContainerIndex != -1)
TextRender()->RenderTextContainer(m_aNamePlates[ClientID].m_NameTextContainerIndex, &TColor, &TOutlineColor, Position.x - tw / 2.0f, Position.y - FontSize - 38.0f);
@ -172,18 +168,25 @@ void CNamePlates::OnRender()
for(int i = 0; i < MAX_CLIENTS; i++)
{
// only render active characters
if(!m_pClient->m_Snap.m_aCharacters[i].m_Active && (!m_pClient->m_aClients[i].m_Spec || !g_Config.m_ClShowSpecTee))
const void *pInfoRaw = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, i);
const CNetObj_PlayerInfo *pInfo = (CNetObj_PlayerInfo *)pInfoRaw;
if(!pInfo)
{
continue;
}
const void *pInfo = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, i);
if(m_pClient->m_aClients[i].m_SpecCharPresent)
{
RenderNameplatePos(m_pClient->m_aClients[i].m_SpecChar, pInfo, 0.4f);
}
if(pInfo)
// only render active characters
if(m_pClient->m_Snap.m_aCharacters[i].m_Active)
{
RenderNameplate(
&m_pClient->m_Snap.m_aCharacters[i].m_Prev,
&m_pClient->m_Snap.m_aCharacters[i].m_Cur,
(const CNetObj_PlayerInfo *)pInfo);
pInfo);
}
}
}

View file

@ -39,6 +39,7 @@ class CNamePlates : public CComponent
const CNetObj_Character *pPlayerChar,
const CNetObj_PlayerInfo *pPlayerInfo
);
void RenderNameplatePos(vec2 Position, const CNetObj_PlayerInfo *pPlayerInfo, float Alpha);
SPlayerNamePlate m_aNamePlates[MAX_CLIENTS];
class CPlayers* m_pPlayers;

View file

@ -81,7 +81,6 @@ void CPlayers::RenderHook(
const CNetObj_Character *pPlayerChar,
const CTeeRenderInfo *pRenderInfo,
int ClientID,
bool Spec,
float Intra
)
{
@ -92,13 +91,8 @@ void CPlayers::RenderHook(
CTeeRenderInfo RenderInfo = *pRenderInfo;
int HookedPlayer = pPlayerChar->m_HookedPlayer;
if(Spec)
HookedPlayer = m_pClient->m_aClients[ClientID].m_SpecChar.m_HookedPlayer;
// don't render hooks to not active character cores
if(HookedPlayer != -1 && !m_pClient->m_Snap.m_aCharacters[HookedPlayer].m_Active)
if(pPlayerChar->m_HookedPlayer != -1 && !m_pClient->m_Snap.m_aCharacters[pPlayerChar->m_HookedPlayer].m_Active)
return;
float IntraTick = Intra;
@ -115,14 +109,8 @@ void CPlayers::RenderHook(
else
Position = mix(vec2(Prev.m_X, Prev.m_Y), vec2(Player.m_X, Player.m_Y), IntraTick);
if(Spec)
{
Position.x = m_pClient->m_aClients[ClientID].m_SpecChar.m_X;
Position.y = m_pClient->m_aClients[ClientID].m_SpecChar.m_Y;
}
// draw hook
if((Prev.m_HookState>0 && Player.m_HookState>0) || (Spec && m_pClient->m_aClients[ClientID].m_SpecChar.m_HookState>0))
if(Prev.m_HookState>0 && Player.m_HookState>0)
{
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
@ -133,13 +121,8 @@ void CPlayers::RenderHook(
vec2 Pos = Position;
vec2 HookPos;
if(in_range(HookedPlayer, MAX_CLIENTS-1))
HookPos = m_pClient->m_aClients[HookedPlayer].m_RenderPos;
else if(Spec)
{
HookPos.x = m_pClient->m_aClients[ClientID].m_SpecChar.m_HookX;
HookPos.y = m_pClient->m_aClients[ClientID].m_SpecChar.m_HookY;
}
if(in_range(pPlayerChar->m_HookedPlayer, MAX_CLIENTS-1))
HookPos = m_pClient->m_aClients[pPlayerChar->m_HookedPlayer].m_RenderPos;
else
HookPos = mix(vec2(Prev.m_HookX, Prev.m_HookY), vec2(Player.m_HookX, Player.m_HookY), IntraTick);
@ -150,7 +133,7 @@ void CPlayers::RenderHook(
Graphics()->QuadsSetRotation(GetAngle(Dir)+pi);
// render head
int QuadOffset = NUM_WEAPONS * 2 + 2;
if(OtherTeam || Spec)
if(OtherTeam)
Graphics()->SetColor(1.0f, 1.0f, 1.0f, g_Config.m_ClShowOthersAlpha / 100.0f);
Graphics()->RenderQuadContainerAsSprite(m_WeaponEmoteQuadContainerIndex, QuadOffset, HookPos.x, HookPos.y);
@ -173,7 +156,7 @@ void CPlayers::RenderHook(
Graphics()->QuadsSetRotation(0);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderHand(&RenderInfo, Position, normalize(HookPos-Pos), -pi/2, vec2(20, 0), (OtherTeam || Spec) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f);
RenderHand(&RenderInfo, Position, normalize(HookPos-Pos), -pi/2, vec2(20, 0), OtherTeam ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f);
}
}
@ -182,7 +165,6 @@ void CPlayers::RenderPlayer(
const CNetObj_Character *pPlayerChar,
const CTeeRenderInfo *pRenderInfo,
int ClientID,
bool Spec,
float Intra
)
{
@ -195,7 +177,7 @@ void CPlayers::RenderPlayer(
bool Local = m_pClient->m_Snap.m_LocalClientID == ClientID;
bool OtherTeam = m_pClient->IsOtherTeam(ClientID);
float Alpha = (OtherTeam || Spec) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
float Alpha = OtherTeam ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
// set size
RenderInfo.m_Size = 64.0f;
@ -253,12 +235,6 @@ void CPlayers::RenderPlayer(
else
Position = mix(vec2(Prev.m_X, Prev.m_Y), vec2(Player.m_X, Player.m_Y), IntraTick);
if(Spec)
{
Position.x = m_pClient->m_aClients[ClientID].m_SpecChar.m_X;
Position.y = m_pClient->m_aClients[ClientID].m_SpecChar.m_Y;
}
vec2 Vel = mix(vec2(Prev.m_VelX/256.0f, Prev.m_VelY/256.0f), vec2(Player.m_VelX/256.0f, Player.m_VelY/256.0f), IntraTick);
m_pClient->m_pFlow->Add(Position, Vel*100.0f, 10.0f);
@ -304,7 +280,6 @@ void CPlayers::RenderPlayer(
}
// draw gun
if(!Spec)
{
#if defined(CONF_VIDEORECORDER)
if(ClientID >= 0 && ((GameClient()->m_GameInfo.m_AllowHookColl && g_Config.m_ClShowHookCollAlways) || (Player.m_PlayerFlags&PLAYERFLAG_AIM && ((!Local && ((!IVideo::Current()&&g_Config.m_ClShowHookCollOther)||(IVideo::Current()&&g_Config.m_ClVideoShowHookCollOther))) || (Local && g_Config.m_ClShowHookCollOwn)))))
@ -586,14 +561,11 @@ void CPlayers::RenderPlayer(
Graphics()->QuadsSetRotation(0);
}
if(OtherTeam || Spec || ClientID < 0)
if(OtherTeam || ClientID < 0)
RenderTools()->RenderTee(&State, &RenderInfo, Player.m_Emote, Direction, Position, g_Config.m_ClShowOthersAlpha / 100.0f);
else
RenderTools()->RenderTee(&State, &RenderInfo, Player.m_Emote, Direction, Position);
if(Spec)
return;
int QuadOffsetToEmoticon = NUM_WEAPONS * 2 + 2 + 2;
if(Player.m_PlayerFlags&PLAYERFLAG_CHATTING)
{
@ -680,57 +652,53 @@ void CPlayers::OnRender()
}
}
}
m_RenderInfoSpec.m_Texture = m_pClient->m_pSkins->Get(m_pClient->m_pSkins->Find("x_spec"))->m_OrgTexture;
m_RenderInfoSpec.m_Size = 64.0f;
// render other players in two passes, first pass we render the other, second pass we render our self
for(int p = 0; p < 4; p++)
// render other players in three passes, first pass we render spectees,
// then everyone but us, and finally we render ourselves
for(int p = 0; p < 6; p++)
{
for(int i = 0; i < MAX_CLIENTS; i++)
{
// only render active characters
if(!m_pClient->m_Snap.m_aCharacters[i].m_Active && (!m_pClient->m_aClients[i].m_Spec || !g_Config.m_ClShowSpecTee))
if(p % 3 == 0 && !m_pClient->m_aClients[i].m_SpecCharPresent)
continue;
if(p % 3 != 0 && !m_pClient->m_Snap.m_aCharacters[i].m_Active)
continue;
const void *pPrevInfo = Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_PLAYERINFO, i);
const void *pInfo = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, i);
if(pPrevInfo && pInfo)
if(p % 3 == 0)
{
if(p < 3)
{
continue;
}
vec2 Pos = m_pClient->m_aClients[i].m_SpecChar;
RenderTools()->RenderTee(CAnimState::GetIdle(), &m_RenderInfoSpec, EMOTE_BLINK, vec2(1, 0), Pos, 1.0f);
}
else
{
const void *pPrevInfo = Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_PLAYERINFO, i);
const void *pInfo = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, i);
if(!pPrevInfo || !pInfo)
{
continue;
}
bool Local = m_pClient->m_Snap.m_LocalClientID == i;
if((p % 2) == 0 && Local) continue;
if((p % 2) == 1 && !Local) continue;
if((p % 3) == 1 && Local) continue;
if((p % 3) == 2 && !Local) continue;
CNetObj_Character PrevChar = m_pClient->m_aClients[i].m_RenderPrev;
CNetObj_Character CurChar = m_pClient->m_aClients[i].m_RenderCur;
if(m_pClient->m_aClients[i].m_Spec && !m_pClient->m_Snap.m_aCharacters[i].m_Active)
if(p<3)
{
int Skin = m_pClient->m_pSkins->Find("x_spec");
if(Skin != -1)
{
m_aRenderInfo[i].m_Texture = m_pClient->m_pSkins->Get(Skin)->m_ColorTexture;
}
}
if(p<2)
{
RenderHook(
&PrevChar,
&CurChar,
&m_aRenderInfo[i],
i,
m_pClient->m_aClients[i].m_Spec && !m_pClient->m_Snap.m_aCharacters[i].m_Active
);
RenderHook(&PrevChar, &CurChar, &m_aRenderInfo[i], i);
}
else
{
RenderPlayer(
&PrevChar,
&CurChar,
&m_aRenderInfo[i],
i,
m_pClient->m_aClients[i].m_Spec && !m_pClient->m_Snap.m_aCharacters[i].m_Active
);
RenderPlayer(&PrevChar, &CurChar, &m_aRenderInfo[i], i);
}
}
}

View file

@ -8,6 +8,7 @@ class CPlayers : public CComponent
{
friend class CGhost;
CTeeRenderInfo m_RenderInfoSpec;
CTeeRenderInfo m_aRenderInfo[MAX_CLIENTS];
void RenderHand(class CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset, float Alpha = 1.0f);
void RenderPlayer(
@ -15,7 +16,6 @@ class CPlayers : public CComponent
const CNetObj_Character *pPlayerChar,
const CTeeRenderInfo *pRenderInfo,
int ClientID,
bool Spec,
float Intra = 0.f
);
void RenderHook(
@ -23,7 +23,6 @@ class CPlayers : public CComponent
const CNetObj_Character *pPlayerChar,
const CTeeRenderInfo *pRenderInfo,
int ClientID,
bool Spec,
float Intra = 0.f
);

View file

@ -1135,6 +1135,11 @@ void CGameClient::OnNewSnapshot()
bool FoundGameInfoEx = false;
for(int i = 0; i < MAX_CLIENTS; i++)
{
m_aClients[i].m_SpecCharPresent = false;
}
// go trough all the items in the snapshot and gather the info we want
{
m_Snap.m_aTeamSize[TEAM_RED] = m_Snap.m_aTeamSize[TEAM_BLUE] = 0;
@ -1287,13 +1292,10 @@ void CGameClient::OnNewSnapshot()
else if(Item.m_Type == NETOBJTYPE_SPECCHAR)
{
const CNetObj_SpecChar *pSpecCharData = (const CNetObj_SpecChar *)pData;
m_aClients[Item.m_ID].m_SpecChar.m_X = pSpecCharData->m_X;
m_aClients[Item.m_ID].m_SpecChar.m_Y = pSpecCharData->m_Y;
m_aClients[Item.m_ID].m_SpecChar.m_HookState = pSpecCharData->m_HookState;
m_aClients[Item.m_ID].m_SpecChar.m_HookedPlayer = pSpecCharData->m_HookedPlayer;
m_aClients[Item.m_ID].m_SpecChar.m_HookX = pSpecCharData->m_HookX;
m_aClients[Item.m_ID].m_SpecChar.m_HookY = pSpecCharData->m_HookY;
m_aClients[Item.m_ID].m_SpecCharPresent = true;
m_aClients[Item.m_ID].m_SpecChar.x = pSpecCharData->m_X;
m_aClients[Item.m_ID].m_SpecChar.y = pSpecCharData->m_Y;
}
else if(Item.m_Type == NETOBJTYPE_SPECTATORINFO)
{
@ -1864,8 +1866,8 @@ void CGameClient::CClientData::Reset()
m_Evolved.m_Tick = -1;
m_SpecChar.m_X = 0;
m_SpecChar.m_Y = 0;
m_SpecChar = vec2(0, 0);
m_SpecCharPresent = false;
UpdateRenderInfo();
}

View file

@ -290,16 +290,8 @@ public:
int64 m_SmoothLen[2];
vec2 m_PredPos[200];
int m_PredTick[200];
struct SpecChar
{
int m_X;
int m_Y;
int m_HookState;
int m_HookedPlayer;
int m_HookX;
int m_HookY;
} m_SpecChar;
bool m_SpecCharPresent;
vec2 m_SpecChar;
};
CClientData m_aClients[MAX_CLIENTS];

View file

@ -412,15 +412,11 @@ void CPlayer::Snap(int SnappingClient)
pRaceInfo->m_RaceStartTick = m_pCharacter->m_StartTime;
}
if(m_Paused == PAUSE_SPEC && m_pCharacter && m_pCharacter->Core())
if(m_pCharacter && m_pCharacter->IsPaused())
{
CNetObj_SpecChar *pSpecChar = static_cast<CNetObj_SpecChar *>(Server()->SnapNewItem(NETOBJTYPE_SPECCHAR, id, sizeof(CNetObj_SpecChar)));
pSpecChar->m_X = m_pCharacter->Core()->m_Pos.x;
pSpecChar->m_Y = m_pCharacter->Core()->m_Pos.y;
pSpecChar->m_HookState = m_pCharacter->Core()->m_HookState;
pSpecChar->m_HookedPlayer = m_pCharacter->Core()->m_HookedPlayer;
pSpecChar->m_HookX = m_pCharacter->Core()->m_HookPos.x;
pSpecChar->m_HookY = m_pCharacter->Core()->m_HookPos.y;
}
}