From 01f0d5cfca1a94b2381712d7d670d2539da830c4 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 19 Dec 2017 16:04:46 -0600 Subject: [PATCH] tAlgorythm fed namespace T3D for better library interoperability. resulted in the need to specify usage in... a few places. --- Engine/source/T3D/decal/decalDataFile.cpp | 2 +- Engine/source/T3D/fx/windEmitter.cpp | 2 +- Engine/source/collision/clippedPolyList.cpp | 4 +- Engine/source/console/simObjectList.cpp | 10 +-- Engine/source/console/simSet.h | 4 +- Engine/source/core/tAlgorithm.h | 69 ++++++++++--------- Engine/source/forest/forestDataFile.cpp | 4 +- Engine/source/forest/forestWindMgr.cpp | 4 +- Engine/source/gui/editor/guiEditCtrl.cpp | 2 +- Engine/source/materials/processedMaterial.cpp | 2 +- Engine/source/math/mIntersector.h | 2 +- Engine/source/math/mPlaneSet.h | 2 +- Engine/source/math/mathUtils.cpp | 2 +- Engine/source/postFx/postEffectManager.cpp | 8 +-- Engine/source/scene/sceneContainer.cpp | 4 +- Engine/source/sfx/sfxController.cpp | 2 +- Engine/source/sfx/sfxDevice.cpp | 4 +- Engine/source/sfx/sfxSystem.cpp | 6 +- Engine/source/terrain/terrCellMaterial.cpp | 4 +- Engine/source/ts/tsLastDetail.cpp | 2 +- 20 files changed, 70 insertions(+), 69 deletions(-) diff --git a/Engine/source/T3D/decal/decalDataFile.cpp b/Engine/source/T3D/decal/decalDataFile.cpp index 002184c16..6dc321a4a 100644 --- a/Engine/source/T3D/decal/decalDataFile.cpp +++ b/Engine/source/T3D/decal/decalDataFile.cpp @@ -131,7 +131,7 @@ bool DecalDataFile::write( Stream& stream ) { DecalInstance *inst = allDecals[i]; - dataIter = find( allDatablocks.begin(), allDatablocks.end(), inst->mDataBlock ); + dataIter = T3D::find( allDatablocks.begin(), allDatablocks.end(), inst->mDataBlock ); U8 dataIndex = dataIter - allDatablocks.begin(); stream.write( dataIndex ); diff --git a/Engine/source/T3D/fx/windEmitter.cpp b/Engine/source/T3D/fx/windEmitter.cpp index 719ecb905..a484be4be 100644 --- a/Engine/source/T3D/fx/windEmitter.cpp +++ b/Engine/source/T3D/fx/windEmitter.cpp @@ -47,7 +47,7 @@ WindEmitter::WindEmitter() WindEmitter::~WindEmitter() { - WindEmitterList::iterator iter = find( smAllEmitters.begin(), smAllEmitters.end(), this ); + WindEmitterList::iterator iter = T3D::find( smAllEmitters.begin(), smAllEmitters.end(), this ); smAllEmitters.erase( iter ); } diff --git a/Engine/source/collision/clippedPolyList.cpp b/Engine/source/collision/clippedPolyList.cpp index 5fd665d87..3eee28a09 100644 --- a/Engine/source/collision/clippedPolyList.cpp +++ b/Engine/source/collision/clippedPolyList.cpp @@ -330,7 +330,7 @@ void ClippedPolyList::cullUnusedVerts() for ( vIter = mVertexList.begin(); vIter != mVertexList.end(); vIter++, i++ ) { // Is this vertex used? - iNextIter = find( mIndexList.begin(), mIndexList.end(), i ); + iNextIter = T3D::find( mIndexList.begin(), mIndexList.end(), i ); if ( iNextIter != mIndexList.end() ) continue; @@ -346,7 +346,7 @@ void ClippedPolyList::cullUnusedVerts() for ( nextVIter = vIter + 1; nextVIter != mVertexList.end(); nextVIter++, n++ ) { - iNextIter = find( mIndexList.begin(), mIndexList.end(), n ); + iNextIter = T3D::find( mIndexList.begin(), mIndexList.end(), n ); // If we found a used vertex // grab its index for later use diff --git a/Engine/source/console/simObjectList.cpp b/Engine/source/console/simObjectList.cpp index 3dec06767..8388f6e9d 100644 --- a/Engine/source/console/simObjectList.cpp +++ b/Engine/source/console/simObjectList.cpp @@ -33,7 +33,7 @@ String SimObjectList::smSortScriptCallbackFn; bool SimObjectList::pushBack(SimObject* obj) { - if (find(begin(),end(),obj) == end()) + if (T3D::find(begin(),end(),obj) == end()) { push_back(obj); return true; @@ -44,7 +44,7 @@ bool SimObjectList::pushBack(SimObject* obj) bool SimObjectList::pushBackForce(SimObject* obj) { - iterator itr = find(begin(),end(),obj); + iterator itr = T3D::find(begin(),end(),obj); if (itr == end()) { push_back(obj); @@ -64,7 +64,7 @@ bool SimObjectList::pushBackForce(SimObject* obj) bool SimObjectList::pushFront(SimObject* obj) { - if (find(begin(),end(),obj) == end()) + if (T3D::find(begin(),end(),obj) == end()) { push_front(obj); return true; @@ -75,7 +75,7 @@ bool SimObjectList::pushFront(SimObject* obj) bool SimObjectList::remove(SimObject* obj) { - iterator ptr = find(begin(),end(),obj); + iterator ptr = T3D::find(begin(),end(),obj); if (ptr != end()) { erase(ptr); @@ -87,7 +87,7 @@ bool SimObjectList::remove(SimObject* obj) bool SimObjectList::removeStable(SimObject* obj) { - iterator ptr = find(begin(),end(),obj); + iterator ptr = T3D::find(begin(),end(),obj); if (ptr != end()) { erase(ptr); diff --git a/Engine/source/console/simSet.h b/Engine/source/console/simSet.h index 9712e7945..4bb6e9300 100644 --- a/Engine/source/console/simSet.h +++ b/Engine/source/console/simSet.h @@ -154,9 +154,9 @@ class SimSet : public SimObject, public TamlChildren value operator[] (S32 index) { return objectList[U32(index)]; } inline iterator find( iterator first, iterator last, SimObject *obj) - { return ::find(first, last, obj); } + { return T3D::find(first, last, obj); } inline iterator find(SimObject *obj) - { return ::find(begin(), end(), obj); } + { return T3D::find(begin(), end(), obj); } /// Reorder the position of "obj" to either be the last object in the list or, if /// "target" is given, to come before "target" in the list of children. diff --git a/Engine/source/core/tAlgorithm.h b/Engine/source/core/tAlgorithm.h index 2c5b6d25f..defe6171f 100644 --- a/Engine/source/core/tAlgorithm.h +++ b/Engine/source/core/tAlgorithm.h @@ -23,40 +23,41 @@ #ifndef _TALGORITHM_H_ #define _TALGORITHM_H_ - -/// Finds the first matching value within the container -/// returning the the element or last if its not found. -template -Iterator find(Iterator first, Iterator last, Value value) +namespace T3D { - while (first != last && *first != value) - ++first; - return first; + /// Finds the first matching value within the container + /// returning the the element or last if its not found. + template + Iterator find(Iterator first, Iterator last, Value value) + { + while (first != last && *first != value) + ++first; + return first; + } + + /// Exchanges the values of the two elements. + template + inline void swap(T &left, T &right) + { + T temp = right; + right = left; + left = temp; + } + + /// Steps thru the elements of an array calling detete for each. + template + void for_each(Iterator first, Iterator last, Functor func) + { + for (; first != last; first++) + func(*first); + } + + /// Functor for deleting a pointer. + /// @see for_each + struct delete_pointer + { + template + void operator()(T *ptr) { delete ptr; } + }; } - -/// Exchanges the values of the two elements. -template -inline void swap( T &left, T &right ) -{ - T temp = right; - right = left; - left = temp; -} - -/// Steps thru the elements of an array calling detete for each. -template -void for_each( Iterator first, Iterator last, Functor func ) -{ - for ( ; first != last; first++ ) - func( *first ); -} - -/// Functor for deleting a pointer. -/// @see for_each -struct delete_pointer -{ - template - void operator()(T *ptr){ delete ptr;} -}; - #endif //_TALGORITHM_H_ diff --git a/Engine/source/forest/forestDataFile.cpp b/Engine/source/forest/forestDataFile.cpp index a50fc2b81..b9a708df7 100644 --- a/Engine/source/forest/forestDataFile.cpp +++ b/Engine/source/forest/forestDataFile.cpp @@ -213,7 +213,7 @@ bool ForestData::write( const char *path ) Vector::const_iterator iter = items.begin(); for ( ; iter != items.end(); iter++ ) { - U8 dataIndex = find( allDatablocks.begin(), allDatablocks.end(), iter->getData() ) - allDatablocks.begin(); + U8 dataIndex = T3D::find( allDatablocks.begin(), allDatablocks.end(), iter->getData() ) - allDatablocks.begin(); stream.write( dataIndex ); @@ -770,7 +770,7 @@ U32 ForestData::getDatablocks( Vector *outVector ) const { ForestItemData *data = item->getData(); - if ( find( outVector->begin(), outVector->end(), data ) != outVector->end() ) + if (T3D::find( outVector->begin(), outVector->end(), data ) != outVector->end() ) continue; count++; diff --git a/Engine/source/forest/forestWindMgr.cpp b/Engine/source/forest/forestWindMgr.cpp index 6db8a03bf..e61e41c83 100644 --- a/Engine/source/forest/forestWindMgr.cpp +++ b/Engine/source/forest/forestWindMgr.cpp @@ -85,7 +85,7 @@ void ForestWindMgr::addEmitter( ForestWindEmitter *emitter ) void ForestWindMgr::removeEmitter( ForestWindEmitter *emitter ) { - ForestWindEmitterList::iterator iter = find( mEmitters.begin(), + ForestWindEmitterList::iterator iter = T3D::find( mEmitters.begin(), mEmitters.end(), emitter ); @@ -161,7 +161,7 @@ void ForestWindMgr::processTick() PROFILE_SCOPE( ForestWindMgr_AdvanceTime_SwapSources ); AssertFatal( mPrevSources->isEmpty(), "prev sources not empty!" ); - swap( mSources, mPrevSources ); + T3D::swap( mSources, mPrevSources ); AssertFatal( mSources->isEmpty(), "swap failed!" ); } diff --git a/Engine/source/gui/editor/guiEditCtrl.cpp b/Engine/source/gui/editor/guiEditCtrl.cpp index 09644d990..0abd6589b 100644 --- a/Engine/source/gui/editor/guiEditCtrl.cpp +++ b/Engine/source/gui/editor/guiEditCtrl.cpp @@ -1015,7 +1015,7 @@ void GuiEditCtrl::removeSelection( GuiControl* ctrl ) { if( selectionContains( ctrl ) ) { - Vector< GuiControl* >::iterator i = ::find( mSelectedControls.begin(), mSelectedControls.end(), ctrl ); + Vector< GuiControl* >::iterator i = T3D::find( mSelectedControls.begin(), mSelectedControls.end(), ctrl ); if ( i != mSelectedControls.end() ) mSelectedControls.erase( i ); diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 1622d50e6..d910d6245 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -103,7 +103,7 @@ ProcessedMaterial::ProcessedMaterial() ProcessedMaterial::~ProcessedMaterial() { - for_each( mPasses.begin(), mPasses.end(), delete_pointer() ); + T3D::for_each( mPasses.begin(), mPasses.end(), T3D::delete_pointer() ); } void ProcessedMaterial::_setBlendState(Material::BlendOp blendOp, GFXStateBlockDesc& desc ) diff --git a/Engine/source/math/mIntersector.h b/Engine/source/math/mIntersector.h index e667e1715..32d8a3d6f 100644 --- a/Engine/source/math/mIntersector.h +++ b/Engine/source/math/mIntersector.h @@ -228,7 +228,7 @@ void PolyhedronBoxIntersector< Polyhedron >::_preprocess( const MatrixF& objToWo Point2F p = _project( i, v2 ); // Second point on line. if( frontFace != 0 ) - swap( p, q ); + T3D::swap( p, q ); Point2F normal( - ( p.y - q.y ), p.x - q.x ); normal.normalize(); diff --git a/Engine/source/math/mPlaneSet.h b/Engine/source/math/mPlaneSet.h index 8d0a919bb..511c7bd92 100644 --- a/Engine/source/math/mPlaneSet.h +++ b/Engine/source/math/mPlaneSet.h @@ -441,7 +441,7 @@ U32 PlaneSet< T >::clipPolygon( const Point3F* inVertices, U32 inNumVertices, Po // Make the output of the last iteration the // input of this iteration. - swap( tempPolygon, clippedPolygon ); + T3D::swap( tempPolygon, clippedPolygon ); numTempPolygonVertices = numClippedPolygonVertices; if( maxOutVertices < numTempPolygonVertices + 1 ) diff --git a/Engine/source/math/mathUtils.cpp b/Engine/source/math/mathUtils.cpp index dfc418deb..745338e10 100644 --- a/Engine/source/math/mathUtils.cpp +++ b/Engine/source/math/mathUtils.cpp @@ -1706,7 +1706,7 @@ bool clipFrustumByPolygon( const Point3F* points, U32 numPoints, const RectI& vi // Make the output of the last iteration the // input of this iteration. - swap( tempPolygon, clippedPolygon ); + T3D::swap( tempPolygon, clippedPolygon ); numTempPolygonVertices = numClippedPolygonVertices; // Clip our current remainder of the original polygon diff --git a/Engine/source/postFx/postEffectManager.cpp b/Engine/source/postFx/postEffectManager.cpp index 4316cfc33..dc37723bb 100644 --- a/Engine/source/postFx/postEffectManager.cpp +++ b/Engine/source/postFx/postEffectManager.cpp @@ -198,7 +198,7 @@ bool PostEffectManager::_addEffect( PostEffect *effect ) bool PostEffectManager::_removeEffect( PostEffect *effect ) { // Check the end of frame list. - EffectVector::iterator iter = find( mEndOfFrameList.begin(), mEndOfFrameList.end(), effect ); + EffectVector::iterator iter = T3D::find( mEndOfFrameList.begin(), mEndOfFrameList.end(), effect ); if ( iter != mEndOfFrameList.end() ) { mEndOfFrameList.erase( iter ); @@ -206,7 +206,7 @@ bool PostEffectManager::_removeEffect( PostEffect *effect ) } // Check the diffuse list. - iter = find( mAfterDiffuseList.begin(), mAfterDiffuseList.end(), effect ); + iter = T3D::find( mAfterDiffuseList.begin(), mAfterDiffuseList.end(), effect ); if ( iter != mAfterDiffuseList.end() ) { mAfterDiffuseList.erase( iter ); @@ -218,7 +218,7 @@ bool PostEffectManager::_removeEffect( PostEffect *effect ) for( ; mapIter != mAfterBinMap.end(); mapIter++ ) { EffectVector &effects = mapIter->value; - iter = find( effects.begin(), effects.end(), effect ); + iter = T3D::find( effects.begin(), effects.end(), effect ); if ( iter != effects.end() ) { effects.erase( iter ); @@ -230,7 +230,7 @@ bool PostEffectManager::_removeEffect( PostEffect *effect ) for( ; mapIter != mBeforeBinMap.end(); mapIter++ ) { EffectVector &effects = mapIter->value; - iter = find( effects.begin(), effects.end(), effect ); + iter = T3D::find( effects.begin(), effects.end(), effect ); if ( iter != effects.end() ) { effects.erase( iter ); diff --git a/Engine/source/scene/sceneContainer.cpp b/Engine/source/scene/sceneContainer.cpp index 6f6202414..a561f45e3 100644 --- a/Engine/source/scene/sceneContainer.cpp +++ b/Engine/source/scene/sceneContainer.cpp @@ -183,7 +183,7 @@ bool SceneContainer::removeObject(SceneObject* obj) // Remove water and physical zone types from the special vector. if ( obj->getTypeMask() & ( WaterObjectType | PhysicalZoneObjectType ) ) { - Vector::iterator iter = find( mWaterAndZones.begin(), mWaterAndZones.end(), obj ); + Vector::iterator iter = T3D::find( mWaterAndZones.begin(), mWaterAndZones.end(), obj ); if( iter != mTerrains.end() ) mWaterAndZones.erase_fast(iter); } @@ -191,7 +191,7 @@ bool SceneContainer::removeObject(SceneObject* obj) // Remove terrain objects from special vector. if( obj->getTypeMask() & TerrainObjectType ) { - Vector< SceneObject* >::iterator iter = find( mTerrains.begin(), mTerrains.end(), obj ); + Vector< SceneObject* >::iterator iter = T3D::find( mTerrains.begin(), mTerrains.end(), obj ); if( iter != mTerrains.end() ) mTerrains.erase_fast(iter); } diff --git a/Engine/source/sfx/sfxController.cpp b/Engine/source/sfx/sfxController.cpp index f5f17dfb6..2d9592eef 100644 --- a/Engine/source/sfx/sfxController.cpp +++ b/Engine/source/sfx/sfxController.cpp @@ -142,7 +142,7 @@ void SFXController::_compileList( SFXPlayList* playList ) { // Randomly exchange slots in the list. for( U32 i = 0; i < SFXPlayList::NUM_SLOTS; ++ i ) - swap( slotList[ gRandGen.randI( 0, SFXPlayList::NUM_SLOTS - 1 ) ], slotList[ i ] ); + T3D::swap( slotList[ gRandGen.randI( 0, SFXPlayList::NUM_SLOTS - 1 ) ], slotList[ i ] ); } break; diff --git a/Engine/source/sfx/sfxDevice.cpp b/Engine/source/sfx/sfxDevice.cpp index 3bb37f68f..1d2f7cf30 100644 --- a/Engine/source/sfx/sfxDevice.cpp +++ b/Engine/source/sfx/sfxDevice.cpp @@ -165,7 +165,7 @@ void SFXDevice::_removeBuffer( SFXBuffer* buffer ) { AssertFatal( buffer, "SFXDevice::_removeBuffer() - Got a null buffer!" ); - BufferIterator iter = find( mBuffers.begin(), mBuffers.end(), buffer ); + BufferIterator iter = T3D::find( mBuffers.begin(), mBuffers.end(), buffer ); if( iter != mBuffers.end() ) { SFXBuffer* buffer = *iter; @@ -201,7 +201,7 @@ void SFXDevice::_removeVoice( SFXVoice* voice ) { AssertFatal( voice, "SFXDevice::_removeVoice() - Got null voice!" ); - VoiceIterator iter = find( mVoices.begin(), mVoices.end(), voice ); + VoiceIterator iter = T3D::find( mVoices.begin(), mVoices.end(), voice ); if( iter != mVoices.end() ) { mStatNumVoices --; diff --git a/Engine/source/sfx/sfxSystem.cpp b/Engine/source/sfx/sfxSystem.cpp index 0ad80df6e..b02d4fc67 100644 --- a/Engine/source/sfx/sfxSystem.cpp +++ b/Engine/source/sfx/sfxSystem.cpp @@ -647,7 +647,7 @@ void SFXSystem::deleteWhenStopped( SFXSource* source ) // If the source isn't already on the play-once source list, // put it there now. - Vector< SFXSource* >::iterator iter = find( mPlayOnceSources.begin(), mPlayOnceSources.end(), source ); + Vector< SFXSource* >::iterator iter = T3D::find( mPlayOnceSources.begin(), mPlayOnceSources.end(), source ); if( iter == mPlayOnceSources.end() ) mPlayOnceSources.push_back( source ); } @@ -674,7 +674,7 @@ void SFXSystem::_onRemoveSource( SFXSource* source ) { // Check if it was a play once source. - Vector< SFXSource* >::iterator iter = find( mPlayOnceSources.begin(), mPlayOnceSources.end(), source ); + Vector< SFXSource* >::iterator iter = T3D::find( mPlayOnceSources.begin(), mPlayOnceSources.end(), source ); if ( iter != mPlayOnceSources.end() ) mPlayOnceSources.erase_fast( iter ); @@ -684,7 +684,7 @@ void SFXSystem::_onRemoveSource( SFXSource* source ) if( dynamic_cast< SFXSound* >( source ) ) { - SFXSoundVector::iterator iter = find( mSounds.begin(), mSounds.end(), static_cast< SFXSound* >( source ) ); + SFXSoundVector::iterator iter = T3D::find( mSounds.begin(), mSounds.end(), static_cast< SFXSound* >( source ) ); if( iter != mSounds.end() ) mSounds.erase_fast( iter ); diff --git a/Engine/source/terrain/terrCellMaterial.cpp b/Engine/source/terrain/terrCellMaterial.cpp index cd1f123d0..de0be345e 100644 --- a/Engine/source/terrain/terrCellMaterial.cpp +++ b/Engine/source/terrain/terrCellMaterial.cpp @@ -289,7 +289,7 @@ void TerrainCellMaterial::init( TerrainBlock *block, // The pass failed to be generated... give up. mPasses.last().materials.clear(); mPasses.clear(); - for_each( materials.begin(), materials.end(), delete_pointer() ); + T3D::for_each( materials.begin(), materials.end(), T3D::delete_pointer() ); return; } @@ -298,7 +298,7 @@ void TerrainCellMaterial::init( TerrainBlock *block, } // Cleanup any remaining matinfo. - for_each( materials.begin(), materials.end(), delete_pointer() ); + T3D::for_each( materials.begin(), materials.end(), T3D::delete_pointer() ); // If we have attached mats then update them too. if ( mDeferredMat ) diff --git a/Engine/source/ts/tsLastDetail.cpp b/Engine/source/ts/tsLastDetail.cpp index 863e79f3f..9619903b0 100644 --- a/Engine/source/ts/tsLastDetail.cpp +++ b/Engine/source/ts/tsLastDetail.cpp @@ -101,7 +101,7 @@ TSLastDetail::~TSLastDetail() mMaterial->deleteObject(); // Remove ourselves from the list. - Vector::iterator iter = find( smLastDetails.begin(), smLastDetails.end(), this ); + Vector::iterator iter = T3D::find( smLastDetails.begin(), smLastDetails.end(), this ); smLastDetails.erase( iter ); }