mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-08-23 07:56:40 +02:00
adopt engine stuff to new update strategy
This commit is contained in:
@@ -12,8 +12,6 @@
|
||||
#include <mm/services/opengl_renderer.hpp>
|
||||
#include <mm/opengl/render_tasks/imgui.hpp>
|
||||
|
||||
#include <mm/imgui/fps_overlay.hpp>
|
||||
|
||||
#include <mm/services/scene_tools.hpp>
|
||||
|
||||
static char* argv0;
|
||||
@@ -39,6 +37,7 @@ TEST(imgui_scene_tools, it) {
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiService>());
|
||||
|
||||
engine.addService<MM::Services::ImGuiSceneToolsService>();
|
||||
engine.getUpdateStrategy().depend("ImGuiSceneToolsService::render"_hs, "SimpleSceneService::scene_tick"_hs);
|
||||
|
||||
auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
|
||||
@@ -49,16 +48,7 @@ TEST(imgui_scene_tools, it) {
|
||||
|
||||
//InitializeYojimbo();
|
||||
|
||||
{
|
||||
MM::ImGuiSimpleFPSOverlay fps_overlay;
|
||||
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fps_overlay.renderImGui();
|
||||
}
|
||||
);
|
||||
|
||||
engine.run();
|
||||
}
|
||||
engine.run();
|
||||
|
||||
|
||||
// TODO: clear asset manager
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
// services
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/filesystem.hpp>
|
||||
@@ -25,7 +27,7 @@
|
||||
|
||||
const char* argv0;
|
||||
|
||||
class ImGuiSpeechy {
|
||||
class ImGuiSpeechy : public MM::Services::Service {
|
||||
private:
|
||||
SoLoud::Speech speech;
|
||||
SoLoud::Sfxr sfxr;
|
||||
@@ -35,13 +37,34 @@ class ImGuiSpeechy {
|
||||
SoLoud::LofiFilter lofi;
|
||||
|
||||
public:
|
||||
explicit ImGuiSpeechy(SoLoud::Soloud& sound) {
|
||||
const char* name(void) override { return "TestWindow"; }
|
||||
|
||||
bool enable(MM::Engine& engine) override {
|
||||
auto& sound = engine.getService<MM::Services::SoundService>().engine;
|
||||
|
||||
speech.setText("Test text. 1. 2. 3.");
|
||||
sfxr.loadPreset(SoLoud::Sfxr::COIN, 0);
|
||||
|
||||
sound.setGlobalFilter(0, &lofi);
|
||||
sound.setGlobalFilter(1, &echo);
|
||||
sound.setGlobalFilter(2, &freeverb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void disable(MM::Engine&) override {}
|
||||
|
||||
std::vector<MM::UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override {
|
||||
return {{
|
||||
"testwindow"_hs,
|
||||
"testwindow",
|
||||
[this](MM::Engine& engine) {
|
||||
MM::ImGuiSoundInfo(engine);
|
||||
MM::ImGuiSoundPref(engine);
|
||||
|
||||
renderImGui(engine);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
void renderImGui(MM::Engine& engine) {
|
||||
@@ -129,19 +152,10 @@ TEST(imgui_sound, basic) {
|
||||
|
||||
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
|
||||
|
||||
{
|
||||
ImGuiSpeechy speechy(sound.engine);
|
||||
engine.addService<ImGuiSpeechy>();
|
||||
ASSERT_TRUE(engine.enableService<ImGuiSpeechy>());
|
||||
|
||||
engine.addUpdate([&](MM::Engine& engine) {
|
||||
MM::ImGuiSoundInfo(engine);
|
||||
MM::ImGuiSoundPref(engine);
|
||||
|
||||
speechy.renderImGui(engine);
|
||||
}
|
||||
);
|
||||
|
||||
engine.run();
|
||||
}
|
||||
engine.run();
|
||||
|
||||
sdl_ss.destroyWindow();
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/resource_manager.hpp>
|
||||
@@ -21,6 +22,25 @@
|
||||
|
||||
static char* argv0;
|
||||
|
||||
|
||||
class TemplateUpdateMainService : public MM::Services::Service {
|
||||
std::function<void(MM::Engine&)> _fn;
|
||||
public:
|
||||
explicit TemplateUpdateMainService(std::function<void(MM::Engine&)> fn) : _fn(fn) {}
|
||||
|
||||
const char* name(void) override { return "TemplateUpdateMainService"; }
|
||||
bool enable(MM::Engine&) override { return true; }
|
||||
void disable(MM::Engine&) override {}
|
||||
|
||||
std::vector<MM::UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override {
|
||||
return {{
|
||||
"TemplateUpdateMainService::fn"_hs,
|
||||
"TemplateUpdateMainService::fn",
|
||||
_fn
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
TEST(imgui_text_edit, it) {
|
||||
MM::Engine engine;
|
||||
|
||||
@@ -50,17 +70,11 @@ TEST(imgui_text_edit, it) {
|
||||
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiSceneToolsService>());
|
||||
|
||||
MM::ImGuiSimpleFPSOverlay fps_overlay;
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fps_overlay.renderImGui();
|
||||
}
|
||||
);
|
||||
|
||||
MM::FileTextEditor fte{engine};
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fte.renderImGui();
|
||||
}
|
||||
);
|
||||
engine.addService<TemplateUpdateMainService>([](MM::Engine& e) {
|
||||
static MM::FileTextEditor fte{e};
|
||||
fte.renderImGui();
|
||||
});
|
||||
ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>());
|
||||
|
||||
engine.run();
|
||||
|
||||
@@ -98,26 +112,16 @@ TEST(imgui_text_edit, shader) {
|
||||
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiSceneToolsService>());
|
||||
|
||||
MM::ImGuiSimpleFPSOverlay fps_overlay;
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fps_overlay.renderImGui();
|
||||
}
|
||||
);
|
||||
|
||||
//auto& rc = engine.getScene().ctx<MM::OpenGL::RenderController>();
|
||||
//rc.registerRenderer<MM::OpenGL::Renderers::QuadRenderer>();
|
||||
|
||||
MM::FileTextEditor fte{engine};
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fte.renderImGui();
|
||||
}
|
||||
);
|
||||
|
||||
MM::FileShaderEditor fse{engine};
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
fse.renderImGui();
|
||||
}
|
||||
);
|
||||
engine.addService<TemplateUpdateMainService>([&](MM::Engine&) {
|
||||
fte.renderImGui();
|
||||
fse.renderImGui();
|
||||
});
|
||||
ASSERT_TRUE(engine.enableService<TemplateUpdateMainService>());
|
||||
|
||||
fte.open("shader/quad_renderer/vert.glsl");
|
||||
fse.open("shader/quad_renderer/frag.glsl");
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
#include <entt/core/hashed_string.hpp>
|
||||
|
||||
// services
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/filesystem.hpp>
|
||||
@@ -16,35 +18,6 @@
|
||||
|
||||
const char* argv0;
|
||||
|
||||
//class ImGuiSpeechy {
|
||||
//private:
|
||||
//SoLoud::Speech speech;
|
||||
//SoLoud::Sfxr sfxr;
|
||||
|
||||
//public:
|
||||
//ImGuiSpeechy(void) {
|
||||
//speech.setText("Test text. 1. 2. 3.");
|
||||
//sfxr.loadPreset(SoLoud::Sfxr::COIN, 0);
|
||||
//}
|
||||
|
||||
//void renderImGui(MM::Engine& engine) {
|
||||
//if (ImGui::Begin("Inputs")) {
|
||||
//auto& sound = *engine.tryGetService<MM::Services::SoundService>();
|
||||
|
||||
//if (ImGui::Button("play sfx")) {
|
||||
//sound.engine.play(sfxr);
|
||||
//}
|
||||
|
||||
////ImGui::Text("Active Voice Count: %d", sound.engine.getActiveVoiceCount());
|
||||
//if (ImGui::Button("Read")) {
|
||||
//sound.engine.play(speech);
|
||||
//}
|
||||
//}
|
||||
//ImGui::End();
|
||||
|
||||
//}
|
||||
//};
|
||||
|
||||
TEST(imgui_widgets, basic) {
|
||||
MM::Engine engine;
|
||||
|
||||
@@ -64,23 +37,35 @@ TEST(imgui_widgets, basic) {
|
||||
|
||||
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
|
||||
|
||||
{
|
||||
//ImGuiSpeechy speechy;
|
||||
class TestWindow : public MM::Services::Service {
|
||||
public:
|
||||
const char* name(void) override { return "TestWindow"; }
|
||||
bool enable(MM::Engine&) override { return true; }
|
||||
void disable(MM::Engine&) override {}
|
||||
|
||||
engine.addUpdate([&](MM::Engine&) {
|
||||
if (ImGui::Begin("test window")) {
|
||||
std::vector<MM::UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override {
|
||||
return {{
|
||||
"testwindow"_hs,
|
||||
"testwindow",
|
||||
[](MM::Engine&) {
|
||||
if (ImGui::Begin("test window")) {
|
||||
|
||||
static float knob_test = 0.f;
|
||||
MM::ImGuiWidgets::KnobFloat("knob1", &knob_test, 0.f, 1.f);
|
||||
ImGui::SameLine();
|
||||
MM::ImGuiWidgets::KnobFloat("knob2", &knob_test, 0.f, 1.f, 0.f, false);
|
||||
static float knob_test = 0.f;
|
||||
MM::ImGuiWidgets::KnobFloat("knob1", &knob_test, 0.f, 1.f);
|
||||
ImGui::SameLine();
|
||||
MM::ImGuiWidgets::KnobFloat("knob2", &knob_test, 0.f, 1.f, 0.f, false);
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}};
|
||||
}
|
||||
ImGui::End();
|
||||
});
|
||||
};
|
||||
|
||||
engine.run();
|
||||
}
|
||||
engine.addService<TestWindow>();
|
||||
ASSERT_TRUE(engine.enableService<TestWindow>());
|
||||
|
||||
engine.run();
|
||||
|
||||
sdl_ss.destroyWindow();
|
||||
}
|
||||
|
Reference in New Issue
Block a user