Panda3D
 All Classes Functions Variables Enumerations
fltObject.cxx
1 // Filename: fltObject.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 "fltObject.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 TypeHandle FltObject::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltObject::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltObject::
27 FltObject(FltHeader *header) : FltBeadID(header) {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: FltObject::extract_record
32 // Access: Protected, Virtual
33 // Description: Fills in the information in this bead based on the
34 // information given in the indicated datagram, whose
35 // opcode has already been read. Returns true on
36 // success, false if the datagram is invalid.
37 ////////////////////////////////////////////////////////////////////
38 bool FltObject::
39 extract_record(FltRecordReader &reader) {
40  if (!FltBeadID::extract_record(reader)) {
41  return false;
42  }
43 
44  nassertr(reader.get_opcode() == FO_object, false);
45  DatagramIterator &iterator = reader.get_iterator();
46 
47  _flags = iterator.get_be_uint32();
48  _relative_priority = iterator.get_be_int16();
49  _transparency = iterator.get_be_int16();
50  _special_id1 = iterator.get_be_int16();
51  _special_id2 = iterator.get_be_int16();
52  _significance = iterator.get_be_int16();
53  iterator.skip_bytes(2);
54 
55  check_remaining_size(iterator);
56  return true;
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: FltObject::build_record
61 // Access: Protected, Virtual
62 // Description: Fills up the current record on the FltRecordWriter with
63 // data for this record, but does not advance the
64 // writer. Returns true on success, false if there is
65 // some error.
66 ////////////////////////////////////////////////////////////////////
67 bool FltObject::
68 build_record(FltRecordWriter &writer) const {
69  if (!FltBeadID::build_record(writer)) {
70  return false;
71  }
72 
73  writer.set_opcode(FO_object);
74  Datagram &datagram = writer.update_datagram();
75 
76  datagram.add_be_uint32(_flags);
77  datagram.add_be_int16(_relative_priority);
78  datagram.add_be_int16(_transparency);
79  datagram.add_be_int16(_special_id1);
80  datagram.add_be_int16(_special_id2);
81  datagram.add_be_int16(_significance);
82  datagram.pad_bytes(2);
83 
84  return true;
85 }
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...
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