From a9187c1f450220bf39d596203d2f79787d8dfd03 Mon Sep 17 00:00:00 2001 From: skypjack Date: Tue, 22 Apr 2025 18:56:10 +0200 Subject: [PATCH] davey: rework storage path --- tools/entt/davey/davey.hpp | 101 +++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 55 deletions(-) diff --git a/tools/entt/davey/davey.hpp b/tools/entt/davey/davey.hpp index fb7d09d54..a4e7238bd 100644 --- a/tools/entt/davey/davey.hpp +++ b/tools/entt/davey/davey.hpp @@ -115,6 +115,31 @@ static void present_element(const entt::meta_any &obj, OnEntity on_entity) { } } +template +static void present_storage(const meta_ctx &ctx, const Storage &storage) { + if(auto type = entt::resolve(ctx, storage.info()); type) { + for(auto entt: storage) { + ImGui::PushID(static_cast(entt::to_entity(entt))); + + if(ImGui::TreeNode(&storage.info(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) { + if(const auto obj = type.from_void(storage.value(entt)); obj) { + present_element::entity_type>(obj, [](const char *name, const entt::entity entt) { + ImGui::Text("%s: %d [%d/%d]", name, entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt)); + }); + } + + ImGui::TreePop(); + } + + ImGui::PopID(); + } + } else { + for(auto entt: storage) { + ImGui::Text("%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt)); + } + } +} + template static void present_entity(const meta_ctx &ctx, const Entity entt, const It from, const It to) { for(auto it = from; it != to; ++it) { @@ -140,57 +165,6 @@ static void present_entity(const meta_ctx &ctx, const Entity entt, const It from } } -template -void storage_tab(const meta_ctx &ctx, const It from, const It to) { - for(auto it = from; it != to; ++it) { - const auto &storage = it->second; - - if(auto type = entt::resolve(ctx, storage.info()); type) { - if(const davey_data *info = type.custom(); ImGui::TreeNode(&storage.info(), "%s (%zu)", DAVEY_OR(storage), storage.size())) { - for(auto entt: storage) { - ImGui::PushID(static_cast(entt::to_entity(entt))); - - if(ImGui::TreeNode(&storage.info(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) { - if(const auto obj = type.from_void(storage.value(entt)); obj) { - present_element::entity_type>(obj, [](const char *name, const entt::entity entt) { - ImGui::Text("%s: %d [%d/%d]", name, entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt)); - }); - } - - ImGui::TreePop(); - } - - ImGui::PopID(); - } - - ImGui::TreePop(); - } - } else { - if(const std::string name{storage.info().name()}; ImGui::TreeNode(&storage.info(), "%s (%zu)", name.data(), storage.size())) { - for(auto entt: storage) { - ImGui::Text("%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt)); - } - - ImGui::TreePop(); - } - } - } -} - -template -void entity_tab(const meta_ctx &ctx, const Storage &storage, const It from, const It to) { - for(const auto [entt]: storage->each()) { - ImGui::PushID(static_cast(entt::to_entity(entt))); - - if(ImGui::TreeNode(&entt::type_id(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) { - present_entity(ctx, entt, from, to); - ImGui::TreePop(); - } - - ImGui::PopID(); - } -} - } // namespace internal template @@ -218,14 +192,31 @@ void davey(const meta_ctx &ctx, const entt::basic_registry &r ImGui::BeginTabBar("#tabs"); if(ImGui::BeginTabItem("Storage")) { - const auto range = registry.storage(); - internal::storage_tab(ctx, range.begin(), range.end()); + for([[maybe_unused]] auto [id, storage]: registry.storage()) { + if(const davey_data *info = entt::resolve(ctx, storage.info()).custom(); ImGui::TreeNode(&storage.info(), "%s (%zu)", DAVEY_OR(storage), storage.size())) { + internal::present_storage(ctx, storage); + ImGui::TreePop(); + } + } + ImGui::EndTabItem(); } if(ImGui::BeginTabItem("Entity")) { - const auto range = registry.storage(); - internal::entity_tab(ctx, registry.template storage(), range.begin(), range.end()); + const auto &storage = registry.template storage(); + + for(const auto [entt]: storage->each()) { + ImGui::PushID(static_cast(entt::to_entity(entt))); + + if(ImGui::TreeNode(&entt::type_id(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) { + const auto range = registry.storage(); + present_entity(ctx, entt, range.begin(), range.end()); + ImGui::TreePop(); + } + + ImGui::PopID(); + } + ImGui::EndTabItem(); }