Panda3D
pStatViewLevel.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pStatViewLevel.cxx
10  * @author drose
11  * @date 2000-07-11
12  */
13 
14 #include "pStatViewLevel.h"
15 #include "pStatClientData.h"
16 
17 #include "pStatCollectorDef.h"
18 #include "pnotify.h"
19 
20 #include <algorithm>
21 
22 /**
23  * Returns the total level value (or elapsed time) represented by this
24  * Collector, including all values in its child Collectors.
25  */
26 double PStatViewLevel::
27 get_net_value() const {
28  double net = _value_alone;
29 
30  Children::const_iterator ci;
31  for (ci = _children.begin(); ci != _children.end(); ++ci) {
32  net += (*ci)->get_net_value();
33  }
34 
35  return net;
36 }
37 
38 
39 // STL function object for sorting children in order by the collector's sort
40 // index, used in sort_children(), below.
41 class SortCollectorLevels {
42 public:
43  SortCollectorLevels(const PStatClientData *client_data) :
44  _client_data(client_data) {
45  }
46  bool operator () (const PStatViewLevel *a, const PStatViewLevel *b) const {
47  return
48  _client_data->get_collector_def(a->get_collector())._sort >
49  _client_data->get_collector_def(b->get_collector())._sort;
50  }
51  const PStatClientData *_client_data;
52 };
53 
54 /**
55  * Sorts the children of this view level into order as specified by the
56  * client's sort index.
57  */
59 sort_children(const PStatClientData *client_data) {
60  SortCollectorLevels sort_levels(client_data);
61 
62  sort(_children.begin(), _children.end(), sort_levels);
63 }
64 
65 /**
66  * Returns the number of children of this Level/Collector. These are the
67  * Collectors whose value is considered to be part of the total value of this
68  * level's Collector.
69  */
72  return _children.size();
73 }
74 
75 /**
76  * Returns the nth child of this Level/Collector.
77  */
79 get_child(int n) const {
80  nassertr(n >= 0 && n < (int)_children.size(), nullptr);
81  return _children[n];
82 }
pStatClientData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatViewLevel::get_collector
int get_collector() const
Returns the Collector index associated with this level.
Definition: pStatViewLevel.I:18
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatClientData
The data associated with a particular client, but not with any one particular frame or thread: the li...
Definition: pStatClientData.h:36
PStatViewLevel::get_child
const PStatViewLevel * get_child(int n) const
Returns the nth child of this Level/Collector.
Definition: pStatViewLevel.cxx:79
pStatViewLevel.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatViewLevel::sort_children
void sort_children(const PStatClientData *client_data)
Sorts the children of this view level into order as specified by the client's sort index.
Definition: pStatViewLevel.cxx:59
PStatViewLevel::get_net_value
double get_net_value() const
Returns the total level value (or elapsed time) represented by this Collector, including all values i...
Definition: pStatViewLevel.cxx:27
PStatViewLevel
This is a single level value, or band of color, within a View.
Definition: pStatViewLevel.h:29
pStatCollectorDef.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatViewLevel::get_num_children
int get_num_children() const
Returns the number of children of this Level/Collector.
Definition: pStatViewLevel.cxx:71