Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
NarrowPhaseStats.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic")
12
13// Shorthand function to ifdef out code if narrow phase stats tracking is off
14#ifdef JPH_TRACK_NARROWPHASE_STATS
15 #define JPH_IF_TRACK_NARROWPHASE_STATS(...) __VA_ARGS__
16#else
17 #define JPH_IF_TRACK_NARROWPHASE_STATS(...)
18#endif // JPH_TRACK_NARROWPHASE_STATS
19
21
22#ifdef JPH_TRACK_NARROWPHASE_STATS
23
25
28{
29public:
32
35 static void sReportStats();
36
37 atomic<uint64> mNumQueries = 0;
38 atomic<uint64> mHitsReported = 0;
39 atomic<uint64> mTotalTicks = 0;
40 atomic<uint64> mChildTicks = 0;
41
42 static NarrowPhaseStat sCollideShape[NumSubShapeTypes][NumSubShapeTypes];
43 static NarrowPhaseStat sCastShape[NumSubShapeTypes][NumSubShapeTypes];
44};
45
48{
49public:
53 mStart(GetProcessorTickCount())
54 {
55 // Make this the new root of the chain
56 sRoot = this;
57 }
58
60 {
62
63 // Notify parent of time spent in child
64 if (mParent != nullptr)
65 mParent->mStat.mChildTicks += delta_ticks;
66
67 // Increment stats at this level
68 mStat.mNumQueries++;
69 mStat.mTotalTicks += delta_ticks;
70
71 // Restore root pointer
72 JPH_ASSERT(sRoot == this);
73 sRoot = mParent;
74 }
75
78 uint64 mStart;
79
80 static thread_local TrackNarrowPhaseStat *sRoot;
81};
82
85{
86public:
88 mStart(GetProcessorTickCount())
89 {
90 }
91
93 {
94 // Mark time spent in collector as 'child' time for the parent
96 if (TrackNarrowPhaseStat::sRoot != nullptr)
97 TrackNarrowPhaseStat::sRoot->mStat.mChildTicks += delta_ticks;
98
99 // Notify all parents of a hit
100 for (TrackNarrowPhaseStat *track = TrackNarrowPhaseStat::sRoot; track != nullptr; track = track->mParent)
101 track->mStat.mHitsReported++;
102 }
103
104private:
105 uint64 mStart;
106};
107
109
110#endif // JPH_TRACK_NARROWPHASE_STATS
std::uint64_t uint64
Definition Core.h:443
#define JPH_NAMESPACE_END
Definition Core.h:367
#define JPH_CLANG_SUPPRESS_WARNING(w)
Definition Core.h:254
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
AllocateFunction Allocate
Definition Memory.cpp:59
EShapeSubType
This enumerates all shape types, each shape can return its type through Shape::GetSubType.
Definition Shape.h:74
JPH_NAMESPACE_BEGIN JPH_INLINE uint64 GetProcessorTickCount()
Functionality to get the processors cycle counter.
Definition TickCounter.h:26