mirror of
https://github.com/ocornut/imgui.git
synced 2025-02-17 19:09:27 +01: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;
|
LastFrameActive = -1;
|
||||||
ItemWidthDefault = 0.0f;
|
ItemWidthDefault = 0.0f;
|
||||||
FontWindowScale = 1.0f;
|
FontWindowScale = 1.0f;
|
||||||
|
SettingsIdx = -1;
|
||||||
|
|
||||||
DrawList = &DrawListInst;
|
DrawList = &DrawListInst;
|
||||||
DrawList->_OwnerName = Name;
|
DrawList->_OwnerName = Name;
|
||||||
@ -3876,9 +3877,14 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting
|
|||||||
ImGuiWindow* window = g.Windows[i];
|
ImGuiWindow* window = g.Windows[i];
|
||||||
if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
|
if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
|
||||||
continue;
|
continue;
|
||||||
ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID);
|
|
||||||
|
ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID);
|
||||||
if (!settings)
|
if (!settings)
|
||||||
|
{
|
||||||
settings = AddWindowSettings(window->Name);
|
settings = AddWindowSettings(window->Name);
|
||||||
|
window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings);
|
||||||
|
}
|
||||||
|
IM_ASSERT(settings->ID == window->ID);
|
||||||
settings->Pos = window->Pos;
|
settings->Pos = window->Pos;
|
||||||
settings->Size = window->SizeFull;
|
settings->Size = window->SizeFull;
|
||||||
settings->Collapsed = window->Collapsed;
|
settings->Collapsed = window->Collapsed;
|
||||||
@ -3981,7 +3987,7 @@ ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id)
|
|||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
for (int i = 0; i != g.SettingsWindows.Size; i++)
|
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 &g.SettingsWindows[i];
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -3992,7 +3998,7 @@ static ImGuiWindowSettings* AddWindowSettings(const char* name)
|
|||||||
g.SettingsWindows.push_back(ImGuiWindowSettings());
|
g.SettingsWindows.push_back(ImGuiWindowSettings());
|
||||||
ImGuiWindowSettings* settings = &g.SettingsWindows.back();
|
ImGuiWindowSettings* settings = &g.SettingsWindows.back();
|
||||||
settings->Name = ImStrdup(name);
|
settings->Name = ImStrdup(name);
|
||||||
settings->Id = ImHash(name, 0);
|
settings->ID = ImHash(name, 0);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5695,6 +5701,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
|
|||||||
// Retrieve settings from .ini file
|
// Retrieve settings from .ini file
|
||||||
if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID))
|
if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID))
|
||||||
{
|
{
|
||||||
|
window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings);
|
||||||
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
|
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
|
||||||
window->Pos = ImFloor(settings->Pos);
|
window->Pos = ImFloor(settings->Pos);
|
||||||
window->Collapsed = settings->Collapsed;
|
window->Collapsed = settings->Collapsed;
|
||||||
|
@ -440,12 +440,12 @@ struct IMGUI_API ImGuiTextEditState
|
|||||||
struct ImGuiWindowSettings
|
struct ImGuiWindowSettings
|
||||||
{
|
{
|
||||||
char* Name;
|
char* Name;
|
||||||
ImGuiID Id;
|
ImGuiID ID;
|
||||||
ImVec2 Pos;
|
ImVec2 Pos;
|
||||||
ImVec2 Size;
|
ImVec2 Size;
|
||||||
bool Collapsed;
|
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
|
struct ImGuiSettingsHandler
|
||||||
@ -994,6 +994,7 @@ struct IMGUI_API ImGuiWindow
|
|||||||
ImGuiStorage StateStorage;
|
ImGuiStorage StateStorage;
|
||||||
ImVector<ImGuiColumnsSet> ColumnsStorage;
|
ImVector<ImGuiColumnsSet> ColumnsStorage;
|
||||||
float FontWindowScale; // User scale multiplier per-window
|
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* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer)
|
||||||
ImDrawList DrawListInst;
|
ImDrawList DrawListInst;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user