Skip to content

Commit

Permalink
Addendum to PR 3402 (multitheftauto#3403)
Browse files Browse the repository at this point in the history
  • Loading branch information
tederis authored May 25, 2024
1 parent 8414476 commit 487c171
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
21 changes: 11 additions & 10 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ int CLuaDrawingDefs::DxDrawLine3D(lua_State* luaVM)
argStream.ReadVector3D(vecEnd);
argStream.ReadColor(color, 0xFFFFFFFF);
argStream.ReadNumber(fWidth, 1);
if (bool bPostGUI = argStream.ReadIfNextIsBool())
renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
if (argStream.NextIsBool())
renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
else
argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX);

Expand Down Expand Up @@ -240,8 +240,8 @@ int CLuaDrawingDefs::DxDrawMaterialLine3D(lua_State* luaVM)
argStream.ReadUserData(pMaterial);
argStream.ReadNumber(fWidth);
argStream.ReadColor(color, 0xFFFFFFFF);
if (bool bPostGUI = argStream.ReadIfNextIsBool())
renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
if (argStream.NextIsBool())
renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
else
argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX);

Expand Down Expand Up @@ -292,10 +292,11 @@ int CLuaDrawingDefs::DxDrawMaterialSectionLine3D(lua_State* luaVM)
argStream.ReadUserData(pMaterial);
argStream.ReadNumber(fWidth);
argStream.ReadColor(color, 0xFFFFFFFF);
if (bool bPostGUI = argStream.ReadIfNextIsBool())
renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
if (argStream.NextIsBool())
renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
else
argStream.ReadIfNextIsEnumString(renderStage, eRenderStage::POST_FX);

if (argStream.NextIsVector3D())
{
argStream.ReadVector3D(vecFaceToward);
Expand Down Expand Up @@ -599,8 +600,8 @@ int CLuaDrawingDefs::DxDrawPrimitive3D(lua_State* luaVM)
eRenderStage renderStage{eRenderStage::POST_FX};
CScriptArgReader argStream(luaVM);
argStream.ReadEnumString(ePrimitiveType);
if (bool bPostGUI = argStream.ReadIfNextIsBool())
renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
if (argStream.NextIsBool())
renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
else
argStream.ReadEnumString(renderStage, eRenderStage::POST_FX);

Expand Down Expand Up @@ -654,8 +655,8 @@ int CLuaDrawingDefs::DxDrawMaterialPrimitive3D(lua_State* luaVM)
CScriptArgReader argStream(luaVM);
argStream.ReadEnumString(ePrimitiveType);
MixedReadMaterialString(argStream, pMaterialElement);
if (bool bPostGUI = argStream.ReadIfNextIsBool())
renderStage = bPostGUI ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
if (argStream.NextIsBool())
renderStage = argStream.ReadBool() ? eRenderStage::POST_GUI : eRenderStage::POST_FX;
else
argStream.ReadEnumString(renderStage, eRenderStage::POST_FX);

Expand Down
24 changes: 16 additions & 8 deletions Shared/sdk/CScriptArgReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,22 @@ class CScriptArgReader
m_iIndex++;
}

//
// Read next bool or false if failed
// Intended for use in pair with NextIsBool()
//
bool ReadBool()
{
int iArgument = lua_type(m_luaVM, m_iIndex);
if (iArgument == LUA_TBOOLEAN)
{
return lua_toboolean(m_luaVM, m_iIndex++) ? true : false;
}

m_iIndex++;
return false;
}

//
// Read next bool, using default if needed
//
Expand Down Expand Up @@ -1331,14 +1347,6 @@ class CScriptArgReader
bOutValue = bDefaultValue;
}

bool ReadIfNextIsBool(const bool bDefaultValue = false)
{
bool bOutValue{bDefaultValue};
if (NextIsBool())
ReadBool(bOutValue, bDefaultValue);
return bOutValue;
}

template <class T>
void ReadIfNextIsUserData(T*& outValue, T* defaultValue)
{
Expand Down

0 comments on commit 487c171

Please sign in to comment.