Skip to content

Commit 058ba77

Browse files
committed
Remove a couple of superfluous checks
`new X()` will raise an exception if memory allocation fails This means it will never return nullptr Therefore these checks are unnecessary
1 parent 51d8717 commit 058ba77

File tree

2 files changed

+52
-72
lines changed

2 files changed

+52
-72
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,27 +3547,21 @@ void CClientGame::Event_OnIngame(void)
35473547

35483548
// Create a local player for us
35493549
m_pLocalPlayer = new CClientPlayer(m_pManager, m_LocalID, true);
3550-
if (m_pLocalPlayer)
3551-
{
3552-
// Set our parent the root entity
3553-
m_pLocalPlayer->SetParent(m_pRootEntity);
35543550

3555-
// Give the local player our nickname
3556-
m_pLocalPlayer->SetNick(m_strLocalNick);
3551+
// Set our parent the root entity
3552+
m_pLocalPlayer->SetParent(m_pRootEntity);
35573553

3558-
// Freeze the player at some location we won't see
3559-
m_pLocalPlayer->SetHealth(100);
3560-
m_pLocalPlayer->SetPosition(CVector(0, 0, 0));
3561-
m_pLocalPlayer->SetFrozen(true);
3562-
m_pLocalPlayer->ResetInterpolation();
3554+
// Give the local player our nickname
3555+
m_pLocalPlayer->SetNick(m_strLocalNick);
35633556

3564-
// Reset him
3565-
m_pLocalPlayer->ResetStats();
3566-
}
3567-
else
3568-
{
3569-
RaiseFatalError(2);
3570-
}
3557+
// Freeze the player at some location we won't see
3558+
m_pLocalPlayer->SetHealth(100);
3559+
m_pLocalPlayer->SetPosition(CVector(0, 0, 0));
3560+
m_pLocalPlayer->SetFrozen(true);
3561+
m_pLocalPlayer->ResetInterpolation();
3562+
3563+
// Reset him
3564+
m_pLocalPlayer->ResetStats();
35713565

35723566
// Make sure we never get tired
35733567
g_pGame->GetPlayerInfo()->SetDoesNotGetTired(true);

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,20 +2661,18 @@ CClientVehicle* CStaticFunctionDefinitions::CreateVehicle(CResource& Resource, u
26612661
CClientVehicleManager::GetRandomVariation(usModel, ucVariation, ucVariation2);
26622662

26632663
CClientVehicle* pVehicle = new CDeathmatchVehicle(m_pManager, NULL, INVALID_ELEMENT_ID, usModel, ucVariation, ucVariation2);
2664-
if (pVehicle)
2665-
{
2666-
pVehicle->SetParent(Resource.GetResourceDynamicEntity());
2667-
pVehicle->SetPosition(vecPosition);
26682664

2669-
pVehicle->SetRotationDegrees(vecRotation);
2670-
if (szRegPlate)
2671-
pVehicle->SetRegPlate(szRegPlate);
2665+
pVehicle->SetParent(Resource.GetResourceDynamicEntity());
2666+
pVehicle->SetPosition(vecPosition);
26722667

2673-
return pVehicle;
2674-
}
2668+
pVehicle->SetRotationDegrees(vecRotation);
2669+
if (szRegPlate)
2670+
pVehicle->SetRegPlate(szRegPlate);
2671+
2672+
return pVehicle;
26752673
}
26762674

2677-
return NULL;
2675+
return nullptr;
26782676
}
26792677

26802678
bool CStaticFunctionDefinitions::FixVehicle(CClientEntity& Entity)
@@ -3738,17 +3736,15 @@ CClientObject* CStaticFunctionDefinitions::CreateObject(CResource& Resource, uns
37383736
#else
37393737
CClientObject* pObject = new CDeathmatchObject(m_pManager, m_pMovingObjectsManager, INVALID_ELEMENT_ID, usModelID, bLowLod);
37403738
#endif
3741-
if (pObject)
3742-
{
3743-
pObject->SetParent(Resource.GetResourceDynamicEntity());
3744-
pObject->SetPosition(vecPosition);
3745-
pObject->SetRotationDegrees(vecRotation);
37463739

3747-
return pObject;
3748-
}
3740+
pObject->SetParent(Resource.GetResourceDynamicEntity());
3741+
pObject->SetPosition(vecPosition);
3742+
pObject->SetRotationDegrees(vecRotation);
3743+
3744+
return pObject;
37493745
}
37503746

3751-
return NULL;
3747+
return nullptr;
37523748
}
37533749

