Panda3D
|
00001 // Filename: animBundle.cxx 00002 // Created by: drose (21Feb99) 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 00016 #include "animBundle.h" 00017 00018 #include "indent.h" 00019 #include "datagram.h" 00020 #include "datagramIterator.h" 00021 #include "bamReader.h" 00022 #include "bamWriter.h" 00023 00024 TypeHandle AnimBundle::_type_handle; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: AnimBundle::Copy Constructor 00028 // Access: Protected 00029 // Description: Creates a new AnimBundle, just like this one, without 00030 // copying any children. The new copy is added to the 00031 // indicated parent. Intended to be called by 00032 // make_copy() only. 00033 //////////////////////////////////////////////////////////////////// 00034 AnimBundle:: 00035 AnimBundle(AnimGroup *parent, const AnimBundle ©) : 00036 AnimGroup(parent, copy), 00037 _fps(copy._fps), 00038 _num_frames(copy._num_frames) 00039 { 00040 nassertv(_root == (AnimBundle *)NULL); 00041 _root = this; 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: AnimBundle::copy_bundle 00046 // Access: Published 00047 // Description: Returns a full copy of the bundle and its entire tree 00048 // of nested AnimGroups. However, the actual data 00049 // stored in the leaves--that is, animation tables, such 00050 // as those stored in an AnimChannelMatrixXfmTable--will 00051 // be shared. 00052 //////////////////////////////////////////////////////////////////// 00053 PT(AnimBundle) AnimBundle:: 00054 copy_bundle() const { 00055 PT(AnimGroup) group = copy_subtree((AnimGroup *)NULL); 00056 return DCAST(AnimBundle, group.p()); 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: AnimBundle::output 00061 // Access: Public, Virtual 00062 // Description: Writes a one-line description of the bundle. 00063 //////////////////////////////////////////////////////////////////// 00064 void AnimBundle:: 00065 output(ostream &out) const { 00066 out << get_type() << " " << get_name() << ", " << get_num_frames() 00067 << " frames at " << get_base_frame_rate() << " fps"; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: AnimBundle::make_copy 00072 // Access: Protected, Virtual 00073 // Description: Returns a copy of this object, and attaches it to the 00074 // indicated parent (which may be NULL only if this is 00075 // an AnimBundle). Intended to be called by 00076 // copy_subtree() only. 00077 //////////////////////////////////////////////////////////////////// 00078 AnimGroup *AnimBundle:: 00079 make_copy(AnimGroup *parent) const { 00080 return new AnimBundle(parent, *this); 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: AnimBundle::write_datagram 00085 // Access: Public 00086 // Description: Function to write the important information in 00087 // the particular object to a Datagram 00088 //////////////////////////////////////////////////////////////////// 00089 void AnimBundle:: 00090 write_datagram(BamWriter *manager, Datagram &me) { 00091 AnimGroup::write_datagram(manager, me); 00092 me.add_stdfloat(_fps); 00093 me.add_uint16(_num_frames); 00094 } 00095 00096 //////////////////////////////////////////////////////////////////// 00097 // Function: AnimBundle::fillin 00098 // Access: Protected 00099 // Description: Function that reads out of the datagram (or asks 00100 // manager to read) all of the data that is needed to 00101 // re-create this object and stores it in the appropiate 00102 // place 00103 //////////////////////////////////////////////////////////////////// 00104 void AnimBundle:: 00105 fillin(DatagramIterator &scan, BamReader *manager) { 00106 AnimGroup::fillin(scan, manager); 00107 _fps = scan.get_stdfloat(); 00108 _num_frames = scan.get_uint16(); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: AnimBundle::make_AnimBundle 00113 // Access: Protected 00114 // Description: Factory method to generate a AnimBundle object 00115 //////////////////////////////////////////////////////////////////// 00116 TypedWritable *AnimBundle:: 00117 make_AnimBundle(const FactoryParams ¶ms) { 00118 AnimBundle *me = new AnimBundle; 00119 DatagramIterator scan; 00120 BamReader *manager; 00121 00122 parse_params(params, scan, manager); 00123 me->fillin(scan, manager); 00124 return me; 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: AnimBundle::register_with_factory 00129 // Access: Public, Static 00130 // Description: Factory method to generate a AnimBundle object 00131 //////////////////////////////////////////////////////////////////// 00132 void AnimBundle:: 00133 register_with_read_factory() { 00134 BamReader::get_factory()->register_factory(get_class_type(), make_AnimBundle); 00135 } 00136