Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/NarrowPhaseStats.cpp
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#include <Jolt/Jolt.h>56#include <Jolt/Physics/Collision/NarrowPhaseStats.h>78#ifdef JPH_TRACK_NARROWPHASE_STATS910JPH_NAMESPACE_BEGIN1112NarrowPhaseStat NarrowPhaseStat::sCollideShape[NumSubShapeTypes][NumSubShapeTypes];13NarrowPhaseStat NarrowPhaseStat::sCastShape[NumSubShapeTypes][NumSubShapeTypes];1415thread_local TrackNarrowPhaseStat *TrackNarrowPhaseStat::sRoot = nullptr;1617void NarrowPhaseStat::ReportStats(const char *inName, EShapeSubType inType1, EShapeSubType inType2, uint64 inTicks100Pct) const18{19double total_pct = 100.0 * double(mTotalTicks) / double(inTicks100Pct);20double total_pct_excl_children = 100.0 * double(mTotalTicks - mChildTicks) / double(inTicks100Pct);2122std::stringstream str;23str << inName << ", " << sSubShapeTypeNames[(int)inType1] << ", " << sSubShapeTypeNames[(int)inType2] << ", " << mNumQueries << ", " << total_pct << ", " << total_pct_excl_children << ", " << total_pct_excl_children / mNumQueries << ", " << mHitsReported;24Trace(str.str().c_str());25}2627void NarrowPhaseStat::sReportStats()28{29Trace("Query Type, Shape Type 1, Shape Type 2, Num Queries, Total Time (%%), Total Time Excl Children (%%), Total Time Excl. Children / Query (%%), Hits Reported");3031uint64 total_ticks = 0;32for (EShapeSubType t1 : sAllSubShapeTypes)33for (EShapeSubType t2 : sAllSubShapeTypes)34{35const NarrowPhaseStat &collide_stat = sCollideShape[(int)t1][(int)t2];36total_ticks += collide_stat.mTotalTicks - collide_stat.mChildTicks;3738const NarrowPhaseStat &cast_stat = sCastShape[(int)t1][(int)t2];39total_ticks += cast_stat.mTotalTicks - cast_stat.mChildTicks;40}4142for (EShapeSubType t1 : sAllSubShapeTypes)43for (EShapeSubType t2 : sAllSubShapeTypes)44{45const NarrowPhaseStat &stat = sCollideShape[(int)t1][(int)t2];46if (stat.mNumQueries > 0)47stat.ReportStats("CollideShape", t1, t2, total_ticks);48}4950for (EShapeSubType t1 : sAllSubShapeTypes)51for (EShapeSubType t2 : sAllSubShapeTypes)52{53const NarrowPhaseStat &stat = sCastShape[(int)t1][(int)t2];54if (stat.mNumQueries > 0)55stat.ReportStats("CastShape", t1, t2, total_ticks);56}57}5859JPH_NAMESPACE_END6061#endif // JPH_TRACK_NARROWPHASE_STATS626364