Added support for tracking event character indices in the dependency tree

This commit is contained in:
parax0
2016-10-21 18:16:57 -06:00
parent 10c87779b3
commit a18655da00
16 changed files with 279 additions and 99 deletions

View File

@@ -0,0 +1,43 @@
#ifndef CANIMEVENTDATA
#define CANIMEVENTDATA
#include "CResource.h"
class CAnimEventData : public CResource
{
struct SEvent
{
u32 mCharacterIndex;
CAssetID mAssetRef;
};
std::vector<SEvent> mEvents;
public:
CAnimEventData(CResourceEntry *pEntry = 0)
: CResource(pEntry)
{
}
CDependencyTree* BuildDependencyTree() const
{
CDependencyTree *pTree = new CDependencyTree(ID());
for (u32 iEvt = 0; iEvt < mEvents.size(); iEvt++)
{
const SEvent& rkEvent = mEvents[iEvt];
pTree->AddEventDependency(rkEvent.mAssetRef, rkEvent.mCharacterIndex);
}
return pTree;
}
inline u32 NumEvents() const { return mEvents.size(); }
inline u32 EventCharacterIndex(u32 EventIdx) const { return mEvents[EventIdx].mCharacterIndex; }
inline CAssetID EventAssetRef(u32 EventIdx) const { return mEvents[EventIdx].mAssetRef; }
inline void AddEvent(u32 CharIdx, CAssetID AssetID) { mEvents.push_back( SEvent { CharIdx, AssetID } ); }
};
#endif // CANIMEVENTDATA

View File

@@ -3,6 +3,7 @@
#include "TResPtr.h"
#include "CAnimation.h"
#include "CAnimEventData.h"
#include "CDependencyGroup.h"
#include "CResource.h"
#include "CSkeleton.h"
@@ -12,7 +13,6 @@
#include <vector>
// will expand later! this is where animation support will come in
struct SSetCharacter
{
TString Name;
@@ -42,7 +42,7 @@ class CAnimSet : public CResource
TResPtr<CAnimation> pAnim;
};
std::vector<SAnimation> mAnims;
std::vector<CDependencyGroup*> mEventDependencies;
std::vector<CAnimEventData*> mEventDependencies;
public:
CAnimSet(CResourceEntry *pEntry = 0) : CResource(pEntry) {}
@@ -85,12 +85,13 @@ public:
for (u32 iEvnt = 0; iEvnt < mEventDependencies.size(); iEvnt++)
{
CDependencyGroup *pGroup = mEventDependencies[iEvnt];
CAnimEventData *pData = mEventDependencies[iEvnt];
for (u32 iDep = 0; iDep < pGroup->NumDependencies(); iDep++)
for (u32 iEvt = 0; iEvt < pData->NumEvents(); iEvt++)
{
CAssetID ID = pGroup->DependencyByIndex(iDep);
pTree->AddDependency(ID);
CAssetID ID = pData->EventAssetRef(iEvt);
u32 CharIdx = pData->EventCharacterIndex(iEvt);
pTree->AddEventDependency(ID, CharIdx);
BaseUsedSet.insert(ID);
}
}

View File

@@ -9,6 +9,7 @@ CWorld::CWorld(CResourceEntry *pEntry /*= 0*/)
, mpSaveWorld(nullptr)
, mpDefaultSkybox(nullptr)
, mpMapWorld(nullptr)
, mTempleKeyWorldIndex(0)
{
}

View File

@@ -157,7 +157,6 @@ bool CWorldCooker::CookMLVL(CWorld *pWorld, IOutputStream& rMLVL)
// Audio Groups
if (Game <= ePrime)
{
#if 0
// Debug: make sure our generated list matches the original, no missing or extra audio groups
std::set<CAssetID> OriginalGroups;
@@ -181,9 +180,7 @@ bool CWorldCooker::CookMLVL(CWorld *pWorld, IOutputStream& rMLVL)
Log::Error("Extra audio group: " + pEntry->Name().ToUTF8());
}
}
#endif
#if 0
// Create sorted list of audio groups (sort by group ID)
std::vector<CAudioGroup*> SortedAudioGroups;
@@ -201,15 +198,14 @@ bool CWorldCooker::CookMLVL(CWorld *pWorld, IOutputStream& rMLVL)
// Write sorted audio group list to file
rMLVL.WriteLong(SortedAudioGroups.size());
for (u32 iGrp = 0; iGrp < pWorld->mAudioGrps.size(); iGrp++)
for (u32 iGrp = 0; iGrp < SortedAudioGroups.size(); iGrp++)
{
CAudioGroup *pGroup = SortedAudioGroups[iGroup];
CAudioGroup *pGroup = SortedAudioGroups[iGrp];
rMLVL.WriteLong(pGroup->GroupID());
pGroup->ID().Write(rMLVL);
}
#endif
#if 1
#if 0
rMLVL.WriteLong(pWorld->mAudioGrps.size());
for (u32 iGrp = 0; iGrp < pWorld->mAudioGrps.size(); iGrp++)

