From 4cb4ba75988856ab6d118f27efca7eea0b5645c2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 8 Jun 2001 22:12:38 +0000 Subject: [PATCH] fix flatten some more --- panda/src/graph/graphReducer.cxx | 6 ++++++ panda/src/graph/node.cxx | 14 ++++++++++++++ panda/src/graph/node.h | 1 + panda/src/sgraph/switchNode.cxx | 15 +++++++++++++++ panda/src/sgraph/switchNode.h | 1 + 5 files changed, 37 insertions(+) diff --git a/panda/src/graph/graphReducer.cxx b/panda/src/graph/graphReducer.cxx index 5159967957..971498065f 100644 --- a/panda/src/graph/graphReducer.cxx +++ b/panda/src/graph/graphReducer.cxx @@ -377,6 +377,12 @@ collapse_siblings(Node *parent, NodeRelation *arc1, NodeRelation *arc2) { //////////////////////////////////////////////////////////////////// Node *GraphReducer:: collapse_nodes(Node *node1, Node *node2, bool) { + if (!node1->safe_to_combine() || !node2->safe_to_combine()) { + // One or both nodes cannot be safely combined with another node; + // do nothing. + return NULL; + } + // We get to choose whether to remove node1 or node2. if (node2->is_exact_type(Node::get_class_type()) || node2->is_exact_type(NamedNode::get_class_type())) { diff --git a/panda/src/graph/node.cxx b/panda/src/graph/node.cxx index aab74d7de5..3c917eb092 100644 --- a/panda/src/graph/node.cxx +++ b/panda/src/graph/node.cxx @@ -159,6 +159,20 @@ safe_to_transform() const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: Node::safe_to_combine +// Access: Public, Virtual +// Description: Returns true if it is generally safe to combine +// this particular kind of Node with other kinds of +// Nodes, adding children or whatever. For instance, an +// LODNode should not be combined with any other node, +// because its set of children is meaningful. +//////////////////////////////////////////////////////////////////// +bool Node:: +safe_to_combine() const { + return true; +} + //////////////////////////////////////////////////////////////////// // Function: Node::xform // Access: Public, Virtual diff --git a/panda/src/graph/node.h b/panda/src/graph/node.h index cca62bb8f6..c141ba58ff 100644 --- a/panda/src/graph/node.h +++ b/panda/src/graph/node.h @@ -68,6 +68,7 @@ public: virtual bool safe_to_flatten() const; virtual bool safe_to_transform() const; + virtual bool safe_to_combine() const; virtual void xform(const LMatrix4f &mat); virtual void transform_changed(NodeRelation *arc); diff --git a/panda/src/sgraph/switchNode.cxx b/panda/src/sgraph/switchNode.cxx index 5f50b94494..e25232c0e2 100644 --- a/panda/src/sgraph/switchNode.cxx +++ b/panda/src/sgraph/switchNode.cxx @@ -19,3 +19,18 @@ #include "switchNode.h" TypeHandle SwitchNode::_type_handle; + + +//////////////////////////////////////////////////////////////////// +// Function: SwitchNode::safe_to_combine +// Access: Public, Virtual +// Description: Returns true if it is generally safe to combine +// this particular kind of Node with other kinds of +// Nodes, adding children or whatever. For instance, an +// LODNode should not be combined with any other node, +// because its set of children is meaningful. +//////////////////////////////////////////////////////////////////// +bool SwitchNode:: +safe_to_combine() const { + return false; +} diff --git a/panda/src/sgraph/switchNode.h b/panda/src/sgraph/switchNode.h index 04c953ddfe..b276842105 100644 --- a/panda/src/sgraph/switchNode.h +++ b/panda/src/sgraph/switchNode.h @@ -44,6 +44,7 @@ PUBLISHED: INLINE void operator = (const SwitchNode ©); public: + virtual bool safe_to_combine() const; virtual void compute_switch(RenderTraverser *trav)=0; virtual bool is_child_visible(TypeHandle type, int index)=0;