Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dparticlesystemlogging.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5#include <float.h> // FLT_MAX
6
8
24
37{
38 return m_loggingInterval;
39}
40
42{
43 if (m_loggingInterval == interval)
44 return;
45
46 m_loggingInterval = interval;
48}
49
58{
59 return m_updates;
60}
61
70{
71 return m_particlesMax;
72}
73
86{
87 return m_particlesUsed;
88}
89
98{
99 return m_time;
100}
101
113{
114 return m_timeAverage;
115}
116
129{
130 return m_timeDeviation;
131}
132
133void QQuick3DParticleSystemLogging::updateTimes(qint64 time)
134{
135 m_time = float(time / 1000000.0) / m_updates;
136
137 m_totalTimesList.append(m_time);
138
139 // Keep max amount of times stored and remove the oldest values
140 const int MAX_TIMES = 100;
141 if (m_totalTimesList.size() > MAX_TIMES)
142 m_totalTimesList.removeFirst();
143
144 auto sortedTimes = m_totalTimesList;
145 std::sort(sortedTimes.begin(), sortedTimes.end());
146
147 // Calculate average from stored times.
148 // Only take into account the middle 50% of the values.
149 // This gives us interquartile range (IQR) and the average time among IQR.
150 if (sortedTimes.size() > 5) {
151 // Skip 25%, count 50%, so maxItem at 75%
152 const int skipAmount = roundf(0.25f * float(sortedTimes.size()));
153 const int maxItem = sortedTimes.size() - skipAmount;
154 int countAmount = 0;
155 double totalTime = 0.0;
156 float maxTime = 0.0f;
157 float minTime = FLT_MAX;
158 for (int i = skipAmount; i < maxItem; i++) {
159 const float time = sortedTimes.at(i);
160 totalTime += time;
161 minTime = std::min(minTime, time);
162 maxTime = std::max(maxTime, time);
163 countAmount++;
164 }
165 m_timeAverage = float(totalTime / countAmount);
166 m_timeDeviation = maxTime - minTime;
168 Q_EMIT timeDeviationChanged();
169 }
171}
172
173void QQuick3DParticleSystemLogging::resetData()
174{
175 m_updates = 0;
176 m_particlesMax = 0;
177 m_particlesUsed = 0;
178 m_time = 0.0f;
179 m_timeAverage = 0.0f;
180 m_timeDeviation = 0.0f;
181 m_totalTimesList.clear();
187 Q_EMIT timeDeviationChanged();
188}
189
qsizetype size() const noexcept
Definition qlist.h:397
void removeFirst() noexcept
Definition qlist.h:807
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
\inmodule QtCore
Definition qobject.h:103
float timeDeviation
\qmlproperty real ParticleSystem3DLogging::timeDeviation
QQuick3DParticleSystemLogging(QObject *parent=nullptr)
\qmltype ParticleSystem3DLogging \inherits QtObject \inqmlmodule QtQuick3D.Particles3D
Combined button and popup list for selecting options.
#define Q_EMIT
long long qint64
Definition qtypes.h:60