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.
| 4123 | // Index A:1 B:2 C:5 D:0 --> A:0 B:2 C:5 D:6 |
| 4124 | // See 'Metrics->Key Owners & Shortcut Routing' to visualize the result of that operation. |
| 4125 | static void UpdateKeyRoutingTable(ImGuiKeyRoutingTable* rt) |
| 4126 | { |
| 4127 | ImGuiContext& g = *GImGui; |
| 4128 | rt->EntriesNext.resize(0); |
| 4129 | for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1)) |
| 4130 | { |
| 4131 | const int new_routing_start_idx = rt->EntriesNext.Size; |
| 4132 | ImGuiKeyRoutingData* routing_entry; |
| 4133 | for (int old_routing_idx = rt->Index[key - ImGuiKey_NamedKey_BEGIN]; old_routing_idx != -1; old_routing_idx = routing_entry->NextEntryIndex) |
| 4134 | { |
| 4135 | routing_entry = &rt->Entries[old_routing_idx]; |
| 4136 | routing_entry->RoutingCurr = routing_entry->RoutingNext; // Update entry |
| 4137 | routing_entry->RoutingNext = ImGuiKeyOwner_None; |
| 4138 | routing_entry->RoutingNextScore = 255; |
| 4139 | if (routing_entry->RoutingCurr == ImGuiKeyOwner_None) |
| 4140 | continue; |
| 4141 | rt->EntriesNext.push_back(*routing_entry); // Write alive ones into new buffer |
| 4142 | |
| 4143 | // Apply routing to owner if there's no owner already (RoutingCurr == None at this point) |
| 4144 | if (routing_entry->Mods == g.IO.KeyMods) |
| 4145 | { |
| 4146 | ImGuiKeyOwnerData* owner_data = ImGui::GetKeyOwnerData(key); |
| 4147 | if (owner_data->OwnerCurr == ImGuiKeyOwner_None) |
| 4148 | owner_data->OwnerCurr = routing_entry->RoutingCurr; |
| 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | // Rewrite linked-list |
| 4153 | rt->Index[key - ImGuiKey_NamedKey_BEGIN] = (ImGuiKeyRoutingIndex)(new_routing_start_idx < rt->EntriesNext.Size ? new_routing_start_idx : -1); |
| 4154 | for (int n = new_routing_start_idx; n < rt->EntriesNext.Size; n++) |
| 4155 | rt->EntriesNext[n].NextEntryIndex = (ImGuiKeyRoutingIndex)((n + 1 < rt->EntriesNext.Size) ? n + 1 : -1); |
| 4156 | } |
| 4157 | rt->Entries.swap(rt->EntriesNext); // Swap new and old indexes |
| 4158 | } |
| 4159 | |
| 4160 | // [Internal] Do not use directly (should read io.KeyMods instead) |
| 4161 | static ImGuiKeyChord GetMergedModsFromBools() |
no test coverage detected