CModelLoader: Make use of unsigned stream helpers where applicable

Same behavior without implicit sign conversions
This commit is contained in:
Lioncash 2020-06-19 02:50:38 -04:00
parent 80e4790384
commit 73d010e6d1
1 changed files with 27 additions and 27 deletions

View File

@ -98,11 +98,11 @@ void CModelLoader::LoadAttribArrays(IInputStream& rModel)
void CModelLoader::LoadSurfaceOffsets(IInputStream& rModel) void CModelLoader::LoadSurfaceOffsets(IInputStream& rModel)
{ {
mSurfaceCount = rModel.ReadLong(); mSurfaceCount = rModel.ReadULong();
mSurfaceOffsets.resize(mSurfaceCount); mSurfaceOffsets.resize(mSurfaceCount);
for (size_t iSurf = 0; iSurf < mSurfaceCount; iSurf++) for (size_t iSurf = 0; iSurf < mSurfaceCount; iSurf++)
mSurfaceOffsets[iSurf] = rModel.ReadLong(); mSurfaceOffsets[iSurf] = rModel.ReadULong();
mpSectionMgr->ToNextSection(); mpSectionMgr->ToNextSection();
} }
@ -121,14 +121,14 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
CMaterial *pMat = mMaterials[0]->MaterialByIndex(pSurf->MaterialID, false); CMaterial *pMat = mMaterials[0]->MaterialByIndex(pSurf->MaterialID, false);
// Primitive table // Primitive table
uint8 Flag = rModel.ReadByte(); uint8 Flag = rModel.ReadUByte();
const uint32 NextSurface = mpSectionMgr->NextOffset(); const uint32 NextSurface = mpSectionMgr->NextOffset();
while (Flag != 0 && (static_cast<uint32>(rModel.Tell()) < NextSurface)) while (Flag != 0 && (static_cast<uint32>(rModel.Tell()) < NextSurface))
{ {
SSurface::SPrimitive Prim; SSurface::SPrimitive Prim;
Prim.Type = EPrimitiveType(Flag & 0xF8); Prim.Type = EPrimitiveType(Flag & 0xF8);
const uint16 VertexCount = rModel.ReadShort(); const uint16 VertexCount = rModel.ReadUShort();
for (uint16 iVtx = 0; iVtx < VertexCount; iVtx++) for (uint16 iVtx = 0; iVtx < VertexCount; iVtx++)
{ {
@ -148,7 +148,7 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
// Position // Position
if ((VtxDesc & EVertexAttribute::Position) != 0) if ((VtxDesc & EVertexAttribute::Position) != 0)
{ {
const uint16 PosIndex = rModel.ReadShort() & 0xFFFF; const uint16 PosIndex = rModel.ReadUShort() & 0xFFFF;
Vtx.Position = mPositions[PosIndex]; Vtx.Position = mPositions[PosIndex];
Vtx.ArrayPosition = PosIndex; Vtx.ArrayPosition = PosIndex;
@ -158,13 +158,13 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
// Normal // Normal
if ((VtxDesc & EVertexAttribute::Normal) != 0) if ((VtxDesc & EVertexAttribute::Normal) != 0)
Vtx.Normal = mNormals[rModel.ReadShort() & 0xFFFF]; Vtx.Normal = mNormals[rModel.ReadUShort() & 0xFFFF];
// Color // Color
for (size_t iClr = 0; iClr < Vtx.Color.size(); iClr++) for (size_t iClr = 0; iClr < Vtx.Color.size(); iClr++)
{ {
if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Color0 << iClr)) != 0) if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Color0 << iClr)) != 0)
Vtx.Color[iClr] = mColors[rModel.ReadShort() & 0xFFFF]; Vtx.Color[iClr] = mColors[rModel.ReadUShort() & 0xFFFF];
} }
// Tex Coords - these are done a bit differently in DKCR than in the Prime series // Tex Coords - these are done a bit differently in DKCR than in the Prime series
@ -174,16 +174,16 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
if ((VtxDesc & EVertexAttribute::Tex0) != 0) if ((VtxDesc & EVertexAttribute::Tex0) != 0)
{ {
if ((mFlags & EModelLoaderFlag::LightmapUVs) != 0 && (pMat->Options() & EMaterialOption::ShortTexCoord) != 0) if ((mFlags & EModelLoaderFlag::LightmapUVs) != 0 && (pMat->Options() & EMaterialOption::ShortTexCoord) != 0)
Vtx.Tex[0] = mTex1[rModel.ReadShort() & 0xFFFF]; Vtx.Tex[0] = mTex1[rModel.ReadUShort() & 0xFFFF];
else else
Vtx.Tex[0] = mTex0[rModel.ReadShort() & 0xFFFF]; Vtx.Tex[0] = mTex0[rModel.ReadUShort() & 0xFFFF];
} }
// Tex1-7 // Tex1-7
for (size_t iTex = 1; iTex < 7; iTex++) for (size_t iTex = 1; iTex < 7; iTex++)
{ {
if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Tex0 << iTex)) != 0) if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Tex0 << iTex)) != 0)
Vtx.Tex[iTex] = mTex0[rModel.ReadShort() & 0xFFFF]; Vtx.Tex[iTex] = mTex0[rModel.ReadUShort() & 0xFFFF];
} }
} }
else else
@ -194,9 +194,9 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Tex0 << iTex)) != 0) if ((VtxDesc & static_cast<uint32>(EVertexAttribute::Tex0 << iTex)) != 0)
{ {
if (!mSurfaceUsingTex1) if (!mSurfaceUsingTex1)
Vtx.Tex[iTex] = mTex0[rModel.ReadShort() & 0xFFFF]; Vtx.Tex[iTex] = mTex0[rModel.ReadUShort() & 0xFFFF];
else else
Vtx.Tex[iTex] = mTex1[rModel.ReadShort() & 0xFFFF]; Vtx.Tex[iTex] = mTex1[rModel.ReadUShort() & 0xFFFF];
} }
} }
} }
@ -231,10 +231,10 @@ SSurface* CModelLoader::LoadSurface(IInputStream& rModel)
void CModelLoader::LoadSurfaceHeaderPrime(IInputStream& rModel, SSurface *pSurf) void CModelLoader::LoadSurfaceHeaderPrime(IInputStream& rModel, SSurface *pSurf)
{ {
pSurf->CenterPoint = CVector3f(rModel); pSurf->CenterPoint = CVector3f(rModel);
pSurf->MaterialID = rModel.ReadLong(); pSurf->MaterialID = rModel.ReadULong();
rModel.Seek(0xC, SEEK_CUR); rModel.Seek(0xC, SEEK_CUR);
uint32 ExtraSize = rModel.ReadLong(); uint32 ExtraSize = rModel.ReadULong();
pSurf->ReflectionDirection = CVector3f(rModel); pSurf->ReflectionDirection = CVector3f(rModel);
if (mVersion >= EGame::EchoesDemo) if (mVersion >= EGame::EchoesDemo)
@ -261,10 +261,10 @@ void CModelLoader::LoadSurfaceHeaderDKCR(IInputStream& rModel, SSurface *pSurf)
{ {
pSurf->CenterPoint = CVector3f(rModel); pSurf->CenterPoint = CVector3f(rModel);
rModel.Seek(0xE, SEEK_CUR); rModel.Seek(0xE, SEEK_CUR);
pSurf->MaterialID = static_cast<uint32>(rModel.ReadShort()); pSurf->MaterialID = rModel.ReadUShort();
rModel.Seek(0x2, SEEK_CUR); rModel.Seek(0x2, SEEK_CUR);
mSurfaceUsingTex1 = (rModel.ReadByte() == 1); mSurfaceUsingTex1 = rModel.ReadUByte() == 1;
uint32 ExtraSize = static_cast<uint8>(rModel.ReadByte()); uint32 ExtraSize = rModel.ReadUByte();
if (ExtraSize > 0) if (ExtraSize > 0)
{ {
@ -395,7 +395,7 @@ std::unique_ptr<CModel> CModelLoader::LoadCMDL(IInputStream& rCMDL, CResourceEnt
CModelLoader Loader; CModelLoader Loader;
// CMDL header - same across the three Primes, but different structure in DKCR // CMDL header - same across the three Primes, but different structure in DKCR
const uint32 Magic = rCMDL.ReadLong(); const uint32 Magic = rCMDL.ReadULong();
uint32 Version, BlockCount, MatSetCount; uint32 Version, BlockCount, MatSetCount;
CAABox AABox; CAABox AABox;
@ -403,11 +403,11 @@ std::unique_ptr<CModel> CModelLoader::LoadCMDL(IInputStream& rCMDL, CResourceEnt
// 0xDEADBABE - Metroid Prime seres // 0xDEADBABE - Metroid Prime seres
if (Magic == 0xDEADBABE) if (Magic == 0xDEADBABE)
{ {
Version = rCMDL.ReadLong(); Version = rCMDL.ReadULong();
const uint32 Flags = rCMDL.ReadLong(); const uint32 Flags = rCMDL.ReadULong();
AABox = CAABox(rCMDL); AABox = CAABox(rCMDL);
BlockCount = rCMDL.ReadLong(); BlockCount = rCMDL.ReadULong();
MatSetCount = rCMDL.ReadLong(); MatSetCount = rCMDL.ReadULong();
if ((Flags & 0x1) != 0) if ((Flags & 0x1) != 0)
Loader.mFlags |= EModelLoaderFlag::Skinned; Loader.mFlags |= EModelLoaderFlag::Skinned;
@ -421,10 +421,10 @@ std::unique_ptr<CModel> CModelLoader::LoadCMDL(IInputStream& rCMDL, CResourceEnt
else if (Magic == 0x9381000A) else if (Magic == 0x9381000A)
{ {
Version = Magic & 0xFFFF; Version = Magic & 0xFFFF;
const uint32 Flags = rCMDL.ReadLong(); const uint32 Flags = rCMDL.ReadULong();
AABox = CAABox(rCMDL); AABox = CAABox(rCMDL);
BlockCount = rCMDL.ReadLong(); BlockCount = rCMDL.ReadULong();
MatSetCount = rCMDL.ReadLong(); MatSetCount = rCMDL.ReadULong();
// todo: unknown flags // todo: unknown flags
Loader.mFlags = EModelLoaderFlag::HalfPrecisionNormals | EModelLoaderFlag::LightmapUVs; Loader.mFlags = EModelLoaderFlag::HalfPrecisionNormals | EModelLoaderFlag::LightmapUVs;
@ -438,11 +438,11 @@ std::unique_ptr<CModel> CModelLoader::LoadCMDL(IInputStream& rCMDL, CResourceEnt
if ((Flags & 0x10) != 0) if ((Flags & 0x10) != 0)
{ {
rCMDL.Seek(0x4, SEEK_CUR); rCMDL.Seek(0x4, SEEK_CUR);
const uint32 VisGroupCount = rCMDL.ReadLong(); const uint32 VisGroupCount = rCMDL.ReadULong();
for (uint32 iVis = 0; iVis < VisGroupCount; iVis++) for (uint32 iVis = 0; iVis < VisGroupCount; iVis++)
{ {
const uint32 NameLength = rCMDL.ReadLong(); const uint32 NameLength = rCMDL.ReadULong();
rCMDL.Seek(NameLength, SEEK_CUR); rCMDL.Seek(NameLength, SEEK_CUR);
} }