Panda3D
 All Classes Functions Variables Enumerations
fltLOD.cxx
1 // Filename: fltLOD.cxx
2 // Created by: drose (25Aug00)
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 "fltLOD.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 TypeHandle FltLOD::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltLOD::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltLOD::
27 FltLOD(FltHeader *header) : FltBeadID(header) {
28  _switch_in = 0.0;
29  _switch_out = 0.0;
30  _special_id1 = 0;
31  _special_id2 = 0;
32  _flags = 0;
33  _center_x = 0.0;
34  _center_y = 0.0;
35  _center_z = 0.0;
36  _transition_range = 0.0;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: FltLOD::extract_record
41 // Access: Protected, Virtual
42 // Description: Fills in the information in this bead based on the
43 // information given in the indicated datagram, whose
44 // opcode has already been read. Returns true on
45 // success, false if the datagram is invalid.
46 ////////////////////////////////////////////////////////////////////
47 bool FltLOD::
48 extract_record(FltRecordReader &reader) {
49  if (!FltBeadID::extract_record(reader)) {
50  return false;
51  }
52 
53  nassertr(reader.get_opcode() == FO_lod, false);
54  DatagramIterator &iterator = reader.get_iterator();
55 
56  iterator.skip_bytes(4);
57  _switch_in = iterator.get_be_float64();
58  _switch_out = iterator.get_be_float64();
59  _special_id1 = iterator.get_be_int16();
60  _special_id2 = iterator.get_be_int16();
61  _flags = iterator.get_be_uint32();
62  _center_x = iterator.get_be_float64();
63  _center_y = iterator.get_be_float64();
64  _center_z = iterator.get_be_float64();
65  _transition_range = iterator.get_be_float64();
66 
67  check_remaining_size(iterator);
68  return true;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: FltLOD::build_record
73 // Access: Protected, Virtual
74 // Description: Fills up the current record on the FltRecordWriter with
75 // data for this record, but does not advance the
76 // writer. Returns true on success, false if there is
77 // some error.
78 ////////////////////////////////////////////////////////////////////
79 bool FltLOD::
80 build_record(FltRecordWriter &writer) const {
81  if (!FltBeadID::build_record(writer)) {
82  return false;
83  }
84 
85  writer.set_opcode(FO_lod);
86  Datagram &datagram = writer.update_datagram();
87 
88  datagram.pad_bytes(4);
89  datagram.add_be_float64(_switch_in);
90  datagram.add_be_float64(_switch_out);
91  datagram.add_be_int16(_special_id1);
92  datagram.add_be_int16(_special_id2);
93  datagram.add_be_uint32(_flags);
94  datagram.add_be_float64(_center_x);
95  datagram.add_be_float64(_center_y);
96  datagram.add_be_float64(_center_z);
97  datagram.add_be_float64(_transition_range);
98 
99  return true;
100 }
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 add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
Definition: datagram.I:339
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
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