MCPcopy Create free account
hub / github.com/ddnet/ddnet / GetNearestAirPos

Method GetNearestAirPos

src/game/server/entity.cpp:55–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55bool CEntity::GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos)
56{
57 for(int k = 0; k < 16 && GameServer()->Collision()->CheckPoint(Pos); k++)
58 {
59 Pos -= normalize(PrevPos - Pos);
60 }
61
62 vec2 PosInBlock = vec2(round_to_int(Pos.x) % 32, round_to_int(Pos.y) % 32);
63 vec2 BlockCenter = vec2(round_to_int(Pos.x), round_to_int(Pos.y)) - PosInBlock + vec2(16.0f, 16.0f);
64
65 *pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f), Pos.y);
66 if(!GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2()))
67 return true;
68
69 *pOutPos = vec2(Pos.x, BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
70 if(!GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2()))
71 return true;
72
73 *pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f),
74 BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
75 return !GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2());
76}
77
78bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *pOutPos)
79{

Callers

nothing calls this directly

Calls 5

normalizeFunction · 0.85
round_to_intFunction · 0.85
CheckPointMethod · 0.80
TestBoxMethod · 0.80
CollisionMethod · 0.45

Tested by

no test coverage detected