mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: Settings: Simple optimization caching index into the settings buffer, to remove an unnecessary O(N*M) search during saving. (with N=active root windows during the session, M=stored settings which grows over time)
This commit is contained in:
parent
242d7e0b0b
commit
004fe8916a
13
imgui.cpp
13
imgui.cpp
@ -2085,6 +2085,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
|
||||
LastFrameActive = -1;
|
||||
ItemWidthDefault = 0.0f;
|
||||
FontWindowScale = 1.0f;
|
||||
SettingsIdx = -1;
|
||||
|
||||
DrawList = &DrawListInst;
|
||||
DrawList->_OwnerName = Name;
|
||||
@ -3876,9 +3877,14 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting
|
||||
ImGuiWindow* window = g.Windows[i];
|
||||
if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
|
||||
continue;
|
||||
ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID);
|
||||
|
||||
ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID);
|
||||
if (!settings)
|
||||
{
|
||||
settings = AddWindowSettings(window->Name);
|
||||
window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings);
|
||||
}
|
||||
IM_ASSERT(settings->ID == window->ID);
|
||||
settings->Pos = window->Pos;
|
||||
settings->Size = window->SizeFull;
|
||||
settings->Collapsed = window->Collapsed;
|
||||
@ -3981,7 +3987,7 @@ ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
for (int i = 0; i != g.SettingsWindows.Size; i++)
|
||||
if (g.SettingsWindows[i].Id == id)
|
||||
if (g.SettingsWindows[i].ID == id)
|
||||
return &g.SettingsWindows[i];
|
||||
return NULL;
|
||||
}
|
||||
@ -3992,7 +3998,7 @@ static ImGuiWindowSettings* AddWindowSettings(const char* name)
|
||||
g.SettingsWindows.push_back(ImGuiWindowSettings());
|
||||
ImGuiWindowSettings* settings = &g.SettingsWindows.back();
|
||||
settings->Name = ImStrdup(name);
|
||||
settings->Id = ImHash(name, 0);
|
||||
settings->ID = ImHash(name, 0);
|
||||
return settings;
|
||||
}
|
||||
|
||||
@ -5695,6 +5701,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
|
||||
// Retrieve settings from .ini file
|
||||
if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID))
|
||||
{
|
||||
window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings);
|
||||
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
|
||||
window->Pos = ImFloor(settings->Pos);
|
||||
window->Collapsed = settings->Collapsed;
|
||||
|
@ -440,12 +440,12 @@ struct IMGUI_API ImGuiTextEditState
|
||||
struct ImGuiWindowSettings
|
||||
{
|
||||
char* Name;
|
||||
ImGuiID Id;
|
||||
ImGuiID ID;
|
||||
ImVec2 Pos;
|
||||
ImVec2 Size;
|
||||
bool Collapsed;
|
||||
|
||||
ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
|
||||
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
|
||||
};
|
||||
|
||||
struct ImGuiSettingsHandler
|
||||
@ -994,6 +994,7 @@ struct IMGUI_API ImGuiWindow
|
||||
ImGuiStorage StateStorage;
|
||||
ImVector<ImGuiColumnsSet> ColumnsStorage;
|
||||
float FontWindowScale; // User scale multiplier per-window
|
||||
int SettingsIdx; // Index into SettingsWindow[] (indices are always valid as we only grow the array from the back)
|
||||
|
||||
ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer)
|
||||
ImDrawList DrawListInst;
|
||||
|
Loading…
Reference in New Issue
Block a user