Panda3D

eggComponentData.cxx

00001 // Filename: eggComponentData.cxx
00002 // Created by:  drose (26Feb01)
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 "eggComponentData.h"
00016 #include "eggBackPointer.h"
00017 #include "nameUniquifier.h"
00018 
00019 #include "indent.h"
00020 
00021 TypeHandle EggComponentData::_type_handle;
00022 
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: EggComponentData::Constructor
00026 //       Access: Public
00027 //  Description:
00028 ////////////////////////////////////////////////////////////////////
00029 EggComponentData::
00030 EggComponentData(EggCharacterCollection *collection,
00031                  EggCharacterData *char_data) :
00032   _collection(collection),
00033   _char_data(char_data)
00034 {
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: EggComponentData::Destructor
00039 //       Access: Public, Virtual
00040 //  Description:
00041 ////////////////////////////////////////////////////////////////////
00042 EggComponentData::
00043 ~EggComponentData() {
00044   BackPointers::iterator bpi;
00045   for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
00046     EggBackPointer *back = (*bpi);
00047     if (back != (EggBackPointer *)NULL) {
00048       delete back;
00049     }
00050   }
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: EggComponentData::add_name
00055 //       Access: Public
00056 //  Description: Adds the indicated name to the set of names that this
00057 //               component can be identified with.  If this is the
00058 //               first name added, it becomes the primary name of the
00059 //               component; later names added do not replace the
00060 //               primary name, but do get added to the list of names
00061 //               that will be accepted by matched_name().
00062 ////////////////////////////////////////////////////////////////////
00063 void EggComponentData::
00064 add_name(const string &name, NameUniquifier &uniquifier) {
00065   if (_names.insert(name).second) {
00066     // This is a new name for this component.
00067     if (!has_name()) {
00068       set_name(uniquifier.add_name(name));
00069       if (get_name() != name) {
00070         nout << "Warning: renamed " << name << " to " << get_name()
00071              << " to avoid naming conflict.\n";
00072       }
00073     }
00074   }
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: EggComponentData::matches_name
00079 //       Access: Public
00080 //  Description: Returns true if the indicated name matches any name
00081 //               that was ever matched with this particular joint,
00082 //               false otherwise.
00083 ////////////////////////////////////////////////////////////////////
00084 bool EggComponentData::
00085 matches_name(const string &name) const {
00086   if (name == get_name()) {
00087     return true;
00088   }
00089   return (_names.find(name) != _names.end());
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: EggComponentData::get_num_frames
00094 //       Access: Public, Virtual
00095 //  Description: Returns the number of frames of animation for this
00096 //               particular component in the indicated model.
00097 ////////////////////////////////////////////////////////////////////
00098 int EggComponentData::
00099 get_num_frames(int model_index) const {
00100   EggBackPointer *back = get_model(model_index);
00101   if (back == (EggBackPointer *)NULL) {
00102     return 0;
00103   }
00104   return back->get_num_frames();
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: EggComponentData::extend_to
00109 //       Access: Public, Virtual
00110 //  Description: Extends the number of frames in the indicated model
00111 //               (presumably an animation table model) to the given
00112 //               number.
00113 ////////////////////////////////////////////////////////////////////
00114 void EggComponentData::
00115 extend_to(int model_index, int num_frames) const {
00116   EggBackPointer *back = get_model(model_index);
00117   nassertv(back != (EggBackPointer *)NULL);
00118   back->extend_to(num_frames);
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: EggComponentData::get_frame_rate
00123 //       Access: Public, Virtual
00124 //  Description: Returns the number of frames of animation for this
00125 //               particular component in the indicated model.
00126 ////////////////////////////////////////////////////////////////////
00127 double EggComponentData::
00128 get_frame_rate(int model_index) const {
00129   EggBackPointer *back = get_model(model_index);
00130   if (back == (EggBackPointer *)NULL) {
00131     return 0.0;
00132   }
00133   return back->get_frame_rate();
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: EggComponentData::set_model
00138 //       Access: Public
00139 //  Description: Sets the back_pointer associated with the given
00140 //               model_index.
00141 ////////////////////////////////////////////////////////////////////
00142 void EggComponentData::
00143 set_model(int model_index, EggBackPointer *back) {
00144   while ((int)_back_pointers.size() <= model_index) {
00145     _back_pointers.push_back((EggBackPointer *)NULL);
00146   }
00147 
00148   if (_back_pointers[model_index] != (EggBackPointer *)NULL) {
00149     nout << "Warning: deleting old back pointer.\n";
00150     delete _back_pointers[model_index];
00151   }
00152   _back_pointers[model_index] = back;
00153 }
 All Classes Functions Variables Enumerations