mirror of https://codeberg.org/topola/topola.git
feat(router/thetastar): Highlight currently attempted navedge
This commit is contained in:
parent
b9b52fb977
commit
2c94b50290
|
|
@ -28,6 +28,7 @@ use topola::{
|
||||||
navmesh::{BinavnodeNodeIndex, Navmesh, NavnodeIndex},
|
navmesh::{BinavnodeNodeIndex, Navmesh, NavnodeIndex},
|
||||||
ng::pie,
|
ng::pie,
|
||||||
prenavmesh::PrenavmeshConstraint,
|
prenavmesh::PrenavmeshConstraint,
|
||||||
|
thetastar::ThetastarState,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -223,13 +224,15 @@ impl<'a> Displayer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if menu_bar.show_navmesh {
|
||||||
let stroke = 'blk: {
|
let stroke = 'blk: {
|
||||||
if let Some(navcord) = activity.maybe_navcord() {
|
if let Some(navcord) = activity.maybe_navcord() {
|
||||||
if let (Some(source_pos), Some(target_pos)) = (
|
if let (Some(source_pos), Some(target_pos)) = (
|
||||||
navcord.path.iter().position(|node| *node == edge.source()),
|
navcord.path.iter().position(|node| *node == edge.source()),
|
||||||
navcord.path.iter().position(|node| *node == edge.target()),
|
navcord.path.iter().position(|node| *node == edge.target()),
|
||||||
) {
|
) {
|
||||||
if target_pos == source_pos + 1 || source_pos == target_pos + 1 {
|
if target_pos == source_pos + 1 || source_pos == target_pos + 1
|
||||||
|
{
|
||||||
break 'blk egui::Stroke::new(
|
break 'blk egui::Stroke::new(
|
||||||
5.0,
|
5.0,
|
||||||
egui::Color32::from_rgb(250, 250, 0),
|
egui::Color32::from_rgb(250, 250, 0),
|
||||||
|
|
@ -241,7 +244,6 @@ impl<'a> Displayer<'a> {
|
||||||
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
|
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
|
||||||
};
|
};
|
||||||
|
|
||||||
if menu_bar.show_navmesh {
|
|
||||||
self.painter.paint_line_segment(from, to, stroke);
|
self.painter.paint_line_segment(from, to, stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,6 +279,34 @@ impl<'a> Displayer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if menu_bar.show_navmesh {
|
||||||
|
match thetastar.state() {
|
||||||
|
ThetastarState::BacktrackAndProbeOnLineOfSight(_, edge)
|
||||||
|
| ThetastarState::ProbeOnNavedge(_, edge) => {
|
||||||
|
let edge_from = PrimitiveIndex::from(
|
||||||
|
navmesh.node_weight(edge.0).unwrap().binavnode,
|
||||||
|
)
|
||||||
|
.primitive_ref(board.layout().drawing())
|
||||||
|
.shape()
|
||||||
|
.center();
|
||||||
|
|
||||||
|
let edge_to = PrimitiveIndex::from(
|
||||||
|
navmesh.node_weight(edge.1).unwrap().binavnode,
|
||||||
|
)
|
||||||
|
.primitive_ref(board.layout().drawing())
|
||||||
|
.shape()
|
||||||
|
.center();
|
||||||
|
|
||||||
|
self.painter.paint_line_segment(
|
||||||
|
edge_from,
|
||||||
|
edge_to,
|
||||||
|
egui::Stroke::new(5.0, egui::Color32::from_rgb(255, 0, 255)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for index in navmesh.graph().node_indices() {
|
for index in navmesh.graph().node_indices() {
|
||||||
if menu_bar.show_guide_circles {
|
if menu_bar.show_guide_circles {
|
||||||
if let Some(navcord) = activity.maybe_navcord() {
|
if let Some(navcord) = activity.maybe_navcord() {
|
||||||
|
|
|
||||||
|
|
@ -116,10 +116,10 @@ pub enum ThetastarState<N: Copy, E: Copy> {
|
||||||
/// on the navmesh.
|
/// on the navmesh.
|
||||||
///
|
///
|
||||||
/// Conditional repeated backtracking is our improvement to Theta*: if
|
/// Conditional repeated backtracking is our improvement to Theta*: if
|
||||||
/// line-of-sight routing fails if a condition is met, continue trying to draw
|
/// line-of-sight routing fails, for as long as a condition is met, continue
|
||||||
/// from parent of the parent navnode, and so on. This is different from Theta*
|
/// trying to draw from parent of the parent navnode, and so on. This is
|
||||||
/// because in Theta* there is only one backtracking step -- only one attempt to
|
/// different from Theta* because in Theta* there is only one backtracking step
|
||||||
/// do line-of-sight routing.
|
/// -- only one attempt to do line-of-sight routing.
|
||||||
#[derive(Getters)]
|
#[derive(Getters)]
|
||||||
pub struct ThetastarStepper<G, K>
|
pub struct ThetastarStepper<G, K>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue