mirror of https://codeberg.org/topola/topola.git
feat(topola-egui): Display A*'s g-scores and f-scores
This commit is contained in:
parent
97b1315eee
commit
53f937f14f
|
|
@ -252,9 +252,9 @@ impl Viewport {
|
||||||
|
|
||||||
if menu_bar.show_navmesh {
|
if menu_bar.show_navmesh {
|
||||||
if let Some(activity) = workspace.interactor.maybe_activity() {
|
if let Some(activity) = workspace.interactor.maybe_activity() {
|
||||||
if let Some(ref navmesh) =
|
if let Some(astar) = activity.maybe_astar() {
|
||||||
activity.maybe_astar().map(|astar| &astar.graph)
|
let navmesh = &astar.graph;
|
||||||
{
|
|
||||||
for edge in navmesh.edge_references() {
|
for edge in navmesh.edge_references() {
|
||||||
let mut from = PrimitiveIndex::from(
|
let mut from = PrimitiveIndex::from(
|
||||||
navmesh.node_weight(edge.source()).unwrap().node,
|
navmesh.node_weight(edge.source()).unwrap().node,
|
||||||
|
|
@ -336,35 +336,46 @@ impl Viewport {
|
||||||
|
|
||||||
for index in navmesh.graph().node_indices() {
|
for index in navmesh.graph().node_indices() {
|
||||||
let navvertex = NavvertexIndex(index);
|
let navvertex = NavvertexIndex(index);
|
||||||
if let Some(text) = activity.navvertex_debug_text(navvertex)
|
let mut pos = PrimitiveIndex::from(
|
||||||
{
|
navmesh.node_weight(navvertex).unwrap().node,
|
||||||
let mut pos = PrimitiveIndex::from(
|
)
|
||||||
navmesh.node_weight(navvertex).unwrap().node,
|
.primitive(board.layout().drawing())
|
||||||
)
|
.shape()
|
||||||
.primitive(board.layout().drawing())
|
.center();
|
||||||
.shape()
|
|
||||||
.center();
|
|
||||||
|
|
||||||
pos += match navmesh
|
pos += match navmesh
|
||||||
.node_weight(navvertex)
|
.node_weight(navvertex)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.maybe_sense
|
.maybe_sense
|
||||||
{
|
{
|
||||||
Some(RotationSense::Counterclockwise) => {
|
Some(RotationSense::Counterclockwise) => {
|
||||||
[0.0, 150.0].into()
|
[0.0, 150.0].into()
|
||||||
}
|
}
|
||||||
Some(RotationSense::Clockwise) => {
|
Some(RotationSense::Clockwise) => [-0.0, -150.0].into(),
|
||||||
[-0.0, -150.0].into()
|
None => [0.0, 0.0].into(),
|
||||||
}
|
};
|
||||||
None => [0.0, 0.0].into(),
|
|
||||||
};
|
//TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)"
|
||||||
painter.paint_text(
|
let score_text = &astar
|
||||||
pos,
|
.scores
|
||||||
egui::Align2::LEFT_BOTTOM,
|
.get(&navvertex)
|
||||||
text,
|
.map_or_else(String::new, |s| format!("g={:.2}", s));
|
||||||
egui::Color32::from_rgb(255, 255, 255),
|
let estimate_score_text = &astar
|
||||||
);
|
.estimate_scores
|
||||||
}
|
.get(&navvertex)
|
||||||
|
.map_or_else(String::new, |s| format!("(f={:.2})", s));
|
||||||
|
let debug_text =
|
||||||
|
activity.navvertex_debug_text(navvertex).unwrap_or("");
|
||||||
|
|
||||||
|
painter.paint_text(
|
||||||
|
pos,
|
||||||
|
egui::Align2::LEFT_BOTTOM,
|
||||||
|
&format!(
|
||||||
|
"{} {} {}",
|
||||||
|
score_text, estimate_score_text, debug_text
|
||||||
|
),
|
||||||
|
egui::Color32::from_rgb(255, 255, 255),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue