00001 // Filename: movingPart.I 00002 // Created by: drose (22Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "animChannelFixed.h" 00016 #include "datagram.h" 00017 #include "datagramIterator.h" 00018 #include "bamReader.h" 00019 #include "bamWriter.h" 00020 00021 template<class SwitchType> 00022 TypeHandle MovingPart<SwitchType>::_type_handle; 00023 00024 // We don't need to explicitly call MovingPart::init_type(), because 00025 // it is an abstract class and therefore must have derived objects. 00026 // Its derived objects will call init_type() for us. 00027 00028 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: MovingPart::Copy Constructor 00032 // Access: Protected 00033 // Description: Normally, you'd use make_copy() or copy_subgraph() to 00034 // make a copy of this. 00035 //////////////////////////////////////////////////////////////////// 00036 template<class SwitchType> 00037 INLINE MovingPart<SwitchType>:: 00038 MovingPart(const MovingPart<SwitchType> ©) : 00039 MovingPartBase(copy), 00040 _value(copy._value), 00041 _default_value(copy._default_value) 00042 { 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: MovingPart::Constructor 00047 // Access: Public 00048 // Description: 00049 //////////////////////////////////////////////////////////////////// 00050 template<class SwitchType> 00051 INLINE MovingPart<SwitchType>:: 00052 MovingPart(PartGroup *parent, const string &name, 00053 const ValueType &default_value) : 00054 MovingPartBase(parent, name), 00055 _value(default_value), 00056 _default_value(default_value) 00057 { 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: MovingPart::Constructor 00062 // Access: Protected 00063 // Description: 00064 //////////////////////////////////////////////////////////////////// 00065 template<class SwitchType> 00066 INLINE MovingPart<SwitchType>:: 00067 MovingPart() { 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: MovingPart::get_value_type 00072 // Access: Public, Virtual 00073 // Description: Returns the TypeHandle associated with the ValueType 00074 // we are concerned with. This is provided to allow a 00075 // bit of run-time checking that joints and channels are 00076 // matching properly in type. 00077 //////////////////////////////////////////////////////////////////// 00078 template<class SwitchType> 00079 TypeHandle MovingPart<SwitchType>:: 00080 get_value_type() const { 00081 return get_type_handle(ValueType); 00082 } 00083 00084 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: MovingPart::make_default_channel 00088 // Access: Public, Virtual 00089 // Description: Creates and returns a new AnimChannel that is not 00090 // part of any hierarchy, but that returns the default 00091 // value associated with this part. 00092 //////////////////////////////////////////////////////////////////// 00093 template<class SwitchType> 00094 AnimChannelBase *MovingPart<SwitchType>:: 00095 make_default_channel() const { 00096 return new AnimChannelFixed<SwitchType>(get_name(), _default_value); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: MovingPart::output_value 00101 // Access: Public, Virtual 00102 // Description: Outputs a very brief description of the channel's 00103 // current value. 00104 //////////////////////////////////////////////////////////////////// 00105 template<class SwitchType> 00106 void MovingPart<SwitchType>:: 00107 output_value(ostream &out) const { 00108 SwitchType::output_value(out, _value); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: MovingPart::write_datagram 00113 // Access: Public 00114 // Description: Function to write the important information in 00115 // the particular object to a Datagram 00116 //////////////////////////////////////////////////////////////////// 00117 template<class SwitchType> 00118 void MovingPart<SwitchType>:: 00119 write_datagram(BamWriter *manager, Datagram &me) { 00120 MovingPartBase::write_datagram(manager, me); 00121 SwitchType::write_datagram(me, _value); 00122 SwitchType::write_datagram(me, _default_value); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: MovingPart::fillin 00127 // Access: Protected 00128 // Description: Function that reads out of the datagram (or asks 00129 // manager to read) all of the data that is needed to 00130 // re-create this object and stores it in the appropiate 00131 // place 00132 //////////////////////////////////////////////////////////////////// 00133 template<class SwitchType> 00134 void MovingPart<SwitchType>:: 00135 fillin(DatagramIterator &scan, BamReader *manager) { 00136 MovingPartBase::fillin(scan, manager); 00137 SwitchType::read_datagram(scan, _value); 00138 SwitchType::read_datagram(scan, _default_value); 00139 } 00140 00141 00142