Panda3D
eggComponentData.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggComponentData.cxx
10  * @author drose
11  * @date 2001-02-26
12  */
13 
14 #include "eggComponentData.h"
15 #include "eggBackPointer.h"
16 #include "nameUniquifier.h"
17 
18 #include "indent.h"
19 
20 TypeHandle EggComponentData::_type_handle;
21 
22 
23 /**
24  *
25  */
26 EggComponentData::
27 EggComponentData(EggCharacterCollection *collection,
28  EggCharacterData *char_data) :
29  _collection(collection),
30  _char_data(char_data)
31 {
32 }
33 
34 /**
35  *
36  */
37 EggComponentData::
38 ~EggComponentData() {
39  BackPointers::iterator bpi;
40  for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
41  EggBackPointer *back = (*bpi);
42  if (back != nullptr) {
43  delete back;
44  }
45  }
46 }
47 
48 /**
49  * Adds the indicated name to the set of names that this component can be
50  * identified with. If this is the first name added, it becomes the primary
51  * name of the component; later names added do not replace the primary name,
52  * but do get added to the list of names that will be accepted by
53  * matched_name().
54  */
56 add_name(const std::string &name, NameUniquifier &uniquifier) {
57  if (_names.insert(name).second) {
58  // This is a new name for this component.
59  if (!has_name()) {
60  set_name(uniquifier.add_name(name));
61  if (get_name() != name) {
62  nout << "Warning: renamed " << name << " to " << get_name()
63  << " to avoid naming conflict.\n";
64  }
65  }
66  }
67 }
68 
69 /**
70  * Returns true if the indicated name matches any name that was ever matched
71  * with this particular joint, false otherwise.
72  */
74 matches_name(const std::string &name) const {
75  if (name == get_name()) {
76  return true;
77  }
78  return (_names.find(name) != _names.end());
79 }
80 
81 /**
82  * Returns the number of frames of animation for this particular component in
83  * the indicated model.
84  */
86 get_num_frames(int model_index) const {
87  EggBackPointer *back = get_model(model_index);
88  if (back == nullptr) {
89  return 0;
90  }
91  return back->get_num_frames();
92 }
93 
94 /**
95  * Extends the number of frames in the indicated model (presumably an
96  * animation table model) to the given number.
97  */
99 extend_to(int model_index, int num_frames) const {
100  EggBackPointer *back = get_model(model_index);
101  nassertv(back != nullptr);
102  back->extend_to(num_frames);
103 }
104 
105 /**
106  * Returns the number of frames of animation for this particular component in
107  * the indicated model.
108  */
109 double EggComponentData::
110 get_frame_rate(int model_index) const {
111  EggBackPointer *back = get_model(model_index);
112  if (back == nullptr) {
113  return 0.0;
114  }
115  return back->get_frame_rate();
116 }
117 
118 /**
119  * Sets the back_pointer associated with the given model_index.
120  */
122 set_model(int model_index, EggBackPointer *back) {
123  while ((int)_back_pointers.size() <= model_index) {
124  _back_pointers.push_back(nullptr);
125  }
126 
127  if (_back_pointers[model_index] != nullptr) {
128  nout << "Warning: deleting old back pointer.\n";
129  delete _back_pointers[model_index];
130  }
131  _back_pointers[model_index] = back;
132 }
int get_num_frames(int model_index) const
Returns the number of frames of animation for this particular component in the indicated model.
void add_name(const std::string &name, NameUniquifier &uniquifier)
Adds the indicated name to the set of names that this component can be identified with.
void set_model(int model_index, EggBackPointer *back)
Sets the back_pointer associated with the given model_index.
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...
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.
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
virtual double get_frame_rate() const
Returns the stated frame rate of this particular joint, or 0.0 if it doesn't state.
virtual void extend_to(int num_frames)
Extends the table to the indicated number of frames.
bool matches_name(const std::string &name) const
Returns true if the indicated name matches any name that was ever matched with this particular joint,...
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a single character, as read and collected from several models and animation files.
std::string add_name(const std::string &name)
If name is nonempty and so far unique, returns it unchanged.
double get_frame_rate(int model_index) const
Returns the number of frames of animation for this particular component in the indicated model.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
Definition: namable.I:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This stores a pointer from an EggJointData or EggSliderData object back to the referencing data in an...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.