The previous behavior stems for a fairly old (
729eb1357d24d1d5) decision
to send a redraw on each input mode change. Since every keypress swaps
between MOUSE_MODE_NORMAL and MOUSE_MODE_COMMAND, holding down a key
could trigger a lot of unnecessary redraws, and for example with no ammo
could max out the process's cpu usage (at least on a `make profile`
build). I'm not actually sure why a webtiles redraw (which mainly send
the map and the player) is needed on any case of changing input mode,
but for now I'll be conservative -- and this is the case that shows up
in profiling.
As it happens, there's still at least one webtiles redraw per key input,
in getch_ck. But, the profiling with just this one doesn't seem like a
problem by itself. It's possible that redraw() itself has some issues
that could be addressed -- sending both the player and the map equally
eat up a lot of cpu with repeated calls.
mouse_control::mouse_control(mouse_mode mode)
{
- m_previous_mode = ms_current_mode;
- ms_current_mode = mode;
-
#ifdef USE_TILE_WEB
if (m_previous_mode != ms_current_mode)
tiles.update_input_mode(mode);
#endif
+
+ m_previous_mode = ms_current_mode;
+ ms_current_mode = mode;
}
mouse_control::~mouse_control()
m_ui_state = state;
}
-void TilesFramework::update_input_mode(mouse_mode mode)
+void TilesFramework::update_input_mode(mouse_mode mode, bool force)
{
- redraw();
+ auto prev_mode = mouse_control::current_mode();
+ if (prev_mode == mode && !force)
+ return;
+
+ // we skip redrawing in this case because it happens on every key input,
+ // and is very heavy on held down keys
+ if (force
+ || !(prev_mode == MOUSE_MODE_COMMAND && mode == MOUSE_MODE_NORMAL
+ || prev_mode == MOUSE_MODE_NORMAL && mode == MOUSE_MODE_COMMAND))
+ {
+ redraw();
+ }
json_open_object();
json_write_string("msg", "input_mode");
_send_messages();
- update_input_mode(mouse_control::current_mode());
+ update_input_mode(mouse_control::current_mode(), true);
m_text_menu.send(true);
WebtilesUIState get_ui_state() { return m_ui_state; }
void dump();
- void update_input_mode(mouse_mode mode);
+ void update_input_mode(mouse_mode mode, bool force=false);
void send_mcache(mcache_entry *entry, bool submerged,
bool send = true);