MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / UpdateKeyRoutingTable

Function UpdateKeyRoutingTable

extern/imgui/imgui.cpp:4298–4331  ·  view source on GitHub ↗

Rewrite routing data buffers to strip old entries + sort by key to make queries not touch scattered data. Entries D,A,B,B,A,C,B --> A,A,B,B,B,C,D Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6 See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation.

Source from the content-addressed store, hash-verified

4296// Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6
4297// See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation.
4298static void UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt)
4299{
4300 ImGuiContext& g = *GImGui;
4301 rt->EntriesNext.resize(0);
4302 for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1))
4303 {
4304 const int new_routing_start_idx = rt->EntriesNext.Size;
4305 ImGuiKeyRoutingData* routing_entry;
4306 for (int old_routing_idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; old_routing_idx != -1; old_routing_idx = routing_entry->NextEntryIndex)
4307 {
4308 routing_entry = &rt->Entries[old_routing_idx];
4309 routing_entry->RoutingCurr = routing_entry->RoutingNext; // Update entry
4310 routing_entry->RoutingNext = ImGuiKeyOwner_None;
4311 routing_entry->RoutingNextScore = 255;
4312 if (routing_entry->RoutingCurr == ImGuiKeyOwner_None)
4313 continue;
4314 rt->EntriesNext.push_back(*routing_entry); // Write alive ones into new buffer
4315
4316 // Apply routing to owner if there's no owner already (RoutingCurr == None at this point)
4317 if (routing_entry->Mods == g.IO.KeyMods)
4318 {
4319 ImGuiKeyOwnerData* owner_data = ImGui::GetKeyOwnerData(key);
4320 if (owner_data->OwnerCurr == ImGuiKeyOwner_None)
4321 owner_data->OwnerCurr = routing_entry->RoutingCurr;
4322 }
4323 }
4324
4325 // Rewrite linked-list
4326 rt->Index[key - ImGuiKey_NamedKey_BEGIN] = (ImGuiKeyRoutingIndex)(new_routing_start_idx < rt->EntriesNext.Size ? new_routing_start_idx : -1);
4327 for (int n = new_routing_start_idx; n < rt->EntriesNext.Size; n++)
4328 rt->EntriesNext[n].NextEntryIndex = (ImGuiKeyRoutingIndex)((n + 1 < rt->EntriesNext.Size) ? n + 1 : -1);
4329 }
4330 rt->Entries.swap(rt->EntriesNext); // Swap new and old indexes
4331}
4332
4333// [Internal] Do not use directly
4334static ImGuiKeyChord GetMergedModsFromKeys()

Callers 1

UpdateKeyboardInputsMethod · 0.85

Calls 4

GetKeyOwnerDataFunction · 0.85
resizeMethod · 0.45
push_backMethod · 0.45
swapMethod · 0.45

Tested by

no test coverage detected