Просмотр исходного кода

davey: present_view function (with quick test example)

skypjack 10 месяцев назад
Родитель
Сommit
b0afed4bd0
2 измененных файлов с 41 добавлено и 8 удалено
  1. 5 1
      testbed/system/imgui_system.cpp
  2. 36 7
      tools/entt/davey/davey.hpp

+ 5 - 1
testbed/system/imgui_system.cpp

@@ -1,7 +1,7 @@
+#include <entt/davey/davey.hpp>
 #include <entt/entity/registry.hpp>
 #include <imgui.h>
 #include <system/imgui_system.h>
-#include <entt/davey/davey.hpp>
 
 namespace testbed {
 
@@ -10,6 +10,10 @@ void imgui_system(const entt::registry &registry) {
     entt::davey(registry);
     ImGui::End();
 
+    ImGui::Begin("Davey - view");
+    entt::davey(registry.view<int, double>());
+    ImGui::End();
+
     ImGui::Begin("Davey - storage");
     entt::davey(*registry.storage<int>());
     ImGui::End();

+ 36 - 7
tools/entt/davey/davey.hpp

@@ -147,7 +147,7 @@ static void present_entity(const meta_ctx &ctx, const Entity entt, const It from
             if(auto type = entt::resolve(ctx, storage.info()); type) {
                 if(const davey_data *info = type.custom(); ImGui::TreeNode(&storage.info(), "%s", DAVEY_OR(storage))) {
                     if(const auto obj = type.from_void(storage.value(entt)); obj) {
-                        present_element<Entity>(obj, [&ctx, from, to](const char *name, const entt::entity other) {
+                        present_element<Entity>(obj, [&ctx, from, to](const char *name, const Entity other) {
                             if(ImGui::TreeNode(name, "%s: %d [%d/%d]", name, entt::to_integral(other), entt::to_entity(other), entt::to_version(other))) {
                                 present_entity<Entity>(ctx, other, from, to);
                                 ImGui::TreePop();
@@ -165,6 +165,40 @@ static void present_entity(const meta_ctx &ctx, const Entity entt, const It from
     }
 }
 
+template<typename... Get, typename... Exclude, std::size_t... Index>
+static void present_view(const meta_ctx &ctx, const entt::basic_view<get_t<Get...>, exclude_t<Exclude...>> &view, std::index_sequence<Index...>) {
+    using view_type = entt::basic_view<get_t<Get...>, exclude_t<Exclude...>>;
+    const std::array<const typename view_type::common_type *, sizeof...(Index)> range{view.template storage<Index>()...};
+
+    for(auto tup: view.each()) {
+        const auto entt = std::get<0>(tup);
+        ImGui::PushID(static_cast<int>(entt::to_entity(entt)));
+
+        if(ImGui::TreeNode(&entt::type_id<typename view_type::entity_type>(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) {
+            for(const auto *storage: range) {
+                if(auto type = entt::resolve(ctx, storage->info()); type) {
+                    if(const davey_data *info = type.custom(); ImGui::TreeNode(&storage->info(), "%s", DAVEY_OR((*storage)))) {
+                        if(const auto obj = type.from_void(storage->value(entt)); obj) {
+                            present_element<typename view_type::entity_type>(obj, [](const char *name, const typename view_type::entity_type entt) {
+                                ImGui::Text("%s: %d [%d/%d]", name, entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt));
+                            });
+                        }
+
+                        ImGui::TreePop();
+                    }
+                } else {
+                    const std::string name{storage->info().name()};
+                    ImGui::Text("%s", name.data());
+                }
+            }
+
+            ImGui::TreePop();
+        }
+
+        ImGui::PopID();
+    }
+}
+
 } // namespace internal
 
 template<typename Entity, typename Type, typename Allocator>
@@ -179,12 +213,7 @@ void davey(const entt::basic_storage<Entity, Type, Allocator> &storage) {
 
 template<typename... Get, typename... Exclude>
 void davey(const meta_ctx &ctx, const entt::basic_view<get_t<Get...>, exclude_t<Exclude...>> &view) {
-    using view_type = entt::basic_view<get_t<Get...>, exclude_t<Exclude...>>;
-    const std::array<typename view_type::common_type, sizeof...(Get)> range{view.template storage<Get>()...};
-
-    for(auto entt: view) {
-        internal::present_entity(ctx, entt, range.begin(), range.end());
-    }
+    internal::present_view(ctx, view, std::index_sequence_for<Get...>{});
 }
 
 template<typename... Get, typename... Exclude>