metaforce/DataSpec/DNAMP2/ANCS.cpp

606 lines
14 KiB
C++
Raw Normal View History

2015-08-15 04:12:15 +00:00
#include "ANCS.hpp"
2017-12-29 08:08:12 +00:00
namespace DataSpec::DNAMP2
2015-08-15 04:12:15 +00:00
{
2018-02-22 07:24:51 +00:00
template <>
void ANCS::CharacterSet::CharacterInfo::Enumerate<BigDNA::Read>(typename Read::StreamT& reader)
2015-08-15 04:12:15 +00:00
{
idx = reader.readUint32Big();
atUint16 sectionCount = reader.readUint16Big();
name = reader.readString();
cmdl.read(reader);
cskr.read(reader);
cinf.read(reader);
atUint32 animationCount = reader.readUint32Big();
reader.enumerate(animations, animationCount);
pasDatabase.read(reader);
atUint32 partCount = reader.readUint32Big();
reader.enumerate(partResData.part, partCount);
atUint32 swhcCount = reader.readUint32Big();
reader.enumerate(partResData.swhc, swhcCount);
atUint32 unkCount = reader.readUint32Big();
reader.enumerate(partResData.unk, unkCount);
atUint32 elscCount = reader.readUint32Big();
reader.enumerate(partResData.elsc, elscCount);
atUint32 spscCount = reader.readUint32Big();
reader.enumerate(partResData.spsc, spscCount);
atUint32 unkCount2 = reader.readUint32Big();
if (unkCount2)
abort();
reader.enumerate(partResData.unk2, unkCount2);
unk1 = reader.readUint32Big();
animAABBs.clear();
if (sectionCount > 1)
{
atUint32 aabbCount = reader.readUint32Big();
reader.enumerate(animAABBs, aabbCount);
}
effects.clear();
if (sectionCount > 2)
{
atUint32 effectCount = reader.readUint32Big();
reader.enumerate(effects, effectCount);
}
if (sectionCount > 3)
{
2015-09-26 03:12:08 +00:00
cmdlOverlay.read(reader);
2015-09-27 02:24:03 +00:00
cskrOverlay.read(reader);
2015-08-15 04:12:15 +00:00
}
animIdxs.clear();
if (sectionCount > 4)
{
atUint32 aidxCount = reader.readUint32Big();
reader.enumerateBig(animIdxs, aidxCount);
}
extents.clear();
if (sectionCount > 9)
{
unk4 = reader.readUint32Big();
unk5 = reader.readUByte();
atUint32 extentsCount = reader.readUint32Big();
reader.enumerate(extents, extentsCount);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::CharacterSet::CharacterInfo::Enumerate<BigDNA::Write>(typename Write::StreamT& writer)
2015-08-15 04:12:15 +00:00
{
writer.writeUint32Big(idx);
atUint16 sectionCount;
if (unk4 || unk5 || extents.size())
sectionCount = 10;
else if (partResData.elsc.size())
sectionCount = 6;
else if (animIdxs.size())
sectionCount = 5;
2015-09-26 03:12:08 +00:00
else if (cmdlOverlay)
2015-08-15 04:12:15 +00:00
sectionCount = 4;
else if (effects.size())
sectionCount = 3;
else if (animAABBs.size())
sectionCount = 2;
else
sectionCount = 1;
writer.writeUint16Big(sectionCount);
writer.writeString(name);
cmdl.write(writer);
cskr.write(writer);
cinf.write(writer);
writer.writeUint32Big(animations.size());
writer.enumerate(animations);
pasDatabase.write(writer);
writer.writeUint32Big(partResData.part.size());
writer.enumerate(partResData.part);
writer.writeUint32Big(partResData.swhc.size());
writer.enumerate(partResData.swhc);
writer.writeUint32Big(partResData.unk.size());
writer.enumerate(partResData.unk);
writer.writeUint32Big(partResData.elsc.size());
writer.enumerate(partResData.elsc);
writer.writeUint32Big(partResData.spsc.size());
writer.enumerate(partResData.spsc);
writer.writeUint32Big(partResData.unk2.size());
writer.enumerate(partResData.unk2);
writer.writeUint32Big(unk1);
if (sectionCount > 1)
{
writer.writeUint32Big(animAABBs.size());
writer.enumerate(animAABBs);
}
if (sectionCount > 2)
{
writer.writeUint32Big(effects.size());
writer.enumerate(effects);
}
if (sectionCount > 3)
{
2015-09-26 03:12:08 +00:00
cmdlOverlay.write(writer);
2015-09-27 02:24:03 +00:00
cskrOverlay.write(writer);
2015-08-15 04:12:15 +00:00
}
if (sectionCount > 4)
{
writer.writeUint32Big(animIdxs.size());
for (atUint32 idx : animIdxs)
writer.writeUint32Big(idx);
}
if (sectionCount > 9)
{
writer.writeUint32Big(unk4);
writer.writeUByte(unk5);
writer.writeUint32Big(extents.size());
writer.enumerate(extents);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::CharacterSet::CharacterInfo::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s)
{
atUint16 sectionCount;
if (unk4 || unk5 || extents.size())
sectionCount = 10;
else if (partResData.elsc.size())
sectionCount = 6;
else if (animIdxs.size())
sectionCount = 5;
else if (cmdlOverlay)
sectionCount = 4;
else if (effects.size())
sectionCount = 3;
else if (animAABBs.size())
sectionCount = 2;
else
sectionCount = 1;
2018-02-22 07:24:51 +00:00
s += 6;
2018-02-22 07:24:51 +00:00
s += name.size() + 1;
s += 12;
2018-02-22 07:24:51 +00:00
s += 4;
for (const Animation& anim : animations)
anim.binarySize(s);
2018-02-22 07:24:51 +00:00
pasDatabase.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.part)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.swhc)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.unk)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.elsc)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.spsc)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const UniqueID32& id : partResData.unk2)
id.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
if (sectionCount > 1)
{
2018-02-22 07:24:51 +00:00
s += 4;
for (const MP1CharacterInfo::ActionAABB& aabb : animAABBs)
aabb.binarySize(s);
}
if (sectionCount > 2)
{
2018-02-22 07:24:51 +00:00
s += 4;
for (const Effect& e : effects)
e.binarySize(s);
}
if (sectionCount > 3)
2018-02-22 07:24:51 +00:00
s += 8;
if (sectionCount > 4)
2018-02-22 07:24:51 +00:00
s += 4 + animIdxs.size() * 4;
if (sectionCount > 9)
{
2018-02-22 07:24:51 +00:00
s += 9;
for (const Extents& e : extents)
e.binarySize(s);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::CharacterSet::CharacterInfo::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader)
2015-08-15 04:12:15 +00:00
{
idx = reader.readUint32("idx");
atUint16 sectionCount = reader.readUint16("sectionCount");
name = reader.readString("name");
2016-03-04 23:04:53 +00:00
reader.enumerate("animations", animations);
2015-08-15 04:12:15 +00:00
reader.enumerate("pasDatabase", pasDatabase);
2016-03-04 23:04:53 +00:00
reader.enumerate("part", partResData.part);
2015-08-15 04:12:15 +00:00
2016-03-04 23:04:53 +00:00
reader.enumerate("swhc", partResData.swhc);
2015-08-15 04:12:15 +00:00
2016-03-04 23:04:53 +00:00
reader.enumerate("unk", partResData.unk);
2015-08-15 04:12:15 +00:00
2016-03-04 23:04:53 +00:00
reader.enumerate("elsc", partResData.elsc);
2015-08-15 04:12:15 +00:00
2016-03-04 23:04:53 +00:00
reader.enumerate("spsc", partResData.spsc);
2015-08-15 04:12:15 +00:00
2016-03-04 23:04:53 +00:00
reader.enumerate("unk2", partResData.unk2);
2015-08-15 04:12:15 +00:00
unk1 = reader.readUint32("unk1");
animAABBs.clear();
if (sectionCount > 1)
{
2016-03-04 23:04:53 +00:00
reader.enumerate("part", animAABBs);
2015-08-15 04:12:15 +00:00
}
effects.clear();
if (sectionCount > 2)
{
2016-03-04 23:04:53 +00:00
reader.enumerate("effects", effects);
2015-08-15 04:12:15 +00:00
}
if (sectionCount > 3)
{
2015-09-27 02:24:03 +00:00
reader.enumerate("cmdlOverlay", cmdlOverlay);
2015-08-15 04:12:15 +00:00
}
animIdxs.clear();
if (sectionCount > 4)
{
2016-03-04 23:04:53 +00:00
reader.enumerate("animIdxs", animIdxs);
2015-08-15 04:12:15 +00:00
}
extents.clear();
if (sectionCount > 9)
{
unk4 = reader.readUint32("unk4");
unk5 = reader.readUByte("unk5");
2016-03-04 23:04:53 +00:00
reader.enumerate("extents", extents);
2015-08-15 04:12:15 +00:00
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::CharacterSet::CharacterInfo::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer)
2015-08-15 04:12:15 +00:00
{
writer.writeUint32("idx", idx);
atUint16 sectionCount;
if (unk4 || unk5 || extents.size())
sectionCount = 10;
else if (partResData.elsc.size())
sectionCount = 6;
else if (animIdxs.size())
sectionCount = 5;
2015-09-26 03:12:08 +00:00
else if (cmdlOverlay)
2015-08-15 04:12:15 +00:00
sectionCount = 4;
else if (effects.size())
sectionCount = 3;
else if (animAABBs.size())
sectionCount = 2;
else
sectionCount = 1;
writer.writeUint16("sectionCount", sectionCount);
writer.writeString("name", name);
writer.enumerate("cmdl", cmdl);
writer.enumerate("animations", animations);
writer.enumerate("pasDatabase", pasDatabase);
writer.enumerate("part", partResData.part);
writer.enumerate("swhc", partResData.swhc);
writer.enumerate("unk", partResData.unk);
writer.enumerate("elsc", partResData.elsc);
writer.enumerate("spsc", partResData.spsc);
writer.enumerate("unk2", partResData.unk2);
writer.writeUint32("unk1", unk1);
if (sectionCount > 1)
{
writer.enumerate("animAABBs", animAABBs);
}
if (sectionCount > 2)
{
writer.enumerate("effects", effects);
}
if (sectionCount > 3)
{
2015-09-27 02:24:03 +00:00
writer.enumerate("cmdlOverlay", cmdlOverlay);
2015-08-15 04:12:15 +00:00
}
if (sectionCount > 4)
{
writer.enumerate("animIdxs", animIdxs);
}
if (sectionCount > 9)
{
writer.writeUint32("unk4", unk4);
writer.writeUByte("unk5", unk5);
writer.enumerate("extents", extents);
}
}
2015-10-01 00:40:21 +00:00
const char* ANCS::CharacterSet::CharacterInfo::DNAType()
{
2016-03-04 23:04:53 +00:00
return "urde::DNAMP2::ANCS::CharacterSet::CharacterInfo";
2015-10-01 00:40:21 +00:00
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::AnimationSet::Enumerate<BigDNA::Read>(typename Read::StreamT& reader)
2015-08-15 04:12:15 +00:00
{
atUint16 sectionCount = reader.readUint16Big();
atUint32 animationCount = reader.readUint32Big();
2016-04-07 03:40:25 +00:00
reader.enumerate(animations, animationCount);
2015-08-15 04:12:15 +00:00
atUint32 transitionCount = reader.readUint32Big();
2016-04-07 03:40:25 +00:00
reader.enumerate(transitions, transitionCount);
2015-08-15 04:12:15 +00:00
defaultTransition.read(reader);
additiveAnims.clear();
if (sectionCount > 1)
{
atUint32 additiveAnimCount = reader.readUint32Big();
reader.enumerate(additiveAnims, additiveAnimCount);
floatA = reader.readFloatBig();
floatB = reader.readFloatBig();
}
halfTransitions.clear();
if (sectionCount > 2)
{
2016-04-07 03:40:25 +00:00
atUint32 halfTransitionCount = reader.readUint32Big();
reader.enumerate(halfTransitions, halfTransitionCount);
2015-08-15 04:12:15 +00:00
}
evnts.clear();
if (sectionCount > 3)
{
atUint32 evntsCount = reader.readUint32Big();
reader.enumerate(evnts, evntsCount);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::AnimationSet::Enumerate<BigDNA::Write>(typename Write::StreamT& writer)
2015-08-15 04:12:15 +00:00
{
atUint16 sectionCount;
if (evnts.size())
sectionCount = 4;
else if (halfTransitions.size())
sectionCount = 3;
else if (additiveAnims.size())
sectionCount = 2;
else
sectionCount = 1;
writer.writeUint16Big(sectionCount);
writer.writeUint32Big(animations.size());
writer.enumerate(animations);
writer.writeUint32Big(transitions.size());
writer.enumerate(transitions);
defaultTransition.write(writer);
if (sectionCount > 1)
{
writer.writeUint32Big(additiveAnims.size());
writer.enumerate(additiveAnims);
writer.writeFloatBig(floatA);
writer.writeFloatBig(floatB);
}
if (sectionCount > 2)
{
writer.writeUint32Big(halfTransitions.size());
writer.enumerate(halfTransitions);
}
if (sectionCount > 3)
{
writer.writeUint32Big(evnts.size());
writer.enumerate(evnts);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::AnimationSet::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s)
{
atUint16 sectionCount;
if (evnts.size())
sectionCount = 4;
else if (halfTransitions.size())
sectionCount = 3;
else if (additiveAnims.size())
sectionCount = 2;
else
sectionCount = 1;
2018-02-22 07:24:51 +00:00
s += 6;
for (const MP1AnimationSet::Animation& anim : animations)
anim.binarySize(s);
2018-02-22 07:24:51 +00:00
s += 4;
for (const MP1AnimationSet::Transition& trans : transitions)
trans.binarySize(s);
defaultTransition.binarySize(s);
if (sectionCount > 1)
{
2018-02-22 07:24:51 +00:00
s += 4;
for (const MP1AnimationSet::AdditiveAnimationInfo& aaInfo : additiveAnims)
aaInfo.binarySize(s);
s += 8;
}
if (sectionCount > 2)
{
2018-02-22 07:24:51 +00:00
s += 4;
for (const MP1AnimationSet::HalfTransition& ht : halfTransitions)
ht.binarySize(s);
}
if (sectionCount > 3)
{
2018-02-22 07:24:51 +00:00
s += 4;
for (const EVNT& evnt : evnts)
evnt.binarySize(s);
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::AnimationSet::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader)
2015-08-15 04:12:15 +00:00
{
atUint16 sectionCount = reader.readUint16("sectionCount");
2016-04-07 03:40:25 +00:00
reader.enumerate("animations", animations);
2015-08-15 04:12:15 +00:00
2016-04-07 03:40:25 +00:00
reader.enumerate("transitions", transitions);
2015-08-15 04:12:15 +00:00
reader.enumerate("defaultTransition", defaultTransition);
additiveAnims.clear();
if (sectionCount > 1)
{
2016-03-04 23:04:53 +00:00
reader.enumerate("additiveAnims", additiveAnims);
2015-08-15 04:12:15 +00:00
floatA = reader.readFloat("floatA");
floatB = reader.readFloat("floatB");
}
halfTransitions.clear();
if (sectionCount > 2)
{
2016-04-07 03:40:25 +00:00
reader.enumerate("halfTransitions", halfTransitions);
2015-08-15 04:12:15 +00:00
}
evnts.clear();
if (sectionCount > 3)
{
2016-03-04 23:04:53 +00:00
reader.enumerate("evnts", evnts);
2015-08-15 04:12:15 +00:00
}
}
2018-02-22 07:24:51 +00:00
template <>
void ANCS::AnimationSet::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer)
2015-08-15 04:12:15 +00:00
{
atUint16 sectionCount;
if (evnts.size())
sectionCount = 4;
else if (halfTransitions.size())
sectionCount = 3;
else if (additiveAnims.size())
sectionCount = 2;
else
sectionCount = 1;
writer.writeUint16("sectionCount", sectionCount);
writer.enumerate("animations", animations);
writer.enumerate("transitions", transitions);
writer.enumerate("defaultTransition", defaultTransition);
if (sectionCount > 1)
{
writer.enumerate("additiveAnims", additiveAnims);
writer.writeFloat("floatA", floatA);
writer.writeFloat("floatB", floatB);
}
if (sectionCount > 2)
{
writer.enumerate("halfTransitions", halfTransitions);
}
if (sectionCount > 3)
{
writer.enumerate("evnts", evnts);
}
}
2015-10-01 00:40:21 +00:00
const char* ANCS::AnimationSet::DNAType()
{
2016-03-04 23:04:53 +00:00
return "urde::DNAMP2::ANCS::AnimationSet";
2015-10-01 00:40:21 +00:00
}
2018-02-22 07:24:51 +00:00
template <class Op>
void ANCS::AnimationSet::EVNT::Enumerate(typename Op::StreamT& s)
2015-08-15 04:12:15 +00:00
{
2018-02-22 07:24:51 +00:00
Do<Op>({"version"}, version, s);
DoSize<Op>({"loopEventCount"}, loopEventCount, s);
Do<Op>({"loopEvents"}, loopEvents, loopEventCount, s);
2015-08-15 04:12:15 +00:00
if (version == 2)
{
2018-02-22 07:24:51 +00:00
DoSize<Op>({"uevtEventCount"}, uevtEventCount, s);
Do<Op>({"uevtEvents"}, uevtEvents, uevtEventCount, s);
2015-08-15 04:12:15 +00:00
}
2018-02-22 07:24:51 +00:00
DoSize<Op>({"effectEventCount"}, effectEventCount, s);
Do<Op>({"effectEvents"}, effectEvents, effectEventCount, s);
DoSize<Op>({"sfxEventCount"}, sfxEventCount, s);
Do<Op>({"sfxEvents"}, sfxEvents, sfxEventCount, s);
2015-08-15 04:12:15 +00:00
}
2018-02-22 07:24:51 +00:00
AT_SPECIALIZE_DNA(ANCS::AnimationSet::EVNT)
2015-08-15 04:12:15 +00:00
2015-10-01 00:40:21 +00:00
const char* ANCS::AnimationSet::EVNT::DNAType()
{
2016-03-04 23:04:53 +00:00
return "urde::DNAMP2::ANCS::AnimationSet::EVNT";
2015-10-01 00:40:21 +00:00
}
2015-08-15 04:12:15 +00:00
}