eggComponentData.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include "eggComponentData.h"
  14. #include "eggBackPointer.h"
  15. #include "nameUniquifier.h"
  16. #include "indent.h"
  17. TypeHandle EggComponentData::_type_handle;
  18. /**
  19. *
  20. */
  21. EggComponentData::
  22. EggComponentData(EggCharacterCollection *collection,
  23. EggCharacterData *char_data) :
  24. _collection(collection),
  25. _char_data(char_data)
  26. {
  27. }
  28. /**
  29. *
  30. */
  31. EggComponentData::
  32. ~EggComponentData() {
  33. for (EggBackPointer *back : _back_pointers) {
  34. delete back;
  35. }
  36. }
  37. /**
  38. * Adds the indicated name to the set of names that this component can be
  39. * identified with. If this is the first name added, it becomes the primary
  40. * name of the component; later names added do not replace the primary name,
  41. * but do get added to the list of names that will be accepted by
  42. * matched_name().
  43. */
  44. void EggComponentData::
  45. add_name(const std::string &name, NameUniquifier &uniquifier) {
  46. if (_names.insert(name).second) {
  47. // This is a new name for this component.
  48. if (!has_name()) {
  49. set_name(uniquifier.add_name(name));
  50. if (get_name() != name) {
  51. nout << "Warning: renamed " << name << " to " << get_name()
  52. << " to avoid naming conflict.\n";
  53. }
  54. }
  55. }
  56. }
  57. /**
  58. * Returns true if the indicated name matches any name that was ever matched
  59. * with this particular joint, false otherwise.
  60. */
  61. bool EggComponentData::
  62. matches_name(const std::string &name) const {
  63. if (name == get_name()) {
  64. return true;
  65. }
  66. return (_names.find(name) != _names.end());
  67. }
  68. /**
  69. * Returns the number of frames of animation for this particular component in
  70. * the indicated model.
  71. */
  72. int EggComponentData::
  73. get_num_frames(int model_index) const {
  74. EggBackPointer *back = get_model(model_index);
  75. if (back == nullptr) {
  76. return 0;
  77. }
  78. return back->get_num_frames();
  79. }
  80. /**
  81. * Extends the number of frames in the indicated model (presumably an
  82. * animation table model) to the given number.
  83. */
  84. void EggComponentData::
  85. extend_to(int model_index, int num_frames) const {
  86. EggBackPointer *back = get_model(model_index);
  87. nassertv(back != nullptr);
  88. back->extend_to(num_frames);
  89. }
  90. /**
  91. * Returns the number of frames of animation for this particular component in
  92. * the indicated model.
  93. */
  94. double EggComponentData::
  95. get_frame_rate(int model_index) const {
  96. EggBackPointer *back = get_model(model_index);
  97. if (back == nullptr) {
  98. return 0.0;
  99. }
  100. return back->get_frame_rate();
  101. }
  102. /**
  103. * Sets the back_pointer associated with the given model_index.
  104. */
  105. void EggComponentData::
  106. set_model(int model_index, EggBackPointer *back) {
  107. while ((int)_back_pointers.size() <= model_index) {
  108. _back_pointers.push_back(nullptr);
  109. }
  110. if (_back_pointers[model_index] != nullptr) {
  111. nout << "Warning: deleting old back pointer.\n";
  112. delete _back_pointers[model_index];
  113. }
  114. _back_pointers[model_index] = back;
  115. }