Panda3D
 All Classes Functions Variables Enumerations
fltGroup.cxx
1 // Filename: fltGroup.cxx
2 // Created by: drose (24Aug00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "fltGroup.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 #include "fltHeader.h"
19 
20 TypeHandle FltGroup::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: FltGroup::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 FltGroup::
28 FltGroup(FltHeader *header) : FltBeadID(header) {
29  _relative_priority = 0;
30  _flags = 0;
31  _special_id1 = 0;
32  _special_id2 = 0;
33  _significance = 0;
34  _layer_id = 0;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: FltGroup::extract_record
39 // Access: Protected, Virtual
40 // Description: Fills in the information in this bead based on the
41 // information given in the indicated datagram, whose
42 // opcode has already been read. Returns true on
43 // success, false if the datagram is invalid.
44 ////////////////////////////////////////////////////////////////////
45 bool FltGroup::
46 extract_record(FltRecordReader &reader) {
47  if (!FltBeadID::extract_record(reader)) {
48  return false;
49  }
50 
51  nassertr(reader.get_opcode() == FO_group, false);
52  DatagramIterator &iterator = reader.get_iterator();
53 
54  _relative_priority = iterator.get_be_int16();
55  iterator.skip_bytes(2);
56  _flags = iterator.get_be_uint32();
57  _special_id1 = iterator.get_be_int16();
58  _special_id2 = iterator.get_be_int16();
59  _significance = iterator.get_be_int16();
60  _layer_id = iterator.get_int8();
61  iterator.skip_bytes(1);
62  if (_header->get_flt_version() >= 1420) {
63  iterator.skip_bytes(4);
64  }
65 
66  check_remaining_size(iterator);
67  return true;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: FltGroup::build_record
72 // Access: Protected, Virtual
73 // Description: Fills up the current record on the FltRecordWriter with
74 // data for this record, but does not advance the
75 // writer. Returns true on success, false if there is
76 // some error.
77 ////////////////////////////////////////////////////////////////////
78 bool FltGroup::
79 build_record(FltRecordWriter &writer) const {
80  if (!FltBeadID::build_record(writer)) {
81  return false;
82  }
83 
84  writer.set_opcode(FO_group);
85  Datagram &datagram = writer.update_datagram();
86 
87  datagram.add_be_int16(_relative_priority);
88  datagram.pad_bytes(2);
89  datagram.add_be_uint32(_flags);
90  datagram.add_be_int16(_special_id1);
91  datagram.add_be_int16(_special_id2);
92  datagram.add_be_int16(_significance);
93  datagram.add_int8(_layer_id);
94  datagram.pad_bytes(5);
95 
96  return true;
97 }
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
A base class for any of a broad family of flt beads that include an ID.
Definition: fltBeadID.h:27
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:128
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:111
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
void check_remaining_size(const DatagramIterator &di, const string &name=string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record...
Definition: fltRecord.cxx:313
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
void add_be_uint32(PN_uint32 value)
Adds an unsigned 32-bit big-endian integer to the datagram.
Definition: datagram.I:303
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
void add_be_int16(PN_int16 value)
Adds a signed 16-bit big-endian integer to the datagram.
Definition: datagram.I:255