nodeChainComponent.I 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Filename: nodeChainComponent.I
  2. // Created by: drose (25Feb02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: NodeChainComponent::CData::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE NodeChainComponent::CData::
  24. CData() {
  25. _length = 1;
  26. }
  27. ////////////////////////////////////////////////////////////////////
  28. // Function: NodeChainComponent::CData::Copy Constructor
  29. // Access: Public
  30. // Description:
  31. ////////////////////////////////////////////////////////////////////
  32. INLINE NodeChainComponent::CData::
  33. CData(const NodeChainComponent::CData &copy) :
  34. _next(copy._next),
  35. _length(copy._length)
  36. {
  37. }
  38. ////////////////////////////////////////////////////////////////////
  39. // Function: NodeChainComponent::Constructor
  40. // Access: Private
  41. // Description: Constructs a new NodeChainComponent from the
  42. // indicated node. Don't try to call this directly; ask
  43. // the PandaNode to do it for you.
  44. ////////////////////////////////////////////////////////////////////
  45. INLINE NodeChainComponent::
  46. NodeChainComponent(PandaNode *node, NodeChainComponent *next) :
  47. _node(node)
  48. {
  49. #ifdef DO_MEMORY_USAGE
  50. MemoryUsage::update_type(this, get_class_type());
  51. #endif
  52. CDWriter cdata(_cycler);
  53. cdata->_next = next;
  54. if (next != (NodeChainComponent *)NULL) {
  55. cdata->_length = next->get_length() + 1;
  56. }
  57. }
  58. ////////////////////////////////////////////////////////////////////
  59. // Function: NodeChainComponent::Copy Constructor
  60. // Access: Private
  61. // Description: NodeChainComponents should not be copied.
  62. ////////////////////////////////////////////////////////////////////
  63. INLINE NodeChainComponent::
  64. NodeChainComponent(const NodeChainComponent &copy) {
  65. nassertv(false);
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: NodeChainComponent::Copy Assignment Operator
  69. // Access: Private
  70. // Description: NodeChainComponents should not be copied.
  71. ////////////////////////////////////////////////////////////////////
  72. INLINE void NodeChainComponent::
  73. operator = (const NodeChainComponent &copy) {
  74. nassertv(false);
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: NodeChainComponent::Destructor
  78. // Access: Public
  79. // Description:
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE NodeChainComponent::
  82. ~NodeChainComponent() {
  83. nassertv(_node != (PandaNode *)NULL);
  84. _node->delete_component(this);
  85. }
  86. ////////////////////////////////////////////////////////////////////
  87. // Function: NodeChainComponent::get_node
  88. // Access: Public
  89. // Description: Returns the node referenced by this component.
  90. ////////////////////////////////////////////////////////////////////
  91. INLINE PandaNode *NodeChainComponent::
  92. get_node() const {
  93. return _node;
  94. }
  95. ////////////////////////////////////////////////////////////////////
  96. // Function: NodeChainComponent::is_top_node
  97. // Access: Public
  98. // Description: Returns true if this component represents the top
  99. // node in the chain.
  100. ////////////////////////////////////////////////////////////////////
  101. INLINE bool NodeChainComponent::
  102. is_top_node() const {
  103. CDReader cdata(_cycler);
  104. return (cdata->_next == (NodeChainComponent *)NULL);
  105. }
  106. ////////////////////////////////////////////////////////////////////
  107. // Function: NodeChainComponent::is_collapsed
  108. // Access: Public
  109. // Description: Returns true if this component has been collapsed
  110. // with another component. In this case, the component
  111. // itself is invalid, and the collapsed component should
  112. // be used instead.
  113. ////////////////////////////////////////////////////////////////////
  114. INLINE bool NodeChainComponent::
  115. is_collapsed() const {
  116. CDReader cdata(_cycler);
  117. return (cdata->_length == 0);
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function: NodeChainComponent::get_length
  121. // Access: Public
  122. // Description: Returns the length of the chain.
  123. ////////////////////////////////////////////////////////////////////
  124. INLINE int NodeChainComponent::
  125. get_length() const {
  126. CDReader cdata(_cycler);
  127. nassertr(!is_collapsed(), 0);
  128. return cdata->_length;
  129. }
  130. ////////////////////////////////////////////////////////////////////
  131. // Function: NodeChainComponent::get_collapsed
  132. // Access: Public
  133. // Description: If is_collapsed() returns true, this is the component
  134. // that this one has been collapsed with, and should be
  135. // replaced with.
  136. ////////////////////////////////////////////////////////////////////
  137. INLINE NodeChainComponent *NodeChainComponent::
  138. get_collapsed() const {
  139. CDReader cdata(_cycler);
  140. nassertr(is_collapsed(), (NodeChainComponent *)NULL);
  141. return cdata->_next;
  142. }
  143. ////////////////////////////////////////////////////////////////////
  144. // Function: NodeChainComponent::set_next
  145. // Access: Private
  146. // Description: Sets the next pointer in the chain.
  147. ////////////////////////////////////////////////////////////////////
  148. INLINE void NodeChainComponent::
  149. set_next(NodeChainComponent *next) {
  150. CDWriter cdata(_cycler);
  151. nassertv(!is_collapsed());
  152. nassertv(next != (NodeChainComponent *)NULL);
  153. cdata->_next = next;
  154. }
  155. ////////////////////////////////////////////////////////////////////
  156. // Function: NodeChainComponent::set_top_node
  157. // Access: Private
  158. // Description: Severs any connection to the next pointer in the
  159. // chain and makes this component a top node.
  160. ////////////////////////////////////////////////////////////////////
  161. INLINE void NodeChainComponent::
  162. set_top_node() {
  163. CDWriter cdata(_cycler);
  164. nassertv(!is_collapsed());
  165. cdata->_next = (NodeChainComponent *)NULL;
  166. }
  167. ////////////////////////////////////////////////////////////////////
  168. // Function: NodeChainComponent::collapse_with
  169. // Access: Private
  170. // Description: Indicates that this component pointer is no longer
  171. // valid, and that the indicated component should be
  172. // used instead. This is done whenever two
  173. // NodeChainComponents have been collapsed together due
  174. // to an instance being removed higher up in the graph.
  175. ////////////////////////////////////////////////////////////////////
  176. INLINE void NodeChainComponent::
  177. collapse_with(NodeChainComponent *next) {
  178. CDWriter cdata(_cycler);
  179. nassertv(!is_collapsed());
  180. nassertv(next != (NodeChainComponent *)NULL);
  181. cdata->_next = next;
  182. cdata->_length = 0;
  183. // We indicate a component has been collapsed by setting its length
  184. // to zero.
  185. }