Skip to content
Permalink
Browse files

Fix signed/unsigned mismatch warnings introduced in #1215 (#1287)

* Fix warnings introduced in #1215

* Change to else if
  • Loading branch information
StrixG committed Mar 12, 2020
1 parent 3dbed31 commit 250053af107fdf3fae64a2ca8d95834e5f132480
@@ -69,28 +69,20 @@ void CClientColPolygon::SetPosition(const CVector& vecPosition)
// Add queued collider refresh for v1.1
}

bool CClientColPolygon::AddPoint(CVector2D vecPoint, int iPointIndex)
bool CClientColPolygon::AddPoint(CVector2D vecPoint)
{
if (iPointIndex < 0)
{
m_Points.push_back(vecPoint);
}
else
{
if (iPointIndex >= m_Points.size())
return false;

m_Points.insert(m_Points.begin() + iPointIndex, vecPoint);
}
m_Points.push_back(vecPoint);
CalculateRadius(vecPoint);
return true;
}

CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();
bool CClientColPolygon::AddPoint(CVector2D vecPoint, unsigned int uiPointIndex)
{
if (uiPointIndex > m_Points.size())
return false;

if (fDistance > m_fRadius)
{
m_fRadius = fDistance;
SizeChanged();
}
m_Points.insert(m_Points.begin() + uiPointIndex, vecPoint);
CalculateRadius(vecPoint);

return true;
}
@@ -105,18 +97,7 @@ bool CClientColPolygon::RemovePoint(unsigned int uiPointIndex)

m_Points.erase(m_Points.begin() + uiPointIndex);

m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
m_fRadius = fDistance;
}

SizeChanged();

CalculateRadius();
return true;
}

@@ -127,6 +108,12 @@ bool CClientColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVecto

m_Points[uiPointIndex] = vecPoint;

CalculateRadius();
return true;
}

void CClientColPolygon::CalculateRadius()
{
m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
@@ -138,8 +125,18 @@ bool CClientColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVecto
}

SizeChanged();
}

return true;
void CClientColPolygon::CalculateRadius(const CVector2D& vecPoint)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
{
m_fRadius = fDistance;
SizeChanged();
}
}

bool CClientColPolygon::IsInBounds(CVector vecPoint)
@@ -26,7 +26,8 @@ class CClientColPolygon : public CClientColShape

void SetPosition(const CVector& vecPosition);

bool AddPoint(CVector2D vecPoint, int iPointIndex = -1);
bool AddPoint(CVector2D vecPoint);
bool AddPoint(CVector2D vecPoint, unsigned int uiPointIndex);
bool SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint);
bool RemovePoint(unsigned int uiPointIndex);

@@ -38,6 +39,8 @@ class CClientColPolygon : public CClientColShape
std::vector<CVector2D> m_Points;

bool IsInBounds(CVector vecPoint);
void CalculateRadius();
void CalculateRadius(const CVector2D& vecPoint);

float m_fRadius;
};
@@ -7313,9 +7313,20 @@ bool CStaticFunctionDefinitions::SetColPolygonPointPosition(CClientColPolygon* p
return false;
}

