Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
91d07d9209

+ 11 - 0
panda/src/cull/cullState.I

@@ -169,6 +169,17 @@ get_attributes() const {
   return *_attrib;
   return *_attrib;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: CullState::get_transitions
+//       Access: Public
+//  Description: Returns the net transitions indicated by the
+//               CullState object.
+////////////////////////////////////////////////////////////////////
+INLINE const AllTransitionsWrapper &CullState::
+get_transitions() const {
+  return _trans;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: CullState::has_bin
 //     Function: CullState::has_bin
 //       Access: Public
 //       Access: Public

+ 1 - 0
panda/src/cull/cullState.h

@@ -60,6 +60,7 @@ public:
 
 
   INLINE void apply_to(const AllAttributesWrapper &initial_state);
   INLINE void apply_to(const AllAttributesWrapper &initial_state);
   INLINE const NodeAttributes &get_attributes() const;
   INLINE const NodeAttributes &get_attributes() const;
+  INLINE const AllTransitionsWrapper &get_transitions() const;
 
 
   INLINE bool has_bin() const;
   INLINE bool has_bin() const;
   INLINE GeomBin *get_bin() const;
   INLINE GeomBin *get_bin() const;

+ 12 - 2
panda/src/cull/cullTraverser.I

@@ -19,10 +19,12 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void CullTraverser::
 INLINE void CullTraverser::
 draw_geom(GeomNode *geom_node, const AllAttributesWrapper &initial_state) {
 draw_geom(GeomNode *geom_node, const AllAttributesWrapper &initial_state) {
+#ifndef NDEBUG
   if (cull_cat.is_spam()) {
   if (cull_cat.is_spam()) {
     cull_cat.spam() 
     cull_cat.spam() 
       << "Drawing " << *geom_node << " with state: " << initial_state << "\n";
       << "Drawing " << *geom_node << " with state: " << initial_state << "\n";
   }
   }
+#endif
   nassertv(geom_node != (GeomNode *)NULL);
   nassertv(geom_node != (GeomNode *)NULL);
   _gsg->set_state(initial_state.get_attributes(), true);
   _gsg->set_state(initial_state.get_attributes(), true);
   _gsg->prepare_display_region();
   _gsg->prepare_display_region();
@@ -56,10 +58,12 @@ draw_direct(const ArcChain &arc_chain,
 	    const AllAttributesWrapper &initial_state) {
 	    const AllAttributesWrapper &initial_state) {
   nassertv(!arc_chain.empty());
   nassertv(!arc_chain.empty());
   Node *node = arc_chain.back()->get_child();
   Node *node = arc_chain.back()->get_child();
+#ifndef NDEBUG
   if (cull_cat.is_spam()) {
   if (cull_cat.is_spam()) {
     cull_cat.spam() 
     cull_cat.spam() 
       << "Drawing " << *node << " in direct mode.\n";
       << "Drawing " << *node << " in direct mode.\n";
   }
   }
+#endif
   nassertv(node != (Node *)NULL);
   nassertv(node != (Node *)NULL);
   DirectRenderTraverser drt(_gsg, _graph_type, arc_chain);
   DirectRenderTraverser drt(_gsg, _graph_type, arc_chain);
   drt.traverse(node, initial_state, AllTransitionsWrapper());
   drt.traverse(node, initial_state, AllTransitionsWrapper());
@@ -101,6 +105,7 @@ find_bin_state(const AllTransitionsWrapper &trans) {
   // corresponding CullState that is (now) stored in the set.
   // corresponding CullState that is (now) stored in the set.
   pair<States::iterator, bool> result = _states.insert(cs);
   pair<States::iterator, bool> result = _states.insert(cs);
 
 
+#ifndef NDEBUG
   if (cull_cat.is_spam()) {
   if (cull_cat.is_spam()) {
     if (result.second) {
     if (result.second) {
       // The insert succeeded, so the CullState was not there
       // The insert succeeded, so the CullState was not there
@@ -109,12 +114,17 @@ find_bin_state(const AllTransitionsWrapper &trans) {
 	<< "Created CullState " << (void *)cs << " for:\n";
 	<< "Created CullState " << (void *)cs << " for:\n";
       trans.write(cull_cat.spam(false), 2);
       trans.write(cull_cat.spam(false), 2);
     } else {
     } else {
+      CullState *found_cs = *result.first;
       cull_cat.spam() 
       cull_cat.spam() 
-	<< "Found existing CullState " << (void *)(*result.first)
-	<< " for:\n";
+	<< "Found existing CullState " << (void *)found_cs
+	<< " which has:\n";
+      found_cs->get_transitions().write(cull_cat.spam(false), 2);
+      cull_cat.spam(false) 
+	<< "for:\n";
       trans.write(cull_cat.spam(false), 2);
       trans.write(cull_cat.spam(false), 2);
     }
     }
   }
   }
+#endif
 		       
 		       
   return *result.first;
   return *result.first;
 }
 }

+ 15 - 0
panda/src/graph/nodeRelation.cxx

@@ -9,6 +9,7 @@
 #include <boundingSphere.h>
 #include <boundingSphere.h>
 #include <notify.h>
 #include <notify.h>
 
 
+#include <algorithm>
 
 
 TypeHandle NodeRelation::_type_handle;
 TypeHandle NodeRelation::_type_handle;
 
 
@@ -401,6 +402,20 @@ compose_transitions_from(const NodeTransitions &trans) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodeRelation::adjust_all_proriorities
+//       Access: Public
+//  Description: Adds the indicated adjustment amount (which may be
+//               negative) to the priority for all transitions on the
+//               arc.  If the priority would drop below zero, it is
+//               set to zero.
+////////////////////////////////////////////////////////////////////
+void NodeRelation::
+adjust_all_priorities(int adjustment) {
+  _net_transitions.clear();
+  _transitions.adjust_all_priorities(adjustment, this);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodeRelation::sub_render_trans
 //     Function: NodeRelation::sub_render_trans
 //       Access: Public
 //       Access: Public

+ 2 - 0
panda/src/graph/nodeRelation.h

@@ -98,6 +98,7 @@ PUBLISHED:
   void compose_transitions_from(const NodeRelation *arc);
   void compose_transitions_from(const NodeRelation *arc);
   void copy_transitions_from(const NodeTransitions &trans);
   void copy_transitions_from(const NodeTransitions &trans);
   void compose_transitions_from(const NodeTransitions &trans);
   void compose_transitions_from(const NodeTransitions &trans);
+  void adjust_all_priorities(int adjustment);
 
 
   INLINE int compare_transitions_to(const NodeRelation *arc) const;
   INLINE int compare_transitions_to(const NodeRelation *arc) const;
 
 
@@ -214,6 +215,7 @@ private:
   friend class Node;
   friend class Node;
   friend class NodeTransitionWrapper;
   friend class NodeTransitionWrapper;
   friend class AllTransitionsWrapper;
   friend class AllTransitionsWrapper;
+  friend class GraphPriorityAdjuster;
 };
 };
 
 
 INLINE ostream &
 INLINE ostream &

+ 7 - 4
panda/src/graph/nodeTransition.I

@@ -117,12 +117,15 @@ compare_to(const NodeTransition &other) const {
   TypeHandle my_handle = get_handle();
   TypeHandle my_handle = get_handle();
   TypeHandle other_handle = other.get_handle();
   TypeHandle other_handle = other.get_handle();
 
 
-  if (my_handle == other_handle) {
-    return internal_compare_to(&other);
-
-  } else {
+  if (my_handle != other_handle) {
     return 
     return 
       (my_handle < other_handle) ? -1 : 1;
       (my_handle < other_handle) ? -1 : 1;
+
+  } else if (_priority != other._priority) {
+    return _priority - other._priority;
+
+  } else {
+    return internal_compare_to(&other);
   }
   }
 }
 }
 
 

+ 29 - 0
panda/src/graph/nodeTransitions.cxx

@@ -226,6 +226,35 @@ compare_to(const NodeTransitions &other) const {
 			    other._transitions.begin(), other._transitions.end());
 			    other._transitions.begin(), other._transitions.end());
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodeTransitions::adjust_all_proriorities
+//       Access: Public
+//  Description: Adds the indicated adjustment amount (which may be
+//               negative) to the priority for all transitions on the
+//               arc.  If the priority would drop below zero, it is
+//               set to zero.
+////////////////////////////////////////////////////////////////////
+void NodeTransitions::
+adjust_all_priorities(int adjustment, NodeRelation *arc) {
+  Transitions::iterator ti;
+  for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) {
+    nassertv((*ti).second != (NodeTransition *)NULL);
+    PT(NodeTransition) &trans = (*ti).second;
+    int new_priority = max(trans->_priority + adjustment, 0);
+
+    if (trans->_priority != new_priority) {
+      if (trans->get_ref_count() > 1) {
+	// Copy-on-write.
+	trans->removed_from_arc(arc);
+	trans = trans->make_copy();
+	trans->added_to_arc(arc);
+      }
+      trans->_priority = new_priority;
+      arc->changed_transition((*ti).first);
+    }
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodeTransitions::remove_all_from_arc
 //     Function: NodeTransitions::remove_all_from_arc
 //       Access: Public
 //       Access: Public

+ 1 - 0
panda/src/graph/nodeTransitions.h

@@ -40,6 +40,7 @@ public:
 			     NodeRelation *to_arc);
 			     NodeRelation *to_arc);
   void compose_transitions_from(const NodeTransitions &other, 
   void compose_transitions_from(const NodeTransitions &other, 
 				NodeRelation *to_arc);
 				NodeRelation *to_arc);
+  void adjust_all_priorities(int adjustment, NodeRelation *arc);
 
 
   void clear();
   void clear();
 
 

+ 17 - 0
panda/src/sgmanip/nodePath.I

@@ -1424,7 +1424,24 @@ has_transparency() const {
   return _head->_arc->has_transition(TransparencyTransition::get_class_type());
   return _head->_arc->has_transition(TransparencyTransition::get_class_type());
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::adjust_all_priorities
+//       Access: Public
+//  Description: Adds the indicated adjustment amount (which may be
+//               negative) to the priority for all transitions on the
+//               bottom arc, and for all arcs in the subgraph below.
+//               This can be used to force these nodes not to be
+//               overridden by a high-level state change above.  If
+//               the priority would drop below zero, it is set to
+//               zero.
+////////////////////////////////////////////////////////////////////
+INLINE void NodePath::
+adjust_all_priorities(int adjustment) {
+  nassertv(has_arcs());
+  nassertv(_head != (ArcComponent *)NULL);
 
 
+  r_adjust_all_priorities(_head->_arc, adjustment);
+}
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::show
 //     Function: NodePath::show

+ 24 - 0
panda/src/sgmanip/nodePath.cxx

@@ -2599,3 +2599,27 @@ r_list_transitions(ostream &out, int indent_level) const {
     }
     }
   }
   }
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::r_adjust_all_priorities
+//       Access: Private
+//  Description: The recursive implementation of
+//               adjust_all_priorities().  This walks through the
+//               subgraph defined by the indicated arc and below.
+////////////////////////////////////////////////////////////////////
+void NodePath::
+r_adjust_all_priorities(NodeRelation *arc, int adjustment) {
+  arc->adjust_all_priorities(adjustment);
+
+  Node *node = arc->get_child();
+  DownRelations::const_iterator dri;
+  dri = node->_children.find(_graph_type);
+  if (dri != node->_children.end()) {
+    const DownRelationPointers &drp = (*dri).second;
+    
+    DownRelationPointers::const_iterator drpi;
+    for (drpi = drp.begin(); drpi != drp.end(); ++drpi) {
+      r_adjust_all_priorities(*drpi, adjustment);
+    }
+  }
+}

