CAnimEventLoader: Use unique_ptr more
Makes memory handling a little more robust.
This commit is contained in:
parent
ecbd3eb83d
commit
2a5ab1ed32
|
@ -14,6 +14,8 @@
|
|||
#include "Core/Resource/Model/CModel.h"
|
||||
#include <Common/BasicTypes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
// Animation structures
|
||||
|
@ -99,7 +101,7 @@ class CAnimSet : public CResource
|
|||
float mDefaultAdditiveFadeIn;
|
||||
float mDefaultAdditiveFadeOut;
|
||||
std::vector<SHalfTransition> mHalfTransitions;
|
||||
std::vector<CAnimEventData*> mAnimEvents; // note: these are for MP2, where event data isn't a standalone resource; these are owned by the animset
|
||||
std::vector<std::unique_ptr<CAnimEventData>> mAnimEvents; // note: these are for MP2, where event data isn't a standalone resource; these are owned by the animset
|
||||
|
||||
public:
|
||||
CAnimSet(CResourceEntry *pEntry = 0)
|
||||
|
@ -124,7 +126,6 @@ public:
|
|||
for (uint32 iEvent = 0; iEvent < mAnimEvents.size(); iEvent++)
|
||||
{
|
||||
ASSERT(mAnimEvents[iEvent] && !mAnimEvents[iEvent]->Entry());
|
||||
delete mAnimEvents[iEvent];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ public:
|
|||
|
||||
else
|
||||
{
|
||||
return (Index < mAnimEvents.size() ? mAnimEvents[Index] : nullptr);
|
||||
return (Index < mAnimEvents.size() ? mAnimEvents[Index].get() : nullptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -142,19 +142,24 @@ std::unique_ptr<CAnimEventData> CAnimEventLoader::LoadEVNT(IInputStream& rEVNT,
|
|||
return ptr;
|
||||
}
|
||||
|
||||
CAnimEventData* CAnimEventLoader::LoadAnimSetEvents(IInputStream& rANCS)
|
||||
std::unique_ptr<CAnimEventData> CAnimEventLoader::LoadAnimSetEvents(IInputStream& rANCS)
|
||||
{
|
||||
auto ptr = std::make_unique<CAnimEventData>();
|
||||
|
||||
CAnimEventLoader Loader;
|
||||
Loader.mpEventData = new CAnimEventData();
|
||||
Loader.mpEventData = ptr.get();
|
||||
Loader.mGame = EGame::Echoes;
|
||||
Loader.LoadEvents(rANCS);
|
||||
return Loader.mpEventData;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
CAnimEventData* CAnimEventLoader::LoadCorruptionCharacterEventSet(IInputStream& rCHAR)
|
||||
std::unique_ptr<CAnimEventData> CAnimEventLoader::LoadCorruptionCharacterEventSet(IInputStream& rCHAR)
|
||||
{
|
||||
auto ptr = std::make_unique<CAnimEventData>();
|
||||
|
||||
CAnimEventLoader Loader;
|
||||
Loader.mpEventData = new CAnimEventData();
|
||||
Loader.mpEventData = ptr.get();
|
||||
Loader.mGame = EGame::Corruption;
|
||||
|
||||
// Read event set header
|
||||
|
@ -179,5 +184,5 @@ CAnimEventData* CAnimEventLoader::LoadCorruptionCharacterEventSet(IInputStream&
|
|||
Loader.LoadSoundEvent(rCHAR);
|
||||
}
|
||||
|
||||
return Loader.mpEventData;
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ class CAnimEventLoader
|
|||
|
||||
public:
|
||||
static std::unique_ptr<CAnimEventData> LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry);
|
||||
static CAnimEventData* LoadAnimSetEvents(IInputStream& rANCS);
|
||||
static CAnimEventData* LoadCorruptionCharacterEventSet(IInputStream& rCHAR);
|
||||
static std::unique_ptr<CAnimEventData> LoadAnimSetEvents(IInputStream& rANCS);
|
||||
static std::unique_ptr<CAnimEventData> LoadCorruptionCharacterEventSet(IInputStream& rCHAR);
|
||||
};
|
||||
|
||||
#endif // CANIMEVENTLOADER_H
|
||||
|
|
|
@ -41,8 +41,7 @@ void CAnimSetLoader::LoadCorruptionCHAR(IInputStream& rCHAR)
|
|||
|
||||
for (uint32 iSet = 0; iSet < NumEventSets; iSet++)
|
||||
{
|
||||
CAnimEventData *pEvents = CAnimEventLoader::LoadCorruptionCharacterEventSet(rCHAR);
|
||||
pSet->mAnimEvents.push_back(pEvents);
|
||||
pSet->mAnimEvents.push_back(CAnimEventLoader::LoadCorruptionCharacterEventSet(rCHAR));
|
||||
}
|
||||
|
||||
// Animations
|
||||
|
@ -383,8 +382,7 @@ void CAnimSetLoader::LoadAnimationSet(IInputStream& rANCS)
|
|||
|
||||
for (uint32 iEvent = 0; iEvent < EventDataCount; iEvent++)
|
||||
{
|
||||
CAnimEventData *pData = CAnimEventLoader::LoadAnimSetEvents(rANCS);
|
||||
pSet->mAnimEvents.push_back(pData);
|
||||
pSet->mAnimEvents.push_back(CAnimEventLoader::LoadAnimSetEvents(rANCS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue