| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/TickCounter.h> |
| 8 |
#include <Jolt/Physics/Collision/Shape/Shape.h> |
| 9 |
|
| 10 |
JPH_SUPPRESS_WARNING_PUSH |
| 11 |
JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") |
| 12 |
|
| 13 |
|
| 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 |
| 19 |
|
| 20 |
JPH_SUPPRESS_WARNING_POP |
| 21 |
|
| 22 |
#ifdef JPH_TRACK_NARROWPHASE_STATS |
| 23 |
|
| 24 |
JPH_NAMESPACE_BEGIN |
| 25 |
|
| 26 |
|
| 27 |
class NarrowPhaseStat |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
void ReportStats(const char *inName, EShapeSubType inType1, EShapeSubType inType2, uint64 inTicks100Pct) const; |
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 46 |
|
| 47 |
class TrackNarrowPhaseStat |
| 48 |
{ |
| 49 |
public: |
| 50 |
TrackNarrowPhaseStat(NarrowPhaseStat &inStat) : |
| 51 |
mStat(inStat), |
| 52 |
mParent(sRoot), |
| 53 |
mStart(GetProcessorTickCount()) |
| 54 |
{ |
| 55 |
|
| 56 |
sRoot = this; |
| 57 |
} |
| 58 |
|
| 59 |
~TrackNarrowPhaseStat() |
| 60 |
{ |
| 61 |
uint64 delta_ticks = GetProcessorTickCount() - mStart; |
| 62 |
|
| 63 |
|
| 64 |
if (mParent != nullptr) |
| 65 |
mParent->mStat.mChildTicks += delta_ticks; |
| 66 |
|
| 67 |
|
| 68 |
mStat.mNumQueries++; |
| 69 |
mStat.mTotalTicks += delta_ticks; |
| 70 |
|
| 71 |
|
| 72 |
JPH_ASSERT(sRoot == this); |
| 73 |
sRoot = mParent; |
| 74 |
} |
| 75 |
|
| 76 |
NarrowPhaseStat & mStat; |
| 77 |
TrackNarrowPhaseStat * mParent; |
| 78 |
uint64 mStart; |
| 79 |
|
| 80 |
static thread_local TrackNarrowPhaseStat *sRoot; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
class TrackNarrowPhaseCollector |
| 85 |
{ |
| 86 |
public: |
| 87 |
TrackNarrowPhaseCollector() : |
| 88 |
mStart(GetProcessorTickCount()) |
| 89 |
{ |
| 90 |
} |
| 91 |
|
| 92 |
~TrackNarrowPhaseCollector() |
| 93 |
{ |
| 94 |
|
| 95 |
uint64 delta_ticks = GetProcessorTickCount() - mStart; |
| 96 |
if (TrackNarrowPhaseStat::sRoot != nullptr) |
| 97 |
TrackNarrowPhaseStat::sRoot->mStat.mChildTicks += delta_ticks; |
| 98 |
|
| 99 |
|
| 100 |
for (TrackNarrowPhaseStat *track = TrackNarrowPhaseStat::sRoot; track != nullptr; track = track->mParent) |
| 101 |
track->mStat.mHitsReported++; |
| 102 |
} |
| 103 |
|
| 104 |
private: |
| 105 |
uint64 mStart; |
| 106 |
}; |
| 107 |
|
| 108 |
JPH_NAMESPACE_END |
| 109 |
|
| 110 |
#endif |