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

Method IntersectLineTeleHook

src/game/collision.cpp:360–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358}
359
360int CCollision::IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr) const
361{
362 float Distance = distance(Pos0, Pos1);
363 int End(Distance + 1);
364 vec2 Last = Pos0;
365 int dx = 0, dy = 0; // Offset for checking the "through" tile
366 ThroughOffset(Pos0, Pos1, &dx, &dy);
367 for(int i = 0; i <= End; i++)
368 {
369 float a = i / (float)End;
370 vec2 Pos = mix(Pos0, Pos1, a);
371 // Temporary position for checking collision
372 int ix = round_to_int(Pos.x);
373 int iy = round_to_int(Pos.y);
374
375 int Index = GetPureMapIndex(Pos);
376 if(pTeleNr)
377 {
378 if(g_Config.m_SvOldTeleportHook)
379 *pTeleNr = IsTeleport(Index);
380 else
381 *pTeleNr = IsTeleportHook(Index);
382 }
383 if(pTeleNr && *pTeleNr)
384 {
385 if(pOutCollision)
386 *pOutCollision = Pos;
387 if(pOutBeforeCollision)
388 *pOutBeforeCollision = Last;
389 return TILE_TELEINHOOK;
390 }
391
392 int Hit = 0;
393 if(CheckPoint(ix, iy))
394 {
395 if(!IsThrough(ix, iy, dx, dy, Pos0, Pos1))
396 Hit = GetCollisionAt(ix, iy);
397 }
398 else if(IsHookBlocker(ix, iy, Pos0, Pos1))
399 {
400 Hit = TILE_NOHOOK;
401 }
402 if(Hit)
403 {
404 if(pOutCollision)
405 *pOutCollision = Pos;
406 if(pOutBeforeCollision)
407 *pOutBeforeCollision = Last;
408 return Hit;
409 }
410
411 Last = Pos;
412 }
413 if(pOutCollision)
414 *pOutCollision = Pos1;
415 if(pOutBeforeCollision)
416 *pOutBeforeCollision = Pos1;
417 return 0;

Callers 2

TickMethod · 0.80
RenderHookCollLineMethod · 0.80

Calls 4

distanceFunction · 0.85
ThroughOffsetFunction · 0.85
mixFunction · 0.85
round_to_intFunction · 0.85

Tested by

no test coverage detected