Panda3D

fltLOD.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 fltLOD.cxx
10 * @author drose
11 * @date 2000-08-25
12 */
13
14 #include "fltLOD.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17
18 TypeHandle FltLOD::_type_handle;
19
20 /**
21 *
22 */
23 FltLOD::
24 FltLOD(FltHeader *header) : FltBeadID(header) {
25 _switch_in = 0.0;
26 _switch_out = 0.0;
27 _special_id1 = 0;
28 _special_id2 = 0;
29 _flags = 0;
30 _center_x = 0.0;
31 _center_y = 0.0;
32 _center_z = 0.0;
33 _transition_range = 0.0;
34 }
35
36 /**
37 * Fills in the information in this bead based on the information given in the
38 * indicated datagram, whose opcode has already been read. Returns true on
39 * success, false if the datagram is invalid.
40 */
41 bool FltLOD::
42 extract_record(FltRecordReader &reader) {
43 if (!FltBeadID::extract_record(reader)) {
44 return false;
45 }
46
47 nassertr(reader.get_opcode() == FO_lod, false);
48 DatagramIterator &iterator = reader.get_iterator();
49
50 iterator.skip_bytes(4);
51 _switch_in = iterator.get_be_float64();
52 _switch_out = iterator.get_be_float64();
53 _special_id1 = iterator.get_be_int16();
54 _special_id2 = iterator.get_be_int16();
55 _flags = iterator.get_be_uint32();
56 _center_x = iterator.get_be_float64();
57 _center_y = iterator.get_be_float64();
58 _center_z = iterator.get_be_float64();
59 _transition_range = iterator.get_be_float64();
60
61 check_remaining_size(iterator);
62 return true;
63 }
64
65 /**
66 * Fills up the current record on the FltRecordWriter with data for this
67 * record, but does not advance the writer. Returns true on success, false if
68 * there is some error.
69 */
70 bool FltLOD::
71 build_record(FltRecordWriter &writer) const {
72 if (!FltBeadID::build_record(writer)) {
73 return false;
74 }
75
76 writer.set_opcode(FO_lod);
77 Datagram &datagram = writer.update_datagram();
78
79 datagram.pad_bytes(4);
80 datagram.add_be_float64(_switch_in);
81 datagram.add_be_float64(_switch_out);
82 datagram.add_be_int16(_special_id1);
83 datagram.add_be_int16(_special_id2);
84 datagram.add_be_uint32(_flags);
85 datagram.add_be_float64(_center_x);
86 datagram.add_be_float64(_center_y);
87 datagram.add_be_float64(_center_z);
88 datagram.add_be_float64(_transition_range);
89
90 return true;
91 }
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
DatagramIterator::skip_bytes
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
Definition: datagramIterator.I:423
DatagramIterator::get_be_uint32
uint32_t get_be_uint32()
Extracts an unsigned 32-bit big-endian integer.
Definition: datagramIterator.I:331
DatagramIterator::get_be_float64
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
Definition: datagramIterator.I:388
DatagramIterator::get_be_int16
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
Definition: datagramIterator.I:255
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
Datagram::add_be_uint32
void add_be_uint32(uint32_t value)
Adds an unsigned 32-bit big-endian integer to the datagram.
Definition: datagram.I:181
Datagram::add_be_int16
void add_be_int16(int16_t value)
Adds a signed 16-bit big-endian integer to the datagram.
Definition: datagram.I:145
Datagram::add_be_float64
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:209
Datagram::pad_bytes
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:99
FltBeadID
A base class for any of a broad family of flt beads that include an ID.
Definition: fltBeadID.h:24
FltHeader
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
FltRecordReader
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
Definition: fltRecordReader.h:30
FltRecordReader::get_opcode
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
Definition: fltRecordReader.cxx:55
FltRecordReader::get_iterator
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
Definition: fltRecordReader.cxx:64
FltRecordWriter
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
Definition: fltRecordWriter.h:31
FltRecordWriter::set_opcode
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Definition: fltRecordWriter.cxx:47
FltRecordWriter::update_datagram
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
Definition: fltRecordWriter.cxx:66
FltRecord::check_remaining_size
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
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
fltLOD.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltRecordReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltRecordWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.