Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/NarrowPhaseStats.cpp
9913 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#include <Jolt/Jolt.h>
6
7
#include <Jolt/Physics/Collision/NarrowPhaseStats.h>
8
9
#ifdef JPH_TRACK_NARROWPHASE_STATS
10
11
JPH_NAMESPACE_BEGIN
12
13
NarrowPhaseStat NarrowPhaseStat::sCollideShape[NumSubShapeTypes][NumSubShapeTypes];
14
NarrowPhaseStat NarrowPhaseStat::sCastShape[NumSubShapeTypes][NumSubShapeTypes];
15
16
thread_local TrackNarrowPhaseStat *TrackNarrowPhaseStat::sRoot = nullptr;
17
18
void NarrowPhaseStat::ReportStats(const char *inName, EShapeSubType inType1, EShapeSubType inType2, uint64 inTicks100Pct) const
19
{
20
double total_pct = 100.0 * double(mTotalTicks) / double(inTicks100Pct);
21
double total_pct_excl_children = 100.0 * double(mTotalTicks - mChildTicks) / double(inTicks100Pct);
22
23
std::stringstream str;
24
str << inName << ", " << sSubShapeTypeNames[(int)inType1] << ", " << sSubShapeTypeNames[(int)inType2] << ", " << mNumQueries << ", " << total_pct << ", " << total_pct_excl_children << ", " << total_pct_excl_children / mNumQueries << ", " << mHitsReported;
25
Trace(str.str().c_str());
26
}
27
28
void NarrowPhaseStat::sReportStats()
29
{
30
Trace("Query Type, Shape Type 1, Shape Type 2, Num Queries, Total Time (%%), Total Time Excl Children (%%), Total Time Excl. Children / Query (%%), Hits Reported");
31
32
uint64 total_ticks = 0;
33
for (EShapeSubType t1 : sAllSubShapeTypes)
34
for (EShapeSubType t2 : sAllSubShapeTypes)
35
{
36
const NarrowPhaseStat &collide_stat = sCollideShape[(int)t1][(int)t2];
37
total_ticks += collide_stat.mTotalTicks - collide_stat.mChildTicks;
38
39
const NarrowPhaseStat &cast_stat = sCastShape[(int)t1][(int)t2];
40
total_ticks += cast_stat.mTotalTicks - cast_stat.mChildTicks;
41
}
42
43
for (EShapeSubType t1 : sAllSubShapeTypes)
44
for (EShapeSubType t2 : sAllSubShapeTypes)
45
{
46
const NarrowPhaseStat &stat = sCollideShape[(int)t1][(int)t2];
47
if (stat.mNumQueries > 0)
48
stat.ReportStats("CollideShape", t1, t2, total_ticks);
49
}
50
51
for (EShapeSubType t1 : sAllSubShapeTypes)
52
for (EShapeSubType t2 : sAllSubShapeTypes)
53
{
54
const NarrowPhaseStat &stat = sCastShape[(int)t1][(int)t2];
55
if (stat.mNumQueries > 0)
56
stat.ReportStats("CastShape", t1, t2, total_ticks);
57
}
58
}
59
60
JPH_NAMESPACE_END
61
62
#endif // JPH_TRACK_NARROWPHASE_STATS
63
64