View File

@@ -0,0 +1,94 @@
#include "CAnimEventLoader.h"
#include "Core/CAudioManager.h"
#include "Core/GameProject/CGameProject.h"
void CAnimEventLoader::LoadEvents(IInputStream& rEVNT, bool IsEchoes)
{
u32 Version = rEVNT.ReadLong();
ASSERT(Version == 1 || Version == 2);
// Loop Events
u32 NumLoopEvents = rEVNT.ReadLong();
for (u32 iLoop = 0; iLoop < NumLoopEvents; iLoop++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1C, SEEK_CUR);
}
// User Events
u32 NumUserEvents = rEVNT.ReadLong();
for (u32 iUser = 0; iUser < NumUserEvents; iUser++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1F, SEEK_CUR);
rEVNT.ReadString();
}
// Effect Events
u32 NumEffectEvents = rEVNT.ReadLong();
for (u32 iFX = 0; iFX < NumEffectEvents; iFX++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x13, SEEK_CUR);
u32 CharIndex = rEVNT.ReadLong();
rEVNT.Seek(0xC, SEEK_CUR);
CAssetID ParticleID = rEVNT.ReadLong();
mpEventData->AddEvent(CharIndex, ParticleID);
if (IsEchoes)
rEVNT.Seek(0x4, SEEK_CUR);
else
rEVNT.ReadString();
rEVNT.Seek(0x8, SEEK_CUR);
}
// Sound Events
if (Version == 2)
{
u32 NumSoundEvents = rEVNT.ReadLong();
for (u32 iSound = 0; iSound < NumSoundEvents; iSound++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x13, SEEK_CUR);
u32 CharIndex = rEVNT.ReadLong();
rEVNT.Seek(0x4, SEEK_CUR);
u32 SoundID = rEVNT.ReadLong() & 0xFFFF;
rEVNT.Seek(0x8, SEEK_CUR);
if (IsEchoes) rEVNT.Seek(0xC, SEEK_CUR);
if (SoundID != 0xFFFF)
{
SSoundInfo SoundInfo = CGameProject::ActiveProject()->AudioManager()->GetSoundInfo(SoundID);
if (SoundInfo.pAudioGroup)
mpEventData->AddEvent(CharIndex, SoundInfo.pAudioGroup->ID());
}
}
}
}
// ************ STATIC ************
CAnimEventData* CAnimEventLoader::LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry)
{
CAnimEventLoader Loader;
Loader.mpEventData = new CAnimEventData(pEntry);
Loader.LoadEvents(rEVNT, false);
return Loader.mpEventData;
}
CAnimEventData* CAnimEventLoader::LoadAnimSetEvents(IInputStream& rANCS)
{
CAnimEventLoader Loader;
Loader.mpEventData = new CAnimEventData();
Loader.LoadEvents(rANCS, true);
return Loader.mpEventData;
}

View File

@@ -0,0 +1,19 @@
#ifndef CANIMEVENTLOADER_H
#define CANIMEVENTLOADER_H
#include "Core/Resource/CAnimEventData.h"
#include "Core/Resource/TResPtr.h"
class CAnimEventLoader
{
TResPtr<CAnimEventData> mpEventData;
CAnimEventLoader() {}
void LoadEvents(IInputStream& rEVNT, bool IsEchoes);
public:
static CAnimEventData* LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry);
static CAnimEventData* LoadAnimSetEvents(IInputStream& rANCS);
};
#endif // CANIMEVENTLOADER_H

View File

@@ -1,5 +1,5 @@
#include "CAnimSetLoader.h"
#include "CUnsupportedFormatLoader.h"
#include "CAnimEventLoader.h"
#include "Core/GameProject/CResourceStore.h"
#include <Common/Log.h>
@@ -381,8 +381,8 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS, CResourceEntry *pEntry)
for (u32 iEvnt = 0; iEvnt < EventDataCount; iEvnt++)
{
CDependencyGroup *pGrp = CUnsupportedFormatLoader::LoadEVNT(rANCS, nullptr, true);
Loader.pSet->mEventDependencies.push_back(pGrp);
CAnimEventData *pData = CAnimEventLoader::LoadAnimSetEvents(rANCS);
Loader.pSet->mEventDependencies.push_back(pData);
}
}