37543750
bool CStaticFunctionDefinitions::GetObjectScale(CClientObject& Object, CVector& vecScale)
@@ -3969,17 +3965,13 @@ CClientRadarArea* CStaticFunctionDefinitions::CreateRadarArea(CResource& Resourc
39693965
{
39703966
// Create it
39713967
CClientRadarArea* pRadarArea = new CClientRadarArea(m_pManager, INVALID_ELEMENT_ID);
3972-
if (pRadarArea)
3973-
{
3974-
pRadarArea->SetParent(Resource.GetResourceDynamicEntity());
3975-
pRadarArea->SetPosition(vecPosition2D);
3976-
pRadarArea->SetSize(vecSize);
3977-
pRadarArea->SetColor(color);
39783968

3979-
return pRadarArea;
3980-
}
3969+
pRadarArea->SetParent(Resource.GetResourceDynamicEntity());
3970+
pRadarArea->SetPosition(vecPosition2D);
3971+
pRadarArea->SetSize(vecSize);
3972+
pRadarArea->SetColor(color);
39813973

3982-
return NULL;
3974+
return pRadarArea;
39833975
}
39843976

39853977
bool CStaticFunctionDefinitions::GetRadarAreaColor(CClientRadarArea* RadarArea, SColor& outColor)
@@ -4321,14 +4313,13 @@ CClientRadarMarker* CStaticFunctionDefinitions::CreateBlip(CResource& Resource,
43214313
if (CClientRadarMarkerManager::IsValidIcon(ucIcon) && ucSize <= 25)
43224314
{
43234315
CClientRadarMarker* pBlip = new CClientRadarMarker(m_pManager, INVALID_ELEMENT_ID, sOrdering, usVisibleDistance);
4324-
if (pBlip)
4325-
{
4326-
pBlip->SetParent(Resource.GetResourceDynamicEntity());
4327-
pBlip->SetPosition(vecPosition);
4328-
pBlip->SetSprite(ucIcon);
4329-
pBlip->SetScale(ucSize);
4330-
pBlip->SetColor(color);
4331-
}
4316+
4317+
pBlip->SetParent(Resource.GetResourceDynamicEntity());
4318+
pBlip->SetPosition(vecPosition);
4319+
pBlip->SetSprite(ucIcon);
4320+
pBlip->SetScale(ucSize);
4321+
pBlip->SetColor(color);
4322+
43324323
return pBlip;
43334324
}
43344325

@@ -4343,14 +4334,13 @@ CClientRadarMarker* CStaticFunctionDefinitions::CreateBlipAttachedTo(CResource&
43434334
if (CClientRadarMarkerManager::IsValidIcon(ucIcon) && ucSize <= 25)
43444335
{
43454336
CClientRadarMarker* pBlip = new CClientRadarMarker(m_pManager, INVALID_ELEMENT_ID, sOrdering, usVisibleDistance);
4346-
if (pBlip)
4347-
{
4348-
pBlip->SetParent(Resource.GetResourceDynamicEntity());
4349-
pBlip->AttachTo(&Entity);
4350-
pBlip->SetSprite(ucIcon);
4351-
pBlip->SetScale(ucSize);
4352-
pBlip->SetColor(color);
4353-
}
4337+
4338+
pBlip->SetParent(Resource.GetResourceDynamicEntity());
4339+
pBlip->AttachTo(&Entity);
4340+
pBlip->SetSprite(ucIcon);
4341+
pBlip->SetScale(ucSize);
4342+
pBlip->SetColor(color);
4343+
43544344
return pBlip;
43554345
}
43564346

@@ -9395,19 +9385,15 @@ CClientPointLights* CStaticFunctionDefinitions::CreateLight(CResource& Resource,
93959385
{
93969386
// Create it
93979387
CClientPointLights* pLight = new CClientPointLights(m_pManager, INVALID_ELEMENT_ID);
9398-
if (pLight)
9399-
{
9400-
pLight->SetParent(Resource.GetResourceDynamicEntity());
9401-
pLight->SetMode(iMode);
9402-
pLight->SetPosition(vecPosition);
9403-
pLight->SetRadius(fRadius);
9404-
pLight->SetColor(color);
9405-
pLight->SetDirection(vecDirection);
94069388

9407-
return pLight;
9408-
}
9389+
pLight->SetParent(Resource.GetResourceDynamicEntity());
9390+
pLight->SetMode(iMode);
9391+
pLight->SetPosition(vecPosition);
9392+
pLight->SetRadius(fRadius);
9393+
pLight->SetColor(color);
9394+
pLight->SetDirection(vecDirection);
94099395

9410-
return NULL;
9396+
return pLight;
94119397
}
94129398

94139399
bool CStaticFunctionDefinitions::GetLightType(CClientPointLights* pLight, int& iMode)

0 commit comments

Comments
 (0)