Proper scratch size computation for ANIM2/3

This commit is contained in:
Jack Andersen 2016-08-28 15:18:49 -10:00
parent 127b754691
commit 7953ca4828
4 changed files with 27 additions and 5 deletions

View File

@ -479,7 +479,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
vit = lastVals.begin();
for (const Channel& chan : channels)
{
const Value& val = (*kit)[f];
const Value& val = (*kit++)[f];
QuantizedValue& last = *vit++;
switch (chan.type)
{
@ -517,7 +517,6 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
}
default: break;
}
++kit;
}
}
return newData;

View File

@ -416,7 +416,7 @@ public:
void write(athena::io::IStreamWriter& writer) const
{
for (atUint32 word : m_words)
writer.writeUint32(word);
writer.writeUint32Big(word);
}
size_t binarySize(size_t __isz) const
{

View File

@ -404,8 +404,30 @@ void ANIM::ANIM2::write(athena::io::IStreamWriter& writer) const
m_version == 3 ? 0x7fffff : 0x7fff,
head.rotDiv, head.translationMult, scaleMult, bsSize);
/* TODO: Figure out proper scratch size computation */
head.scratchSize = keyframeCount * channels.size() * 16;
/* Tally up buffer size */
head.scratchSize = head.binarySize(0) + keyBmp.binarySize(0) + bsSize;
if (m_version == 3)
{
for (const std::pair<atUint32, bool>& bone : bones)
{
ChannelDescPC desc;
desc.keyCount1 = keyframeCount;
if (bone.second)
desc.keyCount2 = keyframeCount;
head.scratchSize = desc.binarySize(head.scratchSize);
}
}
else
{
for (const std::pair<atUint32, bool>& bone : bones)
{
ChannelDesc desc;
desc.keyCount1 = keyframeCount;
if (bone.second)
desc.keyCount2 = keyframeCount;
head.scratchSize = desc.binarySize(head.scratchSize);
}
}
head.write(writer);
keyBmp.write(writer);

View File

@ -473,6 +473,7 @@ void ANIM::ANIM2::read(athena::io::IStreamReader& reader)
void ANIM::ANIM2::write(athena::io::IStreamWriter& writer) const
{
/* TODO: conform to MP1 ANIM3 */
Header head;
head.unk1 = 1;
head.looping = 1;