mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
add imgui engine tools (based on imgui menu bar)
This commit is contained in:
parent
db07c78815
commit
e84e8fc236
@ -18,7 +18,14 @@
|
||||
|
||||
namespace MM {
|
||||
|
||||
// fwd
|
||||
namespace Services {
|
||||
class ImGuiEngineTools;
|
||||
}
|
||||
|
||||
class Engine {
|
||||
friend Services::ImGuiEngineTools;
|
||||
|
||||
private:
|
||||
using service_family = entt::family<struct internal_service_family>;
|
||||
|
||||
|
@ -85,6 +85,9 @@ add_library(imgui_tools
|
||||
|
||||
./src/mm/services/scene_tools.hpp
|
||||
./src/mm/services/scene_tools.cpp
|
||||
|
||||
./src/mm/services/engine_tools.hpp
|
||||
./src/mm/services/engine_tools.cpp
|
||||
)
|
||||
|
||||
target_include_directories(imgui_tools PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
89
framework/imgui/src/mm/services/engine_tools.cpp
Normal file
89
framework/imgui/src/mm/services/engine_tools.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "./engine_tools.hpp"
|
||||
|
||||
#include <entt/config/version.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <mm/logger.hpp>
|
||||
#define LOGIGS(x) LOG("ImGuiSceneToolsService", x)
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
bool ImGuiEngineTools::enable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["Engine"]["Stop Engine"] = [](Engine& e) {
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Stop Engine")) {
|
||||
e.stop();
|
||||
}
|
||||
};
|
||||
|
||||
menu_bar.menu_tree["Engine"]["About"] = [this](Engine&) {
|
||||
ImGui::MenuItem("About", NULL, &_show_about);
|
||||
};
|
||||
|
||||
menu_bar.menu_tree["Engine"]["Services"] = [this](Engine&) {
|
||||
ImGui::MenuItem("Services", NULL, &_show_services);
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::disable(Engine& engine) {
|
||||
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||
|
||||
menu_bar.menu_tree["Engine"].erase("Stop Engine");
|
||||
}
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiEngineTools::registerUpdates(void) {
|
||||
using namespace entt::literals;
|
||||
return {
|
||||
{
|
||||
"ImGuiEngineTools::render"_hs,
|
||||
"ImGuiEngineTools::render",
|
||||
[this](Engine& e){ renderImGui(e); },
|
||||
UpdateStrategies::update_phase_t::MAIN,
|
||||
true,
|
||||
{
|
||||
"ImGuiMenuBar::render"_hs
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderImGui(Engine& engine) {
|
||||
if (_show_about) {
|
||||
renderAbout();
|
||||
}
|
||||
|
||||
if (_show_services) {
|
||||
renderServices(engine);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderAbout(void) {
|
||||
if (ImGui::Begin("About##EngineTools", &_show_about)) {
|
||||
ImGui::Text("TODO");
|
||||
ImGui::Text("MushMachine");
|
||||
ImGui::Text("EnTT v%d.%d.%d", ENTT_VERSION_MAJOR, ENTT_VERSION_MINOR, ENTT_VERSION_PATCH);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ImGuiEngineTools::renderServices(Engine& engine) {
|
||||
if (ImGui::Begin("Services##EngineTools", &_show_services)) {
|
||||
ImGui::Text("TODO: use new table api");
|
||||
|
||||
for (auto& it : engine._services) {
|
||||
ImGui::Text("[%d|%s]: %s", it.first, it.second->second->name(), it.second->first ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace MM::Services
|
||||
|
28
framework/imgui/src/mm/services/engine_tools.hpp
Normal file
28
framework/imgui/src/mm/services/engine_tools.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "./imgui_menu_bar.hpp"
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
class ImGuiEngineTools : public Service {
|
||||
public:
|
||||
const char* name(void) override { return "ImGuiEngineTools"; }
|
||||
|
||||
bool enable(Engine& engine) override;
|
||||
void disable(Engine& engine) override;
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
|
||||
|
||||
private:
|
||||
bool _show_about = false;
|
||||
bool _show_services = false;
|
||||
|
||||
private:
|
||||
void renderImGui(Engine& engine);
|
||||
|
||||
void renderAbout(void);
|
||||
void renderServices(Engine& engine);
|
||||
};
|
||||
|
||||
} // namespace MM::Services
|
||||
|
@ -80,7 +80,7 @@ namespace MM::Services {
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%.1fFPS", ImGui::GetIO().Framerate);
|
||||
ImGui::Text("| %.1fFPS", ImGui::GetIO().Framerate);
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,25 @@ add_test(NAME imgui_scene_tools_test COMMAND imgui_scene_tools_test)
|
||||
|
||||
####################
|
||||
|
||||
add_executable(imgui_engine_tools_test
|
||||
engine_tools_test.cpp
|
||||
)
|
||||
|
||||
target_include_directories(imgui_engine_tools_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(imgui_engine_tools_test
|
||||
engine
|
||||
opengl_renderer_s
|
||||
imgui_service
|
||||
imgui_render_task
|
||||
imgui_tools
|
||||
gtest_main
|
||||
)
|
||||
|
||||
add_test(NAME imgui_engine_tools_test COMMAND imgui_engine_tools_test)
|
||||
|
||||
####################
|
||||
|
||||
add_executable(imgui_sound_test
|
||||
sound_test.cpp
|
||||
)
|
||||
|
55
framework/imgui/test/engine_tools_test.cpp
Normal file
55
framework/imgui/test/engine_tools_test.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "mm/services/imgui_menu_bar.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/filesystem.hpp>
|
||||
#include <mm/services/imgui_s.hpp>
|
||||
|
||||
#include <mm/services/opengl_renderer.hpp>
|
||||
#include <mm/opengl/render_tasks/imgui.hpp>
|
||||
|
||||
#include <mm/services/engine_tools.hpp>
|
||||
|
||||
static char* argv0;
|
||||
|
||||
TEST(imgui_scene_tools, it) {
|
||||
MM::Engine engine;
|
||||
|
||||
auto& sdl_ss = engine.addService<MM::Services::SDLService>(SDL_INIT_VIDEO);
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
|
||||
|
||||
sdl_ss.createGLWindow("imgui_engine_tools_test", 1280, 720);
|
||||
|
||||
engine.addService<MM::Services::FilesystemService>(argv0, "imgui_engine_tools_test");
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::FilesystemService>());
|
||||
|
||||
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>());
|
||||
|
||||
auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
|
||||
|
||||
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
|
||||
|
||||
engine.run();
|
||||
|
||||
sdl_ss.destroyWindow();
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
argv0 = argv[0];
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user