Panda3D
userVertexSlider.cxx
1 // Filename: userVertexSlider.cxx
2 // Created by: drose (28Mar05)
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 "userVertexSlider.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18 
19 TypeHandle UserVertexSlider::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: UserVertexSlider::Constructor
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 UserVertexSlider::
27 UserVertexSlider(const string &name) :
28  VertexSlider(InternalName::make(name))
29 {
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: UserVertexSlider::Constructor
34 // Access: Published
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 UserVertexSlider::
38 UserVertexSlider(const InternalName *name) :
39  VertexSlider(name)
40 {
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: UserVertexSlider::get_slider
45 // Access: Published, Virtual
46 // Description: Returns the current slider value.
47 ////////////////////////////////////////////////////////////////////
48 PN_stdfloat UserVertexSlider::
49 get_slider() const {
50  CDReader cdata(_cycler);
51  return cdata->_slider;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: UserVertexSlider::CData::make_copy
56 // Access: Public, Virtual
57 // Description:
58 ////////////////////////////////////////////////////////////////////
59 CycleData *UserVertexSlider::CData::
60 make_copy() const {
61  return new CData(*this);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: UserVertexSlider::register_with_read_factory
66 // Access: Public, Static
67 // Description: Tells the BamReader how to create objects of type
68 // UserVertexSlider.
69 ////////////////////////////////////////////////////////////////////
72  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: UserVertexSlider::write_datagram
77 // Access: Public, Virtual
78 // Description: Writes the contents of this object to the datagram
79 // for shipping out to a Bam file.
80 ////////////////////////////////////////////////////////////////////
83  VertexSlider::write_datagram(manager, dg);
84 
85  manager->write_cdata(dg, _cycler);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: UserVertexSlider::make_from_bam
90 // Access: Protected, Static
91 // Description: This function is called by the BamReader's factory
92 // when a new object of type UserVertexSlider is encountered
93 // in the Bam file. It should create the UserVertexSlider
94 // and extract its information from the file.
95 ////////////////////////////////////////////////////////////////////
96 TypedWritable *UserVertexSlider::
97 make_from_bam(const FactoryParams &params) {
98  UserVertexSlider *object = new UserVertexSlider("");
99  DatagramIterator scan;
100  BamReader *manager;
101 
102  parse_params(params, scan, manager);
103  object->fillin(scan, manager);
104 
105  return object;
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: UserVertexSlider::fillin
110 // Access: Protected
111 // Description: This internal function is called by make_from_bam to
112 // read in all of the relevant data from the BamFile for
113 // the new UserVertexSlider.
114 ////////////////////////////////////////////////////////////////////
115 void UserVertexSlider::
116 fillin(DatagramIterator &scan, BamReader *manager) {
117  VertexSlider::fillin(scan, manager);
118 
119  manager->read_cdata(scan, _cycler);
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: UserVertexSlider::CData::write_datagram
124 // Access: Public, Virtual
125 // Description: Writes the contents of this object to the datagram
126 // for shipping out to a Bam file.
127 ////////////////////////////////////////////////////////////////////
128 void UserVertexSlider::CData::
129 write_datagram(BamWriter *manager, Datagram &dg) const {
130  dg.add_stdfloat(_slider);
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: UserVertexSlider::CData::fillin
135 // Access: Public, Virtual
136 // Description: This internal function is called by make_from_bam to
137 // read in all of the relevant data from the BamFile for
138 // the new UserVertexSlider.
139 ////////////////////////////////////////////////////////////////////
140 void UserVertexSlider::CData::
141 fillin(DatagramIterator &scan, BamReader *manager) {
142  _slider = scan.get_stdfloat();
143 }
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
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:753
This is a specialization on VertexSlider that allows the user to specify any arbitrary slider valie h...
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 an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:41
static void register_with_read_factory()
Tells the BamReader how to create objects of type UserVertexSlider.
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 ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:240
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
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
virtual PN_stdfloat get_slider() const
Returns the current slider value.
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 write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.