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