diff --git a/src/Core/CRayCollisionTester.cpp b/src/Core/CRayCollisionTester.cpp index 34d06500..d84edbb3 100644 --- a/src/Core/CRayCollisionTester.cpp +++ b/src/Core/CRayCollisionTester.cpp @@ -24,10 +24,10 @@ void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel) // Check each of the model's surfaces and queue them for further testing if they hit for (uint32 iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) { - std::pair SurfResult = pModel->GetSurfaceAABox(iSurf).Transformed(pNode->Transform()).IntersectsRay(mRay); + const auto [intersects, distance] = pModel->GetSurfaceAABox(iSurf).Transformed(pNode->Transform()).IntersectsRay(mRay); - if (SurfResult.first) - AddNode(pNode, iSurf, SurfResult.second); + if (intersects) + AddNode(pNode, iSurf, distance); } } diff --git a/src/Core/Resource/Area/CGameArea.cpp b/src/Core/Resource/Area/CGameArea.cpp index ffb2bace..38c48ecb 100644 --- a/src/Core/Resource/Area/CGameArea.cpp +++ b/src/Core/Resource/Area/CGameArea.cpp @@ -61,18 +61,17 @@ void CGameArea::MergeTerrain() if (mTerrainMerged) return; // Nothing really complicated here - iterate through every terrain submesh, add each to a static model - for (uint32 iMdl = 0; iMdl < mWorldModels.size(); iMdl++) + for (auto& pMdl : mWorldModels) { - auto& pMdl = mWorldModels[iMdl]; - uint32 SubmeshCount = pMdl->GetSurfaceCount(); + const size_t SubmeshCount = pMdl->GetSurfaceCount(); - for (uint32 iSurf = 0; iSurf < SubmeshCount; iSurf++) + for (size_t iSurf = 0; iSurf < SubmeshCount; iSurf++) { SSurface *pSurf = pMdl->GetSurface(iSurf); CMaterial *pMat = mpMaterialSet->MaterialByIndex(pSurf->MaterialID, false); bool NewMat = true; - for (auto it = mStaticWorldModels.begin(); it != mStaticWorldModels.end(); it++) + for (auto it = mStaticWorldModels.begin(); it != mStaticWorldModels.end(); ++it) { if ((*it)->GetMaterial() == pMat) { diff --git a/src/Core/Resource/Cooker/CAreaCooker.cpp b/src/Core/Resource/Cooker/CAreaCooker.cpp index 225c5f58..b43ed913 100644 --- a/src/Core/Resource/Cooker/CAreaCooker.cpp +++ b/src/Core/Resource/Cooker/CAreaCooker.cpp @@ -15,7 +15,7 @@ void CAreaCooker::DetermineSectionNumbersPrime() // Determine how many sections are taken up by geometry... // Each world mesh has 7-9 sections (depending on game) plus one section per surface. uint32 GeometrySections = 0; - uint32 OriginalMeshCount = mpArea->mOriginalWorldMeshCount; + const uint32 OriginalMeshCount = mpArea->mOriginalWorldMeshCount; switch (mVersion) { @@ -38,8 +38,10 @@ void CAreaCooker::DetermineSectionNumbersPrime() // Set section numbers uint32 SecNum = GeometrySections; - if (mVersion <= EGame::Prime) mAROTSecNum = SecNum++; - if (mVersion >= EGame::EchoesDemo) mFFFFSecNum = SecNum++; + if (mVersion <= EGame::Prime) + mAROTSecNum = SecNum++; + if (mVersion >= EGame::EchoesDemo) + mFFFFSecNum = SecNum++; if (mVersion >= EGame::EchoesDemo) { @@ -48,7 +50,9 @@ void CAreaCooker::DetermineSectionNumbersPrime() mSCGNSecNum = SecNum++; } else + { mSCLYSecNum = SecNum++; + } mCollisionSecNum = SecNum++; mUnknownSecNum = SecNum++; diff --git a/src/Core/Resource/Factory/CAreaLoader.cpp b/src/Core/Resource/Factory/CAreaLoader.cpp index d51e1682..e207acc0 100644 --- a/src/Core/Resource/Factory/CAreaLoader.cpp +++ b/src/Core/Resource/Factory/CAreaLoader.cpp @@ -86,9 +86,9 @@ void CAreaLoader::ReadGeometryPrime() else // For Echoes+, load surface mesh IDs, then skip to the start of the next mesh { auto& pModel = FileModels.emplace_back(CModelLoader::LoadWorldModel(*mpMREA, *mpSectionMgr, *mpArea->mpMaterialSet, mVersion)); - const uint16 NumSurfaces = mpMREA->ReadShort(); + const size_t NumSurfaces = mpMREA->ReadShort(); - for (uint32 iSurf = 0; iSurf < NumSurfaces; iSurf++) + for (size_t iSurf = 0; iSurf < NumSurfaces; iSurf++) { mpMREA->Seek(0x2, SEEK_CUR); pModel->GetSurface(iSurf)->MeshID = mpMREA->ReadShort(); @@ -391,9 +391,9 @@ void CAreaLoader::ReadGeometryCorruption() // Load surface mesh IDs mpSectionMgr->ToSection(CurWOBJSection - 2); - uint16 NumSurfaces = mpMREA->ReadShort(); + const size_t NumSurfaces = mpMREA->ReadShort(); - for (uint32 iSurf = 0; iSurf < NumSurfaces; iSurf++) + for (size_t iSurf = 0; iSurf < NumSurfaces; iSurf++) { mpMREA->Seek(0x2, SEEK_CUR); pWorldModel->GetSurface(iSurf)->MeshID = mpMREA->ReadShort(); diff --git a/src/Core/Resource/Model/CBasicModel.cpp b/src/Core/Resource/Model/CBasicModel.cpp index da0bb318..f0bbc5d5 100644 --- a/src/Core/Resource/Model/CBasicModel.cpp +++ b/src/Core/Resource/Model/CBasicModel.cpp @@ -1,6 +1,4 @@ #include "CBasicModel.h" -#include -#include CBasicModel::CBasicModel(CResourceEntry *pEntry) : CResource(pEntry) @@ -14,12 +12,12 @@ CBasicModel::~CBasicModel() delete mSurfaces[iSurf]; } -uint32 CBasicModel::GetVertexCount() const +size_t CBasicModel::GetVertexCount() const { return mVertexCount; } -uint32 CBasicModel::GetTriangleCount() const +size_t CBasicModel::GetTriangleCount() const { return mTriangleCount; } @@ -34,17 +32,17 @@ bool CBasicModel::IsBuffered() const return mBuffered; } -uint32 CBasicModel::GetSurfaceCount() const +size_t CBasicModel::GetSurfaceCount() const { return mSurfaces.size(); } -CAABox CBasicModel::GetSurfaceAABox(uint32 Surface) const +CAABox CBasicModel::GetSurfaceAABox(size_t Surface) const { return mSurfaces[Surface]->AABox; } -SSurface* CBasicModel::GetSurface(uint32 Surface) +SSurface* CBasicModel::GetSurface(size_t Surface) { return mSurfaces[Surface]; } diff --git a/src/Core/Resource/Model/CBasicModel.h b/src/Core/Resource/Model/CBasicModel.h index 86d7ad30..83f1cf2d 100644 --- a/src/Core/Resource/Model/CBasicModel.h +++ b/src/Core/Resource/Model/CBasicModel.h @@ -24,13 +24,13 @@ public: explicit CBasicModel(CResourceEntry *pEntry = nullptr); ~CBasicModel(); - uint32 GetVertexCount() const; - uint32 GetTriangleCount() const; + size_t GetVertexCount() const; + size_t GetTriangleCount() const; CAABox AABox() const; bool IsBuffered() const; - uint32 GetSurfaceCount() const; - CAABox GetSurfaceAABox(uint32 Surface) const; - SSurface* GetSurface(uint32 Surface); + size_t GetSurfaceCount() const; + CAABox GetSurfaceAABox(size_t Surface) const; + SSurface* GetSurface(size_t Surface); virtual void ClearGLBuffer() = 0; }; diff --git a/src/Core/Scene/CModelNode.cpp b/src/Core/Scene/CModelNode.cpp index 066f6551..61b553f7 100644 --- a/src/Core/Scene/CModelNode.cpp +++ b/src/Core/Scene/CModelNode.cpp @@ -152,9 +152,10 @@ SRayIntersection CModelNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Asse CVector3f WorldHitPoint = Transform() * HitPoint; Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } - else + { Out.Hit = false; + } return Out; } diff --git a/src/Core/Scene/CScriptAttachNode.cpp b/src/Core/Scene/CScriptAttachNode.cpp index 8b5cec8e..2b93dc8e 100644 --- a/src/Core/Scene/CScriptAttachNode.cpp +++ b/src/Core/Scene/CScriptAttachNode.cpp @@ -135,8 +135,10 @@ SRayIntersection CScriptAttachNode::RayNodeIntersectTest(const CRay& rkRay, uint CVector3f WorldHitPoint = Transform() * HitPoint; Out.Distance = rkRay.Origin().Distance(WorldHitPoint); } - - else Out.Hit = false; + else + { + Out.Hit = false; + } return Out; } diff --git a/src/Core/Scene/CScriptNode.cpp b/src/Core/Scene/CScriptNode.cpp index 12057f54..55cd3c94 100644 --- a/src/Core/Scene/CScriptNode.cpp +++ b/src/Core/Scene/CScriptNode.cpp @@ -354,7 +354,8 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Ass if (UsesModel()) { CModel *pModel = ActiveModel(); - if (!pModel) pModel = CDrawUtil::GetCubeModel(); + if (!pModel) + pModel = CDrawUtil::GetCubeModel(); CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); std::pair Result = pModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & ERenderOption::EnableBackfaceCull) == 0)); @@ -367,9 +368,10 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Ass CVector3f WorldHitPoint = Transform() * HitPoint; Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } - else + { Out.Hit = false; + } } // Billboard test @@ -403,8 +405,9 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Ass float TexelAlpha = ActiveBillboard()->ReadTexelAlpha(TexCoord); if (TexelAlpha < 0.25f) + { Out.Hit = false; - + } else { // It's opaque... we have a hit! @@ -412,13 +415,15 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Ass Out.Distance = PlaneTest.second; } } - else + { Out.Hit = false; + } } - else + { Out.Hit = false; + } } return Out; diff --git a/src/Core/Scene/CStaticNode.cpp b/src/Core/Scene/CStaticNode.cpp index f43922c5..d9250c82 100644 --- a/src/Core/Scene/CStaticNode.cpp +++ b/src/Core/Scene/CStaticNode.cpp @@ -29,16 +29,22 @@ void CStaticNode::PostLoad() void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo) { - if (!mpModel) return; - if (mpModel->IsOccluder()) return; - if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; + if (!mpModel) + return; + + if (mpModel->IsOccluder()) + return; + + if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) + return; if (!mpModel->IsTransparent()) + { pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawMesh); - + } else { - uint32 NumSurfaces = mpModel->GetSurfaceCount(); + const size_t NumSurfaces = mpModel->GetSurfaceCount(); for (uint32 iSurf = 0; iSurf < NumSurfaces; iSurf++) { CAABox TransformedBox = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()); @@ -96,21 +102,21 @@ void CStaticNode::DrawSelection() void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/) { - if ((!mpModel) || (mpModel->IsOccluder())) + if (!mpModel || mpModel->IsOccluder()) return; const CRay& rkRay = rTester.Ray(); - std::pair BoxResult = AABox().IntersectsRay(rkRay); + const std::pair BoxResult = AABox().IntersectsRay(rkRay); - if (BoxResult.first) + if (!BoxResult.first) + return; + + for (uint32 iSurf = 0; iSurf < mpModel->GetSurfaceCount(); iSurf++) { - for (uint32 iSurf = 0; iSurf < mpModel->GetSurfaceCount(); iSurf++) - { - std::pair SurfResult = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(rkRay); + const auto [intersects, distance] = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(rkRay); - if (SurfResult.first) - rTester.AddNode(this, iSurf, SurfResult.second); - } + if (intersects) + rTester.AddNode(this, iSurf, distance); } } @@ -120,21 +126,22 @@ SRayIntersection CStaticNode::RayNodeIntersectTest(const CRay& rkRay, uint32 Ass Out.pNode = this; Out.ComponentIndex = AssetID; - CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); - FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); - std::pair Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & ERenderOption::EnableBackfaceCull) == 0)); + const CRay TransformedRay = rkRay.Transformed(Transform().Inverse()); + const FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions(); + const auto [intersects, distance] = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & ERenderOption::EnableBackfaceCull) == 0)); - if (Result.first) + if (intersects) { Out.Hit = true; - CVector3f HitPoint = TransformedRay.PointOnRay(Result.second); - CVector3f WorldHitPoint = Transform() * HitPoint; + const CVector3f HitPoint = TransformedRay.PointOnRay(distance); + const CVector3f WorldHitPoint = Transform() * HitPoint; Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint); } - else + { Out.Hit = false; + } return Out; } diff --git a/src/Core/ScriptExtra/CDoorExtra.cpp b/src/Core/ScriptExtra/CDoorExtra.cpp index 324e096d..ab598701 100644 --- a/src/Core/ScriptExtra/CDoorExtra.cpp +++ b/src/Core/ScriptExtra/CDoorExtra.cpp @@ -121,8 +121,10 @@ SRayIntersection CDoorExtra::RayNodeIntersectTest(const CRay& rkRay, uint32 Asse CVector3f WorldHitPoint = Transform() * HitPoint; Out.Distance = rkRay.Origin().Distance(WorldHitPoint); } - - else Out.Hit = false; + else + { + Out.Hit = false; + } return Out; } diff --git a/src/Editor/CGizmo.cpp b/src/Editor/CGizmo.cpp index a017a2ff..b4dd890d 100644 --- a/src/Editor/CGizmo.cpp +++ b/src/Editor/CGizmo.cpp @@ -163,7 +163,7 @@ bool CGizmo::CheckSelectedAxes(const CRay& rkRay) bool Hit = false; float Dist; - for (uint32 iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) + for (size_t iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) { // Skip surface/box check - since we use lines the boxes might be too small SSurface *pSurf = pModel->GetSurface(iSurf); @@ -171,7 +171,7 @@ bool CGizmo::CheckSelectedAxes(const CRay& rkRay) if (SurfCheck.first) { - if ((!Hit) || (SurfCheck.second < Dist)) + if (!Hit || SurfCheck.second < Dist) Dist = SurfCheck.second; Hit = true;