collision traverser doesn't visit switch nodes

This commit is contained in:
David Rose 2003-02-07 23:11:18 +00:00
parent 8dde619073
commit 44d544aeb2
9 changed files with 126 additions and 35 deletions

View File

@ -447,10 +447,22 @@ r_traverse(CollisionLevelState &level_state) {
}
}
int num_children = node->get_num_children();
for (int i = 0; i < num_children; i++) {
CollisionLevelState next_state(level_state, node->get_child(i));
r_traverse(next_state);
if (node->has_single_child_visibility()) {
// If it's a switch node or sequence node, visit just the one
// visible child.
int index = node->get_visible_child();
if (index >= 0 && index < node->get_num_children()) {
CollisionLevelState next_state(level_state, node->get_child(index));
r_traverse(next_state);
}
} else {
// Otherwise, visit all the children.
int num_children = node->get_num_children();
for (int i = 0; i < num_children; i++) {
CollisionLevelState next_state(level_state, node->get_child(i));
r_traverse(next_state);
}
}
}

View File

@ -744,6 +744,39 @@ get_next_visible_child(int n) const {
return n + 1;
}
////////////////////////////////////////////////////////////////////
// Function: PandaNode::has_single_child_visibility
// Access: Public, Virtual
// Description: Should be overridden by derived classes to return
// true if this kind of node has the special property
// that just one of its children is visible at any given
// time, and furthermore that the particular visible
// child can be determined without reference to any
// external information (such as a camera). At present,
// only SequenceNodes and SwitchNodes fall into this
// category.
//
// If this function returns true, get_visible_child()
// can be called to return the index of the
// currently-visible child.
////////////////////////////////////////////////////////////////////
bool PandaNode::
has_single_child_visibility() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: PandaNode::get_visible_child
// Access: Public, Virtual
// Description: Returns the index number of the currently visible
// child of this node. This is only meaningful if
// has_single_child_visibility() has returned true.
////////////////////////////////////////////////////////////////////
int PandaNode::
get_visible_child() const {
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: PandaNode::copy_subgraph
// Access: Published

View File

@ -91,6 +91,8 @@ public:
virtual bool has_selective_visibility() const;
virtual int get_first_visible_child() const;
virtual int get_next_visible_child(int n) const;
virtual bool has_single_child_visibility() const;
virtual int get_visible_child() const;
PUBLISHED:
PT(PandaNode) copy_subgraph() const;

View File

@ -105,24 +105,6 @@ set_visible_child(int index) {
}
}
////////////////////////////////////////////////////////////////////
// Function: SequenceNode::get_visible_child
// Access: Published
// Description: Returns the index of the child that should be visible
// for this particular frame, if there are any children.
////////////////////////////////////////////////////////////////////
INLINE int SequenceNode::
get_visible_child() const {
int num_children = get_num_children();
if (num_children == 0) {
return 0;
}
float frame = calc_frame();
return ((int)frame) % num_children;
}
////////////////////////////////////////////////////////////////////
// Function: SequenceNode::calc_frame
// Access: Private

View File

@ -142,6 +142,45 @@ cull_callback(CullTraverser *, CullTraverserData &) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: SequenceNode::has_single_child_visibility
// Access: Public, Virtual
// Description: Should be overridden by derived classes to return
// true if this kind of node has the special property
// that just one of its children is visible at any given
// time, and furthermore that the particular visible
// child can be determined without reference to any
// external information (such as a camera). At present,
// only SequenceNodes and SwitchNodes fall into this
// category.
//
// If this function returns true, get_visible_child()
// can be called to return the index of the
// currently-visible child.
////////////////////////////////////////////////////////////////////
bool SequenceNode::
has_single_child_visibility() const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: SequenceNode::get_visible_child
// Access: Published, Virtual
// Description: Returns the index of the child that should be visible
// for this particular frame, if there are any children.
////////////////////////////////////////////////////////////////////
int SequenceNode::
get_visible_child() const {
int num_children = get_num_children();
if (num_children == 0) {
return 0;
}
float frame = calc_frame();
return ((int)frame) % num_children;
}
////////////////////////////////////////////////////////////////////
// Function: SequenceNode::register_with_read_factory
// Access: Public, Static

View File

@ -41,13 +41,14 @@ public:
virtual bool has_cull_callback() const;
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
virtual bool has_single_child_visibility() const;
PUBLISHED:
INLINE void set_cycle_rate(float cycle_rate);
INLINE float get_cycle_rate() const;
INLINE void set_visible_child(int index);
INLINE int get_visible_child() const;
virtual int get_visible_child() const;
private:
INLINE float calc_frame(float now) const;

View File

@ -60,14 +60,3 @@ set_visible_child(int index) {
CDWriter cdata(_cycler);
cdata->_visible_child = index;
}
////////////////////////////////////////////////////////////////////
// Function: SwitchNode::get_visible_child
// Access: Published
// Description: Returns the index of the child that should be visible.
////////////////////////////////////////////////////////////////////
INLINE int SwitchNode::
get_visible_child() const {
CDReader cdata(_cycler);
return cdata->_visible_child;
}

View File

@ -134,6 +134,38 @@ cull_callback(CullTraverser *, CullTraverserData &) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: SwitchNode::has_single_child_visibility
// Access: Public, Virtual
// Description: Should be overridden by derived classes to return
// true if this kind of node has the special property
// that just one of its children is visible at any given
// time, and furthermore that the particular visible
// child can be determined without reference to any
// external information (such as a camera). At present,
// only SequenceNodes and SwitchNodes fall into this
// category.
//
// If this function returns true, get_visible_child()
// can be called to return the index of the
// currently-visible child.
////////////////////////////////////////////////////////////////////
bool SwitchNode::
has_single_child_visibility() const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: SwitchNode::get_visible_child
// Access: Published, Virtual
// Description: Returns the index of the child that should be visible.
////////////////////////////////////////////////////////////////////
int SwitchNode::
get_visible_child() const {
CDReader cdata(_cycler);
return cdata->_visible_child;
}
////////////////////////////////////////////////////////////////////
// Function: SwitchNode::register_with_read_factory
// Access: Public, Static

View File

@ -40,10 +40,11 @@ public:
virtual bool has_cull_callback() const;
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
virtual bool has_single_child_visibility() const;
PUBLISHED:
INLINE void set_visible_child(int index);
INLINE int get_visible_child() const;
virtual int get_visible_child() const;
private:
class EXPCL_PANDA CData : public CycleData {