Panda3D
fltObject.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fltObject.cxx
10  * @author drose
11  * @date 2000-08-24
12  */
13 
14 #include "fltObject.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 
18 TypeHandle FltObject::_type_handle;
19 
20 /**
21  *
22  */
23 FltObject::
24 FltObject(FltHeader *header) : FltBeadID(header) {
25 }
26 
27 /**
28  * Fills in the information in this bead based on the information given in the
29  * indicated datagram, whose opcode has already been read. Returns true on
30  * success, false if the datagram is invalid.
31  */
32 bool FltObject::
33 extract_record(FltRecordReader &reader) {
34  if (!FltBeadID::extract_record(reader)) {
35  return false;
36  }
37 
38  nassertr(reader.get_opcode() == FO_object, false);
39  DatagramIterator &iterator = reader.get_iterator();
40 
41  _flags = iterator.get_be_uint32();
42  _relative_priority = iterator.get_be_int16();
43  _transparency = iterator.get_be_int16();
44  _special_id1 = iterator.get_be_int16();
45  _special_id2 = iterator.get_be_int16();
46  _significance = iterator.get_be_int16();
47  iterator.skip_bytes(2);
48 
49  check_remaining_size(iterator);
50  return true;
51 }
52 
53 /**
54  * Fills up the current record on the FltRecordWriter with data for this
55  * record, but does not advance the writer. Returns true on success, false if
56  * there is some error.
57  */
58 bool FltObject::
59 build_record(FltRecordWriter &writer) const {
60  if (!FltBeadID::build_record(writer)) {
61  return false;
62  }
63 
64  writer.set_opcode(FO_object);
65  Datagram &datagram = writer.update_datagram();
66 
67  datagram.add_be_uint32(_flags);
68  datagram.add_be_int16(_relative_priority);
69  datagram.add_be_int16(_transparency);
70  datagram.add_be_int16(_special_id1);
71  datagram.add_be_int16(_special_id2);
72  datagram.add_be_int16(_significance);
73  datagram.pad_bytes(2);
74 
75  return true;
76 }
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:24
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Definition: fltRecord.cxx:254
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:99
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
void add_be_int16(int16_t value)
Adds a signed 16-bit big-endian integer to the datagram.
Definition: datagram.I:145
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_be_uint32(uint32_t value)
Adds an unsigned 32-bit big-endian integer to the datagram.
Definition: datagram.I:181
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
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:38