From dc8b1807f22e10e9f411cf1f8cdfe354ea1a0bc3 Mon Sep 17 00:00:00 2001 From: Shoma SATO Date: Fri, 15 Mar 2024 02:15:15 +0900 Subject: [PATCH] Add FrameRateProfilerRecorder --- .../LifetimeScope/MainLifetimeScope.cs | 1 + .../FrameRateProfilerRecorder.cs | 24 +++++++++++++++++++ .../FrameRateProfilerRecorder.cs.meta | 3 +++ 3 files changed, 28 insertions(+) create mode 100644 Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs create mode 100644 Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs.meta diff --git a/Assets/Hatbor/Scripts/LifetimeScope/MainLifetimeScope.cs b/Assets/Hatbor/Scripts/LifetimeScope/MainLifetimeScope.cs index 8880703..c808053 100644 --- a/Assets/Hatbor/Scripts/LifetimeScope/MainLifetimeScope.cs +++ b/Assets/Hatbor/Scripts/LifetimeScope/MainLifetimeScope.cs @@ -25,6 +25,7 @@ protected override void Configure(IContainerBuilder builder) // PerformanceProfiler builder.RegisterEntryPoint(); + builder.Register(Lifetime.Singleton).AsSelf(); builder.Register(Lifetime.Singleton).AsSelf(); // Rig/VMC diff --git a/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs b/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs new file mode 100644 index 0000000..e0fd54d --- /dev/null +++ b/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs @@ -0,0 +1,24 @@ +using UniRx; + +namespace Hatbor.PerformanceProfiler +{ + public sealed class FrameRateProfilerRecorder : IProfilerRecorder + { + readonly ReactiveProperty text = new(); + IReadOnlyReactiveProperty IProfilerRecorder.Text => text; + + int count; + float time; + + void IProfilerRecorder.Tick(float t) + { + count++; + time += t; + if (!(time >= 1f)) return; + var frameRate = count / time; + text.Value = $"Frame Rate: {frameRate:F2}/s"; + time = 0f; + count = 0; + } + } +} \ No newline at end of file diff --git a/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs.meta b/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs.meta new file mode 100644 index 0000000..26aa0f6 --- /dev/null +++ b/Assets/Hatbor/Scripts/PerformanceProfiler/FrameRateProfilerRecorder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dc4567380c7f49efbd2a847609a91710 +timeCreated: 1710436013 \ No newline at end of file