mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(window): add fps and frame counter to window title
This commit is contained in:
@@ -18,6 +18,7 @@ public:
|
||||
void Destroy() noexcept;
|
||||
SDL_Window* Handle() const;
|
||||
void DrawableSize(std::uint32_t& width, std::uint32_t& height) const;
|
||||
void UpdateTitle();
|
||||
|
||||
private:
|
||||
void create(std::uint32_t sourceWidth, std::uint32_t sourceHeight);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "prx/libSceVideoOut/include/DisplayWindow.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/AspectFit.hpp"
|
||||
#include "prx/libkernel/AppMetadata/include/AppMetadata.hpp"
|
||||
#include "prx/libkernel/Time/include/Time.hpp"
|
||||
#include "SDL_vulkan.h"
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@@ -79,6 +81,27 @@ void DisplayWindow::DrawableSize(std::uint32_t& width, std::uint32_t& height) co
|
||||
height = drawableHeight > 0 ? static_cast<std::uint32_t>(drawableHeight) : 0;
|
||||
}
|
||||
|
||||
void DisplayWindow::UpdateTitle() {
|
||||
require(window != nullptr, "window must exist before updating title");
|
||||
static const AppTitle title = GetAppTitle_nid_postfix();
|
||||
static std::uint64_t fpsStart = sceKernelGetProcessTimeCounter();
|
||||
static std::uint64_t frameNum = 0;
|
||||
static std::uint64_t fpsFrames = 0;
|
||||
static double currentFps = 0.0;
|
||||
const auto now = sceKernelGetProcessTimeCounter();
|
||||
const auto frequency = sceKernelGetProcessTimeCounterFrequency();
|
||||
frameNum++;
|
||||
fpsFrames++;
|
||||
if (now - fpsStart >= frequency * 2) {
|
||||
currentFps = static_cast<double>(fpsFrames) * static_cast<double>(frequency) / static_cast<double>(now - fpsStart);
|
||||
fpsStart = now;
|
||||
fpsFrames = 0;
|
||||
}
|
||||
char text[160];
|
||||
std::snprintf(text, sizeof(text), "%s FPS: %.2f (%llu)", title.value, currentFps, static_cast<unsigned long long>(frameNum));
|
||||
SDL_SetWindowTitle(window, text);
|
||||
}
|
||||
|
||||
void DisplayWindow::installSubclass() {
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo info;
|
||||
|
||||
@@ -354,6 +354,7 @@ void VideoOutDriver::processFlip(FlipRequest& req) {
|
||||
} else {
|
||||
AgcDriverPresentClear_nid_postfix(target, req.index == VIDEO_OUT_BUFFER_INDEX_BLACK, gpuReady, &req);
|
||||
}
|
||||
window.UpdateTitle();
|
||||
std::lock_guard lock(req.cfg->mutex);
|
||||
checkConfig(*req.cfg);
|
||||
require(!req.terminal && req.cfg->generation == req.generation, "flip cancelled during presentation");
|
||||
|
||||
Reference in New Issue
Block a user