Panda3D
 All Classes Functions Variables Enumerations
pStatFrameData.cxx
00001 // Filename: pStatFrameData.cxx
00002 // Created by:  drose (10Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
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 //     Function: PStatFrameData::sort_time
00026 //       Access: Public
00027 //  Description: Ensures the frame data is in monotonically increasing
00028 //               order by time.
00029 ////////////////////////////////////////////////////////////////////
00030 void PStatFrameData::
00031 sort_time() {
00032   stable_sort(_time_data.begin(), _time_data.end());
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: PStatFrameData::write_datagram
00037 //       Access: Public
00038 //  Description: Writes the definition of the FrameData to the
00039 //               datagram.  Returns true on success, false on failure.
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 //     Function: PStatFrameData::read_datagram
00068 //       Access: Public
00069 //  Description: Extracts the FrameData definition from the datagram.
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 
 All Classes Functions Variables Enumerations