From 0a624bcd948148817226c9585db7ce16bf5cb599 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 16 Oct 2009 11:00:40 +0200 Subject: Rewrite find_ray to use precomputed cellrays. During precomputation, we store the minimal cellrays by target and sort them according to niceness. find_ray now simply picks the first non-blocked ray to a target, which means looping through the 10 or so minimal cellrays with that target -- this should be a lot more efficient. (An extended findray test went from 150s to 40s (debug) and 40s to 26s (profile)). The interface to find_ray has changed: cycle_dir=-1,0,1 was changed to cyle=false/true since we never cycle in the other direction anyway. find_shortest was removed: all rays to a target had the same length all along, but now we also return the straightest one automatically. The change also eliminates the duplicate corner-cutting code between ray_def::advance and find_ray as imbalance calculation now relies on ray_def::advance. --- crawl-ref/source/directn.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'crawl-ref/source/directn.cc') diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc index 8e64e63e93..15d3ebd572 100644 --- a/crawl-ref/source/directn.cc +++ b/crawl-ref/source/directn.cc @@ -409,8 +409,7 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = you.prev_grd_targ; - moves.choseRay = find_ray(you.pos(), moves.target, - moves.ray, 0, true); + moves.choseRay = find_ray(you.pos(), moves.target, moves.ray); } else if (you.prev_targ == MHITYOU) { @@ -444,8 +443,7 @@ static void _direction_again(dist& moves, targetting_type restricts, moves.target = montarget->pos(); - moves.choseRay = find_ray(you.pos(), moves.target, - moves.ray, 0, true); + moves.choseRay = find_ray(you.pos(), moves.target, moves.ray); } moves.isValid = true; @@ -967,7 +965,7 @@ static bool _blocked_ray(const coord_def &where, dungeon_feature_type* feat = NULL) { ray_def ray; - if (!find_ray(you.pos(), where, ray, 0, true)) + if (!find_ray(you.pos(), where, ray)) fallback_ray(you.pos(), where, ray); ray.advance_through(where); @@ -1318,8 +1316,7 @@ void direction(dist& moves, targetting_type restricts, #ifdef WIZARD case CMD_TARGET_CYCLE_BEAM: show_beam = true; - have_beam = find_ray(you.pos(), moves.target, - ray, (show_beam ? 1 : 0)); + have_beam = find_ray(you.pos(), moves.target, ray, show_beam); need_beam_redraw = true; break; #endif @@ -1339,8 +1336,7 @@ void direction(dist& moves, targetting_type restricts, break; } - have_beam = find_ray(you.pos(), moves.target, - ray, 0, true); + have_beam = find_ray(you.pos(), moves.target, ray); show_beam = true; need_beam_redraw = true; } @@ -1685,8 +1681,7 @@ void direction(dist& moves, targetting_type restricts, if (show_beam) { - have_beam = find_ray(you.pos(), moves.target, - ray, 0, true); + have_beam = find_ray(you.pos(), moves.target, ray); need_beam_redraw = true; } } -- cgit v1.2.3-54-g00ecf