From fe23b05aa22d3164d6f6388436258d67df7cf3f9 Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sat, 23 Apr 2016 04:05:17 +0300 Subject: [PATCH 1/7] Fix ASSERT() That would never trigger the ASSERT. Now they always do. Conflicts: Sources/EntitiesMP/Summoner.es --- Sources/Engine/Base/Assert.h | 2 +- Sources/EntitiesMP/Common/Particles.cpp | 2 +- Sources/EntitiesMP/Grunt.es | 2 +- Sources/EntitiesMP/GruntSka.es | 2 +- Sources/EntitiesMP/PlayerWeapons.es | 2 +- Sources/EntitiesMP/Summoner.es | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Engine/Base/Assert.h b/Sources/Engine/Base/Assert.h index 80f4aa34c..c1b45de77 100644 --- a/Sources/Engine/Base/Assert.h +++ b/Sources/Engine/Base/Assert.h @@ -83,7 +83,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define BREAKPOINT \ if (1) { \ SAFEBREAKPOINT; \ - _assert("hard-coded breakpoint (CroTeam)",__FILE__,__LINE__); \ + _assert(false && "hard-coded breakpoint (CroTeam)",__FILE__,__LINE__); \ } else NOTHING /* CT DEBUG macro -- the expression is executed only in debug version */ diff --git a/Sources/EntitiesMP/Common/Particles.cpp b/Sources/EntitiesMP/Common/Particles.cpp index c369d050f..73980c128 100755 --- a/Sources/EntitiesMP/Common/Particles.cpp +++ b/Sources/EntitiesMP/Common/Particles.cpp @@ -527,7 +527,7 @@ void Particles_ViewerLocal(CEntity *penView) break; default: - ASSERT("Unknown environment particle type!"); + ASSERT(false && "Unknown environment particle type!"); break; } // for those EPHs that are not rendered, clear possible diff --git a/Sources/EntitiesMP/Grunt.es b/Sources/EntitiesMP/Grunt.es index 5a7c84ed3..e2acee1f1 100644 --- a/Sources/EntitiesMP/Grunt.es +++ b/Sources/EntitiesMP/Grunt.es @@ -99,7 +99,7 @@ functions: } else if (m_gtType==GT_COMMANDER) { return &eiGruntSoldier; } else { - ASSERT("Unknown grunt type!"); + ASSERT(false && "Unknown grunt type!"); return NULL; } }; diff --git a/Sources/EntitiesMP/GruntSka.es b/Sources/EntitiesMP/GruntSka.es index 880cafd6f..021ff35b3 100644 --- a/Sources/EntitiesMP/GruntSka.es +++ b/Sources/EntitiesMP/GruntSka.es @@ -280,7 +280,7 @@ functions: } else if (m_gtType==GT_COMMANDER) { return &eiGruntSoldier; } else { - ASSERT("Unknown grunt type!"); + ASSERT(false && "Unknown grunt type!"); return NULL; } }; diff --git a/Sources/EntitiesMP/PlayerWeapons.es b/Sources/EntitiesMP/PlayerWeapons.es index d98a9dee4..49693d2a6 100755 --- a/Sources/EntitiesMP/PlayerWeapons.es +++ b/Sources/EntitiesMP/PlayerWeapons.es @@ -3442,7 +3442,7 @@ functions: return (WeaponType)i; } } - ASSERT("Non-existant weapon in remap array!"); + ASSERT(false && "Non-existant weapon in remap array!"); return (WeaponType)0; } diff --git a/Sources/EntitiesMP/Summoner.es b/Sources/EntitiesMP/Summoner.es index 1c5469c65..22e61818d 100755 --- a/Sources/EntitiesMP/Summoner.es +++ b/Sources/EntitiesMP/Summoner.es @@ -618,7 +618,7 @@ functions: pen = &m_penGroup03Template01; iCount = IRnd()%m_iGroup03Count+1; } else { - ASSERT("Invalid group!"); + ASSERT(false && "Invalid group!"); iCount = 0; // DG: this should have a deterministic value in case this happens after all! } ASSERT(iCount>0); From 24d61d1cccac8c9b8e0b37781bda630a65f5f803 Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sat, 23 Apr 2016 23:32:03 +0300 Subject: [PATCH 2/7] Use ASSERTALWAYS(msg) instead of ASSERT(false && msg) Thanks @SLAwww (The first parameter to _assert is actually the message, not the expression to evaluate, so "false &&" doesn't belong in there.) Conflicts: Sources/EntitiesMP/Summoner.es --- Sources/Engine/Base/Assert.h | 2 +- Sources/EntitiesMP/Common/Particles.cpp | 2 +- Sources/EntitiesMP/Grunt.es | 2 +- Sources/EntitiesMP/GruntSka.es | 2 +- Sources/EntitiesMP/PlayerWeapons.es | 2 +- Sources/EntitiesMP/Summoner.es | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Engine/Base/Assert.h b/Sources/Engine/Base/Assert.h index c1b45de77..80f4aa34c 100644 --- a/Sources/Engine/Base/Assert.h +++ b/Sources/Engine/Base/Assert.h @@ -83,7 +83,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define BREAKPOINT \ if (1) { \ SAFEBREAKPOINT; \ - _assert(false && "hard-coded breakpoint (CroTeam)",__FILE__,__LINE__); \ + _assert("hard-coded breakpoint (CroTeam)",__FILE__,__LINE__); \ } else NOTHING /* CT DEBUG macro -- the expression is executed only in debug version */ diff --git a/Sources/EntitiesMP/Common/Particles.cpp b/Sources/EntitiesMP/Common/Particles.cpp index 73980c128..d8ad616d3 100755 --- a/Sources/EntitiesMP/Common/Particles.cpp +++ b/Sources/EntitiesMP/Common/Particles.cpp @@ -527,7 +527,7 @@ void Particles_ViewerLocal(CEntity *penView) break; default: - ASSERT(false && "Unknown environment particle type!"); + ASSERTALWAYS("Unknown environment particle type!"); break; } // for those EPHs that are not rendered, clear possible diff --git a/Sources/EntitiesMP/Grunt.es b/Sources/EntitiesMP/Grunt.es index e2acee1f1..d66015e70 100644 --- a/Sources/EntitiesMP/Grunt.es +++ b/Sources/EntitiesMP/Grunt.es @@ -99,7 +99,7 @@ functions: } else if (m_gtType==GT_COMMANDER) { return &eiGruntSoldier; } else { - ASSERT(false && "Unknown grunt type!"); + ASSERTALWAYS("Unknown grunt type!"); return NULL; } }; diff --git a/Sources/EntitiesMP/GruntSka.es b/Sources/EntitiesMP/GruntSka.es index 021ff35b3..e142d8f45 100644 --- a/Sources/EntitiesMP/GruntSka.es +++ b/Sources/EntitiesMP/GruntSka.es @@ -280,7 +280,7 @@ functions: } else if (m_gtType==GT_COMMANDER) { return &eiGruntSoldier; } else { - ASSERT(false && "Unknown grunt type!"); + ASSERTALWAYS("Unknown grunt type!"); return NULL; } }; diff --git a/Sources/EntitiesMP/PlayerWeapons.es b/Sources/EntitiesMP/PlayerWeapons.es index 49693d2a6..0ebc4eb28 100755 --- a/Sources/EntitiesMP/PlayerWeapons.es +++ b/Sources/EntitiesMP/PlayerWeapons.es @@ -3442,7 +3442,7 @@ functions: return (WeaponType)i; } } - ASSERT(false && "Non-existant weapon in remap array!"); + ASSERTALWAYS("Non-existant weapon in remap array!"); return (WeaponType)0; } diff --git a/Sources/EntitiesMP/Summoner.es b/Sources/EntitiesMP/Summoner.es index 22e61818d..5fa1ae9ab 100755 --- a/Sources/EntitiesMP/Summoner.es +++ b/Sources/EntitiesMP/Summoner.es @@ -618,7 +618,7 @@ functions: pen = &m_penGroup03Template01; iCount = IRnd()%m_iGroup03Count+1; } else { - ASSERT(false && "Invalid group!"); + ASSERTALWAYS("Invalid group!"); iCount = 0; // DG: this should have a deterministic value in case this happens after all! } ASSERT(iCount>0); From 5badefaf900165feb7196ee78343ceb5ba3d3a4a Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sun, 24 Apr 2016 00:17:29 +0300 Subject: [PATCH 3/7] Change remaining "if (this!=NULL)" to "ASSERT(this!=NULL)" Also changed all "if (this==NULL) return;"s. Fixes some -Wtautological-undefined-compare warnings. Quoting Clang: "'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false" --- Sources/Engine/Base/Anim.cpp | 10 ++--- Sources/Engine/Base/Console.cpp | 40 +++++-------------- Sources/Engine/Entities/Entity.cpp | 5 +-- Sources/Engine/Entities/Entity.h | 18 ++++----- Sources/Engine/Entities/EntityClass.cpp | 10 ++--- Sources/Engine/Network/Network.cpp | 18 ++++++--- Sources/Engine/Sound/SoundData.cpp | 10 ++--- Sources/Engine/Sound/SoundLibrary.cpp | 3 +- Sources/Engine/World/World.cpp | 9 +++-- Sources/Entities/Common/PathFinding.cpp | 6 ++- Sources/EntitiesMP/Common/PathFinding.cpp | 8 ++-- .../Modeler/DlgPgInfoAttachingPlacement.cpp | 2 +- 12 files changed, 58 insertions(+), 81 deletions(-) diff --git a/Sources/Engine/Base/Anim.cpp b/Sources/Engine/Base/Anim.cpp index e491e12da..10d04e8f2 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 208fa49a1..a8d613a3f 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 b2bd944d1..5f98d3811 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 a0e6163ce..1fb188104 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 e6e2b43b1..d283a1a30 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 f022ebb54..c9852c4be 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 f1e4df3e3..8bf813305 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 bff7b76fd..405904c24 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 e4099b205..91742a694 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 54a68f066..3504155d4 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 3d9b0dfc7..8fbd8a2ca 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(); From 13ba79ea5f5d496dbc80f16d8ba492e4f9e768f9 Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sun, 24 Apr 2016 01:28:13 +0300 Subject: [PATCH 4/7] Remove unneeded -Wno-sign-compare (I didn't receive any warnings after enabling -Wsign-compare.) Conflicts: Sources/CMakeLists.txt --- Sources/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 83d9fd5ef..5683ced54 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -110,8 +110,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG=1 -D_NDEBUG=1 -Os -fno-unsafe-math-optimizations") # TODO fix these warnings - # !!! FIXME: turn a bunch of these off, this is just for now. I hope. --ryan. - add_compile_options(-Wno-sign-compare) add_compile_options(-Wno-switch) add_compile_options(-Wno-char-subscripts) add_compile_options(-Wno-unknown-pragmas) From 16a2048a2cc6a766b36d1e90f7d8f160563dc140 Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sun, 24 Apr 2016 01:33:27 +0300 Subject: [PATCH 5/7] Fix warning -Wchar-subscripts --- Sources/Engine/Graphics/Font.cpp | 4 ++-- Sources/Engine/Graphics/Font.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Engine/Graphics/Font.cpp b/Sources/Engine/Graphics/Font.cpp index f3fe2c7cf..d5fd8d490 100644 --- a/Sources/Engine/Graphics/Font.cpp +++ b/Sources/Engine/Graphics/Font.cpp @@ -99,7 +99,7 @@ void CFontData::Read_t( CTStream *inFile) // throw char * SetCharSpacing(+1); SetLineSpacing(+1); SetSpaceWidth(0.5f); - fd_fcdFontCharData[' '].fcd_pixStart = 0; + fd_fcdFontCharData[(int)' '].fcd_pixStart = 0; } void CFontData::Write_t( CTStream *outFile) // throw char * @@ -201,7 +201,7 @@ void CFontData::Make_t( const CTFileName &fnTexture, PIX pixCharWidth, PIX pixCh iLetter++; // skip carriage return } // set default space width - fd_fcdFontCharData[' '].fcd_pixStart = 0; + fd_fcdFontCharData[(int)' '].fcd_pixStart = 0; SetSpaceWidth(0.5f); // all done diff --git a/Sources/Engine/Graphics/Font.h b/Sources/Engine/Graphics/Font.h index cacb30710..f5056a5a3 100644 --- a/Sources/Engine/Graphics/Font.h +++ b/Sources/Engine/Graphics/Font.h @@ -71,7 +71,7 @@ class ENGINE_API CFontData : public CSerial { inline void SetFixedWidth(void) { fd_bFixedWidth = TRUE; }; inline void SetVariableWidth(void) { fd_bFixedWidth = FALSE; }; inline void SetSpaceWidth( FLOAT fWidthRatio) { // relative to char cell width (1/2 is default) - fd_fcdFontCharData[' '].fcd_pixEnd = (PIX)(fd_pixCharWidth*fWidthRatio); } + fd_fcdFontCharData[(int)' '].fcd_pixEnd = (PIX)(fd_pixCharWidth*fWidthRatio); } void Read_t( CTStream *inFile); // throw char * void Write_t( CTStream *outFile); // throw char * From 4b0e01145e2d9e394788b4a42e7c48fff3a43217 Mon Sep 17 00:00:00 2001 From: Emil Laine Date: Sun, 24 Apr 2016 00:57:23 +0300 Subject: [PATCH 6/7] Fix warning -Wtautological-undefined-compare Quoting Clang: "reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to false" Conflicts: Sources/CMakeLists.txt --- Sources/CMakeLists.txt | 2 +- Sources/Engine/Brushes/BrushShadows.cpp | 8 ++--- Sources/Engine/Entities/Entity.h | 1 + Sources/Engine/Entities/EntityPointer.h | 1 + Sources/Engine/Light/LayerMixer.cpp | 6 ++-- Sources/Engine/Math/ObjectSector.cpp | 10 +++--- Sources/Engine/Rendering/RenCache.cpp | 14 ++++---- Sources/Engine/World/WorldCSG.cpp | 46 ++++++++++++------------- Sources/EntitiesMP/Summoner.es | 8 ++--- 9 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 5683ced54..ef8aee257 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -121,7 +121,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") MESSAGE(WARNING, "re-enable some of the warnings some day!") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") - add_compile_options(-Wno-tautological-undefined-compare) # don't complain about if(this!=NULL) + # !!! FIXME: turn a bunch of these off, this is just for now. I hope. --ryan. add_compile_options(-Wno-c++11-compat-deprecated-writable-strings) endif() diff --git a/Sources/Engine/Brushes/BrushShadows.cpp b/Sources/Engine/Brushes/BrushShadows.cpp index d0d832f12..8cf91d915 100644 --- a/Sources/Engine/Brushes/BrushShadows.cpp +++ b/Sources/Engine/Brushes/BrushShadows.cpp @@ -562,9 +562,9 @@ void CBrushShadowMap::CheckLayersUpToDate(void) CBrushShadowLayer &bsl = *itbsl; if( bsl.bsl_ulFlags&BSLF_ALLDARK) continue; // light source must be valid + ASSERT( bsl.bsl_plsLightSource!=NULL); + if( bsl.bsl_plsLightSource==NULL) continue; CLightSource &ls = *bsl.bsl_plsLightSource; - ASSERT( &ls!=NULL); - if( &ls==NULL) continue; // if the layer is not up to date if( bsl.bsl_colLastAnim != ls.GetLightColor()) { // invalidate entire shadow map @@ -581,9 +581,9 @@ BOOL CBrushShadowMap::HasDynamicLayers(void) // for each layer FOREACHINLIST( CBrushShadowLayer, bsl_lnInShadowMap, bsm_lhLayers, itbsl) { // light source must be valid + ASSERT( itbsl->bsl_plsLightSource!=NULL); + if( itbsl->bsl_plsLightSource==NULL) continue; CLightSource &ls = *itbsl->bsl_plsLightSource; - ASSERT( &ls!=NULL); - if( &ls==NULL) continue; // if the layer is dynamic, it has if( ls.ls_ulFlags&LSF_DYNAMIC) return TRUE; } diff --git a/Sources/Engine/Entities/Entity.h b/Sources/Engine/Entities/Entity.h index 5f98d3811..57d174d7a 100644 --- a/Sources/Engine/Entities/Entity.h +++ b/Sources/Engine/Entities/Entity.h @@ -688,6 +688,7 @@ inline const CEntityPointer &CEntityPointer::operator=(const CEntityPointer &pen return *this; } inline CEntity* CEntityPointer::operator->(void) const { return ep_pen; } +inline CEntity* CEntityPointer::get(void) const { return ep_pen; } inline CEntityPointer::operator CEntity*(void) const { return ep_pen; } inline CEntity& CEntityPointer::operator*(void) const { return *ep_pen; } diff --git a/Sources/Engine/Entities/EntityPointer.h b/Sources/Engine/Entities/EntityPointer.h index 349982a05..614387b20 100644 --- a/Sources/Engine/Entities/EntityPointer.h +++ b/Sources/Engine/Entities/EntityPointer.h @@ -35,6 +35,7 @@ class CEntityPointer { inline const CEntityPointer &operator=(CEntity *pen); inline const CEntityPointer &operator=(const CEntityPointer &penOther); inline CEntity* operator->(void) const; + inline CEntity* get(void) const; inline operator CEntity*(void) const; inline CEntity& operator*(void) const; }; diff --git a/Sources/Engine/Light/LayerMixer.cpp b/Sources/Engine/Light/LayerMixer.cpp index 5d8750f68..9b9992de6 100755 --- a/Sources/Engine/Light/LayerMixer.cpp +++ b/Sources/Engine/Light/LayerMixer.cpp @@ -1770,8 +1770,9 @@ void CLayerMixer::MixOneMipmap(CBrushShadowMap *pbsm, INDEX iMipmap) if( lm_pbpoPolygon->bpo_ulFlags&BPOF_HASDIRECTIONALAMBIENT) { {FOREACHINLIST( CBrushShadowLayer, bsl_lnInShadowMap, lm_pbsmShadowMap->bsm_lhLayers, itbsl) { CBrushShadowLayer &bsl = *itbsl; + ASSERT( bsl.bsl_plsLightSource!=NULL); + if( bsl.bsl_plsLightSource==NULL) continue; // safety check CLightSource &ls = *bsl.bsl_plsLightSource; - ASSERT( &ls!=NULL); if( &ls==NULL) continue; // safety check if( !(ls.ls_ulFlags&LSF_DIRECTIONAL)) continue; // skip non-directional layers COLOR col = AdjustColor( ls.GetLightAmbient(), _slShdHueShift, _slShdSaturation); colAmbient = AddColors( colAmbient, col); @@ -1843,8 +1844,9 @@ void CLayerMixer::MixOneMipmap(CBrushShadowMap *pbsm, INDEX iMipmap) {FORDELETELIST( CBrushShadowLayer, bsl_lnInShadowMap, lm_pbsmShadowMap->bsm_lhLayers, itbsl) { CBrushShadowLayer &bsl = *itbsl; + ASSERT( bsl.bsl_plsLightSource!=NULL); + if( bsl.bsl_plsLightSource==NULL) continue; // safety check CLightSource &ls = *bsl.bsl_plsLightSource; - ASSERT( &ls!=NULL); if( &ls==NULL) continue; // safety check // skip if should not be applied if( (bDynamicOnly && !(ls.ls_ulFlags&LSF_NONPERSISTENT)) || (ls.ls_ulFlags & LSF_DYNAMIC)) continue; diff --git a/Sources/Engine/Math/ObjectSector.cpp b/Sources/Engine/Math/ObjectSector.cpp index f02d59b10..960fb635a 100644 --- a/Sources/Engine/Math/ObjectSector.cpp +++ b/Sources/Engine/Math/ObjectSector.cpp @@ -1115,10 +1115,10 @@ void CObjectPolygon::JoinContinuingEdges(CDynamicArray &oedEdges) // for each edge {FOREACHINDYNAMICARRAY(opo_PolygonEdges, CObjectPolygonEdge, itope) { - CObjectEdge &oedThis = *itope->ope_Edge; + CObjectEdge *poedThis = itope->ope_Edge; // if not already marked for removal - if (&oedThis != NULL) { + if (poedThis != NULL) { CObjectVertex *povxStartThis, *povxEndThis; // get start and end vertices itope->GetVertices(povxStartThis, povxEndThis); @@ -1133,12 +1133,12 @@ void CObjectPolygon::JoinContinuingEdges(CDynamicArray &oedEdges) // for each edge {FOREACHINDYNAMICARRAY(opo_PolygonEdges, CObjectPolygonEdge, itope2) { - CObjectEdge &oedOther = *itope2->ope_Edge; + CObjectEdge *poedOther = itope2->ope_Edge; // if not already marked for removal - if (&oedOther != NULL) { + if (poedOther != NULL) { // if the two edges are collinear - if ( CompareEdgeLines(*oedThis.colinear2.oed_pedxLine, *oedOther.colinear2.oed_pedxLine)==0) { + if ( CompareEdgeLines(*poedThis->colinear2.oed_pedxLine, *poedOther->colinear2.oed_pedxLine)==0) { CObjectVertex *povxStartOther, *povxEndOther; // get start and end vertices itope2->GetVertices(povxStartOther, povxEndOther); diff --git a/Sources/Engine/Rendering/RenCache.cpp b/Sources/Engine/Rendering/RenCache.cpp index dfc631d70..3b6fba0a8 100644 --- a/Sources/Engine/Rendering/RenCache.cpp +++ b/Sources/Engine/Rendering/RenCache.cpp @@ -779,23 +779,23 @@ CScreenPolygon *CRenderer::MakeScreenPolygon(CBrushPolygon &bpo) void CRenderer::AddPolygonToScene( CScreenPolygon *pspo) { // if the polygon is not falid or occluder and not selected - CBrushPolygon &bpo = *pspo->spo_pbpoBrushPolygon; - if( &bpo==NULL || ((bpo.bpo_ulFlags&BPOF_OCCLUDER) && (!(bpo.bpo_ulFlags&BPOF_SELECTED) || + CBrushPolygon *pbpo = pspo->spo_pbpoBrushPolygon; + if(pbpo==NULL || ((pbpo->bpo_ulFlags&BPOF_OCCLUDER) && (!(pbpo->bpo_ulFlags&BPOF_SELECTED) || _wrpWorldRenderPrefs.GetSelectionType()!=CWorldRenderPrefs::ST_POLYGONS))) { // do not add it to rendering return; } - CBrushSector &bsc = *bpo.bpo_pbscSector; + CBrushSector &bsc = *pbpo->bpo_pbscSector; ScenePolygon &sppo = pspo->spo_spoScenePolygon; const CViewVertex *pvvx0 = &re_avvxViewVertices[bsc.bsc_ivvx0]; - const INDEX ctVtx = bpo.bpo_apbvxTriangleVertices.Count(); + const INDEX ctVtx = pbpo->bpo_apbvxTriangleVertices.Count(); sppo.spo_iVtx0 = _avtxScene.Count(); GFXVertex3 *pvtx = _avtxScene.Push(ctVtx); // find vertex with nearest Z distance while copying vertices FLOAT fNearestZ = 123456789.0f; for( INDEX i=0; ibpo_apbvxTriangleVertices[i]; const INDEX iVtx = bsc.bsc_abvxVertices.Index(pbvx); const FLOAT3D &v = pvvx0[iVtx].vvx_vView; if( -v(3)bpo_aiTriangleElements.Count(); + sppo.spo_piElements = sppo.spo_ctElements ? &pbpo->bpo_aiTriangleElements[0] : NULL; _sfStats.IncrementCounter(CStatForm::SCI_SCENE_TRIANGLES, sppo.spo_ctElements/3); } diff --git a/Sources/Engine/World/WorldCSG.cpp b/Sources/Engine/World/WorldCSG.cpp index d69e846ad..1732afa36 100644 --- a/Sources/Engine/World/WorldCSG.cpp +++ b/Sources/Engine/World/WorldCSG.cpp @@ -172,15 +172,15 @@ void CWorld::DoCSGOperation( AssureFPT_53(); // get relevant brush mips in each brush - CBrushMip &bmThis = *GetBrushMip(enThis); - CBrushMip &bmOther = *GetBrushMip(enOther); - if (&bmThis==NULL || &bmOther==NULL) { + CBrushMip *pbmThis = GetBrushMip(enThis); + CBrushMip *pbmOther = GetBrushMip(enOther); + if (pbmThis==NULL || pbmOther==NULL) { return; } // get open sector of the other brush to object CBrushSectorSelectionForCSG selbscOtherOpen; - bmOther.SelectOpenSector(selbscOtherOpen); + pbmOther->SelectOpenSector(selbscOtherOpen); CObject3D obOtherOpen; DOUBLEaabbox3D boxOtherOpen; woOther.CopySourceBrushSectorsToObject(enOther, selbscOtherOpen, plOther, @@ -193,7 +193,7 @@ void CWorld::DoCSGOperation( obOtherOpen.TurnPortalsToWalls(); // if there are any sectors in this brush - if (bmThis.bm_abscSectors.Count()>0) { + if (pbmThis->bm_abscSectors.Count()>0) { // move affected part of this brush to an object3d object CObject3D obThis; MoveTargetBrushPartToObject(enThis, boxOtherOpen, obThis); @@ -213,7 +213,7 @@ void CWorld::DoCSGOperation( // get closed sectors of the other brush to object CBrushSectorSelectionForCSG selbscOtherClosed; - bmOther.SelectClosedSectors(selbscOtherClosed); + pbmOther->SelectClosedSectors(selbscOtherClosed); CObject3D obOtherClosed; DOUBLEaabbox3D boxOtherClosed; woOther.CopySourceBrushSectorsToObject(enOther, selbscOtherClosed, plOther, @@ -224,7 +224,7 @@ void CWorld::DoCSGOperation( CObject3D obResult; // if there are any sectors in this brush - if (bmThis.bm_abscSectors.Count()>0) { + if (pbmThis->bm_abscSectors.Count()>0) { // move affected part of this brush to an object3d object CObject3D obThis; MoveTargetBrushPartToObject(enThis, boxOtherClosed, obThis); @@ -304,16 +304,16 @@ void CWorld::CSGRemove(CEntity &enThis, CWorld &woOther, CEntity &enOther, AssureFPT_53(); // get relevant brush mip in other brush - CBrushMip &bmOther = *GetBrushMip(enOther); - if (&bmOther==NULL) { + CBrushMip *pbmOther = GetBrushMip(enOther); + if (pbmOther==NULL) { return; } // if other brush has more than one sector - if (bmOther.bm_abscSectors.Count()>1) { + if (pbmOther->bm_abscSectors.Count()>1) { // join all sectors of the other brush together CBrushSectorSelection selbscOtherAll; - bmOther.SelectAllSectors(selbscOtherAll); + pbmOther->SelectAllSectors(selbscOtherAll); woOther.JoinSectors(selbscOtherAll); } @@ -380,15 +380,15 @@ void CWorld::SplitSectors(CEntity &enThis, CBrushSectorSelection &selbscSectorsT AssureFPT_53(); // get relevant brush mip in this brush - CBrushMip &bmThis = *GetBrushMip(enThis); - if (&bmThis==NULL) { + CBrushMip *pbmThis = GetBrushMip(enThis); + if (pbmThis==NULL) { _pfWorldEditingProfile.StopTimer(CWorldEditingProfile::PTI_CSGTOTAL); return; } // get relevant brush mip in other brush - CBrushMip &bmOther = *GetBrushMip(enOther); - if (&bmOther==NULL) { + CBrushMip *pbmOther = GetBrushMip(enOther); + if (pbmOther==NULL) { _pfWorldEditingProfile.StopTimer(CWorldEditingProfile::PTI_CSGTOTAL); return; } @@ -396,10 +396,10 @@ void CWorld::SplitSectors(CEntity &enThis, CBrushSectorSelection &selbscSectorsT /* Assure that the other brush has only one sector. */ // if other brush has more than one sector - if (bmOther.bm_abscSectors.Count()>1) { + if (pbmOther->bm_abscSectors.Count()>1) { // join all sectors of the other brush together CBrushSectorSelection selbscOtherAll; - bmOther.SelectAllSectors(selbscOtherAll); + pbmOther->SelectAllSectors(selbscOtherAll); woOther.JoinSectors(selbscOtherAll); } @@ -407,7 +407,7 @@ void CWorld::SplitSectors(CEntity &enThis, CBrushSectorSelection &selbscSectorsT // get the sector of the other brush to object CBrushSectorSelectionForCSG selbscOther; - bmOther.SelectAllSectors(selbscOther); + pbmOther->SelectAllSectors(selbscOther); CObject3D obOther; DOUBLEaabbox3D boxOther; woOther.CopySourceBrushSectorsToObject(enOther, selbscOther, plOther, @@ -416,7 +416,7 @@ void CWorld::SplitSectors(CEntity &enThis, CBrushSectorSelection &selbscSectorsT // if the selection is empty if (selbscSectorsToSplit.Count()==0) { // select all sectors near the splitting tool - bmThis.SelectSectorsInRange(selbscSectorsToSplit, DOUBLEtoFLOAT(boxOther)); + pbmThis->SelectSectorsInRange(selbscSectorsToSplit, DOUBLEtoFLOAT(boxOther)); } // for all sectors in the selection FOREACHINDYNAMICCONTAINER(selbscSectorsToSplit, CBrushSector, itbsc) { @@ -426,7 +426,7 @@ void CWorld::SplitSectors(CEntity &enThis, CBrushSectorSelection &selbscSectorsT } // update the bounding boxes of this brush - bmThis.bm_pbrBrush->CalculateBoundingBoxes(); + pbmThis->bm_pbrBrush->CalculateBoundingBoxes(); // find possible shadow layers near affected area FindShadowLayers(DOUBLEtoFLOAT(boxOther)); @@ -574,8 +574,8 @@ void CWorld::SplitPolygons(CEntity &enThis, CBrushPolygonSelection &selbpoPolygo _pfWorldEditingProfile.IncrementAveragingCounter(); // get relevant brush mip in other brush - CBrushMip &bmOther = *GetBrushMip(enOther); - if (&bmOther==NULL) { + CBrushMip *pbmOther = GetBrushMip(enOther); + if (pbmOther==NULL) { _pfWorldEditingProfile.StopTimer(CWorldEditingProfile::PTI_CSGTOTAL); return; } @@ -596,7 +596,7 @@ void CWorld::SplitPolygons(CEntity &enThis, CBrushPolygonSelection &selbpoPolygo // get the sector of the other brush to object CBrushSectorSelectionForCSG selbscOther; - bmOther.SelectAllSectors(selbscOther); + pbmOther->SelectAllSectors(selbscOther); CObject3D obOther; DOUBLEaabbox3D boxOther; woOther.CopySourceBrushSectorsToObject(enOther, selbscOther, plOther, diff --git a/Sources/EntitiesMP/Summoner.es b/Sources/EntitiesMP/Summoner.es index 5fa1ae9ab..02fe1c6ed 100755 --- a/Sources/EntitiesMP/Summoner.es +++ b/Sources/EntitiesMP/Summoner.es @@ -627,7 +627,7 @@ functions: while (iCount>0) { i++; - while (&*pen[i]==NULL) { + while (pen[i].get()==NULL) { i++; } iCount--; @@ -1337,17 +1337,17 @@ procedures: m_iGroup01Count = 0; pen = &m_penGroup01Template01; for (i=0; i Date: Mon, 30 May 2016 01:06:10 +0200 Subject: [PATCH 7/7] Fix compilation from changes for GCC 6.1.1 At least on my system floor() and log10() return double, so the other arguments to Clamp() and ClampDn() didn't match anymore, now being float instead of double. I replaced the calls to log10f() and floorf() to avoid any ambiguities. --- Sources/Entities/Bullet.es | 2 +- Sources/Entities/Player.es | 2 +- Sources/EntitiesMP/Common/Common.cpp | 2 +- Sources/EntitiesMP/Player.es | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Entities/Bullet.es b/Sources/Entities/Bullet.es index 2c7c99039..c245f8d68 100644 --- a/Sources/Entities/Bullet.es +++ b/Sources/Entities/Bullet.es @@ -344,7 +344,7 @@ functions: GetNormalComponent( vDistance/fDistance, vHitNormal, ese.vDirection); FLOAT fLength = ese.vDirection.Length(); fLength = Clamp( fLength*3, 1.0f, 3.0f); - fDistance = Clamp( log10(fDistance), 0.5f, 2.0f); + fDistance = Clamp( log10f(fDistance), 0.5f, 2.0f); ese.vStretch = FLOAT3D( fDistance, fLength*fDistance, 1.0f); SpawnEffect(vHitPoint, ese); } diff --git a/Sources/Entities/Player.es b/Sources/Entities/Player.es index 2a09bff0e..e62c7f38d 100644 --- a/Sources/Entities/Player.es +++ b/Sources/Entities/Player.es @@ -4588,7 +4588,7 @@ void TeleportPlayer(enum WorldLinkType EwltType) TIME tmLevelTime = _pTimer->CurrentTick()-m_tmLevelStarted; m_psLevelStats.ps_tmTime = tmLevelTime; m_psGameStats.ps_tmTime += tmLevelTime; - FLOAT fTimeDelta = ClampDn(floor(m_tmEstTime)-floor(tmLevelTime), 0.0f); + FLOAT fTimeDelta = ClampDn(floorf(m_tmEstTime)-floorf(tmLevelTime), 0.0f); m_iTimeScore = floor(fTimeDelta*100.0f); m_psLevelStats.ps_iScore+=m_iTimeScore; m_psGameStats.ps_iScore+=m_iTimeScore; diff --git a/Sources/EntitiesMP/Common/Common.cpp b/Sources/EntitiesMP/Common/Common.cpp index 75dd98e2e..14d23db60 100755 --- a/Sources/EntitiesMP/Common/Common.cpp +++ b/Sources/EntitiesMP/Common/Common.cpp @@ -386,7 +386,7 @@ void SpawnHitTypeEffect(CEntity *pen, enum BulletHitType bhtType, BOOL bSound, F GetNormalComponent( vDistance/fDistance, vHitNormal, ese.vDirection); FLOAT fLength = ese.vDirection.Length(); fLength = Clamp( fLength*3, 1.0f, 3.0f); - fDistance = Clamp( log10(fDistance), 0.5f, 2.0f); + fDistance = Clamp( log10f(fDistance), 0.5f, 2.0f); ese.vStretch = FLOAT3D( fDistance, fLength*fDistance, 1.0f); try { diff --git a/Sources/EntitiesMP/Player.es b/Sources/EntitiesMP/Player.es index 02067a98c..505a27025 100755 --- a/Sources/EntitiesMP/Player.es +++ b/Sources/EntitiesMP/Player.es @@ -5381,7 +5381,7 @@ functions: TIME tmLevelTime = _pTimer->CurrentTick()-m_tmLevelStarted; m_psLevelStats.ps_tmTime = tmLevelTime; m_psGameStats.ps_tmTime += tmLevelTime; - FLOAT fTimeDelta = ClampDn(floor(m_tmEstTime)-floor(tmLevelTime), 0.0f); + FLOAT fTimeDelta = ClampDn(floorf(m_tmEstTime)-floorf(tmLevelTime), 0.0f); m_iTimeScore = (INDEX) floor(fTimeDelta*100.0f); m_psLevelStats.ps_iScore+=m_iTimeScore; m_psGameStats.ps_iScore+=m_iTimeScore;