fps display
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Input.h"
|
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#include "Tools.h"
|
||||||
#include "rendering/Rendering.h"
|
#include "rendering/Rendering.h"
|
||||||
|
|
||||||
#include "bx/bx.h"
|
#include "bx/bx.h"
|
||||||
@@ -87,6 +87,7 @@ namespace Game
|
|||||||
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
bx::memCopy(win.LastHeldScanCodes, win.HeldScanCodes, sizeof(win.HeldScanCodes));
|
||||||
bx::memCopy(win.LastHeldMouseButtons, win.HeldMouseButtons, sizeof(win.HeldMouseButtons));
|
bx::memCopy(win.LastHeldMouseButtons, win.HeldMouseButtons, sizeof(win.HeldMouseButtons));
|
||||||
}
|
}
|
||||||
|
Tools::MeasureFrameEnd();
|
||||||
FrameMark;
|
FrameMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
#include "bx/timer.h"
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int32_t FrameTimeBufSize = 512;
|
||||||
|
int64_t FrameTimes[FrameTimeBufSize]{0};
|
||||||
|
int32_t FrameTimeIdx = 0;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace Tools
|
namespace Tools
|
||||||
{
|
{
|
||||||
const char* GetAssetPath(Generated::AssetHandle assetHandle)
|
const char* GetAssetPath(Generated::AssetHandle assetHandle)
|
||||||
@@ -337,10 +345,35 @@ namespace Tools
|
|||||||
{
|
{
|
||||||
auto& drawList = *ImGui::GetWindowDrawList();
|
auto& drawList = *ImGui::GetWindowDrawList();
|
||||||
ImVec2 pos = ImGui::GetWindowPos();
|
ImVec2 pos = ImGui::GetWindowPos();
|
||||||
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0xFFFFFF33);
|
drawList.AddRectFilled(pos, {pos.x + FpsPlotSize.x, pos.y + FpsPlotSize.y}, 0x22222233);
|
||||||
|
|
||||||
|
float scale = 1000.0f;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < FrameTimeBufSize; ++i)
|
||||||
|
{
|
||||||
|
int32_t idx = FrameTimeIdx - i - 1;
|
||||||
|
int32_t prevIdx = idx - 1;
|
||||||
|
if (idx < 0) idx += FrameTimeBufSize;
|
||||||
|
if (prevIdx < 0) prevIdx += FrameTimeBufSize;
|
||||||
|
|
||||||
|
if (FrameTimes[idx] == 0 || FrameTimes[prevIdx] == 0) continue;
|
||||||
|
|
||||||
|
int64_t frameTime = FrameTimes[idx] - FrameTimes[prevIdx];
|
||||||
|
double frameTimeSec = (double)frameTime / bx::getHPFrequency();
|
||||||
|
drawList.AddLine(
|
||||||
|
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y},
|
||||||
|
{pos.x + (FpsPlotSize.x - i - 1), pos.y + FpsPlotSize.y - (float)frameTimeSec * scale},
|
||||||
|
0xFFFFFFFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
void MeasureFrameEnd()
|
||||||
|
{
|
||||||
|
FrameTimes[FrameTimeIdx] = bx::getHPCounter();
|
||||||
|
++FrameTimeIdx;
|
||||||
|
if (FrameTimeIdx >= FrameTimeBufSize) FrameTimeIdx = 0;
|
||||||
|
}
|
||||||
} // namespace Tools
|
} // namespace Tools
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ namespace Tools
|
|||||||
void ModelDropdown(Generated::ModelHandle& modelHandle);
|
void ModelDropdown(Generated::ModelHandle& modelHandle);
|
||||||
void TextureDropdown(Generated::TextureHandle& texHandle);
|
void TextureDropdown(Generated::TextureHandle& texHandle);
|
||||||
void RenderDebugUI(Game::GameRendering& rendering);
|
void RenderDebugUI(Game::GameRendering& rendering);
|
||||||
|
void MeasureFrameEnd();
|
||||||
} // namespace Tools
|
} // namespace Tools
|
||||||
|
|||||||
Reference in New Issue
Block a user