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;
return nullptr;
}
RwFrameForAllChildren( frame, *this );
RwFrameForAllChildren( frame, std::forward<GetFramePredicate>(*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)

View file

@ -4,18 +4,18 @@
#include <rpworld.h>
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 )
{
if ( std::forward<Pred>(callback)(curFrame) == nullptr )
break;
}
return frame;
return std::forward<Pred>(callback);
}
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) )
{
@ -23,27 +23,27 @@ RwFrame* RwFrameForAllObjects(RwFrame* frame, Pred&& callback)
break;
}
return frame;
return std::forward<Pred>(callback);
}
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) )
{
if ( std::forward<Pred>(callback)(rwLLLinkGetData(link, RpAtomic, inClumpLink)) == nullptr )
break;
}
return clump;
return std::forward<Pred>(callback);
}
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++ )
{
if ( std::forward<Pred>(callback)(geometry->matList.materials[i]) == nullptr )
break;
}
return geometry;
return std::forward<Pred>(callback);
}