Speed up autofire somewhat
authoradvil <rawlins@gmail.com>
Sat, 1 Aug 2020 17:55:47 +0000 (13:55 -0400)
committeradvil <rawlins@gmail.com>
Sat, 1 Aug 2020 19:37:24 +0000 (15:37 -0400)
Recent UI improvements have made direction chooser code more robust and
clean, but led to regressions in the behavior of
crawl_state.invisible_targeting, used during autofight calls to hide the
targeting ui. The result is that autofiring has become extremely slow,
resulting in visible ui lag and timeouts when holding tab with a ranged
weapon online. This commit fixes the easiest hot spots to fix, and adds
a comment at the one remaining hot spot in this code where I'm not sure
what the right way is to suppress redraws.

One other remaining part of what makes autofire slow is simply the
animation drawing, which by default at least triggers a lot of
full-screen or at least full-map redraws.

crawl-ref/source/directn.cc

index 0ae70cc..7f672cd 100644 (file)
@@ -1136,6 +1136,8 @@ static void _draw_ray_cell(screen_cell_t& cell, coord_def p, bool on_target,
 
 void direction_chooser_renderer::render(crawl_view_buffer& vbuf)
 {
+    if (crawl_state.invisible_targeting)
+        return;
     m_directn.draw_beam(vbuf);
     m_directn.highlight_summoner(vbuf);
 }
@@ -1371,6 +1373,8 @@ bool direction_chooser::handle_signals()
 // we'll live with that.
 void direction_chooser::show_initial_prompt()
 {
+    if (crawl_state.invisible_targeting)
+        return;
     behaviour->update_top_prompt(&top_prompt);
     describe_cell();
 }
@@ -2064,6 +2068,9 @@ public:
 
     void _render() override
     {
+        if (crawl_state.invisible_targeting)
+            return;
+
 #ifndef USE_TILE_LOCAL
         // do_redraws() only calls viewwindow(); we must first draw the sidebar.
         redraw_screen(false);
@@ -2221,6 +2228,9 @@ bool direction_chooser::choose_direction()
     unwind_bool inhibit_rendering(ui::should_render_current_regions, false);
 #endif
 
+    // TODO: ideally crawl_state.invisible_targeting would suppress the redraws
+    // associated with these ui calls, but I'm not sure of a clean way to make
+    // that work
     ui::push_layout(directn_view, KMC_TARGETING);
     directn_view->_queue_allocation();
     while (directn_view->is_alive() && !handle_signals())