Panda3D
 All Classes Functions Variables Enumerations
eggComponentData.cxx
1 // Filename: eggComponentData.cxx
2 // Created by: drose (26Feb01)
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 "eggComponentData.h"
16 #include "eggBackPointer.h"
17 #include "nameUniquifier.h"
18 
19 #include "indent.h"
20 
21 TypeHandle EggComponentData::_type_handle;
22 
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: EggComponentData::Constructor
26 // Access: Public
27 // Description:
28 ////////////////////////////////////////////////////////////////////
29 EggComponentData::
30 EggComponentData(EggCharacterCollection *collection,
31  EggCharacterData *char_data) :
32  _collection(collection),
33  _char_data(char_data)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: EggComponentData::Destructor
39 // Access: Public, Virtual
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 EggComponentData::
43 ~EggComponentData() {
44  BackPointers::iterator bpi;
45  for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
46  EggBackPointer *back = (*bpi);
47  if (back != (EggBackPointer *)NULL) {
48  delete back;
49  }
50  }
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: EggComponentData::add_name
55 // Access: Public
56 // Description: Adds the indicated name to the set of names that this
57 // component can be identified with. If this is the
58 // first name added, it becomes the primary name of the
59 // component; later names added do not replace the
60 // primary name, but do get added to the list of names
61 // that will be accepted by matched_name().
62 ////////////////////////////////////////////////////////////////////
64 add_name(const string &name, NameUniquifier &uniquifier) {
65  if (_names.insert(name).second) {
66  // This is a new name for this component.
67  if (!has_name()) {
68  set_name(uniquifier.add_name(name));
69  if (get_name() != name) {
70  nout << "Warning: renamed " << name << " to " << get_name()
71  << " to avoid naming conflict.\n";
72  }
73  }
74  }
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: EggComponentData::matches_name
79 // Access: Public
80 // Description: Returns true if the indicated name matches any name
81 // that was ever matched with this particular joint,
82 // false otherwise.
83 ////////////////////////////////////////////////////////////////////
85 matches_name(const string &name) const {
86  if (name == get_name()) {
87  return true;
88  }
89  return (_names.find(name) != _names.end());
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: EggComponentData::get_num_frames
94 // Access: Public, Virtual
95 // Description: Returns the number of frames of animation for this
96 // particular component in the indicated model.
97 ////////////////////////////////////////////////////////////////////
99 get_num_frames(int model_index) const {
100  EggBackPointer *back = get_model(model_index);
101  if (back == (EggBackPointer *)NULL) {
102  return 0;
103  }
104  return back->get_num_frames();
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: EggComponentData::extend_to
109 // Access: Public, Virtual
110 // Description: Extends the number of frames in the indicated model
111 // (presumably an animation table model) to the given
112 // number.
113 ////////////////////////////////////////////////////////////////////
115 extend_to(int model_index, int num_frames) const {
116  EggBackPointer *back = get_model(model_index);
117  nassertv(back != (EggBackPointer *)NULL);
118  back->extend_to(num_frames);
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: EggComponentData::get_frame_rate
123 // Access: Public, Virtual
124 // Description: Returns the number of frames of animation for this
125 // particular component in the indicated model.
126 ////////////////////////////////////////////////////////////////////
127 double EggComponentData::
128 get_frame_rate(int model_index) const {
129  EggBackPointer *back = get_model(model_index);
130  if (back == (EggBackPointer *)NULL) {
131  return 0.0;
132  }
133  return back->get_frame_rate();
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: EggComponentData::set_model
138 // Access: Public
139 // Description: Sets the back_pointer associated with the given
140 // model_index.
141 ////////////////////////////////////////////////////////////////////
143 set_model(int model_index, EggBackPointer *back) {
144  while ((int)_back_pointers.size() <= model_index) {
145  _back_pointers.push_back((EggBackPointer *)NULL);
146  }
147 
148  if (_back_pointers[model_index] != (EggBackPointer *)NULL) {
149  nout << "Warning: deleting old back pointer.\n";
150  delete _back_pointers[model_index];
151  }
152  _back_pointers[model_index] = back;
153 }
void set_model(int model_index, EggBackPointer *back)
Sets the back_pointer associated with the given model_index.
bool matches_name(const string &name) const
Returns true if the indicated name matches any name that was ever matched with this particular joint...
void extend_to(int model_index, int num_frames) const
Extends the number of frames in the indicated model (presumably an animation table model) to the give...
virtual double get_frame_rate() const
Returns the stated frame rate of this particular joint, or 0.0 if it doesn&#39;t state.
int get_num_frames(int model_index) const
Returns the number of frames of animation for this particular component in the indicated model...
EggBackPointer * get_model(int model_index) const
Returns the back pointer to an egg file for the indicated model if it exists, or NULL if it does not...
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
Definition: namable.I:75
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
virtual void extend_to(int num_frames)
Extends the table to the indicated number of frames.
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
Represents a single character, as read and collected from several models and animation files...
string add_name(const string &name)
If name is nonempty and so far unique, returns it unchanged.
void add_name(const string &name, NameUniquifier &uniquifier)
Adds the indicated name to the set of names that this component can be identified with...
double get_frame_rate(int model_index) const
Returns the number of frames of animation for this particular component in the indicated model...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This stores a pointer from an EggJointData or EggSliderData object back to the referencing data in an...