From a727f8908cffcdf9c6290f82b88857f9a62efcbd Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 14 Mar 2025 22:43:43 -0500 Subject: [PATCH] VideoCommon: add graphics mod editor helper utilities for interacting with objects in the scene --- .../GraphicsModEditor/SceneUtils.cpp | 35 ++++++++++++++++++ .../GraphicsModEditor/SceneUtils.h | 36 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.cpp create mode 100644 Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.h diff --git a/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.cpp b/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.cpp new file mode 100644 index 0000000000..050848c6fa --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.cpp @@ -0,0 +1,35 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/GraphicsModEditor/SceneUtils.h" + +#include + +#include "Common/EnumUtils.h" + +namespace GraphicsModEditor +{ +std::string GetDrawCallName(const EditorState& editor_state, + GraphicsModSystem::DrawCallID draw_call) +{ + if (draw_call == GraphicsModSystem::DrawCallID::INVALID) + return ""; + + std::string draw_call_name = std::to_string(Common::ToUnderlying(draw_call)); + auto& draw_call_to_user_data = editor_state.m_user_data.m_draw_call_id_to_user_data; + if (const auto user_data_iter = draw_call_to_user_data.find(draw_call); + user_data_iter != draw_call_to_user_data.end()) + { + if (!user_data_iter->second.m_friendly_name.empty()) + draw_call_name = user_data_iter->second.m_friendly_name; + } + return draw_call_name; +} + +std::string GetActionName(GraphicsModAction* action) +{ + if (!action) [[unlikely]] + return ""; + return fmt::format("{}-{}", action->GetFactoryName(), action->GetID()); +} +} // namespace GraphicsModEditor diff --git a/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.h b/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.h new file mode 100644 index 0000000000..ac19f2bf1f --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModEditor/SceneUtils.h @@ -0,0 +1,36 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include + +#include "VideoCommon/GraphicsModEditor/EditorState.h" +#include "VideoCommon/GraphicsModSystem/Types.h" + +namespace GraphicsModEditor +{ +std::string GetDrawCallName(const EditorState& editor_state, + GraphicsModSystem::DrawCallID draw_call); +std::string GetActionName(GraphicsModAction* action); + +template ActionType> +std::vector GetActionsForDrawCall(const EditorState& editor_state, + GraphicsModSystem::DrawCallID draw_call) +{ + std::vector result; + auto& draw_call_id_to_actions = editor_state.m_user_data.m_draw_call_id_to_actions; + if (const auto actions_iter = draw_call_id_to_actions.find(draw_call); + actions_iter != draw_call_id_to_actions.end()) + { + for (GraphicsModAction* action : actions_iter->second) + { + if (action->GetFactoryName() == ActionType::factory_name) + result.push_back(static_cast(action)); + } + } + return result; +} +} // namespace GraphicsModEditor