Panda3D
characterVertexSlider.cxx
1 // Filename: characterVertexSlider.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 "characterVertexSlider.h"
16 #include "datagram.h"
17 #include "datagramIterator.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
20 
21 TypeHandle CharacterVertexSlider::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: CharacterVertexSlider::Default Constructor
25 // Access: Private
26 // Description: Constructs an invalid object; used only by the bam
27 // loader.
28 ////////////////////////////////////////////////////////////////////
29 CharacterVertexSlider::
30 CharacterVertexSlider() :
31  VertexSlider(InternalName::get_root())
32 {
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: CharacterVertexSlider::Constructor
37 // Access: Published
38 // Description: Constructs a new object that converts vertices from
39 // the indicated joint's coordinate space, into the
40 // other indicated joint's space.
41 ////////////////////////////////////////////////////////////////////
42 CharacterVertexSlider::
43 CharacterVertexSlider(CharacterSlider *char_slider) :
44  VertexSlider(InternalName::make(char_slider->get_name())),
45  _char_slider(char_slider)
46 {
47  // Tell the char_slider that we need to be informed when it moves.
48  _char_slider->_vertex_sliders.insert(this);
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: CharacterVertexSlider::Destructor
53 // Access: Published, Virtual
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 CharacterVertexSlider::
57 ~CharacterVertexSlider() {
58  // Tell the char_slider to stop informing us about its motion.
59  _char_slider->_vertex_sliders.erase(this);
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: CharacterVertexSlider::get_slider
64 // Access: Published, Virtual
65 // Description: Returns the current slider value.
66 ////////////////////////////////////////////////////////////////////
67 PN_stdfloat CharacterVertexSlider::
68 get_slider() const {
69  return _char_slider->_value;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: CharacterVertexSlider::register_with_read_factory
74 // Access: Public, Static
75 // Description: Tells the BamReader how to create objects of type
76 // CharacterVertexSlider.
77 ////////////////////////////////////////////////////////////////////
80  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: CharacterVertexSlider::write_datagram
85 // Access: Public, Virtual
86 // Description: Writes the contents of this object to the datagram
87 // for shipping out to a Bam file.
88 ////////////////////////////////////////////////////////////////////
91  VertexSlider::write_datagram(manager, dg);
92 
93  manager->write_pointer(dg, _char_slider);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: CharacterVertexSlider::complete_pointers
98 // Access: Public, Virtual
99 // Description: Receives an array of pointers, one for each time
100 // manager->read_pointer() was called in fillin().
101 // Returns the number of pointers processed.
102 ////////////////////////////////////////////////////////////////////
105  int pi = VertexSlider::complete_pointers(p_list, manager);
106 
107  _char_slider = DCAST(CharacterSlider, p_list[pi++]);
108  _char_slider->_vertex_sliders.insert(this);
109  _name = InternalName::make(_char_slider->get_name());
110 
111  return pi;
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: CharacterVertexSlider::make_from_bam
116 // Access: Protected, Static
117 // Description: This function is called by the BamReader's factory
118 // when a new object of type CharacterVertexSlider is encountered
119 // in the Bam file. It should create the CharacterVertexSlider
120 // and extract its information from the file.
121 ////////////////////////////////////////////////////////////////////
122 TypedWritable *CharacterVertexSlider::
123 make_from_bam(const FactoryParams &params) {
125  DatagramIterator scan;
126  BamReader *manager;
127 
128  parse_params(params, scan, manager);
129  object->fillin(scan, manager);
130 
131  return object;
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: CharacterVertexSlider::fillin
136 // Access: Protected
137 // Description: This internal function is called by make_from_bam to
138 // read in all of the relevant data from the BamFile for
139 // the new CharacterVertexSlider.
140 ////////////////////////////////////////////////////////////////////
141 void CharacterVertexSlider::
142 fillin(DatagramIterator &scan, BamReader *manager) {
143  VertexSlider::fillin(scan, manager);
144 
145  manager->read_pointer(scan);
146 }
const InternalName * get_name() const
Returns the name of this particular slider.
Definition: vertexSlider.I:25
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 a specialization on VertexSlider that returns the slider value associated with a particular C...
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:41
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is a morph slider within the character.
virtual PN_stdfloat get_slider() const
Returns the current slider value.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
static void register_with_read_factory()
Tells the BamReader how to create objects of type CharacterVertexSlider.
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
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 int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:658