davey: work in progress...

This commit is contained in:
Michele Caini
2025-04-10 13:01:53 +02:00
parent 81b8d01e96
commit f7f30bc5b6
4 changed files with 101 additions and 6 deletions

View File

@@ -1,15 +1,13 @@
#include <entt/entity/registry.hpp>
#include <imgui.h>
#include <system/imgui_system.h>
#include <entt/davey/davey.hpp>
namespace testbed {
void imgui_system(entt::registry &registry) {
void imgui_system(const entt::registry &registry) {
ImGui::Begin("testbed");
// ...
static_cast<void>(registry);
entt::davey(registry);
ImGui::End();
}

View File

@@ -4,6 +4,6 @@
namespace testbed {
void imgui_system(entt::registry &);
void imgui_system(const entt::registry &);
} // namespace testbed

View File

@@ -1,7 +1,92 @@
#ifndef ENTT_DAVEY_DAVEY_HPP
#define ENTT_DAVEY_DAVEY_HPP
#include <string>
#include <entt/entity/registry.hpp>
#include <entt/entity/sparse_set.hpp>
#include <entt/locator/locator.hpp>
#include <entt/meta/context.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include <imgui.h>
#include "meta.hpp"
namespace entt {
namespace internal {
template<typename Entity, typename Allocator>
static void present_entity(const meta_ctx &ctx, const entt::basic_registry<Entity, Allocator> &registry, const Entity entt) {
for([[maybe_unused]] auto [id, storage]: registry.storage()) {
if(storage.contains(entt)) {
if(auto type = entt::resolve(ctx, storage.type()); type) {
if(const davey_data *info = type.custom(); ImGui::TreeNode(&storage.type(), "%s", info ? info->name : std::string{storage.type().name()}.c_str())) {
// TODO
ImGui::TreePop();
}
} else {
const std::string name{storage.type().name()};
ImGui::Text("%s", name.c_str());
}
}
}
}
template<typename Entity, typename Allocator>
void storage_tab(const meta_ctx &ctx, const entt::basic_registry<Entity, Allocator> &registry) {
// TODO
}
template<typename Entity, typename Allocator>
void entity_tab(const meta_ctx &ctx, const entt::basic_registry<Entity, Allocator> &registry) {
for(const auto [entt]: registry.storage<Entity>()->each()) {
ImGui::PushID(static_cast<int>(entt::to_entity(entt)));
if(ImGui::TreeNode(&entt::type_id<entt::entity>(), "%d [%d/%d]", entt::to_integral(entt), entt::to_entity(entt), entt::to_version(entt))) {
present_entity(ctx, registry, entt);
ImGui::TreePop();
}
ImGui::PopID();
}
}
} // namespace internal
template<typename Entity, typename Allocator>
void davey(const meta_ctx &ctx, const entt::basic_sparse_set<Entity, Allocator> &set) {
// TODO
}
template<typename Entity, typename Allocator>
void davey(const entt::basic_sparse_set<Entity, Allocator> &set) {
// TODO
}
template<typename Entity, typename Allocator>
void davey(const meta_ctx &ctx, const entt::basic_registry<Entity, Allocator> &registry) {
ImGui::Begin("Davey");
ImGui::BeginTabBar("#tabs");
if(ImGui::BeginTabItem("Storage")) {
internal::storage_tab(ctx, registry);
ImGui::EndTabItem();
}
if(ImGui::BeginTabItem("Entity")) {
internal::entity_tab(ctx, registry);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
ImGui::End();
}
template<typename Entity, typename Allocator>
void davey(const entt::basic_registry<Entity, Allocator> &registry) {
davey(locator<meta_ctx>::value_or(), registry);
}
} // namespace entt
#endif

12
tools/entt/davey/meta.hpp Normal file
View File

@@ -0,0 +1,12 @@
#ifndef ENTT_DAVEY_META_HPP
#define ENTT_DAVEY_META_HPP
namespace entt {
struct davey_data {
const char *name;
};
} // namespace entt
#endif