CScriptObject: Collapse for loops into ranged for loops

While we're at it, eliminate sign conversion warnings.
This commit is contained in:
Lioncash 2020-06-12 16:55:32 -04:00
parent 5c42bcc580
commit 7b40eec19c
2 changed files with 21 additions and 19 deletions

View File

@ -108,7 +108,8 @@ void CScriptObject::SetLayer(CScriptLayer *pLayer, uint32 NewLayerIndex)
uint32 CScriptObject::LayerIndex() const
{
if (!mpLayer) return -1;
if (!mpLayer)
return UINT32_MAX;
for (uint32 iInst = 0; iInst < mpLayer->NumInstances(); iInst++)
{
@ -116,7 +117,7 @@ uint32 CScriptObject::LayerIndex() const
return iInst;
}
return -1;
return UINT32_MAX;
}
bool CScriptObject::HasNearVisibleActivation() const
@ -127,20 +128,20 @@ bool CScriptObject::HasNearVisibleActivation() const
* instance has a "Near Visible" activation, which is typically done via a trigger that activates the object on
* InternalState04/05/06 (usually through a relay). */
std::list<CScriptObject*> Relays;
bool IsRelay = (ObjectTypeID() == 0x53524C59);
const bool IsRelay = ObjectTypeID() == 0x53524C59;
if (mIsCheckingNearVisibleActivation)
return false;
if (mIsCheckingNearVisibleActivation) return false;
mIsCheckingNearVisibleActivation = true;
for (uint32 iLink = 0; iLink < mInLinks.size(); iLink++)
for (const auto* pLink : mInLinks)
{
CLink *pLink = mInLinks[iLink];
// Check for trigger activation
if (pLink->State() == FOURCC('IS04') || pLink->State() == FOURCC('IS05') || pLink->State() == FOURCC('IS06'))
{
if ( (!IsRelay && pLink->Message() == FOURCC('ACTV')) ||
(IsRelay && pLink->Message() == FOURCC('ACTN')) )
if ((!IsRelay && pLink->Message() == FOURCC('ACTV')) ||
(IsRelay && pLink->Message() == FOURCC('ACTN')))
{
CScriptObject *pObj = pLink->Sender();
@ -167,25 +168,26 @@ bool CScriptObject::HasNearVisibleActivation() const
}
// Check whether any of the relays have a near visible activation
for (auto it = Relays.begin(); it != Relays.end(); it++)
const bool nearVisible = std::any_of(Relays.cbegin(), Relays.cend(),
[](const auto* relay) { return relay->HasNearVisibleActivation(); });
if (nearVisible)
{
if ((*it)->HasNearVisibleActivation())
{
mIsCheckingNearVisibleActivation = false;
return true;
}
mIsCheckingNearVisibleActivation = false;
return true;
}
mIsCheckingNearVisibleActivation = false;
return false;
}
void CScriptObject::AddLink(ELinkType Type, CLink *pLink, uint32 Index /*= -1*/)
void CScriptObject::AddLink(ELinkType Type, CLink *pLink, uint32 Index)
{
std::vector<CLink*> *pLinkVec = (Type == ELinkType::Incoming ? &mInLinks : &mOutLinks);
if (Index == -1 || Index == pLinkVec->size())
if (Index == UINT32_MAX || Index == pLinkVec->size())
{
pLinkVec->push_back(pLink);
}
else
{
auto it = pLinkVec->begin();

View File

@ -73,11 +73,11 @@ public:
void EvaluateCollisionModel();
void EvaluateVolume();
bool IsEditorProperty(IProperty *pProp);
void SetLayer(CScriptLayer *pLayer, uint32 NewLayerIndex = -1);
void SetLayer(CScriptLayer *pLayer, uint32 NewLayerIndex = UINT32_MAX);
uint32 LayerIndex() const;
bool HasNearVisibleActivation() const;
void AddLink(ELinkType Type, CLink *pLink, uint32 Index = -1);
void AddLink(ELinkType Type, CLink *pLink, uint32 Index = UINT32_MAX);
void RemoveLink(ELinkType Type, CLink *pLink);
void BreakAllLinks();