Panda3D

animBundleNode.cxx

00001 // Filename: animBundleNode.cxx
00002 // Created by:  drose (06Mar02)
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 "animBundleNode.h"
00016 #include "datagram.h"
00017 #include "datagramIterator.h"
00018 #include "bamReader.h"
00019 #include "bamWriter.h"
00020 
00021 TypeHandle AnimBundleNode::_type_handle;
00022 
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: AnimBundleNode::make_copy
00026 //       Access: Public, Virtual
00027 //  Description: 
00028 ////////////////////////////////////////////////////////////////////
00029 PandaNode *AnimBundleNode::
00030 make_copy() const {
00031   return new AnimBundleNode(*this);
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: AnimBundleNode::safe_to_flatten
00036 //       Access: Public, Virtual
00037 //  Description: Returns true if it is generally safe to flatten out
00038 //               this particular kind of Node by duplicating
00039 //               instances, false otherwise (for instance, a Camera
00040 //               cannot be safely flattened, because the Camera
00041 //               pointer itself is meaningful).
00042 ////////////////////////////////////////////////////////////////////
00043 bool AnimBundleNode::
00044 safe_to_flatten() const {
00045   return false;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: AnimBundleNode::find_anim_bundle
00050 //       Access: Published, Static
00051 //  Description: Recursively walks the scene graph beginning at the
00052 //               indicated node (which need not be an AnimBundleNode),
00053 //               and returns the first AnimBundle found.  Returns NULL
00054 //               if no AnimBundle can be found.
00055 ////////////////////////////////////////////////////////////////////
00056 AnimBundle *AnimBundleNode::
00057 find_anim_bundle(PandaNode *root) {
00058   nassertr(root != (PandaNode *)NULL, NULL);
00059 
00060   if (root->is_of_type(AnimBundleNode::get_class_type())) {
00061     AnimBundleNode *anode = DCAST(AnimBundleNode, root);
00062     AnimBundle *anim = anode->get_bundle();
00063     if (anim != (AnimBundle *)NULL) {
00064       return anim;
00065     }
00066   }
00067 
00068   Children cr = root->get_children();
00069   int num_children = cr.get_num_children();
00070   for (int i = 0; i < num_children; i++) {
00071     AnimBundle *anim = find_anim_bundle(cr.get_child(i));
00072     if (anim != (AnimBundle *)NULL) {
00073       return anim;
00074     }
00075   }
00076 
00077   return NULL;
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: AnimBundleNode::register_with_read_factory
00082 //       Access: Public, Static
00083 //  Description: Tells the BamReader how to create objects of type
00084 //               AnimBundleNode.
00085 ////////////////////////////////////////////////////////////////////
00086 void AnimBundleNode::
00087 register_with_read_factory() {
00088   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: AnimBundleNode::write_datagram
00093 //       Access: Public, Virtual
00094 //  Description: Writes the contents of this object to the datagram
00095 //               for shipping out to a Bam file.
00096 ////////////////////////////////////////////////////////////////////
00097 void AnimBundleNode::
00098 write_datagram(BamWriter *manager, Datagram &dg) {
00099   PandaNode::write_datagram(manager, dg);
00100   manager->write_pointer(dg, _bundle);
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: AnimBundleNode::complete_pointers
00105 //       Access: Public, Virtual
00106 //  Description: Receives an array of pointers, one for each time
00107 //               manager->read_pointer() was called in fillin().
00108 //               Returns the number of pointers processed.
00109 ////////////////////////////////////////////////////////////////////
00110 int AnimBundleNode::
00111 complete_pointers(TypedWritable **p_list, BamReader* manager) {
00112   int pi = PandaNode::complete_pointers(p_list, manager);
00113   _bundle = DCAST(AnimBundle, p_list[pi++]);
00114   return pi;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: AnimBundleNode::make_from_bam
00119 //       Access: Protected, Static
00120 //  Description: This function is called by the BamReader's factory
00121 //               when a new object of this type is encountered
00122 //               in the Bam file.  It should create the object
00123 //               and extract its information from the file.
00124 ////////////////////////////////////////////////////////////////////
00125 TypedWritable *AnimBundleNode::
00126 make_from_bam(const FactoryParams &params) {
00127   AnimBundleNode *node = new AnimBundleNode;
00128   DatagramIterator scan;
00129   BamReader *manager;
00130 
00131   parse_params(params, scan, manager);
00132   node->fillin(scan, manager);
00133 
00134   return node;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: AnimBundleNode::fillin
00139 //       Access: Protected
00140 //  Description: This internal function is called by make_from_bam to
00141 //               read in all of the relevant data from the BamFile for
00142 //               the new PandaNode.
00143 ////////////////////////////////////////////////////////////////////
00144 void AnimBundleNode::
00145 fillin(DatagramIterator &scan, BamReader* manager) {
00146   PandaNode::fillin(scan, manager);
00147   manager->read_pointer(scan);
00148 }
 All Classes Functions Variables Enumerations