Skip to content

Commit

Permalink
Merge pull request ddnet#9459 from art0007i/hookline-teleport
Browse files Browse the repository at this point in the history
teleport hookline (only when there is 1 possible exit)
  • Loading branch information
Robyt3 authored Jan 4, 2025
2 parents 42228b0 + 4628d38 commit 8bb8a17
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions src/game/client/components/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ void CPlayers::RenderHookCollLine(

bool DoBreak = false;

std::vector<std::pair<vec2, vec2>> vLineSegments;

do
{
OldPos = NewPos;
Expand All @@ -266,9 +268,25 @@ void CPlayers::RenderHookCollLine(
DoBreak = true;
}

int Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0);
int Tele;
int Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0, &Tele);
if(!DoBreak && Hit == TILE_TELEINHOOK)
{
if(Collision()->TeleOuts(Tele - 1).size() != 1)
{
Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0);
}
else
{
std::pair<vec2, vec2> NewPair = std::make_pair(InitPos, FinishPos);
if(std::find(vLineSegments.begin(), vLineSegments.end(), NewPair) != vLineSegments.end())
break;
vLineSegments.push_back(NewPair);
InitPos = NewPos = Collision()->TeleOuts(Tele - 1)[0];
}
}

if(!DoBreak && Hit)
if(!DoBreak && Hit && Hit != TILE_TELEINHOOK)
{
if(Hit != TILE_NOHOOK)
{
Expand All @@ -282,7 +300,7 @@ void CPlayers::RenderHookCollLine(
break;
}

if(Hit)
if(Hit && Hit != TILE_TELEINHOOK)
break;

NewPos.x = round_to_int(NewPos.x);
Expand All @@ -295,28 +313,41 @@ void CPlayers::RenderHookCollLine(
ExDirection.y = round_to_int(ExDirection.y * 256.0f) / 256.0f;
} while(!DoBreak);

std::pair<vec2, vec2> NewPair = std::make_pair(InitPos, FinishPos);
if(std::find(vLineSegments.begin(), vLineSegments.end(), NewPair) == vLineSegments.end())
vLineSegments.push_back(NewPair);

if(AlwaysRenderHookColl && RenderHookCollPlayer)
{
// invert the hook coll colors when using cl_show_hook_coll_always and +showhookcoll is pressed
HookCollColor = color_invert(HookCollColor);
}
Graphics()->SetColor(HookCollColor.WithAlpha(Alpha));
for(const auto &[DrawInitPos, DrawFinishPos] : vLineSegments)
{
if(HookCollSize > 0)
{
float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f;
vec2 PerpToAngle = normalize(vec2(ExDirection.y, -ExDirection.x)) * GameClient()->m_Camera.m_Zoom;
vec2 Pos0 = DrawFinishPos + PerpToAngle * -LineWidth;
vec2 Pos1 = DrawFinishPos + PerpToAngle * LineWidth;
vec2 Pos2 = DrawInitPos + PerpToAngle * -LineWidth;
vec2 Pos3 = DrawInitPos + PerpToAngle * LineWidth;
IGraphics::CFreeformItem FreeformItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y, Pos2.x, Pos2.y, Pos3.x, Pos3.y);
Graphics()->QuadsDrawFreeform(&FreeformItem, 1);
}
else
{
IGraphics::CLineItem LineItem(DrawInitPos.x, DrawInitPos.y, DrawFinishPos.x, DrawFinishPos.y);
Graphics()->LinesDraw(&LineItem, 1);
}
}
if(HookCollSize > 0)
{
float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f;
vec2 PerpToAngle = normalize(vec2(ExDirection.y, -ExDirection.x)) * GameClient()->m_Camera.m_Zoom;
vec2 Pos0 = FinishPos + PerpToAngle * -LineWidth;
vec2 Pos1 = FinishPos + PerpToAngle * LineWidth;
vec2 Pos2 = InitPos + PerpToAngle * -LineWidth;
vec2 Pos3 = InitPos + PerpToAngle * LineWidth;
IGraphics::CFreeformItem FreeformItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y, Pos2.x, Pos2.y, Pos3.x, Pos3.y);
Graphics()->QuadsDrawFreeform(&FreeformItem, 1);
Graphics()->QuadsEnd();
}
else
{
IGraphics::CLineItem LineItem(InitPos.x, InitPos.y, FinishPos.x, FinishPos.y);
Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd();
}
}
Expand Down

0 comments on commit 8bb8a17

Please sign in to comment.