Changes for debug testing in ANIM bitstream encoder

This commit is contained in:
Jack Andersen 2016-08-28 12:29:49 -10:00
parent b4b19d460c
commit 969e2a86de
3 changed files with 29 additions and 22 deletions

View File

@ -452,9 +452,9 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
it != kit->end(); it != kit->end();
++it) ++it)
{ {
QuantizedValue cur = {atInt32(it->v3.vec[0] * rotDivOut), QuantizedValue cur = {atInt32(it->v3.vec[0] / scaleMultOut),
atInt32(it->v3.vec[1] * rotDivOut), atInt32(it->v3.vec[1] / scaleMultOut),
atInt32(it->v3.vec[2] * rotDivOut)}; atInt32(it->v3.vec[2] / scaleMultOut)};
chan.q[0] = std::max(chan.q[0], atUint8(ceilf(log2f(cur[0] - last[0])))); chan.q[0] = std::max(chan.q[0], atUint8(ceilf(log2f(cur[0] - last[0]))));
chan.q[1] = std::max(chan.q[1], atUint8(ceilf(log2f(cur[1] - last[1])))); chan.q[1] = std::max(chan.q[1], atUint8(ceilf(log2f(cur[1] - last[1]))));
chan.q[2] = std::max(chan.q[2], atUint8(ceilf(log2f(cur[2] - last[2])))); chan.q[2] = std::max(chan.q[2], atUint8(ceilf(log2f(cur[2] - last[2]))));
@ -469,7 +469,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
/* Generate Bitstream */ /* Generate Bitstream */
sizeOut = ComputeBitstreamSize(keyFrameCount, channels); sizeOut = ComputeBitstreamSize(keyFrameCount, channels);
atUint8* newData = new atUint8[sizeOut]; std::unique_ptr<atUint8[]> newData(new atUint8[sizeOut]);
for (size_t f=0 ; f<keyFrameCount ; ++f) for (size_t f=0 ; f<keyFrameCount ; ++f)
{ {
kit = chanKeys.begin(); kit = chanKeys.begin();
@ -485,10 +485,10 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
++it) ++it)
{ {
QuantizedRot qrCur = QuantizeRotation(*it, rotDivOut); QuantizedRot qrCur = QuantizeRotation(*it, rotDivOut);
quantizeBit(newData, qrCur.w); quantizeBit(newData.get(), qrCur.w);
quantize(newData, chan.q[0], qrCur.v[0] - qrLast.v[0]); quantize(newData.get(), chan.q[0], qrCur.v[0] - qrLast.v[0]);
quantize(newData, chan.q[1], qrCur.v[1] - qrLast.v[1]); quantize(newData.get(), chan.q[1], qrCur.v[1] - qrLast.v[1]);
quantize(newData, chan.q[2], qrCur.v[2] - qrLast.v[2]); quantize(newData.get(), chan.q[2], qrCur.v[2] - qrLast.v[2]);
qrLast = qrCur; qrLast = qrCur;
} }
break; break;
@ -505,9 +505,9 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
QuantizedValue cur = {atInt32(it->v3.vec[0] / transMultOut), QuantizedValue cur = {atInt32(it->v3.vec[0] / transMultOut),
atInt32(it->v3.vec[1] / transMultOut), atInt32(it->v3.vec[1] / transMultOut),
atInt32(it->v3.vec[2] / transMultOut)}; atInt32(it->v3.vec[2] / transMultOut)};
quantize(newData, chan.q[0], cur[0] - last[0]); quantize(newData.get(), chan.q[0], cur[0] - last[0]);
quantize(newData, chan.q[1], cur[1] - last[1]); quantize(newData.get(), chan.q[1], cur[1] - last[1]);
quantize(newData, chan.q[2], cur[2] - last[2]); quantize(newData.get(), chan.q[2], cur[2] - last[2]);
last = cur; last = cur;
} }
break; break;
@ -524,9 +524,9 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
QuantizedValue cur = {atInt32(it->v3.vec[0] / scaleMultOut), QuantizedValue cur = {atInt32(it->v3.vec[0] / scaleMultOut),
atInt32(it->v3.vec[1] / scaleMultOut), atInt32(it->v3.vec[1] / scaleMultOut),
atInt32(it->v3.vec[2] / scaleMultOut)}; atInt32(it->v3.vec[2] / scaleMultOut)};
quantize(newData, chan.q[0], cur[0] - last[0]); quantize(newData.get(), chan.q[0], cur[0] - last[0]);
quantize(newData, chan.q[1], cur[1] - last[1]); quantize(newData.get(), chan.q[1], cur[1] - last[1]);
quantize(newData, chan.q[2], cur[2] - last[2]); quantize(newData.get(), chan.q[2], cur[2] - last[2]);
last = cur; last = cur;
} }
break; break;
@ -536,7 +536,7 @@ BitstreamWriter::write(const std::vector<std::vector<Value>>& chanKeys,
++kit; ++kit;
} }
} }
return std::unique_ptr<atUint8[]>(newData); return newData;
} }
} }

