Return predicate instead of meaningless pointer in rwpred functions

This commit is contained in:
Silent 2018-01-06 15:48:47 +01:00
parent 47cd773c46
commit dfb46efa88
2 changed files with 11 additions and 13 deletions

View file

@ -73,17 +73,15 @@ static RwFrame* GetFrameFromName( RwFrame* topFrame, const char* name )
foundFrame = frame; foundFrame = frame;
return nullptr; return nullptr;
} }
RwFrameForAllChildren( frame, *this ); RwFrameForAllChildren( frame, std::forward<GetFramePredicate>(*this) );
return foundFrame != nullptr ? nullptr : frame; return foundFrame != nullptr ? nullptr : frame;
} }
private: private:
const char* const m_name; const char* const m_name;
}; };
;
GetFramePredicate p( name ); return RwFrameForAllChildren( topFrame, GetFramePredicate(name) ).foundFrame;
RwFrameForAllChildren( topFrame, p );
return p.foundFrame;
} }
void ReadRotorFixExceptions(const wchar_t* pPath) void ReadRotorFixExceptions(const wchar_t* pPath)

View file

@ -4,18 +4,18 @@
#include <rpworld.h> #include <rpworld.h>
template <typename Pred> template <typename Pred>
RwFrame* RwFrameForAllChildren(RwFrame* frame, Pred&& callback) Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback)
{ {
for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next ) for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next )
{ {
if ( std::forward<Pred>(callback)(curFrame) == nullptr ) if ( std::forward<Pred>(callback)(curFrame) == nullptr )
break; break;
} }
return frame; return std::forward<Pred>(callback);
} }
template <typename Pred> template <typename Pred>
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) ) for ( RwLLLink* link = rwLinkListGetFirstLLLink(&frame->objectList); link != rwLinkListGetTerminator(&frame->objectList); link = rwLLLinkGetNext(link) )
{ {
@ -23,27 +23,27 @@ RwFrame* RwFrameForAllObjects(RwFrame* frame, Pred&& callback)
break; break;
} }
return frame; return std::forward<Pred>(callback);
} }
template <typename Pred> template <typename Pred>
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) ) for ( RwLLLink* link = rwLinkListGetFirstLLLink(&clump->atomicList); link != rwLinkListGetTerminator(&clump->atomicList); link = rwLLLinkGetNext(link) )
{ {
if ( std::forward<Pred>(callback)(rwLLLinkGetData(link, RpAtomic, inClumpLink)) == nullptr ) if ( std::forward<Pred>(callback)(rwLLLinkGetData(link, RpAtomic, inClumpLink)) == nullptr )
break; break;
} }
return clump; return std::forward<Pred>(callback);
} }
template <typename Pred> template <typename Pred>
RpGeometry* RpGeometryForAllMaterials(RpGeometry* geometry, Pred&& callback) Pred RpGeometryForAllMaterials(RpGeometry* geometry, Pred&& callback)
{ {
for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ ) for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ )
{ {
if ( std::forward<Pred>(callback)(geometry->matList.materials[i]) == nullptr ) if ( std::forward<Pred>(callback)(geometry->matList.materials[i]) == nullptr )
break; break;
} }
return geometry; return std::forward<Pred>(callback);
} }