Skip to content

Commit 98a9267

Browse files
committed
Refactor
1 parent bcf244b commit 98a9267

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ CVector g_vecBulletFireEndPosition;
7373
#define DOUBLECLICK_TIMEOUT 330
7474
#define DOUBLECLICK_MOVE_THRESHOLD 10.0f
7575

76-
// Ray casting constants for marker click detection
77-
constexpr float MARKER_CLICK_RAY_DEPTH = 300.0f; // Screen-to-world ray projection depth
78-
constexpr float MARKER_CLICK_MAX_DISTANCE = 99999.9f; // Maximum distance for closest marker comparison
76+
// Ray casting constants for click detection
77+
constexpr float CLICK_RAY_DEPTH = 300.0f; // Screen-to-world ray projection depth
78+
constexpr float MAX_CLICK_DISTANCE = 6000.0f; // Maximum distance for closest marker comparison
7979

8080
static constexpr long long TIME_DISCORD_UPDATE_RATE = 15000;
8181

@@ -2329,55 +2329,55 @@ void CClientGame::ProcessServerControlBind(CControlFunctionBind* pBind)
23292329
m_pNetAPI->RPC(KEY_BIND, bitStream.pBitStream);
23302330
}
23312331

2332-
CClientMarker* CClientGame::CheckMarkerClick(float fScreenX, float fScreenY, float& fDistance)
2332+
CClientMarker* CClientGame::CheckMarkerClick(float screenX, float screenY, float& distance) noexcept
23332333
{
23342334
if (!m_pMarkerManager)
23352335
return nullptr;
23362336

2337-
CCamera* pCamera = g_pGame->GetCamera();
2338-
CMatrix matCamera;
2339-
pCamera->GetMatrix(&matCamera);
2340-
CVector vecOrigin = matCamera.vPos;
2337+
CCamera* camera = g_pGame->GetCamera();
2338+
CMatrix cameraMatrix;
2339+
camera->GetMatrix(&cameraMatrix);
2340+
CVector origin = cameraMatrix.vPos;
23412341

2342-
CVector vecTarget, vecScreen(fScreenX, fScreenY, MARKER_CLICK_RAY_DEPTH);
2343-
g_pCore->GetGraphics()->CalcWorldCoors(&vecScreen, &vecTarget);
2342+
CVector target, screen(screenX, screenY, CLICK_RAY_DEPTH);
2343+
g_pCore->GetGraphics()->CalcWorldCoors(&screen, &target);
23442344

2345-
CVector vecRayDir = vecTarget - vecOrigin;
2346-
vecRayDir.Normalize();
2345+
CVector rayDirection = target - origin;
2346+
rayDirection.Normalize();
23472347

2348-
CClientMarker* pClosestMarker = nullptr;
2349-
float fClosestDist = MARKER_CLICK_MAX_DISTANCE;
2348+
CClientMarker* closestMarker = nullptr;
2349+
float closestDistance = MAX_CLICK_DISTANCE;
23502350

2351-
for (auto* pMarker : m_pMarkerManager->m_Markers)
2351+
for (auto* marker : m_pMarkerManager->m_Markers)
23522352
{
2353-
if (!pMarker || !pMarker->IsStreamedIn() || !pMarker->IsVisible())
2353+
if (!marker || !marker->IsStreamedIn() || !marker->IsVisible())
23542354
continue;
23552355

2356-
if (!pMarker->IsClientSideOnScreen())
2356+
if (!marker->IsClientSideOnScreen())
23572357
continue;
23582358

2359-
CSphere boundingSphere = pMarker->GetWorldBoundingSphere();
2359+
CSphere boundingSphere = marker->GetWorldBoundingSphere();
23602360

2361-
CVector vecToSphere = boundingSphere.vecPosition - vecOrigin;
2362-
float fProjection = vecToSphere.DotProduct(&vecRayDir);
2361+
CVector toSphere = boundingSphere.vecPosition - origin;
2362+
float projection = toSphere.DotProduct(&rayDirection);
23632363

2364-
if (fProjection <= 0.0f)
2364+
if (projection <= 0.0f)
23652365
continue;
23662366

2367-
CVector vecClosestPoint = vecOrigin + vecRayDir * fProjection;
2368-
float fDistanceToRay = (boundingSphere.vecPosition - vecClosestPoint).Length();
2367+
CVector closestPoint = origin + rayDirection * projection;
2368+
float distanceToRay = (boundingSphere.vecPosition - closestPoint).Length();
23692369

2370-
if (fDistanceToRay <= boundingSphere.fRadius && fProjection < fClosestDist)
2370+
if (distanceToRay <= boundingSphere.fRadius && projection < closestDistance)
23712371
{
2372-
fClosestDist = fProjection;
2373-
pClosestMarker = pMarker;
2372+
closestDistance = projection;
2373+
closestMarker = marker;
23742374
}
23752375
}
23762376

2377-
if (pClosestMarker)
2378-
fDistance = fClosestDist;
2377+
if (closestMarker)
2378+
distance = closestDistance;
23792379

2380-
return pClosestMarker;
2380+
return closestMarker;
23812381
}
23822382

