From dfb46efa887ab7323331c7aafa8a2fdf528d0c9e Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 6 Jan 2018 15:48:47 +0100 Subject: [PATCH] Return predicate instead of meaningless pointer in rwpred functions --- SilentPatchSA/VehicleSA.cpp | 8 +++----- SilentPatchSA/rwpred.hpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 6cc84b9..01ce4d7 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -73,17 +73,15 @@ static RwFrame* GetFrameFromName( RwFrame* topFrame, const char* name ) foundFrame = frame; return nullptr; } - RwFrameForAllChildren( frame, *this ); + RwFrameForAllChildren( frame, std::forward(*this) ); return foundFrame != nullptr ? nullptr : frame; } private: const char* const m_name; }; - - GetFramePredicate p( name ); - RwFrameForAllChildren( topFrame, p ); - return p.foundFrame; +; + return RwFrameForAllChildren( topFrame, GetFramePredicate(name) ).foundFrame; } void ReadRotorFixExceptions(const wchar_t* pPath) diff --git a/SilentPatchSA/rwpred.hpp b/SilentPatchSA/rwpred.hpp index a1e4745..7df9d2a 100644 --- a/SilentPatchSA/rwpred.hpp +++ b/SilentPatchSA/rwpred.hpp @@ -4,18 +4,18 @@ #include template -RwFrame* RwFrameForAllChildren(RwFrame* frame, Pred&& callback) +Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback) { for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next ) { if ( std::forward(callback)(curFrame) == nullptr ) break; } - return frame; + return std::forward(callback); } template -RwFrame* RwFrameForAllObjects(RwFrame* frame, Pred&& callback) +Pred RwFrameForAllObjects(RwFrame* frame, Pred&& callback) { for ( RwLLLink* link = rwLinkListGetFirstLLLink(&frame->objectList); link != rwLinkListGetTerminator(&frame->objectList); link = rwLLLinkGetNext(link) ) { @@ -23,27 +23,27 @@ RwFrame* RwFrameForAllObjects(RwFrame* frame, Pred&& callback) break; } - return frame; + return std::forward(callback); } template -RpClump* RpClumpForAllAtomics(RpClump* clump, Pred&& callback) +Pred RpClumpForAllAtomics(RpClump* clump, Pred&& callback) { for ( RwLLLink* link = rwLinkListGetFirstLLLink(&clump->atomicList); link != rwLinkListGetTerminator(&clump->atomicList); link = rwLLLinkGetNext(link) ) { if ( std::forward(callback)(rwLLLinkGetData(link, RpAtomic, inClumpLink)) == nullptr ) break; } - return clump; + return std::forward(callback); } template -RpGeometry* RpGeometryForAllMaterials(RpGeometry* geometry, Pred&& callback) +Pred RpGeometryForAllMaterials(RpGeometry* geometry, Pred&& callback) { for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ ) { if ( std::forward(callback)(geometry->matList.materials[i]) == nullptr ) break; } - return geometry; + return std::forward(callback); } \ No newline at end of file