Panda3D
|
00001 // Filename: fltVertexList.cxx 00002 // Created by: drose (25Aug00) 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 "fltVertexList.h" 00016 #include "fltRecordReader.h" 00017 #include "fltRecordWriter.h" 00018 #include "fltHeader.h" 00019 00020 TypeHandle FltVertexList::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: FltVertexList::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 FltVertexList:: 00028 FltVertexList(FltHeader *header) : FltRecord(header) { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: FltVertexList::get_num_vertices 00033 // Access: Public 00034 // Description: Returns the number of vertices in this vertex list. 00035 //////////////////////////////////////////////////////////////////// 00036 int FltVertexList:: 00037 get_num_vertices() const { 00038 return _vertices.size(); 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: FltVertexList::get_vertex 00043 // Access: Public 00044 // Description: Returns the nth vertex of this vertex list. 00045 //////////////////////////////////////////////////////////////////// 00046 FltVertex *FltVertexList:: 00047 get_vertex(int n) const { 00048 nassertr(n >= 0 && n < (int)_vertices.size(), 0); 00049 return _vertices[n]; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: FltVertexList::clear_vertices 00054 // Access: Public 00055 // Description: Removes all vertices from this vertex list. 00056 //////////////////////////////////////////////////////////////////// 00057 void FltVertexList:: 00058 clear_vertices() { 00059 _vertices.clear(); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: FltVertexList::add_vertex 00064 // Access: Public 00065 // Description: Adds a new vertex to the end of the vertex list. 00066 //////////////////////////////////////////////////////////////////// 00067 void FltVertexList:: 00068 add_vertex(FltVertex *vertex) { 00069 _header->add_vertex(vertex); 00070 _vertices.push_back(vertex); 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: FltVertexList::output 00075 // Access: Public 00076 // Description: Writes a quick one-line description of the record, but 00077 // not its children. This is a human-readable 00078 // description, primarily for debugging; to write a flt 00079 // file, use FltHeader::write_flt(). 00080 //////////////////////////////////////////////////////////////////// 00081 void FltVertexList:: 00082 output(ostream &out) const { 00083 out << _vertices.size() << " vertices"; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: FltVertexList::extract_record 00088 // Access: Protected, Virtual 00089 // Description: Fills in the information in this bead based on the 00090 // information given in the indicated datagram, whose 00091 // opcode has already been read. Returns true on 00092 // success, false if the datagram is invalid. 00093 //////////////////////////////////////////////////////////////////// 00094 bool FltVertexList:: 00095 extract_record(FltRecordReader &reader) { 00096 if (!FltRecord::extract_record(reader)) { 00097 return false; 00098 } 00099 00100 nassertr(reader.get_opcode() == FO_vertex_list, false); 00101 DatagramIterator &iterator = reader.get_iterator(); 00102 00103 _vertices.clear(); 00104 while (iterator.get_remaining_size() >= 4) { 00105 int vertex_offset = iterator.get_be_int32(); 00106 _vertices.push_back(_header->get_vertex_by_offset(vertex_offset)); 00107 } 00108 00109 check_remaining_size(iterator); 00110 return true; 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: FltVertexList::build_record 00115 // Access: Protected, Virtual 00116 // Description: Fills up the current record on the FltRecordWriter with 00117 // data for this record, but does not advance the 00118 // writer. Returns true on success, false if there is 00119 // some error. 00120 //////////////////////////////////////////////////////////////////// 00121 bool FltVertexList:: 00122 build_record(FltRecordWriter &writer) const { 00123 if (!FltRecord::build_record(writer)) { 00124 return false; 00125 } 00126 00127 writer.set_opcode(FO_vertex_list); 00128 Datagram &datagram = writer.update_datagram(); 00129 00130 Vertices::const_iterator vi; 00131 for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) { 00132 datagram.add_be_uint32(_header->get_offset_by_vertex(*vi)); 00133 } 00134 00135 return true; 00136 }