mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-04-20 01:52:59 +02:00
added screen director tools
minor additions / fixes
This commit is contained in:
parent
9e9b644856
commit
2c1faa60c6
@ -91,6 +91,9 @@ add_library(imgui_tools
|
|||||||
|
|
||||||
./src/mm/services/engine_tools.hpp
|
./src/mm/services/engine_tools.hpp
|
||||||
./src/mm/services/engine_tools.cpp
|
./src/mm/services/engine_tools.cpp
|
||||||
|
|
||||||
|
./src/mm/services/screen_director_tools.hpp
|
||||||
|
./src/mm/services/screen_director_tools.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(imgui_tools PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
target_include_directories(imgui_tools PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
@ -98,6 +101,8 @@ target_link_libraries(imgui_tools
|
|||||||
imgui_render_task
|
imgui_render_task
|
||||||
imgui_widgets
|
imgui_widgets
|
||||||
imgui_color_text_edit
|
imgui_color_text_edit
|
||||||
|
|
||||||
|
screen_director
|
||||||
)
|
)
|
||||||
|
|
||||||
################## imgui_sound
|
################## imgui_sound
|
||||||
|
87
framework/imgui/src/mm/services/screen_director_tools.cpp
Normal file
87
framework/imgui/src/mm/services/screen_director_tools.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "./screen_director_tools.hpp"
|
||||||
|
|
||||||
|
#include <mm/engine.hpp>
|
||||||
|
|
||||||
|
#include <mm/services/screen_director.hpp>
|
||||||
|
|
||||||
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
|
namespace MM::Services {
|
||||||
|
|
||||||
|
using UpdateStrategies::update_key_t;
|
||||||
|
|
||||||
|
bool ImGuiScreenDirectorTools::enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) {
|
||||||
|
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||||
|
|
||||||
|
menu_bar.menu_tree["Screens"]["ShowList"] = [this](Engine&) {
|
||||||
|
ImGui::MenuItem("ShowScreenList", NULL, &_show_screen_list);
|
||||||
|
};
|
||||||
|
|
||||||
|
// add task
|
||||||
|
task_array.push_back(
|
||||||
|
UpdateStrategies::TaskInfo{"ImGuiScreenDirectorTools::render"}
|
||||||
|
.fn([this](Engine& e){ renderImGui(e); })
|
||||||
|
.phase(UpdateStrategies::update_phase_t::PRE)
|
||||||
|
.succeed("ImGuiMenuBar::render")
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiScreenDirectorTools::disable(Engine& engine) {
|
||||||
|
auto& menu_bar = engine.getService<MM::Services::ImGuiMenuBar>();
|
||||||
|
|
||||||
|
menu_bar.menu_tree["Engine"].erase("ShowList");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiScreenDirectorTools::renderImGui(Engine& engine) {
|
||||||
|
if (_show_screen_list) {
|
||||||
|
renderScreenList(engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiScreenDirectorTools::renderScreenList(Engine& engine) {
|
||||||
|
if (ImGui::Begin("Screens##ScreenDirectorTools", &_show_screen_list)) {
|
||||||
|
ImGui::Text("TODO: make sortable");
|
||||||
|
//ImGui::Checkbox("edit mode", &_services_edit_mode);
|
||||||
|
|
||||||
|
if (ImGui::BeginTable(
|
||||||
|
"screens_table",
|
||||||
|
2,
|
||||||
|
ImGuiTableFlags_RowBg //|
|
||||||
|
)) {
|
||||||
|
ImGui::TableSetupColumn("name"/*, ImGuiTableColumnFlags_WidthFixed*/);
|
||||||
|
ImGui::TableSetupColumn("##goto", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
//ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
auto& sd = engine.getService<MM::Services::ScreenDirector>();
|
||||||
|
|
||||||
|
const auto active_screen_color = ImGui::GetColorU32(ImVec4(0.3f, 0.7f, 0.3f, 0.4f));
|
||||||
|
|
||||||
|
for (const auto& it : sd.screens) {
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
|
if (it.first == sd.curr_screen_id) {
|
||||||
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, active_screen_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%s", it.first.c_str());
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::PushID(it.first.c_str());
|
||||||
|
if (ImGui::SmallButton("-> GoTo")) {
|
||||||
|
sd.queueChangeScreenTo(it.first);
|
||||||
|
}
|
||||||
|
//ImGui::SetTooltip("click to toggle!"); the heck?
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace MM::Services
|
||||||
|
|
26
framework/imgui/src/mm/services/screen_director_tools.hpp
Normal file
26
framework/imgui/src/mm/services/screen_director_tools.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "./imgui_menu_bar.hpp"
|
||||||
|
|
||||||
|
namespace MM::Services {
|
||||||
|
|
||||||
|
class ImGuiScreenDirectorTools : public Service {
|
||||||
|
public:
|
||||||
|
const char* name(void) override { return "ImGuiScreenDirectorTools"; }
|
||||||
|
|
||||||
|
bool enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) override;
|
||||||
|
void disable(Engine& engine) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _show_screen_list = false;
|
||||||
|
|
||||||
|
//bool _edit_mode = false;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void renderImGui(Engine& engine);
|
||||||
|
|
||||||
|
void renderScreenList(Engine& engine);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace MM::Services
|
||||||
|
|
@ -48,6 +48,10 @@ namespace MM::OpenGL {
|
|||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t getSizeBytes(void) const {
|
||||||
|
return _size * sizeof(TInstance);
|
||||||
|
}
|
||||||
|
|
||||||
TInstance* map(size_t size, GLenum usage = GL_DYNAMIC_DRAW, bool shrink = false) {
|
TInstance* map(size_t size, GLenum usage = GL_DYNAMIC_DRAW, bool shrink = false) {
|
||||||
if (size > _size || (shrink && (size < _size)))
|
if (size > _size || (shrink && (size < _size)))
|
||||||
resize(size, usage);
|
resize(size, usage);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
namespace MM::OpenGL {
|
namespace MM::OpenGL {
|
||||||
|
|
||||||
Camera3D::Camera3D(void) {
|
Camera3D::Camera3D(void) {
|
||||||
@ -81,6 +83,8 @@ glm::mat4 Camera3D::getProjection() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
||||||
|
ZoneScopedN("Camera3D::getFrustumPlanes")
|
||||||
|
|
||||||
std::array<glm::vec4, 6> planes;
|
std::array<glm::vec4, 6> planes;
|
||||||
|
|
||||||
glm::mat4 wvp = getViewProjection();
|
glm::mat4 wvp = getViewProjection();
|
||||||
@ -172,11 +176,38 @@ std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
|||||||
// normalize
|
// normalize
|
||||||
for (size_t i = 0; i < 6; i++) {
|
for (size_t i = 0; i < 6; i++) {
|
||||||
planes[i] = glm::normalize(planes[i]);
|
planes[i] = glm::normalize(planes[i]);
|
||||||
//planes[i] /= glm::length(glm::vec3(planes[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return planes;
|
return planes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static T dot34(glm::vec<3, T> lhs, glm::vec<4, T> rhs) {
|
||||||
|
return glm::dot(lhs, glm::vec<3, T>(rhs)) + rhs.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool in_frustum_aabb(
|
||||||
|
const std::array<glm::vec4, 6>& frustum,
|
||||||
|
const std::array<glm::vec3, 8>& aabb
|
||||||
|
) {
|
||||||
|
// test each plane
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
bool inside = false; // inside current plane
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
if (dot34(aabb[j], frustum[i]) >= 0) { // == for on plane
|
||||||
|
inside = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inside) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // MM::Rendering
|
} // MM::Rendering
|
||||||
|
|
||||||
|
@ -50,5 +50,20 @@ namespace MM::OpenGL {
|
|||||||
// call updateView beforehand, does not cache
|
// call updateView beforehand, does not cache
|
||||||
std::array<glm::vec4, 6> getFrustumPlanes(void) const;
|
std::array<glm::vec4, 6> getFrustumPlanes(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// test if aabb in frustum
|
||||||
|
// aabb is in world space
|
||||||
|
bool in_frustum_aabb(
|
||||||
|
const std::array<glm::vec4, 6>& frustum,
|
||||||
|
const std::array<glm::vec3, 8>& aabb
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: implement
|
||||||
|
//// test if sphere in frustum
|
||||||
|
//bool in_frustum_sphere(
|
||||||
|
//const std::array<glm::vec4, 6>& frustum,
|
||||||
|
//const glm::vec3 position, const float radius
|
||||||
|
//);
|
||||||
|
|
||||||
} // MM::OpenGL
|
} // MM::OpenGL
|
||||||
|
|
||||||
|
@ -28,10 +28,21 @@
|
|||||||
|
|
||||||
namespace MM::Services {
|
namespace MM::Services {
|
||||||
|
|
||||||
SDLService::SDLService(uint32_t sdl_init_flags) {
|
SDLService::SDLService(uint32_t _sdl_init_flags) {
|
||||||
MM::Logger::initSectionLogger("SDLService");
|
MM::Logger::initSectionLogger("SDLService");
|
||||||
|
|
||||||
LOG_TRACE("constructing SDLService...");
|
//#ifdef __EMSCRIPTEN__
|
||||||
|
//_sdl_init_flags &= ~SDL_INIT_HAPTIC;
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
sdl_init_flags = _sdl_init_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDLService::~SDLService(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SDLService::enable(Engine&, std::vector<UpdateStrategies::TaskInfo>& task_array) {
|
||||||
|
LOG_TRACE("enabling SDLService...");
|
||||||
|
|
||||||
SDL_LogSetOutputFunction(
|
SDL_LogSetOutputFunction(
|
||||||
+[](void*, int category, SDL_LogPriority priority, const char* message) {
|
+[](void*, int category, SDL_LogPriority priority, const char* message) {
|
||||||
@ -43,19 +54,25 @@ SDLService::SDLService(uint32_t sdl_init_flags) {
|
|||||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
|
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
|
||||||
|
|
||||||
|
|
||||||
//#ifdef __EMSCRIPTEN__
|
|
||||||
//sdl_init_flags &= ~SDL_INIT_HAPTIC;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
if (SDL_Init(sdl_init_flags)) {
|
if (SDL_Init(sdl_init_flags)) {
|
||||||
LOG_CRIT("SDL_Init() failed: {}", SDL_GetError());
|
LOG_CRIT("SDL_Init() failed: {}", SDL_GetError());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add task
|
||||||
|
task_array.push_back(
|
||||||
|
UpdateStrategies::TaskInfo{"SDLService::events"}
|
||||||
|
.phase(UpdateStrategies::update_phase_t::PRE)
|
||||||
|
.fn([this](Engine& e) { this->processEvents(e); })
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLService::~SDLService(void) {
|
void SDLService::disable(Engine&) {
|
||||||
LOG_TRACE("deconstructing SDLService...");
|
LOG_TRACE("disabling SDLService...");
|
||||||
|
|
||||||
|
// destroy stuff
|
||||||
if (gl_context) {
|
if (gl_context) {
|
||||||
SDL_GL_DeleteContext(gl_context);
|
SDL_GL_DeleteContext(gl_context);
|
||||||
}
|
}
|
||||||
@ -68,30 +85,6 @@ SDLService::~SDLService(void) {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDLService::enable(Engine&, std::vector<UpdateStrategies::TaskInfo>& task_array) {
|
|
||||||
// add task
|
|
||||||
task_array.push_back(
|
|
||||||
UpdateStrategies::TaskInfo{"SDLService::events"}
|
|
||||||
.phase(UpdateStrategies::update_phase_t::PRE)
|
|
||||||
.fn([this](Engine& e) { this->processEvents(e); })
|
|
||||||
);
|
|
||||||
|
|
||||||
bool succ = true;
|
|
||||||
return succ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDLService::disable(Engine&) {
|
|
||||||
// destroy stuff
|
|
||||||
if (gl_context) {
|
|
||||||
SDL_GL_DeleteContext(gl_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (win) {
|
|
||||||
LOG_WARN("destroying open window");
|
|
||||||
destroyWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDLService::createWindow(const char* title, int screen_width, int screen_height, uint32_t sdl_window_flags) {
|
bool SDLService::createWindow(const char* title, int screen_width, int screen_height, uint32_t sdl_window_flags) {
|
||||||
if (!win) {
|
if (!win) {
|
||||||
win = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, sdl_window_flags);
|
win = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, sdl_window_flags);
|
||||||
|
@ -11,6 +11,8 @@ namespace MM::Services {
|
|||||||
|
|
||||||
class SDLService : public Service {
|
class SDLService : public Service {
|
||||||
public:
|
public:
|
||||||
|
uint32_t sdl_init_flags = SDL_INIT_EVERYTHING;
|
||||||
|
|
||||||
SDL_Window* win{nullptr};
|
SDL_Window* win{nullptr};
|
||||||
SDL_GLContext gl_context{nullptr};
|
SDL_GLContext gl_context{nullptr};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user