bool CStaticFunctionDefinitions::AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint)
bool CStaticFunctionDefinitions::AddColPolygonPoint(CClientColPolygon* pColPolygon, const CVector2D& vecPoint)
{
if (pColPolygon->AddPoint(vecPoint, iPointIndex))
if (pColPolygon->AddPoint(vecPoint))
{
RefreshColShapeColliders(pColPolygon);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::AddColPolygonPoint(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint)
{
if (pColPolygon->AddPoint(vecPoint, uiPointIndex))
{
RefreshColShapeColliders(pColPolygon);
return true;
@@ -674,8 +674,9 @@ class CStaticFunctionDefinitions
static bool SetColShapeSize(CClientColShape* pColShape, CVector& vecSize);
static bool SetColPolygonPointPosition(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);

static bool AddColPolygonPoint(CClientColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint);
static bool RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint iPointIndex);
static bool AddColPolygonPoint(CClientColPolygon* pColPolygon, const CVector2D& vecPoint);
static bool AddColPolygonPoint(CClientColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);
static bool RemoveColPolygonPoint(CClientColPolygon* pColPolygon, uint uiPointIndex);

// Weapon funcs
static bool GetWeaponNameFromID(unsigned char ucID, SString& strOutName);
@@ -632,21 +632,25 @@ int CLuaColShapeDefs::SetColPolygonPointPosition(lua_State* luaVM)
int CLuaColShapeDefs::AddColPolygonPoint(lua_State* luaVM)
{
CClientColShape* pColShape;
int iPointIndex;
uint uiPointIndex;
CVector2D vecPoint;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pColShape);
argStream.ReadVector2D(vecPoint);
argStream.ReadNumber(iPointIndex, 0);
argStream.ReadNumber(uiPointIndex, 0);

if (argStream.HasErrors())
return luaL_error(luaVM, argStream.GetFullErrorMessage());

if (pColShape->GetShapeType() == COLSHAPE_POLYGON)
{
CClientColPolygon* pColPolygon = static_cast<CClientColPolygon*>(pColShape);
if (CStaticFunctionDefinitions::AddColPolygonPoint(pColPolygon, iPointIndex - 1, vecPoint))
if (uiPointIndex == 0)
{
lua_pushboolean(luaVM, CStaticFunctionDefinitions::AddColPolygonPoint(pColPolygon, vecPoint));
}
else if (CStaticFunctionDefinitions::AddColPolygonPoint(pColPolygon, uiPointIndex - 1, vecPoint))
{
lua_pushboolean(luaVM, true);
}
@@ -23,7 +23,7 @@ void CColShapeRPCs::LoadFunctions(void)

void CColShapeRPCs::SetColShapeRadius(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
float fRadius;
float fRadius;
if (bitStream.Read(fRadius))
{
CClientColShape* pColShape = static_cast<CClientColShape*>(pSource);
@@ -33,7 +33,7 @@ void CColShapeRPCs::SetColShapeRadius(CClientEntity* pSource, NetBitStreamInterf

void CColShapeRPCs::SetColShapeSize(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
CVector vecSize;
CVector vecSize;
if (bitStream.ReadVector(vecSize.fX, vecSize.fY, vecSize.fZ))
{
CClientColShape* pColShape = static_cast<CClientColShape*>(pSource);
@@ -55,17 +55,24 @@ void CColShapeRPCs::UpdateColPolygonPoint(CClientEntity* pSource, NetBitStreamIn
void CColShapeRPCs::AddColPolygonPoint(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
SPosition2DSync size(false);
int iPointIndex;
if (bitStream.Read(&size) && bitStream.Read(iPointIndex))
unsigned int uiPointIndex;
if (bitStream.Read(&size))
{
CClientColPolygon* pColShape = static_cast<CClientColPolygon*>(pSource);
CStaticFunctionDefinitions::AddColPolygonPoint(pColShape, iPointIndex, size.data.vecPosition);
if (bitStream.Read(uiPointIndex))
{
CStaticFunctionDefinitions::AddColPolygonPoint(pColShape, uiPointIndex, size.data.vecPosition);
}
else
{
CStaticFunctionDefinitions::AddColPolygonPoint(pColShape, size.data.vecPosition);
}
}
}

void CColShapeRPCs::RemoveColPolygonPoint(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
unsigned int uiPointIndex;
unsigned int uiPointIndex;
if (bitStream.Read(uiPointIndex))
{
CClientColPolygon* pColShape = static_cast<CClientColPolygon*>(pSource);
@@ -85,28 +85,20 @@ void CColPolygon::SetPosition(const CVector& vecPosition)
// Add queued collider refresh for v1.1
}

bool CColPolygon::AddPoint(CVector2D vecPoint, int iPointIndex)
bool CColPolygon::AddPoint(CVector2D vecPoint)
{
if (iPointIndex < 0)
{
m_Points.push_back(vecPoint);
}
else
{
if (iPointIndex >= m_Points.size())
return false;

m_Points.insert(m_Points.begin() + iPointIndex, vecPoint);
}
m_Points.push_back(vecPoint);
CalculateRadius(vecPoint);
return true;
}

CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();
bool CColPolygon::AddPoint(CVector2D vecPoint, unsigned int uiPointIndex)
{
if (uiPointIndex > m_Points.size())
return false;

if (fDistance > m_fRadius)
{
m_fRadius = fDistance;
SizeChanged();
}
m_Points.insert(m_Points.begin() + uiPointIndex, vecPoint);
CalculateRadius(vecPoint);

return true;
}
@@ -118,28 +110,23 @@ bool CColPolygon::RemovePoint(unsigned int uiPointIndex)

m_Points.erase(m_Points.begin() + uiPointIndex);

m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
m_fRadius = fDistance;
}

SizeChanged();

CalculateRadius();
return true;
}

bool CColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint)
{
if (uiPointIndex >= m_Points.size())
return false;

m_Points[uiPointIndex] = vecPoint;

CalculateRadius();
return true;
}

void CColPolygon::CalculateRadius()
{
m_fRadius = 0.0f;
for (auto vecPoint : m_Points)
{
@@ -151,8 +138,18 @@ bool CColPolygon::SetPointPosition(unsigned int uiPointIndex, const CVector2D& v
}

SizeChanged();
}

return true;
void CColPolygon::CalculateRadius(const CVector2D& vecPoint)
{
CVector2D vecDistance = vecPoint - m_vecPosition;
float fDistance = vecDistance.Length();

if (fDistance > m_fRadius)
{
m_fRadius = fDistance;
SizeChanged();
}
}

bool CColPolygon::IsInBounds(CVector vecPoint)
@@ -29,7 +29,8 @@ class CColPolygon : public CColShape

void SetPosition(const CVector& vecPosition);

bool AddPoint(CVector2D vecPoint, int iPointIndex = -1);
bool AddPoint(CVector2D vecPoint);
bool AddPoint(CVector2D vecPoint, unsigned int uiPointIndex);
bool SetPointPosition(unsigned int uiPointIndex, const CVector2D& vecPoint);
bool RemovePoint(unsigned int uiPointIndex);

@@ -43,6 +44,8 @@ class CColPolygon : public CColShape
bool ReadSpecialData(const int iLine) override;

bool IsInBounds(CVector vecPoint);
void CalculateRadius();
void CalculateRadius(const CVector2D& vecPoint);

float m_fRadius;
};
@@ -9449,17 +9449,34 @@ bool CStaticFunctionDefinitions::SetColPolygonPointPosition(CColPolygon* pColPol
return false;
}

bool CStaticFunctionDefinitions::AddColPolygonPoint(CColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint)
bool CStaticFunctionDefinitions::AddColPolygonPoint(CColPolygon* pColPolygon, const CVector2D& vecPoint)
{
if (pColPolygon->AddPoint(vecPoint, iPointIndex))
if (pColPolygon->AddPoint(vecPoint))
{
RefreshColShapeColliders(pColPolygon);

CBitStream BitStream;
SPosition2DSync size(false);
size.data.vecPosition = vecPoint;
BitStream.pBitStream->Write(&size);
BitStream.pBitStream->Write(iPointIndex);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pColPolygon, ADD_COLPOLYGON_POINT, *BitStream.pBitStream));
return true;
}

return false;
}

bool CStaticFunctionDefinitions::AddColPolygonPoint(CColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint)
{
if (pColPolygon->AddPoint(vecPoint, uiPointIndex))
{
RefreshColShapeColliders(pColPolygon);

CBitStream BitStream;
SPosition2DSync size(false);
size.data.vecPosition = vecPoint;
BitStream.pBitStream->Write(&size);
BitStream.pBitStream->Write(uiPointIndex);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pColPolygon, ADD_COLPOLYGON_POINT, *BitStream.pBitStream));
return true;
}
@@ -463,8 +463,9 @@ class CStaticFunctionDefinitions
static bool SetColShapeSize(CColShape* pColShape, CVector& vecSize);
static bool SetColPolygonPointPosition(CColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);

static bool AddColPolygonPoint(CColPolygon* pColPolygon, int iPointIndex, const CVector2D& vecPoint);
static bool RemoveColPolygonPoint(CColPolygon* pColPolygon, uint iPointIndex);
static bool AddColPolygonPoint(CColPolygon* pColPolygon, const CVector2D& vecPoint);
static bool AddColPolygonPoint(CColPolygon* pColPolygon, uint uiPointIndex, const CVector2D& vecPoint);
static bool RemoveColPolygonPoint(CColPolygon* pColPolygon, uint uiPointIndex);

// Weapon funcs
static CCustomWeapon* CreateWeapon(CResource* pResource, eWeaponType weaponType, CVector vecPosition);

0 comments on commit 250053a

Please sign in to comment.
You can’t perform that action at this time.