View File

@ -1244,7 +1244,7 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath,
{ {
hecl::SystemStringView sysStr(act.name); hecl::SystemStringView sysStr(act.name);
hecl::ProjectPath pathOut = inPath.getWithExtension((_S('.') + sysStr.sys_str()).c_str(), true).ensureAuxInfo(_S("ANIM")); hecl::ProjectPath pathOut = inPath.getWithExtension((_S('.') + sysStr.sys_str()).c_str(), true).ensureAuxInfo(_S("ANIM"));
hecl::ProjectPath cookedOut = inPath.getCookedPath(SpecEntMP1).getWithExtension((_S('.') + sysStr.sys_str()).c_str(), true); hecl::ProjectPath cookedOut = inPath.getCookedPath(SpecEntMP1PC).getWithExtension((_S('.') + sysStr.sys_str()).c_str(), true);
athena::io::FileWriter w(cookedOut.getAbsolutePath(), true, false); athena::io::FileWriter w(cookedOut.getAbsolutePath(), true, false);
if (w.hasError()) if (w.hasError())
Log.report(logvisor::Fatal, _S("unable to open '%s' for writing"), Log.report(logvisor::Fatal, _S("unable to open '%s' for writing"),

View File

@ -10,7 +10,9 @@ void CFBStreamedAnimReaderTotals::Allocate(u32 chanCount)
u32 chan2 = chanCount * 2; u32 chan2 = chanCount * 2;
u32 chan32 = chanCount * 32; u32 chan32 = chanCount * 32;
x0_buffer.reset(new u8[chan32 + chanCount + chan2 + chan32]); size_t sz = chan32 + chanCount + chan2 + chan32;
x0_buffer.reset(new u8[sz]);
memset(x0_buffer.get(), 0, sz);
x4_cumulativeInts32 = reinterpret_cast<s32*>(x0_buffer.get()); x4_cumulativeInts32 = reinterpret_cast<s32*>(x0_buffer.get());
x8_hasTrans1 = reinterpret_cast<u8*>(x4_cumulativeInts32 + chanCount * 8); x8_hasTrans1 = reinterpret_cast<u8*>(x4_cumulativeInts32 + chanCount * 8);
xc_segIds2 = reinterpret_cast<u16*>(x8_hasTrans1 + chanCount); xc_segIds2 = reinterpret_cast<u16*>(x8_hasTrans1 + chanCount);
@ -19,6 +21,7 @@ void CFBStreamedAnimReaderTotals::Allocate(u32 chanCount)
void CFBStreamedAnimReaderTotals::Initialize(const CFBStreamedCompression& source) void CFBStreamedAnimReaderTotals::Initialize(const CFBStreamedCompression& source)
{ {
x20_calculated = false;
const u8* chans = source.GetPerChannelHeaders(); const u8* chans = source.GetPerChannelHeaders();
u32 boneChanCount = *reinterpret_cast<const u32*>(chans); u32 boneChanCount = *reinterpret_cast<const u32*>(chans);
chans += 4; chans += 4;
@ -194,6 +197,10 @@ CFBStreamedPairOfTotals::CFBStreamedPairOfTotals(const TSubAnimTypeToken<CFBStre
void CFBStreamedPairOfTotals::SetTime(CBitLevelLoader& loader, const CCharAnimTime& time) void CFBStreamedPairOfTotals::SetTime(CBitLevelLoader& loader, const CCharAnimTime& time)
{ {
/* Implementation is a bit different than original;
* T evaluated pre-emptively with key indices.
* CalculateDown is also called here as needed. */
const CFBStreamedCompression::Header& header = x0_source->MainHeader(); const CFBStreamedCompression::Header& header = x0_source->MainHeader();
CCharAnimTime interval(header.interval); CCharAnimTime interval(header.interval);
const u32* timeBitmap = x0_source->GetTimes(); const u32* timeBitmap = x0_source->GetTimes();
@ -262,13 +269,13 @@ u32 CBitLevelLoader::LoadUnsigned(u8 q)
/* Fill 32 bit buffer with region containing bits */ /* Fill 32 bit buffer with region containing bits */
/* Make them least significant */ /* Make them least significant */
u32 tempBuf = hecl::SBig(*reinterpret_cast<const u32*>(m_data + byteCur)) >> bitRem; u32 tempBuf = *reinterpret_cast<const u32*>(m_data + byteCur) >> bitRem;
/* If this shift underflows the value, buffer the next 32 bits */ /* If this shift underflows the value, buffer the next 32 bits */
/* And tack onto shifted buffer */ /* And tack onto shifted buffer */
if ((bitRem + q) > 32) if ((bitRem + q) > 32)
{ {
u32 tempBuf2 = hecl::SBig(*reinterpret_cast<const u32*>(m_data + byteCur + 4)); u32 tempBuf2 = *reinterpret_cast<const u32*>(m_data + byteCur + 4);
tempBuf |= (tempBuf2 << (32 - bitRem)); tempBuf |= (tempBuf2 << (32 - bitRem));
} }
@ -288,13 +295,13 @@ s32 CBitLevelLoader::LoadSigned(u8 q)
/* Fill 32 bit buffer with region containing bits */ /* Fill 32 bit buffer with region containing bits */
/* Make them least significant */ /* Make them least significant */
u32 tempBuf = hecl::SBig(*reinterpret_cast<const u32*>(m_data + byteCur)) >> bitRem; u32 tempBuf = *reinterpret_cast<const u32*>(m_data + byteCur) >> bitRem;
/* If this shift underflows the value, buffer the next 32 bits */ /* If this shift underflows the value, buffer the next 32 bits */
/* And tack onto shifted buffer */ /* And tack onto shifted buffer */
if ((bitRem + q) > 32) if ((bitRem + q) > 32)
{ {
u32 tempBuf2 = hecl::SBig(*reinterpret_cast<const u32*>(m_data + byteCur + 4)); u32 tempBuf2 = *reinterpret_cast<const u32*>(m_data + byteCur + 4);
tempBuf |= (tempBuf2 << (32 - bitRem)); tempBuf |= (tempBuf2 << (32 - bitRem));
} }
@ -319,7 +326,7 @@ bool CBitLevelLoader::LoadBool()
/* Fill 32 bit buffer with region containing bits */ /* Fill 32 bit buffer with region containing bits */
/* Make them least significant */ /* Make them least significant */
u32 tempBuf = hecl::SBig(*reinterpret_cast<const u32*>(m_data + byteCur)) >> bitRem; u32 tempBuf = *reinterpret_cast<const u32*>(m_data + byteCur) >> bitRem;
/* That's it */ /* That's it */
m_bitIdx += 1; m_bitIdx += 1;