Skip to content

Commit b108390

Browse files
4O4Marek Kulik
authored andcommitted
Fix isInsideRadarArea() not working with negative dimensions (#157)
* Fix isElementInsideRadarArea not working when radarArea size is negative * Fix arguments naming in RadarArea *Position methods * Adjust copypasted signatures in comments to match the reality
1 parent 3c644fd commit b108390

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

Client/mods/deathmatch/logic/CClientRadarArea.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class CClientRadarArea : public CClientEntity
3737
inline eClientEntityType GetType ( void ) const { return CCLIENTRADARAREA; };
3838

3939
inline const CVector2D& GetPosition ( void ) const { return m_vecPosition; };
40-
inline void GetPosition ( CVector2D& vecBottomLeft ) const { vecBottomLeft = m_vecPosition; };
41-
inline void GetPosition ( CVector& vecBottomLeft ) const { vecBottomLeft = CVector ( m_vecPosition.fX, m_vecPosition.fY, 0.0f ); };
42-
inline void SetPosition ( const CVector2D& vecBottomLeft ) { m_vecPosition = vecBottomLeft; };
43-
inline void SetPosition ( const CVector& vecBottomLeft ) { m_vecPosition = CVector2D ( vecBottomLeft.fX, vecBottomLeft.fY ); };
40+
inline void GetPosition ( CVector2D& vecPosition ) const { vecPosition = m_vecPosition; };
41+
inline void GetPosition ( CVector& vecPosition ) const { vecPosition = CVector ( m_vecPosition.fX, m_vecPosition.fY, 0.0f ); };
42+
inline void SetPosition ( const CVector2D& vecPosition ) { m_vecPosition = vecPosition; };
43+
inline void SetPosition ( const CVector& vecPosition ) { m_vecPosition = CVector2D ( vecPosition.fX, vecPosition.fY ); };
4444

4545
inline const CVector2D& GetSize ( void ) const { return m_vecSize; };
4646
inline void GetSize ( CVector2D& vecSize ) { vecSize = m_vecSize; };

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,22 +4063,28 @@ bool CStaticFunctionDefinitions::SetRadarAreaFlashing ( CClientRadarArea* RadarA
40634063

40644064
bool CStaticFunctionDefinitions::IsInsideRadarArea ( CClientRadarArea* RadarArea, CVector2D vecPosition, bool& inside )
40654065
{
4066-
if ( RadarArea )
4066+
assert ( RadarArea );
4067+
4068+
CVector2D vecAreaPosition = RadarArea->GetPosition ();
4069+
CVector2D vecAreaSize = RadarArea->GetSize ();
4070+
4071+
inside = false;
4072+
4073+
// Calculate boundaries and make sure they're in ascending order,
4074+
// so it is always safe to start checking from the bottom-left corner
4075+
std::pair<float, float> fHorizontalBounds = std::minmax ( vecAreaPosition.fX, vecAreaPosition.fX + vecAreaSize.fX );
4076+
std::pair<float, float> fVerticalBounds = std::minmax ( vecAreaPosition.fY, vecAreaPosition.fY + vecAreaSize.fY );
4077+
4078+
// Do the calc from the bottom-left corner
4079+
if ( vecPosition.fX >= fHorizontalBounds.first && vecPosition.fX <= fHorizontalBounds.second )
40674080
{
4068-
CVector2D vecRadarPos = RadarArea->GetPosition();
4069-
CVector2D vecRadarSize = RadarArea->GetSize();
4070-
float fMaxX = vecRadarPos.fX + vecRadarSize.fX;
4071-
float fMaxY = vecRadarPos.fY + vecRadarSize.fY;
4072-
if ( vecPosition.fX >= vecRadarPos.fX && vecPosition.fX <= fMaxX )
4081+
if ( vecPosition.fY >= fVerticalBounds.first && vecPosition.fY <= fVerticalBounds.second )
40734082
{
4074-
if ( vecPosition.fY >= vecRadarPos.fY && vecPosition.fY <= fMaxY )
4075-
{
4076-
inside = true;
4077-
}
4083+
inside = true;
40784084
}
4079-
return true;
40804085
}
4081-
return false;
4086+
4087+
return true;
40824088
}
40834089

40844090

Client/mods/deathmatch/logic/luadefs/CLuaRadarAreaDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void CLuaRadarAreaDefs::AddClass ( lua_State* luaVM )
4949

5050
int CLuaRadarAreaDefs::CreateRadarArea ( lua_State* luaVM )
5151
{
52-
// radararea createRadarArea ( float leftX, float bottomY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] )
52+
// radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] )
5353
CVector2D vecPosition; CVector2D vecSize; float dRed; float dGreen; float dBlue; float dAlpha;
5454

5555
CScriptArgReader argStream ( luaVM );
@@ -146,7 +146,7 @@ int CLuaRadarAreaDefs::GetRadarAreaSize ( lua_State* luaVM )
146146

147147
int CLuaRadarAreaDefs::OOP_GetRadarAreaSize ( lua_State* luaVM )
148148
{
149-
// float, float getRadarAreaSize ( radararea theRadararea )
149+
// vector2 getRadarAreaSize ( radararea theRadararea )
150150
CClientRadarArea* pRadarArea;
151151

152152
CScriptArgReader argStream ( luaVM );

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8399,19 +8399,25 @@ bool CStaticFunctionDefinitions::IsInsideRadarArea ( CRadarArea* pRadarArea, con
83998399
{
84008400
assert ( pRadarArea );
84018401

8402-
CVector vecTemp = pRadarArea->GetPosition ();
8403-
CVector2D vecSize = pRadarArea->GetSize ();
8404-
// Remove this line if the position of radar areas isnt in the center
8405-
//vecTemp -= ( CVector ( vecSize.fX, vecSize.fY, 0.0f ) * CVector ( 0.5f, 0.5f, 0.5f ) );
8402+
CVector vecAreaPosition = pRadarArea->GetPosition ();
8403+
CVector2D vecAreaSize = pRadarArea->GetSize ();
8404+
84068405
bInside = false;
8407-
// Do the calc from the bottom left
8408-
if ( vecPosition.fX >= vecTemp.fX && vecPosition.fX <= ( vecTemp.fX + vecSize.fX ) )
8406+
8407+
// Calculate boundaries and make sure they're in ascending order,
8408+
// so it is always safe to start checking from the bottom-left corner
8409+
std::pair<float, float> fHorizontalBounds = std::minmax ( vecAreaPosition.fX, vecAreaPosition.fX + vecAreaSize.fX );
8410+
std::pair<float, float> fVerticalBounds = std::minmax ( vecAreaPosition.fY, vecAreaPosition.fY + vecAreaSize.fY );
8411+
8412+
// Do the calc from the bottom-left corner
8413+
if ( vecPosition.fX >= fHorizontalBounds.first && vecPosition.fX <= fHorizontalBounds.second )
84098414
{
8410-
if ( vecPosition.fY >= vecTemp.fY && vecPosition.fY <= ( vecTemp.fY + vecSize.fY ) )
8415+
if ( vecPosition.fY >= fVerticalBounds.first && vecPosition.fY <= fVerticalBounds.second )
84118416
{
84128417
bInside = true;
84138418
}
84148419
}
8420+
84158421
return true;
84168422
}
84178423

Server/mods/deathmatch/logic/luadefs/CLuaRadarAreaDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void CLuaRadarAreaDefs::AddClass ( lua_State* luaVM )
5353

5454
int CLuaRadarAreaDefs::CreateRadarArea ( lua_State* luaVM )
5555
{
56-
// radararea createRadarArea ( float leftX, float bottomY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] )
56+
// radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = getRootElement() ] )
5757
CVector2D vecPosition; CVector2D vecSize; float dRed; float dGreen; float dBlue; float dAlpha; CElement* pVisibleTo;
5858

5959
CScriptArgReader argStream ( luaVM );
@@ -122,7 +122,7 @@ int CLuaRadarAreaDefs::GetRadarAreaSize ( lua_State* luaVM )
122122

123123
int CLuaRadarAreaDefs::OOP_GetRadarAreaSize ( lua_State* luaVM )
124124
{
125-
// float, float getRadarAreaSize ( radararea theRadararea )
125+
// vector2 getRadarAreaSize ( radararea theRadararea )
126126
CRadarArea* pRadarArea;
127127

128128
CScriptArgReader argStream ( luaVM );

0 commit comments

Comments
 (0)