adopt scene tools to imgui menu bar, some features are now lost

This commit is contained in:
Green Sky 2021-01-11 18:47:15 +01:00
parent e84e8fc236
commit 3471b949cc
5 changed files with 126 additions and 171 deletions

View File

@ -37,6 +37,8 @@ namespace MM::Services {
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
menu_bar.menu_tree["Engine"].erase("Stop Engine");
menu_bar.menu_tree["Engine"].erase("About");
menu_bar.menu_tree["Engine"].erase("Services");
}
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiEngineTools::registerUpdates(void) {

View File

@ -1,12 +1,11 @@
#include "./scene_tools.hpp"
#include <entt/config/version.h>
//#include <mm/services/opengl_renderer.hpp>
#include <mm/services/opengl_renderer.hpp>
#include <mm/resource_manager.hpp>
//#include <mm/resource_manager.hpp>
#include <mm/engine.hpp>
#include "./imgui_menu_bar.hpp"
#include <imgui/imgui.h>
@ -14,7 +13,7 @@
#include <mm/components/transform2d.hpp>
#include <mm/components/velocity2d.hpp>
#include <mm/imgui/widgets/texture_resource_manager.hpp>
//#include <mm/imgui/widgets/texture_resource_manager.hpp>
#include <mm/imgui/widgets/entity.hpp>
#include <mm/imgui/widgets/components/name.hpp>
@ -28,50 +27,89 @@
#include <mm/imgui/widgets/camera.hpp>
#include <mm/imgui/widgets/filesystem.hpp>
#include <mm/services/filesystem.hpp>
//#include <mm/imgui/widgets/filesystem.hpp>
//#include <mm/services/filesystem.hpp>
#include <mm/logger.hpp>
#define LOGIGS(x) LOG("ImGuiSceneToolsService", x)
namespace MM::Services {
void ImGuiSceneToolsService::renderImGui(Engine& engine) {
if (show_menu && ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("Engine")) {
if (ImGui::MenuItem("Stop Engine")) {
engine.stop();
}
ImGui::EndMenu();
bool ImGuiSceneToolsService::enable(Engine& engine) {
if (!engine.tryService<MM::Services::SceneServiceInterface>()) {
LOGIGS("error: no SceneServiceInterface");
return false;
}
if (ImGui::BeginMenu("TextEditor")) {
if (ImGui::MenuItem("New Editor")) {
_text_editor_list.emplace_back(engine);
}
ImGui::EndMenu();
// setup entity editor defaults
{
_entity_editor.show_window = false;
_entity_editor.registerComponent<MM::Components::Name>("Name");
_entity_editor.registerComponent<MM::Components::Transform2D>("Transform2D");
_entity_editor.registerComponent<MM::Components::Transform3D>("Transform3D");
_entity_editor.registerComponent<MM::Components::Velocity2D>("Velocity2D");
_entity_editor.registerComponent<MM::Components::ViewDir2D>("ViewDir2D");
_entity_editor.registerComponent<MM::Components::ViewDir3D>("ViewDir3D");
_entity_editor.registerComponent<MM::Components::Color>("Color");
_entity_editor.registerComponent<MM::Components::OpenGL::Texture>("Texture");
}
if (ImGui::BeginMenu("Windows")) {
ImGui::MenuItem("MM Metrics", NULL, &_show_mm_metrics);
ImGui::MenuItem("ImGui Metrics", NULL, &_show_imgui_metrics);
ImGui::MenuItem("Texture Loader", NULL, &_show_texture_loader);
ImGui::MenuItem("Texture List", NULL, &_show_texture_list);
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
menu_bar.menu_tree["Scene"]["Metrics"] = [this](Engine&) {
ImGui::MenuItem("Metrics", NULL, &_show_scene_metrics);
};
menu_bar.menu_tree["Scene"]["EntityEditor"] = [this](Engine&) {
ImGui::MenuItem("EntityEditor", NULL, &_show_entity_editor);
ImGui::MenuItem("Camera Tool", NULL, &_show_camera_tool);
ImGui::EndMenu();
};
menu_bar.menu_tree["Scene"]["CameraTool"] = [this](Engine&) {
ImGui::MenuItem("Camera3D Tool", NULL, &_show_camera_tool);
};
return true;
}
ImGui::Text("%.1fFPS", ImGui::GetIO().Framerate);
ImGui::EndMainMenuBar();
void ImGuiSceneToolsService::disable(Engine& engine) {
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
menu_bar.menu_tree["Scene"].erase("Metrics");
menu_bar.menu_tree["Scene"].erase("EntityEditor");
}
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiSceneToolsService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ImGuiSceneToolsService::render"_hs,
"ImGuiSceneToolsService::render",
[this](Engine& e){ renderImGui(e); },
UpdateStrategies::update_phase_t::MAIN,
true,
{
"ImGuiMenuBar::render"_hs
}
}
};
}
void ImGuiSceneToolsService::renderImGui(Engine& engine) {
//if (show_menu && ImGui::BeginMainMenuBar()) {
//if (ImGui::BeginMenu("Windows")) {
//ImGui::MenuItem("Camera Tool", NULL, &_show_camera_tool);
//ImGui::EndMenu();
//}
//}
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
if (_show_mm_metrics) {
if (ImGui::Begin("Metrics##MM", &_show_mm_metrics)) {
if (ImGui::CollapsingHeader("ECS")) {
ImGui::Text("EnTT v%d.%d.%d", ENTT_VERSION_MAJOR, ENTT_VERSION_MINOR, ENTT_VERSION_PATCH);
if (_show_scene_metrics) {
if (ImGui::Begin("Scene Metrics##ImGuiSceneToolsService", &_show_scene_metrics)) {
ImGui::Text("capacity: %lu", scene.capacity());
ImGui::Text("size: %lu", scene.size());
ImGui::Text("alive: %lu", scene.alive());
@ -79,25 +117,6 @@ namespace MM::Services {
scene.orphans([&](auto) { orphans++; });
ImGui::Text("orphans: %lu", orphans);
}
}
ImGui::End();
}
if (_show_imgui_metrics) {
ImGui::ShowMetricsWindow(&_show_imgui_metrics);
}
if (_show_texture_loader) {
if (ImGui::Begin("Texture Loader", &_show_texture_loader)) {
ImGuiWidgets::TextureResourceManagerLoader(engine);
}
ImGui::End();
}
if (_show_texture_list) {
if (ImGui::Begin("Texture List", &_show_texture_list)) {
ImGuiWidgets::TextureResourceManagerList();
}
ImGui::End();
}
@ -131,86 +150,11 @@ namespace MM::Services {
}
ImGui::End();
}
for (auto it = _text_editor_list.begin(); it != _text_editor_list.end();) {
bool keep_open = true;
it->renderImGui(&keep_open);
if (!keep_open) {
it = _text_editor_list.erase(it);
continue;
}
it++;
}
}
EntityEditor<Entity>& ImGuiSceneToolsService::getEntityEditor(void) {
return _entity_editor;
}
bool ImGuiSceneToolsService::enable(Engine& engine) {
if (!engine.tryService<MM::Services::OpenGLRenderer>()) {
LOGIGS("error: rendering is not in engine");
return false;
}
if (!engine.tryService<MM::Services::FilesystemService>()) {
LOGIGS("error: filesystem not initialized");
return false;
}
if (!engine.tryService<MM::Services::SceneServiceInterface>()) {
LOGIGS("error: no SceneServiceInterface");
return false;
}
// setup entity editor defaults
{
_entity_editor.show_window = false;
_entity_editor.registerComponent<MM::Components::Name>("Name");
_entity_editor.registerComponent<MM::Components::Transform2D>("Transform2D");
_entity_editor.registerComponent<MM::Components::Transform3D>("Transform3D");
_entity_editor.registerComponent<MM::Components::Velocity2D>("Velocity2D");
_entity_editor.registerComponent<MM::Components::ViewDir2D>("ViewDir2D");
_entity_editor.registerComponent<MM::Components::ViewDir3D>("ViewDir3D");
_entity_editor.registerComponent<MM::Components::Color>("Color");
_entity_editor.registerComponent<MM::Components::OpenGL::Texture>("Texture");
}
auto* sdl_ss = engine.tryService<MM::Services::SDLService>();
if (sdl_ss) {
_event_handle = sdl_ss->addEventHandler([this](const SDL_Event& e) -> bool {
if (e.type == SDL_KEYDOWN && !e.key.repeat && e.key.keysym.sym == this->toggle_key) {
this->show_menu = !this->show_menu;
}
return false; // invis
});
} else {
LOGIGS("Warn: no SDLService, skipping toggle hotkey");
}
return true;
}
void ImGuiSceneToolsService::disable(Engine& engine) {
if (_event_handle) {
auto* sdl_ss = engine.tryService<MM::Services::SDLService>();
sdl_ss->removeEventHandler(_event_handle);
_event_handle = nullptr;
}
}
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiSceneToolsService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ImGuiSceneToolsService::render"_hs,
"ImGuiSceneToolsService::render",
[this](Engine& e){ renderImGui(e); }
}
};
}
} // namespace MM::Services

View File

@ -1,46 +1,15 @@
#pragma once
#include <mm/services/sdl_service.hpp>
#define MM_IEEE_ENTITY_WIDGET ::MM::ImGuiWidgets::Entity // evil
#define MM_IEEE_ASSERT(x)
#include <mm/imgui/widgets/entity.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/imgui/file_text_editor.hpp>
//#include <mm/imgui/file_text_editor.hpp>
namespace MM::Services {
class ImGuiSceneToolsService : public Service {
public:
bool show_menu = true;
SDL_Keycode toggle_key = SDLK_F2;
private:
bool _show_mm_metrics = false;
bool _show_imgui_metrics = false;
bool _show_texture_loader = false;
bool _show_texture_list = false;
bool _show_entity_editor = false;
bool _show_entity_list = true;
bool _show_camera_tool = false;
EntityEditor<Entity> _entity_editor;
// for list
std::set<EntityEditor<Entity>::ComponentTypeID> _entity_comp_list;
std::vector<MM::FileTextEditor> _text_editor_list;
MM::Services::SDLService::EventHandlerHandle _event_handle = nullptr;
private:
void renderImGui(Engine& engine);
public:
EntityEditor<Entity>& getEntityEditor(void);
Entity _e = entt::null; // entity currently in editor
public:
bool enable(Engine& engine) override;
void disable(Engine& engine) override;
@ -49,6 +18,24 @@ namespace MM::Services {
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
private:
bool _show_scene_metrics = false;
bool _show_entity_editor = false;
bool _show_entity_list = true;
bool _show_camera_tool = false;
EntityEditor<Entity> _entity_editor;
// for list
std::set<EntityEditor<Entity>::ComponentTypeID> _entity_comp_list;
//std::vector<MM::FileTextEditor> _text_editor_list;
private:
void renderImGui(Engine& engine);
public:
EntityEditor<Entity>& getEntityEditor(void);
Entity _e = entt::null; // entity currently in editor
};
} // namespace MM::Services

View File

@ -8,6 +8,8 @@
#include <mm/services/filesystem.hpp>
#include <mm/services/simple_scene.hpp>
#include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp>
#include <mm/services/opengl_renderer.hpp>
#include <mm/opengl/render_tasks/imgui.hpp>
@ -38,6 +40,12 @@ TEST(imgui_scene_tools, it) {
engine.addService<MM::Services::ImGuiService>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiService>());
engine.addService<MM::Services::ImGuiMenuBar>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiMenuBar>());
engine.addService<MM::Services::ImGuiEngineTools>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiEngineTools>());
engine.addService<MM::Services::ImGuiSceneToolsService>();
engine.getUpdateStrategy().depend("ImGuiSceneToolsService::render"_hs, "SimpleSceneService::scene_tick"_hs);

View File

@ -10,6 +10,8 @@
#include <mm/services/simple_scene.hpp>
#include <mm/services/opengl_renderer.hpp>
#include <mm/services/imgui_s.hpp>
#include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp>
#include <mm/opengl/render_tasks/imgui.hpp>
@ -62,6 +64,12 @@ TEST(imgui_text_edit, it) {
engine.addService<MM::Services::ImGuiService>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiService>());
engine.addService<MM::Services::ImGuiMenuBar>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiMenuBar>());
engine.addService<MM::Services::ImGuiEngineTools>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiEngineTools>());
engine.addService<MM::Services::ImGuiSceneToolsService>();
auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
@ -104,6 +112,12 @@ TEST(imgui_text_edit, shader) {
engine.addService<MM::Services::ImGuiService>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiService>());
engine.addService<MM::Services::ImGuiMenuBar>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiMenuBar>());
engine.addService<MM::Services::ImGuiEngineTools>();
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiEngineTools>());
engine.addService<MM::Services::ImGuiSceneToolsService>();
auto& rs = engine.addService<MM::Services::OpenGLRenderer>();