View File

@@ -2,6 +2,7 @@
#define CRESOURCEFACTORY
#include "CAnimationLoader.h"
#include "CAnimEventLoader.h"
#include "CAnimSetLoader.h"
#include "CAreaLoader.h"
#include "CAudioGroupLoader.h"
@@ -34,6 +35,7 @@ public:
switch (pEntry->ResourceType())
{
case eAnimation: return new CAnimation(pEntry);
case eAnimEventData: return new CAnimEventData(pEntry);
case eAnimSet: return new CAnimSet(pEntry);
case eArea: return new CGameArea(pEntry);
case eAudioGroup: return new CAudioGroup(pEntry);
@@ -63,7 +65,7 @@ public:
switch (pEntry->ResourceType())
{
case eAnimation: pRes = CAnimationLoader::LoadANIM(rInput, pEntry); break;
case eAnimEventData: pRes = CUnsupportedFormatLoader::LoadEVNT(rInput, pEntry); break;
case eAnimEventData: pRes = CAnimEventLoader::LoadEVNT(rInput, pEntry); break;
case eAnimSet: pRes = CAnimSetLoader::LoadANCSOrCHAR(rInput, pEntry); break;
case eArea: pRes = CAreaLoader::LoadMREA(rInput, pEntry); break;
case eAudioGroup: pRes = CAudioGroupLoader::LoadAGSC(rInput, pEntry); break;

View File

@@ -13,77 +13,6 @@ CDependencyGroup* CUnsupportedFormatLoader::LoadCSNG(IInputStream& rCSNG, CResou
return pGroup;
}
CDependencyGroup* CUnsupportedFormatLoader::LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry, bool IsEchoes /*= false*/)
{
u32 Version = rEVNT.ReadLong();
ASSERT(Version == 1 || Version == 2);
CDependencyGroup *pGroup = new CDependencyGroup(pEntry);
// Loop Events
u32 NumLoopEvents = rEVNT.ReadLong();
for (u32 iLoop = 0; iLoop < NumLoopEvents; iLoop++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1C, SEEK_CUR);
}
// User Events
u32 NumUserEvents = rEVNT.ReadLong();
for (u32 iUser = 0; iUser < NumUserEvents; iUser++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1F, SEEK_CUR);
rEVNT.ReadString();
}
// Effect Events
u32 NumEffectEvents = rEVNT.ReadLong();
for (u32 iFX = 0; iFX < NumEffectEvents; iFX++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x23, SEEK_CUR);
pGroup->AddDependency(rEVNT.ReadLong());
if (IsEchoes)
rEVNT.Seek(0x4, SEEK_CUR);
else
rEVNT.ReadString();
rEVNT.Seek(0x8, SEEK_CUR);
}
// Sound Events
if (Version == 2)
{
u32 NumSoundEvents = rEVNT.ReadLong();
for (u32 iSound = 0; iSound < NumSoundEvents; iSound++)
{
rEVNT.Seek(0x2, SEEK_CUR);
rEVNT.ReadString();
rEVNT.Seek(0x1B, SEEK_CUR);
u32 SoundID = rEVNT.ReadLong() & 0xFFFF;
rEVNT.Seek(0x8, SEEK_CUR);
if (IsEchoes) rEVNT.Seek(0xC, SEEK_CUR);
if (SoundID != 0xFFFF)
{
SSoundInfo SoundInfo = CGameProject::ActiveProject()->AudioManager()->GetSoundInfo(SoundID);
pGroup->AddDependency(SoundInfo.pAudioGroup);
}
}
}
return pGroup;
}
CDependencyGroup* CUnsupportedFormatLoader::LoadFRME(IInputStream& rFRME, CResourceEntry *pEntry)
{
u32 Version = rFRME.ReadLong();

View File

@@ -12,7 +12,6 @@ class CUnsupportedFormatLoader
public:
static CDependencyGroup* LoadCSNG(IInputStream& rCSNG, CResourceEntry *pEntry);
static CDependencyGroup* LoadEVNT(IInputStream& rEVNT, CResourceEntry *pEntry, bool IsEchoes = false);
static CDependencyGroup* LoadFRME(IInputStream& rFRME, CResourceEntry *pEntry);
static CDependencyGroup* LoadFSM2(IInputStream& rFSM2, CResourceEntry *pEntry);
static CDependencyGroup* LoadHINT(IInputStream& rHINT, CResourceEntry *pEntry);