mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-28 05:11:37 +00:00
Implement implot.
This commit is contained in:
parent
939f4a4771
commit
755b48d3f0
3 changed files with 60 additions and 2 deletions
|
|
@ -196,11 +196,14 @@ set(SWA_USER_CXX_SOURCES
|
|||
|
||||
set(SWA_THIRDPARTY_SOURCES
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/implot/implot.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/implot/implot_demo.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/implot/implot_items.cpp"
|
||||
"${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c"
|
||||
"${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c"
|
||||
"${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp"
|
||||
|
|
@ -209,7 +212,8 @@ set(SWA_THIRDPARTY_SOURCES
|
|||
set(SWA_THIRDPARTY_INCLUDES
|
||||
"${SWA_THIRDPARTY_ROOT}/concurrentqueue"
|
||||
"${SWA_THIRDPARTY_ROOT}/ddspp"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui"
|
||||
"${SWA_THIRDPARTY_ROOT}/imgui"
|
||||
"${SWA_THIRDPARTY_ROOT}/implot"
|
||||
"${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack"
|
||||
"${SWA_THIRDPARTY_ROOT}/magic_enum/include"
|
||||
"${SWA_THIRDPARTY_ROOT}/stb"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "imgui/imgui_snapshot.h"
|
||||
#include "imgui/imgui_font_builder.h"
|
||||
|
||||
#include <app.h>
|
||||
#include <bc_diff.h>
|
||||
#include <cpu/code_cache.h>
|
||||
#include <cpu/guest_code.h>
|
||||
|
|
@ -1317,6 +1318,7 @@ void Video::CreateHostDevice(bool sdlVideoDefault)
|
|||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImPlot::CreateContext();
|
||||
|
||||
GameWindow::Init(sdlVideoDefault);
|
||||
|
||||
|
|
@ -1885,6 +1887,54 @@ static uint32_t HashVertexDeclaration(uint32_t vertexDeclaration)
|
|||
return vertexDeclaration;
|
||||
}
|
||||
|
||||
static bool g_profilerVisible;
|
||||
static bool g_profilerWasToggled;
|
||||
static constexpr size_t PROFILER_VALUE_COUNT = 256;
|
||||
static double g_profilerDeltaTimes[PROFILER_VALUE_COUNT];
|
||||
static size_t g_profilerValueIndex;
|
||||
|
||||
static void DrawProfiler()
|
||||
{
|
||||
bool toggleProfiler = SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_F1] != 0;
|
||||
|
||||
if (!g_profilerWasToggled && toggleProfiler)
|
||||
g_profilerVisible = !g_profilerVisible;
|
||||
|
||||
g_profilerWasToggled = toggleProfiler;
|
||||
|
||||
if (!g_profilerVisible)
|
||||
return;
|
||||
|
||||
ImFont* font = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf");
|
||||
float defaultScale = font->Scale;
|
||||
font->Scale = 16.0f / font->FontSize;
|
||||
ImGui::PushFont(font);
|
||||
|
||||
if (ImGui::Begin("Profiler", &g_profilerVisible))
|
||||
{
|
||||
g_profilerDeltaTimes[g_profilerValueIndex] = App::s_deltaTime * 1000.0;
|
||||
|
||||
if (ImPlot::BeginPlot("Frametimes"))
|
||||
{
|
||||
ImPlot::SetupAxisLimits(ImAxis_Y1, 8.0, 32.0);
|
||||
ImPlot::SetupAxis(ImAxis_Y1, "ms", ImPlotAxisFlags_None);
|
||||
ImPlot::PlotLine<double>("Application", g_profilerDeltaTimes, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex);
|
||||
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
|
||||
g_profilerValueIndex = (g_profilerValueIndex + 1) % PROFILER_VALUE_COUNT;
|
||||
|
||||
const double deltaTimeAvg = std::accumulate(g_profilerDeltaTimes, g_profilerDeltaTimes + PROFILER_VALUE_COUNT, 0.0) / PROFILER_VALUE_COUNT;
|
||||
|
||||
ImGui::Text("Average Application: %g ms (%g FPS)", deltaTimeAvg, 1000.0 / deltaTimeAvg);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::PopFont();
|
||||
font->Scale = defaultScale;
|
||||
}
|
||||
|
||||
static void DrawImGui()
|
||||
{
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
|
|
@ -1916,6 +1966,8 @@ static void DrawImGui()
|
|||
MessageWindow::Draw();
|
||||
ButtonGuide::Draw();
|
||||
|
||||
DrawProfiler();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
auto drawData = ImGui::GetDrawData();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ using Microsoft::WRL::ComPtr;
|
|||
#include <SDL_mixer.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <implot.h>
|
||||
#include <backends/imgui_impl_sdl2.h>
|
||||
#include <o1heap.h>
|
||||
#include <cstddef>
|
||||
|
|
@ -47,6 +48,7 @@ using Microsoft::WRL::ComPtr;
|
|||
#include <fmt/core.h>
|
||||
#include <list>
|
||||
#include <semaphore>
|
||||
#include <numeric>
|
||||
|
||||
#include "framework.h"
|
||||
#include "mutex.h"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue