00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "findApproxLevelEntry.h"
00020 #include "nodePathCollection.h"
00021 #include "pandaNode.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 void FindApproxLevelEntry::
00031 output(ostream &out) const {
00032 out << "(" << _node_path << "):";
00033 if (is_solution(0)) {
00034 out << " solution!";
00035 } else {
00036 out << "(";
00037 _approx_path.output_component(out, _i);
00038 out << ")," << _i;
00039 }
00040 }
00041
00042
00043
00044
00045
00046
00047 void FindApproxLevelEntry::
00048 consider_node(NodePathCollection &result, FindApproxLevel &next_level,
00049 int max_matches, int increment) const {
00050 nassertv(_i + increment < _approx_path.get_num_components());
00051
00052 if (_approx_path.is_component_match_many(_i + increment)) {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 if (is_solution(increment + 1)) {
00068
00069 result.add_path(_node_path.get_node_path());
00070 if (max_matches > 0 && result.get_num_paths() >= max_matches) {
00071 return;
00072 }
00073 } else {
00074 consider_node(result, next_level, max_matches, increment + 1);
00075 }
00076 }
00077
00078 PandaNode *this_node = _node_path.node();
00079 nassertv(this_node != (PandaNode *)NULL);
00080
00081 bool stashed_only = next_is_stashed(increment);
00082
00083 if (!stashed_only) {
00084
00085 int num_children = this_node->get_num_children();
00086 for (int i = 0; i < num_children; i++) {
00087 PandaNode *child_node = this_node->get_child(i);
00088
00089 consider_next_step(result, child_node, next_level, max_matches, increment);
00090 if (max_matches > 0 && result.get_num_paths() >= max_matches) {
00091 return;
00092 }
00093 }
00094 }
00095
00096 if (_approx_path.return_stashed() || stashed_only) {
00097
00098 int num_stashed = this_node->get_num_stashed();
00099 for (int i = 0; i < num_stashed; i++) {
00100 PandaNode *stashed_node = this_node->get_stashed(i);
00101
00102 consider_next_step(result, stashed_node, next_level, max_matches, increment);
00103 if (max_matches > 0 && result.get_num_paths() >= max_matches) {
00104 return;
00105 }
00106 }
00107 }
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 void FindApproxLevelEntry::
00122 consider_next_step(NodePathCollection &result, PandaNode *child_node,
00123 FindApproxLevel &next_level, int max_matches,
00124 int increment) const {
00125 if (!_approx_path.return_hidden() &&
00126 child_node->get_draw_mask().is_zero()) {
00127
00128
00129
00130 return;
00131 }
00132
00133 nassertv(_i + increment < _approx_path.get_num_components());
00134
00135 if (_approx_path.is_component_match_many(_i + increment)) {
00136
00137
00138
00139
00140
00141
00142 FindApproxLevelEntry next(*this, increment);
00143 next._node_path = WorkingNodePath(_node_path, child_node);
00144 next_level.add_entry(next);
00145
00146 } else {
00147 if (_approx_path.matches_component(_i + increment, child_node)) {
00148
00149 FindApproxLevelEntry next(*this, increment);
00150 next._i++;
00151 next._node_path = WorkingNodePath(_node_path, child_node);
00152 next_level.add_entry(next);
00153 }
00154 }
00155 }