+ 5 - 1
panda/src/sgmanip/nodePath.h

@@ -413,6 +413,8 @@ PUBLISHED:
   INLINE bool has_transparency() const;
   INLINE bool has_transparency() const;
   bool get_transparency() const;
   bool get_transparency() const;
 
 
+  INLINE void adjust_all_priorities(int adjustment);
+
   INLINE void show();
   INLINE void show();
   INLINE void hide();
   INLINE void hide();
   INLINE void show_collision_solids();
   INLINE void show_collision_solids();
@@ -447,7 +449,7 @@ private:
   void r_write_transitions(const ArcComponent *comp,
   void r_write_transitions(const ArcComponent *comp,
 			   ostream &out, int indent_level) const;
 			   ostream &out, int indent_level) const;
   void r_get_net_transitions(const ArcComponent *comp, 
   void r_get_net_transitions(const ArcComponent *comp, 
-		      AllTransitionsWrapper &trans) const;
+			     AllTransitionsWrapper &trans) const;
   string format_node_name(Node *node) const;
   string format_node_name(Node *node) const;
 
 
   void find_matches(NodePathCollection &result, 
   void find_matches(NodePathCollection &result, 
@@ -465,6 +467,8 @@ private:
   void r_list_descendants(ostream &out, int indent_level) const;
   void r_list_descendants(ostream &out, int indent_level) const;
   void r_list_transitions(ostream &out, int indent_level) const;
   void r_list_transitions(ostream &out, int indent_level) const;
 
 
+  void r_adjust_all_priorities(NodeRelation *arc, int adjustment);
+
   // It's important that there are no data members in this class.  Put
   // It's important that there are no data members in this class.  Put
   // them in NodePathBase instead.
   // them in NodePathBase instead.
 
 

+ 14 - 0
panda/src/switchnode/sequenceNode.cxx

@@ -56,6 +56,20 @@ set_switch_time(float switch_time)
   set_cycle_time(switch_time);
   set_cycle_time(switch_time);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: SequenceNode::make_copy
+//       Access: Public, Virtual
+//  Description: Returns a newly-allocated Node that is a shallow copy
+//               of this one.  It will be a different Node pointer,
+//               but its internal data may or may not be shared with
+//               that of the original Node.  No children will be
+//               copied.
+////////////////////////////////////////////////////////////////////
+Node *SequenceNode::
+make_copy() const {
+  return new SequenceNode(*this);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: SequenceNode::sub_render
 //     Function: SequenceNode::sub_render
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 2 - 0
panda/src/switchnode/sequenceNode.h

@@ -30,6 +30,8 @@ PUBLISHED:
   void set_switch_time(float switch_time);
   void set_switch_time(float switch_time);
 
 
 public:
 public:
+  virtual Node *make_copy() const;
+
   virtual bool sub_render(const AllAttributesWrapper &attrib,
   virtual bool sub_render(const AllAttributesWrapper &attrib,
 			  AllTransitionsWrapper &trans,
 			  AllTransitionsWrapper &trans,
 			  RenderTraverser *trav);
 			  RenderTraverser *trav);