Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltVertexList.cxx

Go to the documentation of this file.
00001 // Filename: fltVertexList.cxx
00002 // Created by:  drose (25Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "fltVertexList.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 #include "fltHeader.h"
00023 
00024 TypeHandle FltVertexList::_type_handle;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: FltVertexList::Constructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 FltVertexList::
00032 FltVertexList(FltHeader *header) : FltRecord(header) {
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: FltVertexList::get_num_vertices
00037 //       Access: Public
00038 //  Description: Returns the number of vertices in this vertex list.
00039 ////////////////////////////////////////////////////////////////////
00040 int FltVertexList::
00041 get_num_vertices() const {
00042   return _vertices.size();
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: FltVertexList::get_vertex
00047 //       Access: Public
00048 //  Description: Returns the nth vertex of this vertex list.
00049 ////////////////////////////////////////////////////////////////////
00050 FltVertex *FltVertexList::
00051 get_vertex(int n) const {
00052   nassertr(n >= 0 && n < (int)_vertices.size(), 0);
00053   return _vertices[n];
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: FltVertexList::clear_vertices
00058 //       Access: Public
00059 //  Description: Removes all vertices from this vertex list.
00060 ////////////////////////////////////////////////////////////////////
00061 void FltVertexList::
00062 clear_vertices() {
00063   _vertices.clear();
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: FltVertexList::add_vertex
00068 //       Access: Public
00069 //  Description: Adds a new vertex to the end of the vertex list.
00070 //               Care must be taken to ensure the vertex is also added
00071 //               to the vertex palette.
00072 ////////////////////////////////////////////////////////////////////
00073 void FltVertexList::
00074 add_vertex(FltVertex *vertex) {
00075   _vertices.push_back(vertex);
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: FltVertexList::output
00080 //       Access: Public
00081 //  Description: Writes a quick one-line description of the record, but
00082 //               not its children.  This is a human-readable
00083 //               description, primarily for debugging; to write a flt
00084 //               file, use FltHeader::write_flt().
00085 ////////////////////////////////////////////////////////////////////
00086 void FltVertexList::
00087 output(ostream &out) const {
00088   out << _vertices.size() << " vertices";
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: FltVertexList::extract_record
00093 //       Access: Protected, Virtual
00094 //  Description: Fills in the information in this bead based on the
00095 //               information given in the indicated datagram, whose
00096 //               opcode has already been read.  Returns true on
00097 //               success, false if the datagram is invalid.
00098 ////////////////////////////////////////////////////////////////////
00099 bool FltVertexList::
00100 extract_record(FltRecordReader &reader) {
00101   if (!FltRecord::extract_record(reader)) {
00102     return false;
00103   }
00104 
00105   nassertr(reader.get_opcode() == FO_vertex_list, false);
00106   DatagramIterator &iterator = reader.get_iterator();
00107 
00108   _vertices.clear();
00109   while (iterator.get_remaining_size() >= 4) {
00110     int vertex_offset = iterator.get_be_int32();
00111     _vertices.push_back(_header->get_vertex_by_offset(vertex_offset));
00112   }
00113 
00114   check_remaining_size(iterator);
00115   return true;
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: FltVertexList::build_record
00120 //       Access: Protected, Virtual
00121 //  Description: Fills up the current record on the FltRecordWriter with
00122 //               data for this record, but does not advance the
00123 //               writer.  Returns true on success, false if there is
00124 //               some error.
00125 ////////////////////////////////////////////////////////////////////
00126 bool FltVertexList::
00127 build_record(FltRecordWriter &writer) const {
00128   if (!FltRecord::build_record(writer)) {
00129     return false;
00130   }
00131 
00132   writer.set_opcode(FO_vertex_list);
00133   Datagram &datagram = writer.update_datagram();
00134 
00135   Vertices::const_iterator vi;
00136   for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
00137     datagram.add_be_uint32(_header->get_offset_by_vertex(*vi));
00138   }
00139 
00140   return true;
00141 }

Generated on Fri May 2 03:19:50 2003 for Panda-Tool by doxygen1.3