MCPcopy Create free account
hub / github.com/DFHack/dfhack / command_result plugin_onupdate

Function command_result plugin_onupdate

plugins/edgescroll.cpp:202–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202DFhackCExport command_result plugin_onupdate(color_ostream &out) {
203 // Apply a cooldown to any potential edgescrolls
204 auto& core = Core::getInstance();
205 static uint32_t last_action = 0;
206 uint32_t now = core.p->getTickCount();
207 if (now < last_action + cooldown_ms)
208 return CR_OK;
209
210 // Update mouse_x/y from values read in render thread callback
211 if (!update_mouse_pos())
212 return CR_OK; // No new input to process
213
214 if (state.xdiff == 0 && state.ydiff == 0)
215 return CR_OK; // No work to do
216
217 // Ensure either a map viewscreen or the main viewport are visible
218 auto worldmap = get_map();
219 if (!worldmap.has_value() && (!gps->main_viewport || !gps->main_viewport->flag.bits.active))
220 return CR_OK;
221
222 // Dispatch scrolling to active scrollables
223 if (worldmap.has_value())
224 scroll_world(worldmap.value(), state.xdiff, state.ydiff);
225 else if (gps->main_viewport->flag.bits.active)
226 scroll_dwarfmode(state.xdiff, state.ydiff);
227
228 // Update cooldown
229 last_action = now;
230
231 return CR_OK;
232}

Callers

nothing calls this directly

Calls 5

update_mouse_posFunction · 0.85
get_mapFunction · 0.85
scroll_worldFunction · 0.85
scroll_dwarfmodeFunction · 0.85
getTickCountMethod · 0.80

Tested by

no test coverage detected