From e875c2bf08b052ca9aa785bd8c283709c7e57f1d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 19 Jun 2020 00:19:42 -0400 Subject: [PATCH] CCollisionLoader: Make use of unsigned helper functions where applicable Same behavior minus several sign conversion warnings. --- .../Resource/Factory/CCollisionLoader.cpp | 154 +++++++++--------- 1 file changed, 76 insertions(+), 78 deletions(-) diff --git a/src/Core/Resource/Factory/CCollisionLoader.cpp b/src/Core/Resource/Factory/CCollisionLoader.cpp index 2c1b1ad7..d83b2a8f 100644 --- a/src/Core/Resource/Factory/CCollisionLoader.cpp +++ b/src/Core/Resource/Factory/CCollisionLoader.cpp @@ -34,11 +34,11 @@ std::unique_ptr CCollisionLoader::ParseOBBNode(IInputStream& DCLN) if (IsLeaf) { auto pLeaf = std::make_unique(); - const uint NumTris = DCLN.ReadLong(); + const uint32 NumTris = DCLN.ReadULong(); pLeaf->TriangleIndices.resize(NumTris); - for (uint i = 0; i < NumTris; i++) - pLeaf->TriangleIndices[i] = DCLN.ReadShort(); + for (auto& index : pLeaf->TriangleIndices) + index = DCLN.ReadShort(); pOut = std::move(pLeaf); } @@ -57,82 +57,80 @@ std::unique_ptr CCollisionLoader::ParseOBBNode(IInputStream& DCLN) void CCollisionLoader::LoadCollisionMaterial(IInputStream& Src, CCollisionMaterial& OutMaterial) { - uint64 RawFlags = (mVersion <= EGame::Prime ? Src.ReadLong() : Src.ReadLongLong()); + const uint64 RawFlags = mVersion <= EGame::Prime ? Src.ReadULong() : Src.ReadULongLong(); OutMaterial.mRawFlags = RawFlags; if (mVersion <= EGame::Prime) { - if (RawFlags & 0x00000001) OutMaterial |= eCF_Unknown; - if (RawFlags & 0x00000002) OutMaterial |= eCF_Stone; - if (RawFlags & 0x00000004) OutMaterial |= eCF_Metal; - if (RawFlags & 0x00000008) OutMaterial |= eCF_Grass; - if (RawFlags & 0x00000010) OutMaterial |= eCF_Ice; - if (RawFlags & 0x00000040) OutMaterial |= eCF_MetalGrating; - if (RawFlags & 0x00000080) OutMaterial |= eCF_Phazon; - if (RawFlags & 0x00000100) OutMaterial |= eCF_Dirt; - if (RawFlags & 0x00000200) OutMaterial |= eCF_Lava; - if (RawFlags & 0x00000800) OutMaterial |= eCF_Snow; - if (RawFlags & 0x00001000) OutMaterial |= eCF_SlowMud; - if (RawFlags & 0x00004000) OutMaterial |= eCF_Mud; - if (RawFlags & 0x00008000) OutMaterial |= eCF_Glass; - if (RawFlags & 0x00010000) OutMaterial |= eCF_Shield; - if (RawFlags & 0x00020000) OutMaterial |= eCF_Sand; - if (RawFlags & 0x00040000) OutMaterial |= eCF_ShootThru; - if (RawFlags & 0x00200000) OutMaterial |= eCF_CameraThru; - if (RawFlags & 0x00400000) OutMaterial |= eCF_Wood; - if (RawFlags & 0x00800000) OutMaterial |= eCF_Organic; - if (RawFlags & 0x02000000) OutMaterial |= eCF_FlippedTri; - if (RawFlags & 0x08000000) OutMaterial |= eCF_ScanThru; - if (RawFlags & 0x10000000) OutMaterial |= eCF_AiWalkThru; - if (RawFlags & 0x20000000) OutMaterial |= eCF_Ceiling; - if (RawFlags & 0x40000000) OutMaterial |= eCF_Wall; - if (RawFlags & 0x80000000) OutMaterial |= eCF_Floor; + if ((RawFlags & 0x00000001) != 0) OutMaterial |= eCF_Unknown; + if ((RawFlags & 0x00000002) != 0) OutMaterial |= eCF_Stone; + if ((RawFlags & 0x00000004) != 0) OutMaterial |= eCF_Metal; + if ((RawFlags & 0x00000008) != 0) OutMaterial |= eCF_Grass; + if ((RawFlags & 0x00000010) != 0) OutMaterial |= eCF_Ice; + if ((RawFlags & 0x00000040) != 0) OutMaterial |= eCF_MetalGrating; + if ((RawFlags & 0x00000080) != 0) OutMaterial |= eCF_Phazon; + if ((RawFlags & 0x00000100) != 0) OutMaterial |= eCF_Dirt; + if ((RawFlags & 0x00000200) != 0) OutMaterial |= eCF_Lava; + if ((RawFlags & 0x00000800) != 0) OutMaterial |= eCF_Snow; + if ((RawFlags & 0x00001000) != 0) OutMaterial |= eCF_SlowMud; + if ((RawFlags & 0x00004000) != 0) OutMaterial |= eCF_Mud; + if ((RawFlags & 0x00008000) != 0) OutMaterial |= eCF_Glass; + if ((RawFlags & 0x00010000) != 0) OutMaterial |= eCF_Shield; + if ((RawFlags & 0x00020000) != 0) OutMaterial |= eCF_Sand; + if ((RawFlags & 0x00040000) != 0) OutMaterial |= eCF_ShootThru; + if ((RawFlags & 0x00200000) != 0) OutMaterial |= eCF_CameraThru; + if ((RawFlags & 0x00400000) != 0) OutMaterial |= eCF_Wood; + if ((RawFlags & 0x00800000) != 0) OutMaterial |= eCF_Organic; + if ((RawFlags & 0x02000000) != 0) OutMaterial |= eCF_FlippedTri; + if ((RawFlags & 0x08000000) != 0) OutMaterial |= eCF_ScanThru; + if ((RawFlags & 0x10000000) != 0) OutMaterial |= eCF_AiWalkThru; + if ((RawFlags & 0x20000000) != 0) OutMaterial |= eCF_Ceiling; + if ((RawFlags & 0x40000000) != 0) OutMaterial |= eCF_Wall; + if ((RawFlags & 0x80000000) != 0) OutMaterial |= eCF_Floor; } - else if (mVersion <= EGame::Corruption) { - if (RawFlags & 0x00000001) OutMaterial |= eCF_Unknown; - if (RawFlags & 0x00000002) OutMaterial |= eCF_Stone; - if (RawFlags & 0x00000004) OutMaterial |= eCF_Metal; - if (RawFlags & 0x00000008) OutMaterial |= eCF_Grass; - if (RawFlags & 0x00000010) OutMaterial |= eCF_Ice; - if (RawFlags & 0x00000040) OutMaterial |= eCF_MetalGrating; - if (RawFlags & 0x00000080) OutMaterial |= eCF_Phazon; - if (RawFlags & 0x00000100) OutMaterial |= eCF_Dirt; - if (RawFlags & 0x00000200) OutMaterial |= eCF_AltMetal; - if (RawFlags & 0x00000400) OutMaterial |= eCF_Glass; - if (RawFlags & 0x00000800) OutMaterial |= eCF_Snow; - if (RawFlags & 0x00001000) OutMaterial |= eCF_Fabric; - if (RawFlags & 0x00010000) OutMaterial |= eCF_Shield; - if (RawFlags & 0x00020000) OutMaterial |= eCF_Sand; - if (RawFlags & 0x00040000) OutMaterial |= eCF_MothSeedOrganics; - if (RawFlags & 0x00080000) OutMaterial |= eCF_Web; - if (RawFlags & 0x00100000) OutMaterial |= eCF_ShootThru; - if (RawFlags & 0x00200000) OutMaterial |= eCF_CameraThru; - if (RawFlags & 0x00400000) OutMaterial |= eCF_Wood; - if (RawFlags & 0x00800000) OutMaterial |= eCF_Organic; - if (RawFlags & 0x01000000) OutMaterial |= eCF_FlippedTri; - if (RawFlags & 0x02000000) OutMaterial |= eCF_Rubber; - if (RawFlags & 0x08000000) OutMaterial |= eCF_ScanThru; - if (RawFlags & 0x10000000) OutMaterial |= eCF_AiWalkThru; - if (RawFlags & 0x20000000) OutMaterial |= eCF_Ceiling; - if (RawFlags & 0x40000000) OutMaterial |= eCF_Wall; - if (RawFlags & 0x80000000) OutMaterial |= eCF_Floor; + if ((RawFlags & 0x00000001) != 0) OutMaterial |= eCF_Unknown; + if ((RawFlags & 0x00000002) != 0) OutMaterial |= eCF_Stone; + if ((RawFlags & 0x00000004) != 0) OutMaterial |= eCF_Metal; + if ((RawFlags & 0x00000008) != 0) OutMaterial |= eCF_Grass; + if ((RawFlags & 0x00000010) != 0) OutMaterial |= eCF_Ice; + if ((RawFlags & 0x00000040) != 0) OutMaterial |= eCF_MetalGrating; + if ((RawFlags & 0x00000080) != 0) OutMaterial |= eCF_Phazon; + if ((RawFlags & 0x00000100) != 0) OutMaterial |= eCF_Dirt; + if ((RawFlags & 0x00000200) != 0) OutMaterial |= eCF_AltMetal; + if ((RawFlags & 0x00000400) != 0) OutMaterial |= eCF_Glass; + if ((RawFlags & 0x00000800) != 0) OutMaterial |= eCF_Snow; + if ((RawFlags & 0x00001000) != 0) OutMaterial |= eCF_Fabric; + if ((RawFlags & 0x00010000) != 0) OutMaterial |= eCF_Shield; + if ((RawFlags & 0x00020000) != 0) OutMaterial |= eCF_Sand; + if ((RawFlags & 0x00040000) != 0) OutMaterial |= eCF_MothSeedOrganics; + if ((RawFlags & 0x00080000) != 0) OutMaterial |= eCF_Web; + if ((RawFlags & 0x00100000) != 0) OutMaterial |= eCF_ShootThru; + if ((RawFlags & 0x00200000) != 0) OutMaterial |= eCF_CameraThru; + if ((RawFlags & 0x00400000) != 0) OutMaterial |= eCF_Wood; + if ((RawFlags & 0x00800000) != 0) OutMaterial |= eCF_Organic; + if ((RawFlags & 0x01000000) != 0) OutMaterial |= eCF_FlippedTri; + if ((RawFlags & 0x02000000) != 0) OutMaterial |= eCF_Rubber; + if ((RawFlags & 0x08000000) != 0) OutMaterial |= eCF_ScanThru; + if ((RawFlags & 0x10000000) != 0) OutMaterial |= eCF_AiWalkThru; + if ((RawFlags & 0x20000000) != 0) OutMaterial |= eCF_Ceiling; + if ((RawFlags & 0x40000000) != 0) OutMaterial |= eCF_Wall; + if ((RawFlags & 0x80000000) != 0) OutMaterial |= eCF_Floor; - if (RawFlags & 0x0001000000000000) OutMaterial |= eCF_AiBlock; - if (RawFlags & 0x0400000000000000) OutMaterial |= eCF_JumpNotAllowed; + if ((RawFlags & 0x0001000000000000) != 0) OutMaterial |= eCF_AiBlock; + if ((RawFlags & 0x0400000000000000) != 0) OutMaterial |= eCF_JumpNotAllowed; } - else if (mVersion == EGame::DKCReturns) { - if (RawFlags & 0x10000000) OutMaterial |= eCF_FlippedTri; + if ((RawFlags & 0x10000000) != 0) OutMaterial |= eCF_FlippedTri; } } void CCollisionLoader::LoadCollisionIndices(IInputStream& File, SCollisionIndexData& OutData) { // Materials - const uint NumMaterials = File.ReadLong(); + const uint32 NumMaterials = File.ReadULong(); OutData.Materials.resize(NumMaterials); for (auto& material : OutData.Materials) @@ -141,45 +139,45 @@ void CCollisionLoader::LoadCollisionIndices(IInputStream& File, SCollisionIndexD } // Property indices for vertices/edges/triangles - const uint32 VertexMaterialCount = File.ReadLong(); + const uint32 VertexMaterialCount = File.ReadULong(); OutData.VertexMaterialIndices.resize(VertexMaterialCount); File.ReadBytes(OutData.VertexMaterialIndices.data(), VertexMaterialCount); - const uint32 EdgeMaterialCount = File.ReadLong(); + const uint32 EdgeMaterialCount = File.ReadULong(); OutData.EdgeMaterialIndices.resize(EdgeMaterialCount); File.ReadBytes(OutData.EdgeMaterialIndices.data(), EdgeMaterialCount); - const uint32 TriMaterialCount = File.ReadLong(); + const uint32 TriMaterialCount = File.ReadULong(); OutData.TriangleMaterialIndices.resize(TriMaterialCount); File.ReadBytes(OutData.TriangleMaterialIndices.data(), TriMaterialCount); // Edges - const uint32 NumEdges = File.ReadLong(); + const uint32 NumEdges = File.ReadULong(); OutData.EdgeIndices.resize(NumEdges * 2); for (auto& edge : OutData.EdgeIndices) { - edge = File.ReadShort(); + edge = File.ReadUShort(); } // Triangles - const uint32 NumTris = File.ReadLong(); + const uint32 NumTris = File.ReadULong(); OutData.TriangleIndices.resize(NumTris); for (auto& triangle : OutData.TriangleIndices) { - triangle = File.ReadShort(); + triangle = File.ReadUShort(); } // Echoes introduces a new data chunk; don't know what it is yet, skipping for now if (mVersion >= EGame::Echoes) { - const uint32 UnknownCount = File.ReadLong(); + const uint32 UnknownCount = File.ReadULong(); File.Skip(UnknownCount * 2); } // Vertices - const uint32 NumVertices = File.ReadLong(); + const uint32 NumVertices = File.ReadULong(); OutData.Vertices.resize(NumVertices); for (auto& vert : OutData.Vertices) @@ -197,7 +195,7 @@ std::unique_ptr CCollisionLoader::LoadAreaCollision(IInputS rMREA.Skip(0x8); // Skipping unknown value + collion section size // Validate magic - uint32 DeafBabe = rMREA.ReadLong(); + const uint32 DeafBabe = rMREA.ReadULong(); if (DeafBabe != 0xDEAFBABE) { errorf("%s [0x%X]: Invalid collision magic: 0x%08X", *rMREA.GetSourceString(), rMREA.Tell() - 4, DeafBabe); @@ -207,13 +205,13 @@ std::unique_ptr CCollisionLoader::LoadAreaCollision(IInputS auto mesh = std::make_unique(); CCollisionLoader Loader; - Loader.mVersion = GetFormatVersion(rMREA.ReadLong()); + Loader.mVersion = GetFormatVersion(rMREA.ReadULong()); Loader.mpMesh = mesh.get(); // Octree - structure is known, but not coding this right now Loader.mpMesh->mAABox = CAABox(rMREA); rMREA.Skip(0x4); - uint32 OctreeSize = rMREA.ReadLong(); + const uint32 OctreeSize = rMREA.ReadULong(); rMREA.Skip(OctreeSize); // Skipping the octree for now // Read collision indices and return @@ -233,11 +231,11 @@ std::unique_ptr CCollisionLoader::LoadDCLN(IInputStream& rD CCollisionLoader Loader; Loader.mpGroup = ptr.get(); - const uint32 NumMeshes = rDCLN.ReadLong(); + const uint32 NumMeshes = rDCLN.ReadULong(); for (uint32 MeshIdx = 0; MeshIdx < NumMeshes; MeshIdx++) { - const uint32 DeafBabe = rDCLN.ReadLong(); + const uint32 DeafBabe = rDCLN.ReadULong(); if (DeafBabe != 0xDEAFBABE) { @@ -246,7 +244,7 @@ std::unique_ptr CCollisionLoader::LoadDCLN(IInputStream& rD } auto mesh = std::make_unique(); - Loader.mVersion = GetFormatVersion(rDCLN.ReadLong()); + Loader.mVersion = GetFormatVersion(rDCLN.ReadULong()); Loader.mpMesh = mesh.get(); if (Loader.mVersion == EGame::DKCReturns) @@ -269,7 +267,7 @@ std::unique_ptr CCollisionLoader::LoadDCLN(IInputStream& rD } // Parse OBB tree - CCollidableOBBTree* pOBBTree = static_cast(Loader.mpMesh); + auto* pOBBTree = static_cast(Loader.mpMesh); pOBBTree->mpOBBTree = Loader.ParseOBBNode(rDCLN); }