From 91d07d92098de31c39d41fc51ca659115a421f12 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 30 Jan 2001 17:42:42 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/cull/cullState.I | 11 ++++++++++ panda/src/cull/cullState.h | 1 + panda/src/cull/cullTraverser.I | 14 +++++++++++-- panda/src/graph/nodeRelation.cxx | 15 ++++++++++++++ panda/src/graph/nodeRelation.h | 2 ++ panda/src/graph/nodeTransition.I | 11 ++++++---- panda/src/graph/nodeTransitions.cxx | 29 +++++++++++++++++++++++++++ panda/src/graph/nodeTransitions.h | 1 + panda/src/sgmanip/nodePath.I | 17 ++++++++++++++++ panda/src/sgmanip/nodePath.cxx | 24 ++++++++++++++++++++++ panda/src/sgmanip/nodePath.h | 6 +++++- panda/src/switchnode/sequenceNode.cxx | 14 +++++++++++++ panda/src/switchnode/sequenceNode.h | 2 ++ 13 files changed, 140 insertions(+), 7 deletions(-) diff --git a/panda/src/cull/cullState.I b/panda/src/cull/cullState.I index 690379a8e7..d7ff71844a 100644 --- a/panda/src/cull/cullState.I +++ b/panda/src/cull/cullState.I @@ -169,6 +169,17 @@ get_attributes() const { 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 // Access: Public diff --git a/panda/src/cull/cullState.h b/panda/src/cull/cullState.h index d8b767f83e..28b1703f64 100644 --- a/panda/src/cull/cullState.h +++ b/panda/src/cull/cullState.h @@ -60,6 +60,7 @@ public: INLINE void apply_to(const AllAttributesWrapper &initial_state); INLINE const NodeAttributes &get_attributes() const; + INLINE const AllTransitionsWrapper &get_transitions() const; INLINE bool has_bin() const; INLINE GeomBin *get_bin() const; diff --git a/panda/src/cull/cullTraverser.I b/panda/src/cull/cullTraverser.I index b32380ef9a..5874081c9f 100644 --- a/panda/src/cull/cullTraverser.I +++ b/panda/src/cull/cullTraverser.I @@ -19,10 +19,12 @@ //////////////////////////////////////////////////////////////////// INLINE void CullTraverser:: draw_geom(GeomNode *geom_node, const AllAttributesWrapper &initial_state) { +#ifndef NDEBUG if (cull_cat.is_spam()) { cull_cat.spam() << "Drawing " << *geom_node << " with state: " << initial_state << "\n"; } +#endif nassertv(geom_node != (GeomNode *)NULL); _gsg->set_state(initial_state.get_attributes(), true); _gsg->prepare_display_region(); @@ -56,10 +58,12 @@ draw_direct(const ArcChain &arc_chain, const AllAttributesWrapper &initial_state) { nassertv(!arc_chain.empty()); Node *node = arc_chain.back()->get_child(); +#ifndef NDEBUG if (cull_cat.is_spam()) { cull_cat.spam() << "Drawing " << *node << " in direct mode.\n"; } +#endif nassertv(node != (Node *)NULL); DirectRenderTraverser drt(_gsg, _graph_type, arc_chain); 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. pair result = _states.insert(cs); +#ifndef NDEBUG if (cull_cat.is_spam()) { if (result.second) { // 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"; trans.write(cull_cat.spam(false), 2); } else { + CullState *found_cs = *result.first; 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); } } +#endif return *result.first; } diff --git a/panda/src/graph/nodeRelation.cxx b/panda/src/graph/nodeRelation.cxx index 2dbf7ab5a8..99bb83a21a 100644 --- a/panda/src/graph/nodeRelation.cxx +++ b/panda/src/graph/nodeRelation.cxx @@ -9,6 +9,7 @@ #include #include +#include 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 // Access: Public diff --git a/panda/src/graph/nodeRelation.h b/panda/src/graph/nodeRelation.h index d9bb4a4a4b..05909399d2 100644 --- a/panda/src/graph/nodeRelation.h +++ b/panda/src/graph/nodeRelation.h @@ -98,6 +98,7 @@ PUBLISHED: void compose_transitions_from(const NodeRelation *arc); void copy_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; @@ -214,6 +215,7 @@ private: friend class Node; friend class NodeTransitionWrapper; friend class AllTransitionsWrapper; + friend class GraphPriorityAdjuster; }; INLINE ostream & diff --git a/panda/src/graph/nodeTransition.I b/panda/src/graph/nodeTransition.I index 7a827124e1..2c1607ab9e 100644 --- a/panda/src/graph/nodeTransition.I +++ b/panda/src/graph/nodeTransition.I @@ -117,12 +117,15 @@ compare_to(const NodeTransition &other) const { TypeHandle my_handle = 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 (my_handle < other_handle) ? -1 : 1; + + } else if (_priority != other._priority) { + return _priority - other._priority; + + } else { + return internal_compare_to(&other); } } diff --git a/panda/src/graph/nodeTransitions.cxx b/panda/src/graph/nodeTransitions.cxx index 1beb532934..576b3e6fc1 100644 --- a/panda/src/graph/nodeTransitions.cxx +++ b/panda/src/graph/nodeTransitions.cxx @@ -226,6 +226,35 @@ compare_to(const NodeTransitions &other) const { 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 // Access: Public diff --git a/panda/src/graph/nodeTransitions.h b/panda/src/graph/nodeTransitions.h index fc950803de..61d909fd9c 100644 --- a/panda/src/graph/nodeTransitions.h +++ b/panda/src/graph/nodeTransitions.h @@ -40,6 +40,7 @@ public: NodeRelation *to_arc); void compose_transitions_from(const NodeTransitions &other, NodeRelation *to_arc); + void adjust_all_priorities(int adjustment, NodeRelation *arc); void clear(); diff --git a/panda/src/sgmanip/nodePath.I b/panda/src/sgmanip/nodePath.I index 0e19eddaed..b6cfc2ca0e 100644 --- a/panda/src/sgmanip/nodePath.I +++ b/panda/src/sgmanip/nodePath.I @@ -1424,7 +1424,24 @@ has_transparency() const { 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 diff --git a/panda/src/sgmanip/nodePath.cxx b/panda/src/sgmanip/nodePath.cxx index b8ce62c4aa..b8b3b2a0bf 100644 --- a/panda/src/sgmanip/nodePath.cxx +++ b/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); + } + } +} diff --git a/panda/src/sgmanip/nodePath.h b/panda/src/sgmanip/nodePath.h index 25c04ece81..786fa2779b 100644 --- a/panda/src/sgmanip/nodePath.h +++ b/panda/src/sgmanip/nodePath.h @@ -413,6 +413,8 @@ PUBLISHED: INLINE bool has_transparency() const; bool get_transparency() const; + INLINE void adjust_all_priorities(int adjustment); + INLINE void show(); INLINE void hide(); INLINE void show_collision_solids(); @@ -447,7 +449,7 @@ private: void r_write_transitions(const ArcComponent *comp, ostream &out, int indent_level) const; void r_get_net_transitions(const ArcComponent *comp, - AllTransitionsWrapper &trans) const; + AllTransitionsWrapper &trans) const; string format_node_name(Node *node) const; void find_matches(NodePathCollection &result, @@ -465,6 +467,8 @@ private: void r_list_descendants(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 // them in NodePathBase instead. diff --git a/panda/src/switchnode/sequenceNode.cxx b/panda/src/switchnode/sequenceNode.cxx index 685a445caf..c886a81e11 100644 --- a/panda/src/switchnode/sequenceNode.cxx +++ b/panda/src/switchnode/sequenceNode.cxx @@ -56,6 +56,20 @@ set_switch_time(float 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 // Access: Public, Virtual diff --git a/panda/src/switchnode/sequenceNode.h b/panda/src/switchnode/sequenceNode.h index 65a8e90cee..7bcf5160c3 100644 --- a/panda/src/switchnode/sequenceNode.h +++ b/panda/src/switchnode/sequenceNode.h @@ -30,6 +30,8 @@ PUBLISHED: void set_switch_time(float switch_time); public: + virtual Node *make_copy() const; + virtual bool sub_render(const AllAttributesWrapper &attrib, AllTransitionsWrapper &trans, RenderTraverser *trav);