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