Panda3D
userVertexSlider.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 userVertexSlider.cxx
10  * @author drose
11  * @date 2005-03-28
12  */
13 
14 #include "userVertexSlider.h"
15 #include "bamReader.h"
16 #include "bamWriter.h"
17 
18 TypeHandle UserVertexSlider::_type_handle;
19 
20 /**
21  *
22  */
23 UserVertexSlider::
24 UserVertexSlider(const std::string &name) :
25  VertexSlider(InternalName::make(name))
26 {
27 }
28 
29 /**
30  *
31  */
32 UserVertexSlider::
33 UserVertexSlider(const InternalName *name) :
34  VertexSlider(name)
35 {
36 }
37 
38 /**
39  * Returns the current slider value.
40  */
41 PN_stdfloat UserVertexSlider::
42 get_slider() const {
43  CDReader cdata(_cycler);
44  return cdata->_slider;
45 }
46 
47 /**
48  *
49  */
50 CycleData *UserVertexSlider::CData::
51 make_copy() const {
52  return new CData(*this);
53 }
54 
55 /**
56  * Tells the BamReader how to create objects of type UserVertexSlider.
57  */
60  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
61 }
62 
63 /**
64  * Writes the contents of this object to the datagram for shipping out to a
65  * Bam file.
66  */
69  VertexSlider::write_datagram(manager, dg);
70 
71  manager->write_cdata(dg, _cycler);
72 }
73 
74 /**
75  * This function is called by the BamReader's factory when a new object of
76  * type UserVertexSlider is encountered in the Bam file. It should create the
77  * UserVertexSlider and extract its information from the file.
78  */
79 TypedWritable *UserVertexSlider::
80 make_from_bam(const FactoryParams &params) {
81  UserVertexSlider *object = new UserVertexSlider("");
82  DatagramIterator scan;
83  BamReader *manager;
84 
85  parse_params(params, scan, manager);
86  object->fillin(scan, manager);
87 
88  return object;
89 }
90 
91 /**
92  * This internal function is called by make_from_bam to read in all of the
93  * relevant data from the BamFile for the new UserVertexSlider.
94  */
95 void UserVertexSlider::
96 fillin(DatagramIterator &scan, BamReader *manager) {
97  VertexSlider::fillin(scan, manager);
98 
99  manager->read_cdata(scan, _cycler);
100 }
101 
102 /**
103  * Writes the contents of this object to the datagram for shipping out to a
104  * Bam file.
105  */
106 void UserVertexSlider::CData::
107 write_datagram(BamWriter *manager, Datagram &dg) const {
108  dg.add_stdfloat(_slider);
109 }
110 
111 /**
112  * This internal function is called by make_from_bam to read in all of the
113  * relevant data from the BamFile for the new UserVertexSlider.
114  */
115 void UserVertexSlider::CData::
116 fillin(DatagramIterator &scan, BamReader *manager) {
117  _slider = scan.get_stdfloat();
118 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:110
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
Definition: bamReader.cxx:695
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:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
Definition: bamWriter.cxx:425
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:37
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:63
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:133
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.