CAnimSet: Make use of size_t where applicable

This commit is contained in:
Lioncash 2020-06-22 22:26:35 -04:00
parent d52b05d71c
commit a2ecb2a98c
9 changed files with 40 additions and 38 deletions

View File

@ -503,9 +503,9 @@ void GenerateAssetNames(CGameProject *pProj)
{
TString SetDir = It->DirectoryPath();
TString NewSetName;
CAnimSet *pSet = (CAnimSet*) It->Load();
auto* pSet = static_cast<CAnimSet*>(It->Load());
for (uint32 iChar = 0; iChar < pSet->NumCharacters(); iChar++)
for (size_t iChar = 0; iChar < pSet->NumCharacters(); iChar++)
{
const SSetCharacter *pkChar = pSet->Character(iChar);

View File

@ -104,15 +104,15 @@ void CCharacterUsageMap::Clear()
void CCharacterUsageMap::DebugPrintContents()
{
for (auto& [ID, usedList] : mUsageMap)
for (const auto& [ID, usedList] : mUsageMap)
{
const CAnimSet *pSet = mpStore->LoadResource<CAnimSet>(ID);
const auto* pSet = mpStore->LoadResource<CAnimSet>(ID);
for (uint32 iChar = 0; iChar < pSet->NumCharacters(); iChar++)
for (size_t iChar = 0; iChar < pSet->NumCharacters(); iChar++)
{
const bool Used = usedList.size() > iChar && usedList[iChar];
const TString CharName = pSet->Character(iChar)->Name;
debugf("%s : Char %d : %s : %s", *ID.ToString(), iChar, *CharName, (Used ? "USED" : "UNUSED"));
debugf("%s : Char %zu : %s : %s", *ID.ToString(), iChar, *CharName, (Used ? "USED" : "UNUSED"));
}
}
}

View File

@ -175,7 +175,7 @@ public:
return pTree;
}
CAnimation* FindAnimationAsset(uint32 AnimID) const
CAnimation* FindAnimationAsset(size_t AnimID) const
{
if (AnimID < mAnimPrimitives.size())
{
@ -192,29 +192,29 @@ public:
}
// Accessors
uint32 NumCharacters() const { return mCharacters.size(); }
uint32 NumAnimations() const { return mAnimations.size(); }
size_t NumCharacters() const { return mCharacters.size(); }
size_t NumAnimations() const { return mAnimations.size(); }
const SSetCharacter* Character(uint32 Index) const
const SSetCharacter* Character(size_t Index) const
{
ASSERT(Index < NumCharacters());
return &mCharacters[Index];
}
const SAnimation* Animation(uint32 Index) const
const SAnimation* Animation(size_t Index) const
{
ASSERT(Index < NumAnimations());
return &mAnimations[Index];
}
CAnimEventData* AnimationEventData(uint32 Index) const
CAnimEventData* AnimationEventData(size_t Index) const
{
ASSERT(Index < NumAnimations());
if (Game() <= EGame::Prime)
{
const CAnimPrimitive& rkPrim = mAnimPrimitives[Index];
return rkPrim.Animation() ? rkPrim.Animation()->EventData() : nullptr;
return rkPrim.Animation() != nullptr ? rkPrim.Animation()->EventData() : nullptr;
}
else
{

View File

@ -139,36 +139,36 @@ void CAnimationParameters::Serialize(IArchive& rArc)
}
}
const SSetCharacter* CAnimationParameters::GetCurrentSetCharacter(int32 NodeIndex /*= -1*/)
const SSetCharacter* CAnimationParameters::GetCurrentSetCharacter(int32 NodeIndex) const
{
CAnimSet *pSet = AnimSet();
const CAnimSet *pSet = AnimSet();
if (pSet && (pSet->Type() == EResourceType::AnimSet || pSet->Type() == EResourceType::Character))
if (pSet != nullptr && (pSet->Type() == EResourceType::AnimSet || pSet->Type() == EResourceType::Character))
{
if (NodeIndex == -1)
NodeIndex = mCharIndex;
if (mCharIndex != -1 && pSet->NumCharacters() > (uint32) NodeIndex)
if (mCharIndex != UINT32_MAX && pSet->NumCharacters() > static_cast<uint32>(NodeIndex))
return pSet->Character(NodeIndex);
}
return nullptr;
}
CModel* CAnimationParameters::GetCurrentModel(int32 NodeIndex /*= -1*/)
CModel* CAnimationParameters::GetCurrentModel(int32 NodeIndex)
{
const SSetCharacter *pkChar = GetCurrentSetCharacter(NodeIndex);
return pkChar ? pkChar->pModel : nullptr;
return pkChar != nullptr ? pkChar->pModel : nullptr;
}
TString CAnimationParameters::GetCurrentCharacterName(int32 NodeIndex /*= -1*/)
TString CAnimationParameters::GetCurrentCharacterName(int32 NodeIndex) const
{
const SSetCharacter *pkChar = GetCurrentSetCharacter(NodeIndex);
return pkChar ? pkChar->Name : "";
return pkChar != nullptr ? pkChar->Name : "";
}
// ************ ACCESSORS ************
uint32 CAnimationParameters::Unknown(uint32 Index)
uint32 CAnimationParameters::Unknown(uint32 Index) const
{
// mAnimIndex isn't unknown, but I'm too lazy to move it because there's a lot
// of UI stuff that depends on these functions atm for accessing and editing parameters.

View File

@ -27,9 +27,9 @@ public:
void Write(IOutputStream& rSCLY);
void Serialize(IArchive& rArc);
const SSetCharacter* GetCurrentSetCharacter(int32 NodeIndex = -1);
const SSetCharacter* GetCurrentSetCharacter(int32 NodeIndex = -1) const;
CModel* GetCurrentModel(int32 NodeIndex = -1);
TString GetCurrentCharacterName(int32 NodeIndex = -1);
TString GetCurrentCharacterName(int32 NodeIndex = -1) const;
// Accessors
EGame Version() const { return mGame; }
@ -54,7 +54,7 @@ public:
}
}
uint32 Unknown(uint32 Index);
uint32 Unknown(uint32 Index) const;
void SetResource(const CAssetID& rkID);
void SetUnknown(uint32 Index, uint32 Value);

View File

@ -209,7 +209,7 @@ CResource* CScriptTemplate::FindDisplayAsset(void* pPropertyData, uint32& rOutCh
if (pRes != nullptr)
{
const uint32 MaxNumChars = static_cast<const CAnimSet*>(pRes)->NumCharacters();
const size_t MaxNumChars = static_cast<const CAnimSet*>(pRes)->NumCharacters();
rOutCharIndex = (asset.ForceNodeIndex >= 0 && asset.ForceNodeIndex < static_cast<int32>(MaxNumChars) ? asset.ForceNodeIndex : Params.CharacterIndex());
rOutAnimIndex = Params.AnimIndex();
}

View File

@ -17,11 +17,11 @@ ENodeType CCharacterNode::NodeType()
void CCharacterNode::PostLoad()
{
if (mpCharacter)
{
for (uint32 iChar = 0; iChar < mpCharacter->NumCharacters(); iChar++)
mpCharacter->Character(iChar)->pModel->BufferGL();
}
if (mpCharacter == nullptr)
return;
for (size_t iChar = 0; iChar < mpCharacter->NumCharacters(); iChar++)
mpCharacter->Character(iChar)->pModel->BufferGL();
}
void CCharacterNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)

View File

@ -185,8 +185,8 @@ void CCharacterEditor::SetActiveAnimSet(CAnimSet *pSet)
mpCharComboBox->blockSignals(true);
mpCharComboBox->clear();
for (uint32 iChar = 0; iChar < mpSet->NumCharacters(); iChar++)
mpCharComboBox->addItem( TO_QSTRING(mpSet->Character(iChar)->Name) );
for (size_t iChar = 0; iChar < mpSet->NumCharacters(); iChar++)
mpCharComboBox->addItem(TO_QSTRING(mpSet->Character(iChar)->Name));
SetActiveCharacterIndex(0);
mpCharComboBox->blockSignals(false);
@ -195,7 +195,7 @@ void CCharacterEditor::SetActiveAnimSet(CAnimSet *pSet)
mpAnimComboBox->blockSignals(true);
mpAnimComboBox->clear();
for (uint32 iAnim = 0; iAnim < mpSet->NumAnimations(); iAnim++)
for (size_t iAnim = 0; iAnim < mpSet->NumAnimations(); iAnim++)
mpAnimComboBox->addItem( TO_QSTRING(mpSet->Animation(iAnim)->Name) );
SetActiveAnimation(0);
@ -334,13 +334,15 @@ void CCharacterEditor::SetActiveAnimation(int AnimIndex)
void CCharacterEditor::PrevAnim()
{
if (mCurrentAnim > 0) SetActiveAnimation(mCurrentAnim - 1);
if (mCurrentAnim > 0)
SetActiveAnimation(mCurrentAnim - 1);
}
void CCharacterEditor::NextAnim()
{
uint32 MaxAnim = (mpSet ? mpSet->NumAnimations() - 1 : 0);
if (mCurrentAnim < MaxAnim) SetActiveAnimation(mCurrentAnim + 1);
const size_t MaxAnim = (mpSet ? mpSet->NumAnimations() - 1 : 0);
if (mCurrentAnim < MaxAnim)
SetActiveAnimation(mCurrentAnim + 1);
}
void CCharacterEditor::SetAnimTime(int Time)

View File

@ -592,7 +592,7 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel
if (pAnimSet)
{
for (uint32 CharIdx = 0; CharIdx < pAnimSet->NumCharacters(); CharIdx++)
for (size_t CharIdx = 0; CharIdx < pAnimSet->NumCharacters(); CharIdx++)
pComboBox->addItem(TO_QSTRING(pAnimSet->Character(CharIdx)->Name));
}