23832383
bool CClientGame::ProcessMessageForCursorEvents(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -2429,7 +2429,7 @@ bool CClientGame::ProcessMessageForCursorEvents(HWND hwnd, UINT uMsg, WPARAM wPa
24292429

24302430
CVector2D vecCursorPosition((float)iX, (float)iY);
24312431

2432-
CVector vecOrigin, vecTarget, vecScreen((float)iX, (float)iY, 300.0f);
2432+
CVector vecOrigin, vecTarget, vecScreen((float)iX, (float)iY, CLICK_RAY_DEPTH);
24332433
g_pCore->GetGraphics()->CalcWorldCoors(&vecScreen, &vecTarget);
24342434

24352435
// Grab the camera position
@@ -2613,7 +2613,7 @@ bool CClientGame::ProcessMessageForCursorEvents(HWND hwnd, UINT uMsg, WPARAM wPa
26132613
CVector2D vecResolution = g_pCore->GetGUI()->GetResolution();
26142614
CVector2D vecCursorPosition(((float)iX) / vecResolution.fX, ((float)iY) / vecResolution.fY);
26152615

2616-
CVector vecTarget, vecScreen((float)iX, (float)iY, MARKER_CLICK_RAY_DEPTH);
2616+
CVector vecTarget, vecScreen((float)iX, (float)iY, CLICK_RAY_DEPTH);
26172617
g_pCore->GetGraphics()->CalcWorldCoors(&vecScreen, &vecTarget);
26182618

26192619
// Call the onClientCursorMove event

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class CClientGame
381381
void ProcessServerControlBind(CControlFunctionBind* pBind);
382382

383383
bool ProcessMessageForCursorEvents(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
384-
CClientMarker* CheckMarkerClick(float fScreenX, float fScreenY, float& fDistance);
384+
CClientMarker* CheckMarkerClick(float screenX, float screenY, float& distance) noexcept;
385385
bool AreCursorEventsEnabled() { return m_bCursorEventsEnabled; }
386386
void SetCursorEventsEnabled(bool bCursorEventsEnabled) { m_bCursorEventsEnabled = bCursorEventsEnabled; }
387387

Client/mods/deathmatch/logic/CClientMarker.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -546,35 +546,35 @@ void CClientMarker::SetIgnoreAlphaLimits(bool ignore)
546546
m_pMarker->SetIgnoreAlphaLimits(ignore);
547547
}
548548

549-
bool CClientMarker::IsClientSideOnScreen()
549+
bool CClientMarker::IsClientSideOnScreen() noexcept
550550
{
551551
if (!IsStreamedIn() || !IsVisible())
552552
return false;
553553

554-
CVector vecPosition;
555-
GetPosition(vecPosition);
554+
CVector position;
555+
GetPosition(position);
556556

557-
CVector vecScreen;
558-
g_pCore->GetGraphics()->CalcScreenCoors(&vecPosition, &vecScreen);
557+
CVector screen;
558+
g_pCore->GetGraphics()->CalcScreenCoors(&position, &screen);
559559

560-
if (vecScreen.fZ <= CLIENT_MARKER_ONSCREEN_THRESHOLD)
560+
if (screen.fZ <= CLIENT_MARKER_ONSCREEN_THRESHOLD)
561561
return false;
562562

563-
float fResWidth = static_cast<float>(g_pCore->GetGraphics()->GetViewportWidth());
564-
float fResHeight = static_cast<float>(g_pCore->GetGraphics()->GetViewportHeight());
563+
float resWidth = static_cast<float>(g_pCore->GetGraphics()->GetViewportWidth());
564+
float resHeight = static_cast<float>(g_pCore->GetGraphics()->GetViewportHeight());
565565

566566
CSphere boundingSphere = GetWorldBoundingSphere();
567-
CVector vecEdgePos = boundingSphere.vecPosition;
568-
vecEdgePos.fX += boundingSphere.fRadius;
567+
CVector edgePos = boundingSphere.vecPosition;
568+
edgePos.fX += boundingSphere.fRadius;
569569

570-
CVector vecEdgeScreen;
571-
g_pCore->GetGraphics()->CalcScreenCoors(&vecEdgePos, &vecEdgeScreen);
570+
CVector edgeScreen;
571+
g_pCore->GetGraphics()->CalcScreenCoors(&edgePos, &edgeScreen);
572572

573-
if (vecEdgeScreen.fZ <= CLIENT_MARKER_ONSCREEN_THRESHOLD)
573+
if (edgeScreen.fZ <= CLIENT_MARKER_ONSCREEN_THRESHOLD)
574574
return true;
575575

576-
float fScreenRadius = fabs(vecEdgeScreen.fX - vecScreen.fX);
576+
float screenRadius = fabs(edgeScreen.fX - screen.fX);
577577

578-
return (vecScreen.fX + fScreenRadius) >= 0.0f && (vecScreen.fX - fScreenRadius) <= fResWidth &&
579-
(vecScreen.fY + fScreenRadius) >= 0.0f && (vecScreen.fY - fScreenRadius) <= fResHeight;
578+
return (screen.fX + screenRadius) >= 0.0f && (screen.fX - screenRadius) <= resWidth &&
579+
(screen.fY + screenRadius) >= 0.0f && (screen.fY - screenRadius) <= resHeight;
580580
}

Client/mods/deathmatch/logic/CClientMarker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CClientMarker final : public CClientStreamElement, private CClientColCallb
7777

7878
static bool IsLimitReached();
7979

80-
bool IsClientSideOnScreen();
80+
bool IsClientSideOnScreen() noexcept;
8181

8282
CClientColShape* GetColShape() { return m_pCollision; }
8383

0 commit comments

Comments
 (0)