2017-03-28 00:17:43 +05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <rwcore.h>
|
|
|
|
#include <rpworld.h>
|
|
|
|
|
2019-03-06 01:26:46 +05:00
|
|
|
class RwScopedRenderState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RwScopedRenderState( RwRenderState state )
|
|
|
|
: m_state( state )
|
|
|
|
{
|
|
|
|
[[maybe_unused]] RwBool result = RwRenderStateGet( m_state, &m_value );
|
|
|
|
assert( result != FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
~RwScopedRenderState()
|
|
|
|
{
|
|
|
|
[[maybe_unused]] RwBool result = RwRenderStateSet( m_state, m_value );
|
|
|
|
assert( result != FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RwScopedRenderState( const RwScopedRenderState& ) = delete;
|
|
|
|
|
|
|
|
const RwRenderState m_state;
|
|
|
|
void* m_value = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-03-28 00:17:43 +05:00
|
|
|
template <typename Pred>
|
2018-01-06 19:48:47 +05:00
|
|
|
Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback)
|
2017-03-28 00:17:43 +05:00
|
|
|
{
|
|
|
|
for ( RwFrame* curFrame = frame->child; curFrame != nullptr; curFrame = curFrame->next )
|
|
|
|
{
|
2017-04-02 21:45:16 +05:00
|
|
|
if ( std::forward<Pred>(callback)(curFrame) == nullptr )
|
2017-03-28 00:17:43 +05:00
|
|
|
break;
|
|
|
|
}
|
2018-01-06 19:48:47 +05:00
|
|
|
return std::forward<Pred>(callback);
|
2017-03-28 00:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Pred>
|
2018-01-06 19:48:47 +05:00
|
|
|
Pred RwFrameForAllObjects(RwFrame* frame, Pred&& callback)
|
2017-03-28 00:17:43 +05:00
|
|
|
{
|
|
|
|
for ( RwLLLink* link = rwLinkListGetFirstLLLink(&frame->objectList); link != rwLinkListGetTerminator(&frame->objectList); link = rwLLLinkGetNext(link) )
|
|
|
|
{
|
2017-04-02 21:45:16 +05:00
|
|
|
if ( std::forward<Pred>(callback)(&rwLLLinkGetData(link, RwObjectHasFrame, lFrame)->object) == nullptr )
|
2017-03-28 00:17:43 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-06 19:48:47 +05:00
|
|
|
return std::forward<Pred>(callback);
|
2017-03-28 00:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Pred>
|
2018-01-06 19:48:47 +05:00
|
|
|
Pred RpClumpForAllAtomics(RpClump* clump, Pred&& callback)
|
2017-03-28 00:17:43 +05:00
|
|
|
{
|
|
|
|
for ( RwLLLink* link = rwLinkListGetFirstLLLink(&clump->atomicList); link != rwLinkListGetTerminator(&clump->atomicList); link = rwLLLinkGetNext(link) )
|
|
|
|
{
|
2017-04-02 21:45:16 +05:00
|
|
|
if ( std::forward<Pred>(callback)(rwLLLinkGetData(link, RpAtomic, inClumpLink)) == nullptr )
|
2017-03-28 00:17:43 +05:00
|
|
|
break;
|
|
|
|
}
|
2018-01-06 19:48:47 +05:00
|
|
|
return std::forward<Pred>(callback);
|
2017-03-28 00:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Pred>
|
2018-01-06 19:48:47 +05:00
|
|
|
Pred RpGeometryForAllMaterials(RpGeometry* geometry, Pred&& callback)
|
2017-03-28 00:17:43 +05:00
|
|
|
{
|
|
|
|
for ( RwInt32 i = 0, j = geometry->matList.numMaterials; i < j; i++ )
|
|
|
|
{
|
2017-04-02 21:45:16 +05:00
|
|
|
if ( std::forward<Pred>(callback)(geometry->matList.materials[i]) == nullptr )
|
2017-03-28 00:17:43 +05:00
|
|
|
break;
|
|
|
|
}
|
2018-01-06 19:48:47 +05:00
|
|
|
return std::forward<Pred>(callback);
|
2017-03-28 00:17:43 +05:00
|
|
|
}
|