mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
faster avg computation
This commit is contained in:
parent
89006b755f
commit
4454566aa1
@ -307,12 +307,46 @@ is_title_unknown() const {
|
||||
void PStatStripChart::
|
||||
accumulate_frame_data(FrameData &fdata, const FrameData &additional,
|
||||
float weight) {
|
||||
FrameData result;
|
||||
FrameData::const_iterator ai, bi;
|
||||
FrameData::iterator ai;
|
||||
FrameData::const_iterator bi;
|
||||
|
||||
ai = fdata.begin();
|
||||
bi = additional.begin();
|
||||
|
||||
FrameData result;
|
||||
|
||||
if (fdata.size() == additional.size()) {
|
||||
// Start out assuming that fdata and additional contain exactly
|
||||
// the same set of collectors. If we discover otherwise, we'll
|
||||
// have to bail at that point.
|
||||
while (ai != fdata.end() &&
|
||||
(*ai)._collector_index == (*bi)._collector_index) {
|
||||
(*ai)._net_value += ((*bi)._net_value * weight);
|
||||
++ai;
|
||||
++bi;
|
||||
}
|
||||
|
||||
if (ai == fdata.end()) {
|
||||
// If we successfully reached the end of the list, great!
|
||||
// We're done without any merging.
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, the two lists weren't identical. In that case, copy
|
||||
// the accumulated data so far and continue from this point with
|
||||
// the full-blown merge.
|
||||
result.reserve(max(fdata.size(), additional.size()));
|
||||
FrameData::const_iterator ci;
|
||||
for (ci = fdata.begin(); ci != ai; ++ci) {
|
||||
result.push_back(*ci);
|
||||
}
|
||||
|
||||
} else {
|
||||
// If the two lists had different lengths, clearly they aren't
|
||||
// identical.
|
||||
result.reserve(max(fdata.size(), additional.size()));
|
||||
}
|
||||
|
||||
while (ai != fdata.end() && bi != additional.end()) {
|
||||
if ((*ai)._collector_index < (*bi)._collector_index) {
|
||||
// Here's a data value that's in data, but not in additional.
|
||||
|
Loading…
x
Reference in New Issue
Block a user