1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-25 22:09:35 +00:00

Add template RAII class to change-restore arbitrary parameters: ValueKeeper Use it in TexrectDrawer::draw()

This commit is contained in:
Sergey Lipskiy 2018-12-01 18:24:55 +07:00
parent db106546a8
commit 11e87a46d8
2 changed files with 23 additions and 6 deletions

View File

@ -297,10 +297,8 @@ bool TexrectDrawer::draw()
if (m_numRects == 0)
return false;
const u64 otherMode = gDP.otherMode._u64;
const gDPScissor scissor = gDP.scissor;
gDP.scissor = m_scissor;
gDP.otherMode._u64 = m_otherMode;
ValueKeeper<u64> otherMode(gDP.otherMode._u64, m_otherMode);
ValueKeeper<gDPScissor> scissor(gDP.scissor, m_scissor);
DisplayWindow & wnd = dwnd();
GraphicsDrawer & drawer = wnd.getDrawer();
drawer._setBlendMode();
@ -420,8 +418,6 @@ bool TexrectDrawer::draw()
m_numRects = 0;
m_vecRectCoords.clear();
gDP.otherMode._u64 = otherMode;
gDP.scissor = scissor;
gDP.changed |= CHANGED_COMBINE | CHANGED_SCISSOR | CHANGED_RENDERMODE;
gSP.changed |= CHANGED_VIEWPORT | CHANGED_TEXTURE | CHANGED_GEOMETRYMODE;

View File

@ -40,4 +40,25 @@ typedef double f64; /* double prec floating point */
#define PLUGIN_PATH_SIZE 260
#endif
template <typename T>
class ValueKeeper
{
public:
ValueKeeper(T& _obj, T _newVal)
: m_obj(_obj)
, m_val(_obj)
{
m_obj = _newVal;
}
~ValueKeeper()
{
m_obj = m_val;
}
private:
T & m_obj;
T m_val;
};
#endif // TYPES_H