Panda3D
 All Classes Functions Variables Enumerations
userVertexTransform.cxx
1 // Filename: userVertexTransform.cxx
2 // Created by: drose (24Mar05)
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 "userVertexTransform.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18 
19 TypeHandle UserVertexTransform::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: UserVertexTransform::Constructor
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 UserVertexTransform::
27 UserVertexTransform(const string &name) :
28  _name(name)
29 {
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: UserVertexTransform::get_matrix
34 // Access: Published, Virtual
35 // Description: Returns the transform's matrix.
36 ////////////////////////////////////////////////////////////////////
38 get_matrix(LMatrix4 &matrix) const {
39  CDReader cdata(_cycler);
40  matrix = cdata->_matrix;
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: UserVertexTransform::output
45 // Access: Published, Virtual
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 void UserVertexTransform::
49 output(ostream &out) const {
50  out << get_type() << " " << get_name();
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: UserVertexTransform::CData::make_copy
55 // Access: Public, Virtual
56 // Description:
57 ////////////////////////////////////////////////////////////////////
58 CycleData *UserVertexTransform::CData::
59 make_copy() const {
60  return new CData(*this);
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: UserVertexTransform::register_with_read_factory
65 // Access: Public, Static
66 // Description: Tells the BamReader how to create objects of type
67 // UserVertexTransform.
68 ////////////////////////////////////////////////////////////////////
71  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: UserVertexTransform::write_datagram
76 // Access: Public, Virtual
77 // Description: Writes the contents of this object to the datagram
78 // for shipping out to a Bam file.
79 ////////////////////////////////////////////////////////////////////
83 
84  manager->write_cdata(dg, _cycler);
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: UserVertexTransform::make_from_bam
89 // Access: Protected, Static
90 // Description: This function is called by the BamReader's factory
91 // when a new object of type UserVertexTransform is encountered
92 // in the Bam file. It should create the UserVertexTransform
93 // and extract its information from the file.
94 ////////////////////////////////////////////////////////////////////
95 TypedWritable *UserVertexTransform::
96 make_from_bam(const FactoryParams &params) {
97  UserVertexTransform *object = new UserVertexTransform("");
98  DatagramIterator scan;
99  BamReader *manager;
100 
101  parse_params(params, scan, manager);
102  object->fillin(scan, manager);
103 
104  return object;
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: UserVertexTransform::fillin
109 // Access: Protected
110 // Description: This internal function is called by make_from_bam to
111 // read in all of the relevant data from the BamFile for
112 // the new UserVertexTransform.
113 ////////////////////////////////////////////////////////////////////
114 void UserVertexTransform::
115 fillin(DatagramIterator &scan, BamReader *manager) {
116  VertexTransform::fillin(scan, manager);
117 
118  manager->read_cdata(scan, _cycler);
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: UserVertexTransform::CData::write_datagram
123 // Access: Public, Virtual
124 // Description: Writes the contents of this object to the datagram
125 // for shipping out to a Bam file.
126 ////////////////////////////////////////////////////////////////////
127 void UserVertexTransform::CData::
128 write_datagram(BamWriter *manager, Datagram &dg) const {
129  _matrix.write_datagram(dg);
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: UserVertexTransform::CData::fillin
134 // Access: Public, Virtual
135 // Description: This internal function is called by make_from_bam to
136 // read in all of the relevant data from the BamFile for
137 // the new UserVertexTransform.
138 ////////////////////////////////////////////////////////////////////
139 void UserVertexTransform::CData::
140 fillin(DatagramIterator &scan, BamReader *manager) {
141  _matrix.read_datagram(scan);
142 }
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
Definition: bamReader.cxx:747
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
void write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
Definition: bamWriter.cxx:398
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
const string & get_name() const
Returns the name passed to the constructor.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
This is a specialization on VertexTransform that allows the user to specify any arbitrary transform m...
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
virtual void get_matrix(LMatrix4 &matrix) const
Returns the transform&#39;s matrix.
static void register_with_read_factory()
Tells the BamReader how to create objects of type UserVertexTransform.