Panda3D
movingPart.I
1 // Filename: movingPart.I
2 // Created by: drose (22Feb99)
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 "animChannelFixed.h"
16 #include "datagram.h"
17 #include "datagramIterator.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
20 
21 template<class SwitchType>
22 TypeHandle MovingPart<SwitchType>::_type_handle;
23 
24 // We don't need to explicitly call MovingPart::init_type(), because
25 // it is an abstract class and therefore must have derived objects.
26 // Its derived objects will call init_type() for us.
27 
28 
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: MovingPart::Copy Constructor
32 // Access: Protected
33 // Description: Normally, you'd use make_copy() or copy_subgraph() to
34 // make a copy of this.
35 ////////////////////////////////////////////////////////////////////
36 template<class SwitchType>
39  MovingPartBase(copy),
40  _value(copy._value),
41  _default_value(copy._default_value)
42 {
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: MovingPart::Constructor
47 // Access: Public
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 template<class SwitchType>
52 MovingPart(PartGroup *parent, const string &name,
53  const ValueType &default_value) :
54  MovingPartBase(parent, name),
55  _value(default_value),
56  _default_value(default_value)
57 {
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: MovingPart::Constructor
62 // Access: Protected
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 template<class SwitchType>
67 MovingPart() {
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: MovingPart::get_value_type
72 // Access: Public, Virtual
73 // Description: Returns the TypeHandle associated with the ValueType
74 // we are concerned with. This is provided to allow a
75 // bit of run-time checking that joints and channels are
76 // matching properly in type.
77 ////////////////////////////////////////////////////////////////////
78 template<class SwitchType>
80 get_value_type() const {
81  return get_type_handle(ValueType);
82 }
83 
84 
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: MovingPart::make_default_channel
88 // Access: Public, Virtual
89 // Description: Creates and returns a new AnimChannel that is not
90 // part of any hierarchy, but that returns the default
91 // value associated with this part.
92 ////////////////////////////////////////////////////////////////////
93 template<class SwitchType>
96  return new AnimChannelFixed<SwitchType>(get_name(), _default_value);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: MovingPart::output_value
101 // Access: Public, Virtual
102 // Description: Outputs a very brief description of the channel's
103 // current value.
104 ////////////////////////////////////////////////////////////////////
105 template<class SwitchType>
107 output_value(ostream &out) const {
108  SwitchType::output_value(out, _value);
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: MovingPart::write_datagram
113 // Access: Public
114 // Description: Function to write the important information in
115 // the particular object to a Datagram
116 ////////////////////////////////////////////////////////////////////
117 template<class SwitchType>
120  MovingPartBase::write_datagram(manager, me);
121  SwitchType::write_datagram(me, _value);
122  SwitchType::write_datagram(me, _default_value);
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: MovingPart::fillin
127 // Access: Protected
128 // Description: Function that reads out of the datagram (or asks
129 // manager to read) all of the data that is needed to
130 // re-create this object and stores it in the appropiate
131 // place
132 ////////////////////////////////////////////////////////////////////
133 template<class SwitchType>
135 fillin(DatagramIterator &scan, BamReader *manager) {
136  MovingPartBase::fillin(scan, manager);
137  SwitchType::read_datagram(scan, _value);
138  SwitchType::read_datagram(scan, _default_value);
139 }
140 
141 
142 
virtual AnimChannelBase * make_default_channel() const
Creates and returns a new AnimChannel that is not part of any hierarchy, but that returns the default...
Definition: movingPart.I:95
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the template instantiation of MovingPartBase, on the particular type of value provided by the...
Definition: movingPart.h:30
This is the base class for a single animatable piece that may be bound to one channel (or more...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
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 &me)
Function to write the important information in the particular object to a Datagram.
Definition: movingPart.I:119
Parent class for all animation channels.
This template class is a special kind of AnimChannel that always returns just one fixed value...
virtual TypeHandle get_value_type() const
Returns the TypeHandle associated with the ValueType we are concerned with.
Definition: movingPart.I:80
virtual void output_value(ostream &out) const
Outputs a very brief description of the channel&#39;s current value.
Definition: movingPart.I:107
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
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45