CMaterialCooker: Make use of unsigned write variants where applicable

Gets rid of a bunch of implicit sign conversion warnings.
This commit is contained in:
Lioncash 2020-06-18 17:50:21 -04:00
parent c7ff608d1a
commit 4b20a8ad9f
1 changed files with 70 additions and 69 deletions

View File

@ -137,11 +137,11 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
} }
// Get group index // Get group index
uint32 GroupIndex; size_t GroupIndex = 0;
uint64 MatHash = mpMat->HashParameters(); const uint64 MatHash = mpMat->HashParameters();
bool NewHash = true; bool NewHash = true;
for (uint32 iHash = 0; iHash < mMaterialHashes.size(); iHash++) for (size_t iHash = 0; iHash < mMaterialHashes.size(); iHash++)
{ {
if (mMaterialHashes[iHash] == MatHash) if (mMaterialHashes[iHash] == MatHash)
{ {
@ -159,7 +159,7 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
// Start writing! // Start writing!
// Generate flags value // Generate flags value
bool HasKonst = (NumKonst > 0); const bool HasKonst = NumKonst > 0;
uint32 Flags; uint32 Flags;
if (mVersion <= EGame::Prime) if (mVersion <= EGame::Prime)
@ -169,12 +169,12 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
Flags |= (HasKonst ? 0x8 : 0x0) | (mpMat->Options() & ~0x8) | (TexFlags << 16); Flags |= (HasKonst ? 0x8 : 0x0) | (mpMat->Options() & ~0x8) | (TexFlags << 16);
rOut.WriteLong(Flags); rOut.WriteULong(Flags);
// Texture indices // Texture indices
rOut.WriteLong(TexIndices.size()); rOut.WriteULong(static_cast<uint32>(TexIndices.size()));
for (uint32 iTex = 0; iTex < TexIndices.size(); iTex++) for (const auto index : TexIndices)
rOut.WriteLong(TexIndices[iTex]); rOut.WriteULong(index);
// Vertex description // Vertex description
uint32 VtxFlags = ConvertFromVertexDescription(mpMat->VtxDesc()); uint32 VtxFlags = ConvertFromVertexDescription(mpMat->VtxDesc());
@ -182,99 +182,101 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
if (mVersion < EGame::Echoes) if (mVersion < EGame::Echoes)
VtxFlags &= 0x00FFFFFF; VtxFlags &= 0x00FFFFFF;
rOut.WriteLong(VtxFlags); rOut.WriteULong(VtxFlags);
// Echoes unknowns // Echoes unknowns
if (mVersion == EGame::Echoes) if (mVersion == EGame::Echoes)
{ {
rOut.WriteLong(mpMat->EchoesUnknownA()); rOut.WriteULong(mpMat->EchoesUnknownA());
rOut.WriteLong(mpMat->EchoesUnknownB()); rOut.WriteULong(mpMat->EchoesUnknownB());
} }
// Group index // Group index
rOut.WriteLong(GroupIndex); rOut.WriteULong(static_cast<uint32>(GroupIndex));
// Konst // Konst
if (HasKonst) if (HasKonst)
{ {
rOut.WriteLong(NumKonst); rOut.WriteULong(NumKonst);
for (uint32 iKonst = 0; iKonst < NumKonst; iKonst++) for (size_t iKonst = 0; iKonst < NumKonst; iKonst++)
rOut.WriteLong(mpMat->Konst(iKonst).ToLongRGBA()); rOut.WriteLong(mpMat->Konst(iKonst).ToLongRGBA());
} }
// Blend Mode // Blend Mode
// Some modifications are done to convert the GLenum to the corresponding GX enum // Some modifications are done to convert the GLenum to the corresponding GX enum
uint16 BlendSrcFac = (uint16) mpMat->BlendSrcFac(); auto BlendSrcFac = static_cast<uint16>(mpMat->BlendSrcFac());
uint16 BlendDstFac = (uint16) mpMat->BlendDstFac(); auto BlendDstFac = static_cast<uint16>(mpMat->BlendDstFac());
if (BlendSrcFac >= 0x300) BlendSrcFac -= 0x2FE; if (BlendSrcFac >= 0x300) BlendSrcFac -= 0x2FE;
if (BlendDstFac >= 0x300) BlendDstFac -= 0x2FE; if (BlendDstFac >= 0x300) BlendDstFac -= 0x2FE;
rOut.WriteShort(BlendDstFac); rOut.WriteUShort(BlendDstFac);
rOut.WriteShort(BlendSrcFac); rOut.WriteUShort(BlendSrcFac);
// Color Channels // Color Channels
rOut.WriteLong(1); rOut.WriteLong(1);
rOut.WriteLong(0x3000 | (mpMat->IsLightingEnabled() ? 1 : 0)); rOut.WriteLong(0x3000 | (mpMat->IsLightingEnabled() ? 1 : 0));
// TEV // TEV
uint32 NumPasses = mpMat->PassCount(); const uint32 NumPasses = mpMat->PassCount();
rOut.WriteLong(NumPasses); rOut.WriteULong(NumPasses);
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (uint32 iPass = 0; iPass < NumPasses; iPass++)
{ {
CMaterialPass *pPass = mpMat->Pass(iPass); CMaterialPass *pPass = mpMat->Pass(iPass);
uint32 ColorInputFlags = ((pPass->ColorInput(0)) | const uint32 ColorInputFlags = ((pPass->ColorInput(0)) |
(pPass->ColorInput(1) << 5) | (pPass->ColorInput(1) << 5) |
(pPass->ColorInput(2) << 10) | (pPass->ColorInput(2) << 10) |
(pPass->ColorInput(3) << 15)); (pPass->ColorInput(3) << 15));
uint32 AlphaInputFlags = ((pPass->AlphaInput(0)) | const uint32 AlphaInputFlags = ((pPass->AlphaInput(0)) |
(pPass->AlphaInput(1) << 5) | (pPass->AlphaInput(1) << 5) |
(pPass->AlphaInput(2) << 10) | (pPass->AlphaInput(2) << 10) |
(pPass->AlphaInput(3) << 15)); (pPass->AlphaInput(3) << 15));
uint32 ColorOpFlags = 0x100 | (pPass->ColorOutput() << 9); const uint32 ColorOpFlags = 0x100 | (pPass->ColorOutput() << 9);
uint32 AlphaOpFlags = 0x100 | (pPass->AlphaOutput() << 9); const uint32 AlphaOpFlags = 0x100 | (pPass->AlphaOutput() << 9);
rOut.WriteLong(ColorInputFlags); rOut.WriteULong(ColorInputFlags);
rOut.WriteLong(AlphaInputFlags); rOut.WriteULong(AlphaInputFlags);
rOut.WriteLong(ColorOpFlags); rOut.WriteULong(ColorOpFlags);
rOut.WriteLong(AlphaOpFlags); rOut.WriteULong(AlphaOpFlags);
rOut.WriteByte(0); // Padding rOut.WriteUByte(0); // Padding
rOut.WriteByte(pPass->KAlphaSel()); rOut.WriteUByte(static_cast<uint8>(pPass->KAlphaSel()));
rOut.WriteByte(pPass->KColorSel()); rOut.WriteUByte(static_cast<uint8>(pPass->KColorSel()));
rOut.WriteByte(pPass->RasSel()); rOut.WriteUByte(static_cast<uint8>(pPass->RasSel()));
} }
// TEV Tex/UV input selection // TEV Tex/UV input selection
uint32 CurTexIdx = 0; uint32 CurTexIdx = 0;
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (size_t iPass = 0; iPass < NumPasses; iPass++)
{ {
rOut.WriteShort(0); // Padding rOut.WriteUShort(0); // Padding
if (mpMat->Pass(iPass)->Texture()) if (mpMat->Pass(iPass)->Texture() != nullptr)
{ {
rOut.WriteByte((uint8) CurTexIdx); rOut.WriteUByte(static_cast<uint8>(CurTexIdx));
rOut.WriteByte((uint8) CurTexIdx); rOut.WriteUByte(static_cast<uint8>(CurTexIdx));
CurTexIdx++; CurTexIdx++;
} }
else else
rOut.WriteShort((uint16) 0xFFFF); {
rOut.WriteUShort(static_cast<uint16>(0xFFFF));
}
} }
// TexGen // TexGen
uint32 NumTexCoords = CurTexIdx; // TexIdx is currently equal to the tex coord count const uint32 NumTexCoords = CurTexIdx; // TexIdx is currently equal to the tex coord count
rOut.WriteLong(NumTexCoords); rOut.WriteULong(NumTexCoords);
uint32 CurTexMtx = 0; uint32 CurTexMtx = 0;
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (size_t iPass = 0; iPass < NumPasses; iPass++)
{ {
CMaterialPass *pPass = mpMat->Pass(iPass); CMaterialPass *pPass = mpMat->Pass(iPass);
if (pPass->Texture() == nullptr) continue; if (pPass->Texture() == nullptr)
continue;
EUVAnimMode AnimType = pPass->AnimMode(); const EUVAnimMode AnimType = pPass->AnimMode();
uint32 CoordSource = pPass->TexCoordSource(); const uint32 CoordSource = pPass->TexCoordSource();
uint32 TexMtxIdx, PostMtxIdx; uint32 TexMtxIdx, PostMtxIdx;
bool Normalize; bool Normalize;
@ -286,13 +288,11 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
PostMtxIdx = 61; PostMtxIdx = 61;
Normalize = false; Normalize = false;
} }
else // Animation - set parameters as the animation mode needs them
// Animation - set parameters as the animation mode needs them
else
{ {
TexMtxIdx = CurTexMtx; TexMtxIdx = CurTexMtx;
if ((AnimType <= EUVAnimMode::InverseMVTranslated) || (AnimType >= EUVAnimMode::ModelMatrix)) if (AnimType <= EUVAnimMode::InverseMVTranslated || AnimType >= EUVAnimMode::ModelMatrix)
{ {
PostMtxIdx = CurTexMtx; PostMtxIdx = CurTexMtx;
Normalize = true; Normalize = true;
@ -305,24 +305,25 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
CurTexMtx += 3; CurTexMtx += 3;
} }
uint32 TexGenFlags = (CoordSource << 4) | (TexMtxIdx << 9) | (Normalize << 14) | (PostMtxIdx << 15); const uint32 TexGenFlags = (CoordSource << 4) | (TexMtxIdx << 9) | (Normalize << 14) | (PostMtxIdx << 15);
rOut.WriteLong(TexGenFlags); rOut.WriteULong(TexGenFlags);
} }
// Animations // Animations
uint32 AnimSizeOffset = rOut.Tell(); const uint32 AnimSizeOffset = rOut.Tell();
uint32 NumAnims = CurTexMtx; // CurTexMtx is currently equal to the anim count const uint32 NumAnims = CurTexMtx; // CurTexMtx is currently equal to the anim count
rOut.WriteLong(0); // Anim size filler rOut.WriteULong(0); // Anim size filler
uint32 AnimsStart = rOut.Tell(); const uint32 AnimsStart = rOut.Tell();
rOut.WriteLong(NumAnims); rOut.WriteULong(NumAnims);
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (uint32 iPass = 0; iPass < NumPasses; iPass++)
{ {
CMaterialPass *pPass = mpMat->Pass(iPass); CMaterialPass *pPass = mpMat->Pass(iPass);
EUVAnimMode AnimMode = pPass->AnimMode(); EUVAnimMode AnimMode = pPass->AnimMode();
if (AnimMode == EUVAnimMode::NoUVAnim) continue; if (AnimMode == EUVAnimMode::NoUVAnim)
continue;
rOut.WriteLong((int) AnimMode); rOut.WriteLong(static_cast<int>(AnimMode));
if ((AnimMode >= EUVAnimMode::UVScroll) && (AnimMode != EUVAnimMode::ModelMatrix)) if ((AnimMode >= EUVAnimMode::UVScroll) && (AnimMode != EUVAnimMode::ModelMatrix))
{ {
@ -337,10 +338,10 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& rOut)
} }
} }
uint32 AnimsEnd = rOut.Tell(); const uint32 AnimsEnd = rOut.Tell();
uint32 AnimsSize = AnimsEnd - AnimsStart; const uint32 AnimsSize = AnimsEnd - AnimsStart;
rOut.Seek(AnimSizeOffset, SEEK_SET); rOut.Seek(AnimSizeOffset, SEEK_SET);
rOut.WriteLong(AnimsSize); rOut.WriteULong(AnimsSize);
rOut.Seek(AnimsEnd, SEEK_SET); rOut.Seek(AnimsEnd, SEEK_SET);
// Done! // Done!