Panda3D
pStatFrameData.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 pStatFrameData.cxx
10  * @author drose
11  * @date 2000-07-10
12  */
13 
14 #include "pStatFrameData.h"
15 #include "pStatClientVersion.h"
16 #include "config_pstatclient.h"
17 
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 
21 #include <algorithm>
22 
23 /**
24  * Ensures the frame data is in monotonically increasing order by time.
25  */
28  std::stable_sort(_time_data.begin(), _time_data.end());
29 }
30 
31 /**
32  * Writes the definition of the FrameData to the datagram. Returns true on
33  * success, false on failure.
34  */
36 write_datagram(Datagram &destination, PStatClient *client) const {
37  Data::const_iterator di;
38  if (_time_data.size() >= 65536 || _level_data.size() >= 65536) {
39  pstats_cat.info()
40  << "Dropping frame with " << _time_data.size()
41  << " time measurements and " << _level_data.size()
42  << " level measurements.\n";
43  return false;
44  }
45 
46  destination.add_uint16(_time_data.size());
47  for (di = _time_data.begin(); di != _time_data.end(); ++di) {
48  destination.add_uint16((*di)._index);
49  destination.add_float32((*di)._value);
50  }
51  destination.add_uint16(_level_data.size());
52  for (di = _level_data.begin(); di != _level_data.end(); ++di) {
53  destination.add_uint16((*di)._index);
54  destination.add_float32((*di)._value);
55  }
56 
57  return true;
58 }
59 
60 /**
61  * Extracts the FrameData definition from the datagram.
62  */
65  clear();
66 
67  int i;
68  int time_size = source.get_uint16();
69  for (i = 0; i < time_size; i++) {
70  nassertv(source.get_remaining_size() > 0);
71  DataPoint dp;
72  dp._index = source.get_uint16();
73  dp._value = source.get_float32();
74  _time_data.push_back(dp);
75  }
76  int level_size = source.get_uint16();
77  for (i = 0; i < level_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  _level_data.push_back(dp);
83  }
84  nassertv(source.get_remaining_size() == 0);
85 }
void add_float32(PN_float32 value)
Adds a 32-bit single-precision floating-point number to the datagram.
Definition: datagram.I:114
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
size_t get_remaining_size() const
Return the bytes left in the datagram.
PN_float32 get_float32()
Extracts a 32-bit single-precision floating-point number.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:85
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool write_datagram(Datagram &destination, PStatClient *client) const
Writes the definition of the FrameData to the datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
void clear()
Removes all the data points from the frame data, in preparation for building up a new frame'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:263
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38