From b8805f43897bc5b22a7e7491b055b8dad84a34aa Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Wed, 29 Apr 2020 23:52:34 +0200 Subject: Core/Objects: optimize and improve MovePositionToFirstCollision results * removed redundant static LOS checks as they are covered by the mmap raycast prior to the check * removed unnecessary VMap height lookups to determine rapid falloffs as they are covered by the mmap raycast as well (cherry picked from commit cf849df50af0e930b08c0fa3cd1bb4426be9c69a) --- src/server/game/Entities/Object/Object.cpp | 45 +++++------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index b1e8ed78cf8..484631d902d 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -3217,64 +3217,33 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float desty = result.y; destz = result.z; - float halfHeight = GetCollisionHeight() * 0.5f; UpdateAllowedPositionZ(destx, desty, destz); - bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY), - pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, - destx, desty, destz + halfHeight, - destx, desty, destz, -0.5f); - destz -= halfHeight; - - // collision occured - if (col) - { - // move back a bit - destx -= CONTACT_DISTANCE * std::cos(angle); - desty -= CONTACT_DISTANCE * std::sin(angle); - dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); - } // check dynamic collision - col = GetMap()->getObjectHitPos(GetPhaseShift(), + float halfHeight = GetCollisionHeight() * 0.5f; + bool col = GetMap()->getObjectHitPos(GetPhaseShift(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, destx, desty, destz + halfHeight, destx, desty, destz, -0.5f); destz -= halfHeight; - // Collided with a gameobject + // Collided with a gameobject, move back to collision point if (col) { destx -= CONTACT_DISTANCE * std::cos(angle); desty -= CONTACT_DISTANCE * std::sin(angle); - dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); - } - - float step = dist / 10.0f; - - for (uint8 j = 0; j < 10; ++j) - { - // do not allow too big z changes - if (std::fabs(pos.m_positionZ - destz) > 6.0f) - { - destx -= step * std::cos(angle); - desty -= step * std::sin(angle); - UpdateAllowedPositionZ(destx, desty, destz); - } - // we have correct destz now - else - { - pos.Relocate(destx, desty, destz); - break; - } + dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty)); } float groundZ = VMAP_INVALID_HEIGHT_VALUE; Trinity::NormalizeMapCoord(pos.m_positionX); Trinity::NormalizeMapCoord(pos.m_positionY); - UpdateAllowedPositionZ(destx, desty, pos.m_positionZ, &groundZ); + UpdateAllowedPositionZ(destx, desty, destz, &groundZ); + pos.SetOrientation(GetOrientation()); + pos.Relocate(destx, desty, destz); // position has no ground under it (or is too far away) if (groundZ <= INVALID_HEIGHT) -- cgit v1.2.3