Panda3D
 All Classes Functions Variables Enumerations
pStatFrameData.cxx
1 // Filename: pStatFrameData.cxx
2 // Created by: drose (10Jul00)
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 "pStatFrameData.h"
16 #include "pStatClientVersion.h"
17 #include "config_pstats.h"
18 
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 
22 #include <algorithm>
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: PStatFrameData::sort_time
26 // Access: Public
27 // Description: Ensures the frame data is in monotonically increasing
28 // order by time.
29 ////////////////////////////////////////////////////////////////////
32  stable_sort(_time_data.begin(), _time_data.end());
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: PStatFrameData::write_datagram
37 // Access: Public
38 // Description: Writes the definition of the FrameData to the
39 // datagram. Returns true on success, false on failure.
40 ////////////////////////////////////////////////////////////////////
42 write_datagram(Datagram &destination, PStatClient *client) const {
43  Data::const_iterator di;
44  if (_time_data.size() >= 65536 || _level_data.size() >= 65536) {
45  pstats_cat.info()
46  << "Dropping frame with " << _time_data.size()
47  << " time measurements and " << _level_data.size()
48  << " level measurements.\n";
49  return false;
50  }
51 
52  destination.add_uint16(_time_data.size());
53  for (di = _time_data.begin(); di != _time_data.end(); ++di) {
54  destination.add_uint16((*di)._index);
55  destination.add_float32((*di)._value);
56  }
57  destination.add_uint16(_level_data.size());
58  for (di = _level_data.begin(); di != _level_data.end(); ++di) {
59  destination.add_uint16((*di)._index);
60  destination.add_float32((*di)._value);
61  }
62 
63  return true;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PStatFrameData::read_datagram
68 // Access: Public
69 // Description: Extracts the FrameData definition from the datagram.
70 ////////////////////////////////////////////////////////////////////
73  clear();
74 
75  int i;
76  int time_size = source.get_uint16();
77  for (i = 0; i < time_size; i++) {
78  nassertv(source.get_remaining_size() > 0);
79  DataPoint dp;
80  dp._index = source.get_uint16();
81  dp._value = source.get_float32();
82  _time_data.push_back(dp);
83  }
84  int level_size = source.get_uint16();
85  for (i = 0; i < level_size; i++) {
86  nassertv(source.get_remaining_size() > 0);
87  DataPoint dp;
88  dp._index = source.get_uint16();
89  dp._value = source.get_float32();
90  _level_data.push_back(dp);
91  }
92  nassertv(source.get_remaining_size() == 0);
93 }
94 
bool write_datagram(Datagram &destination, PStatClient *client) const
Writes the definition of the FrameData to the datagram.
void add_float32(PN_float32 value)
Adds a 32-bit single-precision floating-point number to the datagram.
Definition: datagram.I:217
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
PN_float32 get_float32()
Extracts a 32-bit single-precision floating-point number.
int get_remaining_size() const
Return the bytes left in the datagram.
void sort_time()
Ensures the frame data is in monotonically increasing order by time.
Records the version number of a particular client.
void read_datagram(DatagramIterator &source, PStatClientVersion *version)
Extracts the FrameData definition from the datagram.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:181
void clear()
Removes all the data points from the frame data, in preparation for building up a new frame&#39;s worth...
A class to retrieve the individual data elements previously stored in a Datagram. ...
Manages the communications to report statistics via a network connection to a remote PStatServer...
Definition: pStatClient.h:261
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43