Panda3D
recorderHeader.cxx
1 // Filename: recorderHeader.cxx
2 // Created by: drose (29Jan04)
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 "recorderHeader.h"
16 #include "recorderTable.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "config_recorder.h"
20 
21 TypeHandle RecorderHeader::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: RecorderHeader::register_with_read_factory
25 // Access: Public, Static
26 // Description: Tells the BamReader how to create objects of type
27 // Lens.
28 ////////////////////////////////////////////////////////////////////
31  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: RecorderHeader::write_datagram
36 // Access: Public, Virtual
37 // Description: Writes the contents of this object to the datagram
38 // for shipping out to a Bam file.
39 ////////////////////////////////////////////////////////////////////
42  TypedWritable::write_datagram(manager, dg);
43 
44  // One day this will need to be upgraded to a uint64, but probably
45  // not before 2106. (In 2038, Unix time will overflow a signed
46  // 32-bit number, but this is an unsigned number and will still be
47  // good until 2106.)
48  dg.add_uint32(_start_time);
49 
50  dg.add_int32(_random_seed);
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: RecorderHeader::make_from_bam
55 // Access: Protected, Static
56 // Description: This function is called by the BamReader's factory
57 // when a new object of type Lens is encountered
58 // in the Bam file. It should create the Lens
59 // and extract its information from the file.
60 ////////////////////////////////////////////////////////////////////
61 TypedWritable *RecorderHeader::
62 make_from_bam(const FactoryParams &params) {
63  RecorderHeader *header = new RecorderHeader;
64  DatagramIterator scan;
65  BamReader *manager;
66 
67  parse_params(params, scan, manager);
68  header->fillin(scan, manager);
69 
70  return header;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: RecorderHeader::fillin
75 // Access: Protected
76 // Description: This internal function is called by make_from_bam to
77 // read in all of the relevant data from the BamFile for
78 // the new RecorderHeader.
79 ////////////////////////////////////////////////////////////////////
80 void RecorderHeader::
81 fillin(DatagramIterator &scan, BamReader *manager) {
82  TypedWritable::fillin(scan, manager);
83 
84  _start_time = scan.get_uint32();
85  _random_seed = scan.get_int32();
86 }
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
PN_int32 get_int32()
Extracts a signed 32-bit integer.
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
Definition: datagram.I:192
This object contains the header information written out at the beginning of a recorded session file...
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
static void register_with_read_factory()
Tells the BamReader how to create objects of type Lens.
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:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43