speedTreeNode.I 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Filename: speedTreeNode.I
  2. // Created by: drose (30Sep10)
  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. // Function: SpeedTreeNode::is_valid
  16. // Access: Published
  17. // Description: Returns true if the node is valid and ready to
  18. // render, false otherwise. Note that this might not
  19. // become false until after the first time the node is
  20. // rendered.
  21. ////////////////////////////////////////////////////////////////////
  22. INLINE bool SpeedTreeNode::
  23. is_valid() const {
  24. return _is_valid;
  25. }
  26. ////////////////////////////////////////////////////////////////////
  27. // Function: SpeedTreeNode::get_num_trees
  28. // Access: Published
  29. // Description: Returns the number of unique tree objects that have
  30. // been added to the node. This count does not include
  31. // multiple instances of the same tree that appear in
  32. // different transforms.
  33. ////////////////////////////////////////////////////////////////////
  34. INLINE int SpeedTreeNode::
  35. get_num_trees() const {
  36. return (int)_trees.size();
  37. }
  38. ////////////////////////////////////////////////////////////////////
  39. // Function: SpeedTreeNode::get_tree
  40. // Access: Published
  41. // Description: Returns the STTree pointer for the nth tree.
  42. // See get_num_trees().
  43. ////////////////////////////////////////////////////////////////////
  44. INLINE const STTree *SpeedTreeNode::
  45. get_tree(int n) const {
  46. nassertr(n >= 0 && n < (int)_trees.size(), NULL);
  47. InstanceList *instance_list = _trees[n];
  48. return instance_list->get_tree();
  49. }
  50. ////////////////////////////////////////////////////////////////////
  51. // Function: SpeedTreeNode::get_instance_list
  52. // Access: Published
  53. // Description: Returns a list of transforms that corresponds to the
  54. // instances at which the nth tree appears.
  55. ////////////////////////////////////////////////////////////////////
  56. INLINE const SpeedTreeNode::InstanceList &SpeedTreeNode::
  57. get_instance_list(int n) const {
  58. nassertr(n >= 0 && n < (int)_trees.size(), *(InstanceList *)NULL);
  59. InstanceList *instance_list = _trees[n];
  60. return *instance_list;
  61. }
  62. ////////////////////////////////////////////////////////////////////
  63. // Function: SpeedTreeNode::modify_tree
  64. // Access: Published
  65. // Description: Returns a modifiable STTree pointer for the nth tree
  66. // instance.
  67. ////////////////////////////////////////////////////////////////////
  68. INLINE STTree *SpeedTreeNode::
  69. modify_tree(int n) {
  70. nassertr(n >= 0 && n < (int)_trees.size(), NULL);
  71. InstanceList *instance_list = _trees[n];
  72. _needs_repopulate = true;
  73. return (STTree *)instance_list->get_tree();
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: SpeedTreeNode::clear_terrain
  77. // Access: Published
  78. // Description: Removes the terrain associated with the node.
  79. ////////////////////////////////////////////////////////////////////
  80. INLINE void SpeedTreeNode::
  81. clear_terrain() {
  82. set_terrain(NULL);
  83. }
  84. ////////////////////////////////////////////////////////////////////
  85. // Function: SpeedTreeNode::has_terrain
  86. // Access: Published
  87. // Description: Returns true if a valid terrain has been associated
  88. // with the node, false otherwise.
  89. ////////////////////////////////////////////////////////////////////
  90. INLINE bool SpeedTreeNode::
  91. has_terrain() const {
  92. return _terrain != (STTerrain *)NULL;
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: SpeedTreeNode::get_terrain
  96. // Access: Published
  97. // Description: Returns the terrain associated with the node, or NULL
  98. // if there is no terrain.
  99. ////////////////////////////////////////////////////////////////////
  100. INLINE STTerrain *SpeedTreeNode::
  101. get_terrain() const {
  102. return _terrain;
  103. }
  104. ////////////////////////////////////////////////////////////////////
  105. // Function: SpeedTreeNode::set_time_delta
  106. // Access: Published
  107. // Description: Specifies an offset that is to be added each frame to
  108. // the global clock's frame_time for the purpose of
  109. // animating the trees in this particular node. Also
  110. // see set_global_time_delta().
  111. ////////////////////////////////////////////////////////////////////
  112. INLINE void SpeedTreeNode::
  113. set_time_delta(double delta) {
  114. _time_delta = delta;
  115. }
  116. ////////////////////////////////////////////////////////////////////
  117. // Function: SpeedTreeNode::get_time_delta
  118. // Access: Published
  119. // Description: Returns an offset that is to be added each frame to
  120. // the global clock's frame_time for the purpose of
  121. // animating the trees in this particular node. Also
  122. // see get_global_time_delta().
  123. ////////////////////////////////////////////////////////////////////
  124. INLINE double SpeedTreeNode::
  125. get_time_delta() const {
  126. return _time_delta;
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function: SpeedTreeNode::set_global_time_delta
  130. // Access: Published, Static
  131. // Description: Specifies an offset that is to be added each frame to
  132. // the global clock's frame_time for the purpose of
  133. // animating the trees in all SpeedTreeNodes. Also
  134. // see set_time_delta().
  135. ////////////////////////////////////////////////////////////////////
  136. INLINE void SpeedTreeNode::
  137. set_global_time_delta(double delta) {
  138. _global_time_delta = delta;
  139. }
  140. ////////////////////////////////////////////////////////////////////
  141. // Function: SpeedTreeNode::get_global_time_delta
  142. // Access: Published, Static
  143. // Description: Returns an offset that is to be added each frame to
  144. // the global clock's frame_time for the purpose of
  145. // animating the trees in all SpeedTreeNodes. Also
  146. // see get_time_delta().
  147. ////////////////////////////////////////////////////////////////////
  148. INLINE double SpeedTreeNode::
  149. get_global_time_delta() {
  150. return _global_time_delta;
  151. }
  152. ////////////////////////////////////////////////////////////////////
  153. // Function: SpeedTreeNode::InstanceList::Constructor
  154. // Access: Public
  155. // Description:
  156. ////////////////////////////////////////////////////////////////////
  157. INLINE SpeedTreeNode::InstanceList::
  158. InstanceList(const STTree *tree) : _tree((STTree *)tree) {
  159. }
  160. ////////////////////////////////////////////////////////////////////
  161. // Function: SpeedTreeNode::InstanceList::operator <
  162. // Access: Public
  163. // Description: Used for comparison for ov_set.
  164. ////////////////////////////////////////////////////////////////////
  165. INLINE bool SpeedTreeNode::InstanceList::
  166. operator < (const InstanceList &other) const {
  167. return _tree < other._tree;
  168. }
  169. ////////////////////////////////////////////////////////////////////
  170. // Function: SpeedTreeNode::InstanceList::get_tree
  171. // Access: Published
  172. // Description: Returns the particular tree this list refers to.
  173. ////////////////////////////////////////////////////////////////////
  174. INLINE const STTree *SpeedTreeNode::InstanceList::
  175. get_tree() const {
  176. return _tree;
  177. }
  178. ////////////////////////////////////////////////////////////////////
  179. // Function: SpeedTreeNode::InstanceList::get_num_instances
  180. // Access: Published
  181. // Description: Returns the number of instances of this tree.
  182. ////////////////////////////////////////////////////////////////////
  183. INLINE int SpeedTreeNode::InstanceList::
  184. get_num_instances() const {
  185. return (int)_instances.size();
  186. }
  187. ////////////////////////////////////////////////////////////////////
  188. // Function: SpeedTreeNode::InstanceList::get_instance
  189. // Access: Published
  190. // Description: Returns the transform of the nth instance of this
  191. // tree.
  192. ////////////////////////////////////////////////////////////////////
  193. INLINE STTransform SpeedTreeNode::InstanceList::
  194. get_instance(int n) const {
  195. nassertr(n >= 0 && n < (int)_instances.size(), STTransform::ident_mat());
  196. return _instances[n];
  197. }
  198. ////////////////////////////////////////////////////////////////////
  199. // Function: SpeedTreeNode::InstanceList::set_instance
  200. // Access: Published
  201. // Description: Replaces the transform of the nth instance of this
  202. // tree.
  203. ////////////////////////////////////////////////////////////////////
  204. INLINE void SpeedTreeNode::InstanceList::
  205. set_instance(int n, const STTransform &transform) {
  206. nassertv(n >= 0 && n < (int)_instances.size());
  207. _instances[n] = transform;
  208. }
  209. ////////////////////////////////////////////////////////////////////
  210. // Function: SpeedTreeNode::InstanceList::add_instance
  211. // Access: Published
  212. // Description: Adds a new instance of this tree at the indicated
  213. // transform. Returns the index number of the new
  214. // instance.
  215. ////////////////////////////////////////////////////////////////////
  216. INLINE int SpeedTreeNode::InstanceList::
  217. add_instance(const STTransform &transform) {
  218. _instances.push_back(transform);
  219. return ((int)_instances.size() - 1);
  220. }
  221. ////////////////////////////////////////////////////////////////////
  222. // Function: SpeedTreeNode::InstanceList::remove_instance
  223. // Access: Published
  224. // Description: Removes the nth instance of this tree.
  225. ////////////////////////////////////////////////////////////////////
  226. INLINE void SpeedTreeNode::InstanceList::
  227. remove_instance(int n) {
  228. nassertv(n >= 0 && n < (int)_instances.size());
  229. _instances.erase(_instances.begin() + n);
  230. }
  231. ////////////////////////////////////////////////////////////////////
  232. // Function: SpeedTreeNode::DrawCallback::Constructor
  233. // Access: Published
  234. // Description:
  235. ////////////////////////////////////////////////////////////////////
  236. INLINE SpeedTreeNode::DrawCallback::
  237. DrawCallback(SpeedTreeNode *node) : _node(node) {
  238. }