Minor - Améliore la gestion des entités ImGui - V14.9.0
Optimizes entity management in ImGui by deferring updates to the entity list until necessary. Changes include: - Sets the entity list as dirty upon adding or deleting entities to ensure the list is only updated when needed - Changes the type of entity ID stored in CachedEntity - Adjusts ImGui window size
This commit is contained in:
@@ -42,7 +42,7 @@ struct ComponentEntry {
|
||||
struct CachedEntity
|
||||
{
|
||||
std::string name;
|
||||
ecs::EntityID id;
|
||||
int id;
|
||||
};
|
||||
|
||||
class imguiManager
|
||||
|
||||
@@ -502,6 +502,8 @@ void imguiManager::WidgetAddObject()
|
||||
// Remplacer les antislashs par des slashs
|
||||
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
||||
app_->add_kobject(relativePath);
|
||||
// set entities list as dirty
|
||||
entityListDirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -596,13 +598,15 @@ void imguiManager::WidgetObjectWindow()
|
||||
// Remplacer les antislashs par des slashs
|
||||
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
|
||||
app_->add_kobject(relativePath);
|
||||
// set list as dirty since new entity has been added to the scene
|
||||
entityListDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
S_LINE
|
||||
TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount())
|
||||
SEP
|
||||
|
||||
|
||||
UpdateCachedEntitiesIfNeeded();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2));
|
||||
@@ -660,6 +664,7 @@ void imguiManager::WidgetInspectorWindow()
|
||||
entity_manager_->DestroyEntity(m_selected_entity_id);
|
||||
m_selected_entity_id = -1;
|
||||
show_inspector_window_ = false;
|
||||
entityListDirty = true;
|
||||
}
|
||||
S_LINE
|
||||
|
||||
@@ -1223,9 +1228,10 @@ void imguiManager::UpdateCachedEntitiesIfNeeded() {
|
||||
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||
if (identity) {
|
||||
std::string name = identity->GetName();
|
||||
auto id = identity->GetId();
|
||||
if (name.empty())
|
||||
name = "Entity " + std::to_string(identity->GetId());
|
||||
cachedEntities_.push_back({ name, identity->GetId() });
|
||||
cachedEntities_.push_back({name,id});
|
||||
}
|
||||
}
|
||||
entityListDirty = false;
|
||||
|
||||
Reference in New Issue
Block a user