diff --git a/Sources/Engine/Base/Anim.cpp b/Sources/Engine/Base/Anim.cpp index e491e12..10d04e8 100644 --- a/Sources/Engine/Base/Anim.cpp +++ b/Sources/Engine/Base/Anim.cpp @@ -173,16 +173,14 @@ BOOL CAnimData::IsAutoFreed(void) // Reference counting functions void CAnimData::AddReference(void) { - if (this!=NULL) { - MarkUsed(); - } + ASSERT(this!=NULL); + MarkUsed(); } void CAnimData::RemReference(void) { - if (this!=NULL) { - RemReference_internal(); - } + ASSERT(this!=NULL); + RemReference_internal(); } void CAnimData::RemReference_internal(void) diff --git a/Sources/Engine/Base/Console.cpp b/Sources/Engine/Base/Console.cpp index 208fa49..a8d613a 100644 --- a/Sources/Engine/Base/Console.cpp +++ b/Sources/Engine/Base/Console.cpp @@ -44,9 +44,7 @@ CConsole::CConsole(void) // Destructor. CConsole::~CConsole(void) { - if (this==NULL) { - return; - } + ASSERT(this!=NULL); if (con_fLog!=NULL) { fclose(con_fLog); con_fLog = NULL; @@ -102,25 +100,19 @@ void CConsole::Initialize(const CTFileName &fnmLog, INDEX ctCharsPerLine, INDEX // Get current console buffer. const char *CConsole::GetBuffer(void) { - if (this==NULL) { - return ""; - } + ASSERT(this!=NULL); return con_strBuffer+(con_ctLines-con_ctLinesPrinted)*(con_ctCharsPerLine+1); } INDEX CConsole::GetBufferSize(void) { - if (this==NULL) { - return 1; - } + ASSERT(this!=NULL); return (con_ctCharsPerLine+1)*con_ctLines+1; } // Discard timing info for last lines void CConsole::DiscardLastLineTimes(void) { - if (this==NULL) { - return; - } + ASSERT(this!=NULL); for(INDEX i=0; i=con_ctLinesPrinted) { return ""; } @@ -166,9 +154,7 @@ CTString CConsole::GetLastLine(INDEX iLine) // clear one given line in buffer void CConsole::ClearLine(INDEX iLine) { - if (this==NULL) { - return; - } + ASSERT(this!=NULL); // line must be valid ASSERT(iLine>=0 && iLine0 && ctLines _aseSentEvents; // delayed events /* Send an event to this entity. */ void CEntity::SendEvent(const CEntityEvent &ee) { - if (this==NULL) { - ASSERT(FALSE); - return; - } + ASSERT(this!=NULL); CSentEvent &se = _aseSentEvents.Push(); se.se_penEntity = this; se.se_peeEvent = ((CEntityEvent&)ee).MakeCopy(); // discard const qualifier diff --git a/Sources/Engine/Entities/Entity.h b/Sources/Engine/Entities/Entity.h index b2bd944..5f98d38 100644 --- a/Sources/Engine/Entities/Entity.h +++ b/Sources/Engine/Entities/Entity.h @@ -694,18 +694,16 @@ inline CEntity& CEntityPointer::operator*(void) const { return *ep_pen; } ///////////////////////////////////////////////////////////////////// // Reference counting functions inline void CEntity::AddReference(void) { - if (this!=NULL) { - ASSERT(en_ctReferences>=0); - en_ctReferences++; - } + ASSERT(this!=NULL); + ASSERT(en_ctReferences>=0); + en_ctReferences++; }; inline void CEntity::RemReference(void) { - if (this!=NULL) { - ASSERT(en_ctReferences>0); - en_ctReferences--; - if(en_ctReferences==0) { - delete this; - } + ASSERT(this!=NULL); + ASSERT(en_ctReferences>0); + en_ctReferences--; + if(en_ctReferences==0) { + delete this; } }; diff --git a/Sources/Engine/Entities/EntityClass.cpp b/Sources/Engine/Entities/EntityClass.cpp index a0e6163..1fb1881 100644 --- a/Sources/Engine/Entities/EntityClass.cpp +++ b/Sources/Engine/Entities/EntityClass.cpp @@ -64,14 +64,12 @@ CEntityClass::~CEntityClass(void) ///////////////////////////////////////////////////////////////////// // Reference counting functions void CEntityClass::AddReference(void) { - if (this!=NULL) { - MarkUsed(); - } + ASSERT(this!=NULL); + MarkUsed(); }; void CEntityClass::RemReference(void) { - if (this!=NULL) { - _pEntityClassStock->Release(this); - } + ASSERT(this!=NULL); + _pEntityClassStock->Release(this); }; /* diff --git a/Sources/Engine/Network/Network.cpp b/Sources/Engine/Network/Network.cpp index e6e2b43..d283a1a 100644 --- a/Sources/Engine/Network/Network.cpp +++ b/Sources/Engine/Network/Network.cpp @@ -655,7 +655,8 @@ extern void FreeUnusedStock(void) */ void CNetworkTimerHandler::HandleTimer(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return; // this can happen during NET_MakeDefaultState_t()! } // enable stream handling during timer @@ -902,7 +903,8 @@ void CNetworkLibrary::Init(const CTString &strGameID) */ void CNetworkLibrary::AddTimerHandler(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return; // this can happen during NET_MakeDefaultState_t()! } _pTimer->AddHandler(&ga_thTimerHandler); @@ -912,7 +914,8 @@ void CNetworkLibrary::AddTimerHandler(void) */ void CNetworkLibrary::RemoveTimerHandler(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return; // this can happen during NET_MakeDefaultState_t()! } _pTimer->RemHandler(&ga_thTimerHandler); @@ -1390,7 +1393,8 @@ void CNetworkLibrary::TogglePause(void) // test if game is paused BOOL CNetworkLibrary::IsPaused(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return TRUE; // this can happen during NET_MakeDefaultState_t()! } return ga_sesSessionState.ses_bPause; @@ -1427,7 +1431,8 @@ void CNetworkLibrary::SetLocalPause(BOOL bPause) BOOL CNetworkLibrary::GetLocalPause(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return TRUE; // this can happen during NET_MakeDefaultState_t()! } return ga_bLocalPause; @@ -2033,7 +2038,8 @@ void CNetworkLibrary::SendActionsToServer(void) */ void CNetworkLibrary::TimerLoop(void) { - if (this==NULL || _bTempNetwork) { + ASSERT(this!=NULL); + if (_bTempNetwork) { return; // this can happen during NET_MakeDefaultState_t()! } _pfNetworkProfile.StartTimer(CNetworkProfile::PTI_TIMERLOOP); diff --git a/Sources/Engine/Sound/SoundData.cpp b/Sources/Engine/Sound/SoundData.cpp index f022ebb..c9852c4 100644 --- a/Sources/Engine/Sound/SoundData.cpp +++ b/Sources/Engine/Sound/SoundData.cpp @@ -252,16 +252,14 @@ SLONG CSoundData::GetUsedMemory(void) // Add one reference void CSoundData::AddReference(void) { - if (this!=NULL) { - MarkUsed(); - } + ASSERT(this!=NULL); + MarkUsed(); } // Remove one reference void CSoundData::RemReference(void) { - if (this!=NULL) { - _pSoundStock->Release(this); - } + ASSERT(this!=NULL); + _pSoundStock->Release(this); } diff --git a/Sources/Engine/Sound/SoundLibrary.cpp b/Sources/Engine/Sound/SoundLibrary.cpp index f1e4df3..8bf8133 100644 --- a/Sources/Engine/Sound/SoundLibrary.cpp +++ b/Sources/Engine/Sound/SoundLibrary.cpp @@ -1233,6 +1233,7 @@ BOOL CSoundLibrary::SetEnvironment( INDEX iEnvNo, FLOAT fEnvSize/*=0*/) // mute all sounds (erase playing buffer(s) and supress mixer) void CSoundLibrary::Mute(void) { + ASSERT(this!=NULL); // stop all IFeel effects IFeel_StopEffect(NULL); @@ -1244,7 +1245,7 @@ void CSoundLibrary::Mute(void) #ifdef PLATFORM_WIN32 // erase direct sound buffer (waveout will shut-up by itself), but skip if there's no more sound library - if( this==NULL || !sl_bUsingDirectSound) return; + if(!sl_bUsingDirectSound) return; // synchronize access to sounds CTSingleLock slSounds(&sl_csSound, TRUE); diff --git a/Sources/Engine/World/World.cpp b/Sources/Engine/World/World.cpp index bff7b76..405904c 100644 --- a/Sources/Engine/World/World.cpp +++ b/Sources/Engine/World/World.cpp @@ -936,10 +936,11 @@ void CWorld::TriangularizeForVertices( CBrushVertexSelection &selVertex) // add this entity to prediction void CEntity::AddToPrediction(void) { - // this function may be called even for NULLs - so ignore it - if (this==NULL) { - return; - } + // this function may be called even for NULLs - TODO: fix those cases + // (The compiler is free to assume that "this" is never NULL and optimize + // based on that assumption. For example, an "if (this==NULL) {...}" could + // be optimized away completely.) + ASSERT(this!=NULL); // if already added if (en_ulFlags&ENF_WILLBEPREDICTED) { // do nothing diff --git a/Sources/Entities/Common/PathFinding.cpp b/Sources/Entities/Common/PathFinding.cpp index e4099b2..91742a6 100644 --- a/Sources/Entities/Common/PathFinding.cpp +++ b/Sources/Entities/Common/PathFinding.cpp @@ -35,8 +35,9 @@ CPathNode::~CPathNode(void) // get name of this node const CTString &CPathNode::GetName(void) { + ASSERT(this!=NULL); static CTString strNone=""; - if (this==NULL || pn_pnmMarker==NULL) { + if (pn_pnmMarker==NULL) { return strNone; } else { return pn_pnmMarker->GetName(); @@ -46,7 +47,8 @@ const CTString &CPathNode::GetName(void) // get link with given index or null if no more (for iteration along the graph) CPathNode *CPathNode::GetLink(INDEX i) { - if (this==NULL || pn_pnmMarker==NULL) { + ASSERT(this!=NULL); + if (pn_pnmMarker==NULL) { ASSERT(FALSE); return NULL; } diff --git a/Sources/EntitiesMP/Common/PathFinding.cpp b/Sources/EntitiesMP/Common/PathFinding.cpp index 54a68f0..3504155 100644 --- a/Sources/EntitiesMP/Common/PathFinding.cpp +++ b/Sources/EntitiesMP/Common/PathFinding.cpp @@ -50,8 +50,9 @@ CPathNode::~CPathNode(void) // get name of this node const CTString &CPathNode::GetName(void) { + ASSERT(this!=NULL); static CTString strNone=""; - if (this==NULL || pn_pnmMarker==NULL) { + if (pn_pnmMarker==NULL) { return strNone; } else { return pn_pnmMarker->GetName(); @@ -61,10 +62,7 @@ const CTString &CPathNode::GetName(void) // get link with given index or null if no more (for iteration along the graph) CPathNode *CPathNode::GetLink(INDEX i) { - if (this==NULL || pn_pnmMarker==NULL) { - ASSERT(FALSE); - return NULL; - } + ASSERT(this!=NULL && pn_pnmMarker!=NULL); CNavigationMarker *pnm = pn_pnmMarker->GetLink(i); if (pnm==NULL) { return NULL; diff --git a/Sources/Modeler/DlgPgInfoAttachingPlacement.cpp b/Sources/Modeler/DlgPgInfoAttachingPlacement.cpp index 3d9b0df..8fbd8a2 100644 --- a/Sources/Modeler/DlgPgInfoAttachingPlacement.cpp +++ b/Sources/Modeler/DlgPgInfoAttachingPlacement.cpp @@ -69,7 +69,7 @@ INDEX CDlgPgInfoAttachingPlacement::GetCurrentAttachingPlacement(void) void CDlgPgInfoAttachingPlacement::SetPlacementReferenceVertex(INDEX iCenter, INDEX iFront, INDEX iUp) { // patch for calling before page is refreshed - if(this == NULL) return; + ASSERT(this!=NULL); CModelerView *pModelerView = CModelerView::GetActiveView(); if(pModelerView == NULL) return; CModelerDoc* pDoc = pModelerView->GetDocument();