Minor - Améliore la gestion des entités ImGui - V14.8.0
Optimizes entity list updates in the ImGui interface by caching entity names and IDs. This reduces unnecessary string operations during rendering and improves performance, especially when dealing with a large number of entities. The initial ImGui window size has also been reduced for performance reasons.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[Window][DockSpace]
|
||||
Pos=0,0
|
||||
Size=1536,793
|
||||
Size=32,32
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
@@ -22,15 +22,15 @@ DockId=0x00000009,0
|
||||
|
||||
[Window][Objects]
|
||||
Pos=0,19
|
||||
Size=251,774
|
||||
Size=15,22
|
||||
Collapsed=0
|
||||
DockId=0x0000000B,1
|
||||
DockId=0x0000000B,0
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=0,19
|
||||
Size=251,774
|
||||
Size=15,22
|
||||
Collapsed=0
|
||||
DockId=0x0000000B,0
|
||||
DockId=0x0000000B,1
|
||||
|
||||
[Window][Log Window]
|
||||
Pos=0,630
|
||||
@@ -57,7 +57,7 @@ Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1536,774 Split=X
|
||||
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=32,22 Split=X
|
||||
DockNode ID=0x00000001 Parent=0xCCBD8CF7 SizeRef=1350,842 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1265,842 Split=Y
|
||||
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1584,609 Split=X
|
||||
|
||||
@@ -39,6 +39,12 @@ struct ComponentEntry {
|
||||
std::function<void()> addFunc;
|
||||
};
|
||||
|
||||
struct CachedEntity
|
||||
{
|
||||
std::string name;
|
||||
ecs::EntityID id;
|
||||
};
|
||||
|
||||
class imguiManager
|
||||
{
|
||||
public:
|
||||
@@ -175,6 +181,10 @@ private:
|
||||
// --------------------------------------------- //
|
||||
// ----------------- Functions ----------------- //
|
||||
// --------------------------------------------- //
|
||||
/**
|
||||
* Update the cached entity list if there is a new, delete or rename entity
|
||||
*/
|
||||
void UpdateCachedEntitiesIfNeeded();
|
||||
|
||||
// --------------------------------------------- //
|
||||
// ----------------- Variables ----------------- //
|
||||
@@ -232,6 +242,8 @@ private:
|
||||
std::string version_driver_;
|
||||
|
||||
ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity
|
||||
std::vector<CachedEntity> cachedEntities_;
|
||||
bool entityListDirty = true;
|
||||
|
||||
int BUILD_VERSION_VER = -1;
|
||||
};
|
||||
|
||||
@@ -603,25 +603,17 @@ void imguiManager::WidgetObjectWindow()
|
||||
TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount())
|
||||
SEP
|
||||
|
||||
auto entities = entity_manager_->GetAllEntities();
|
||||
UpdateCachedEntitiesIfNeeded();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2));
|
||||
|
||||
for (auto& entity : entities)
|
||||
for (auto& cachedEntitie : cachedEntities_)
|
||||
{
|
||||
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||
if (identity)
|
||||
bool isSelected = (cachedEntitie.id == m_selected_entity_id);
|
||||
if (SEL(cachedEntitie.name.c_str(), isSelected))
|
||||
{
|
||||
std::string name = identity->GetName();
|
||||
if (name.empty()) name = "Entity #" + std::to_string(identity->GetId());
|
||||
// avoid same label by adding the ID at the end
|
||||
name += "##" + std::to_string(identity->GetId());
|
||||
bool isSelected = (entity->GetID() == m_selected_entity_id);
|
||||
if (SEL(name.c_str(), isSelected))
|
||||
{
|
||||
m_selected_entity_id = entity->GetID();
|
||||
show_inspector_window_ = true;
|
||||
}
|
||||
m_selected_entity_id = cachedEntitie.id;
|
||||
show_inspector_window_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1223,3 +1215,18 @@ void imguiManager::WidgetRenderStats()
|
||||
END
|
||||
}
|
||||
|
||||
void imguiManager::UpdateCachedEntitiesIfNeeded() {
|
||||
if (!entityListDirty) return;
|
||||
cachedEntities_.clear();
|
||||
auto entities = entity_manager_->GetAllEntities();
|
||||
for (auto& entity : entities) {
|
||||
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||
if (identity) {
|
||||
std::string name = identity->GetName();
|
||||
if (name.empty())
|
||||
name = "Entity " + std::to_string(identity->GetId());
|
||||
cachedEntities_.push_back({ name, identity->GetId() });
|
||||
}
|
||||
}
|
||||
entityListDirty = false;
|
||||
}
|
||||
BIN
x64/Debug/config.txt
(Stored with Git LFS)
BIN
x64/Debug/config.txt
(Stored with Git LFS)
Binary file not shown.
BIN
x64/Release/config.txt
(Stored with Git LFS)
BIN
x64/Release/config.txt
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user