CCharacterFactory: Eliminate usages of const_cast within CreateCharacter()

We can simply make this member function non-const and eliminate the need
for casts like this.
This commit is contained in:
Lioncash 2020-04-05 08:11:49 -04:00
parent b99122dae8
commit 0a7ccace44
2 changed files with 5 additions and 6 deletions

View File

@ -76,17 +76,16 @@ std::unique_ptr<u8[]> CCharacterFactory::CDummyFactory::LoadNewResourcePartSync(
std::unique_ptr<CAnimData> CCharacterFactory::CreateCharacter(int charIdx, bool loop, std::unique_ptr<CAnimData> CCharacterFactory::CreateCharacter(int charIdx, bool loop,
const TLockedToken<CCharacterFactory>& factory, const TLockedToken<CCharacterFactory>& factory,
int defaultAnim, int drawInsts) const { int defaultAnim, int drawInsts) {
const CCharacterInfo& charInfo = x4_charInfoDB[charIdx]; const CCharacterInfo& charInfo = x4_charInfoDB[charIdx];
const CVParamTransfer charParm(new TObjOwnerParam<const CCharacterInfo*>(&charInfo)); const CVParamTransfer charParm(new TObjOwnerParam<const CCharacterInfo*>(&charInfo));
TToken<CSkinnedModel> skinnedModel = const_cast<CCharacterFactory*>(this)->x70_cacheResPool.GetObj( TToken<CSkinnedModel> skinnedModel =
{FourCC(drawInsts << 16), charInfo.GetModelId()}, charParm); x70_cacheResPool.GetObj({FourCC(drawInsts << 16), charInfo.GetModelId()}, charParm);
std::optional<TToken<CMorphableSkinnedModel>> iceModel; std::optional<TToken<CMorphableSkinnedModel>> iceModel;
if (charInfo.GetIceModelId().IsValid() && charInfo.GetIceSkinRulesId().IsValid()) { if (charInfo.GetIceModelId().IsValid() && charInfo.GetIceSkinRulesId().IsValid()) {
iceModel.emplace(const_cast<CCharacterFactory*>(this)->x70_cacheResPool.GetObj( iceModel.emplace(x70_cacheResPool.GetObj({FourCC((drawInsts << 16) | 1), charInfo.GetIceModelId()}, charParm));
{FourCC((drawInsts << 16) | 1), charInfo.GetIceModelId()}, charParm));
} }
return std::make_unique<CAnimData>(x68_selfId, charInfo, defaultAnim, charIdx, loop, x14_charLayoutInfoDB[charIdx], return std::make_unique<CAnimData>(x68_selfId, charInfo, defaultAnim, charIdx, loop, x14_charLayoutInfoDB[charIdx],

View File

@ -68,7 +68,7 @@ public:
CCharacterFactory(CSimplePool& store, const CAnimCharacterSet& ancs, CAssetId); CCharacterFactory(CSimplePool& store, const CAnimCharacterSet& ancs, CAssetId);
std::unique_ptr<CAnimData> CreateCharacter(int charIdx, bool loop, const TLockedToken<CCharacterFactory>& factory, std::unique_ptr<CAnimData> CreateCharacter(int charIdx, bool loop, const TLockedToken<CCharacterFactory>& factory,
int defaultAnim, int drawInsts) const; int defaultAnim, int drawInsts);
CAssetId GetEventResourceIdForAnimResourceId(CAssetId animId) const; CAssetId GetEventResourceIdForAnimResourceId(CAssetId animId) const;
const CCharacterInfo& GetCharInfo(int charIdx) const { return x4_charInfoDB[charIdx]; } const CCharacterInfo& GetCharInfo(int charIdx) const { return x4_charInfoDB[charIdx]; }