00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "pStatFrameData.h"
00016 #include "pStatClientVersion.h"
00017 #include "config_pstats.h"
00018
00019 #include "datagram.h"
00020 #include "datagramIterator.h"
00021
00022 #include <algorithm>
00023
00024
00025
00026
00027
00028
00029
00030 void PStatFrameData::
00031 sort_time() {
00032 stable_sort(_time_data.begin(), _time_data.end());
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 bool PStatFrameData::
00042 write_datagram(Datagram &destination, PStatClient *client) const {
00043 Data::const_iterator di;
00044 if (_time_data.size() >= 65536 || _level_data.size() >= 65536) {
00045 pstats_cat.info()
00046 << "Dropping frame with " << _time_data.size()
00047 << " time measurements and " << _level_data.size()
00048 << " level measurements.\n";
00049 return false;
00050 }
00051
00052 destination.add_uint16(_time_data.size());
00053 for (di = _time_data.begin(); di != _time_data.end(); ++di) {
00054 destination.add_uint16((*di)._index);
00055 destination.add_float32((*di)._value);
00056 }
00057 destination.add_uint16(_level_data.size());
00058 for (di = _level_data.begin(); di != _level_data.end(); ++di) {
00059 destination.add_uint16((*di)._index);
00060 destination.add_float32((*di)._value);
00061 }
00062
00063 return true;
00064 }
00065
00066
00067
00068
00069
00070
00071 void PStatFrameData::
00072 read_datagram(DatagramIterator &source, PStatClientVersion *) {
00073 clear();
00074
00075 int i;
00076 int time_size = source.get_uint16();
00077 for (i = 0; i < time_size; i++) {
00078 nassertv(source.get_remaining_size() > 0);
00079 DataPoint dp;
00080 dp._index = source.get_uint16();
00081 dp._value = source.get_float32();
00082 _time_data.push_back(dp);
00083 }
00084 int level_size = source.get_uint16();
00085 for (i = 0; i < level_size; i++) {
00086 nassertv(source.get_remaining_size() > 0);
00087 DataPoint dp;
00088 dp._index = source.get_uint16();
00089 dp._value = source.get_float32();
00090 _level_data.push_back(dp);
00091 }
00092 nassertv(source.get_remaining_size() == 0);
00093 }
00094