123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 Jiang Yin. All rights reserved.
- // Homepage: https://gameframework.cn/
- // Feedback: mailto:ellan@gameframework.cn
- //------------------------------------------------------------
- namespace UnityGameFramework.Runtime
- {
- public sealed partial class DebuggerComponent : GameFrameworkComponent
- {
- private sealed class FpsCounter
- {
- private float m_UpdateInterval;
- private float m_CurrentFps;
- private int m_Frames;
- private float m_Accumulator;
- private float m_TimeLeft;
- public FpsCounter(float updateInterval)
- {
- if (updateInterval <= 0f)
- {
- Log.Error("Update interval is invalid.");
- return;
- }
- m_UpdateInterval = updateInterval;
- Reset();
- }
- public float UpdateInterval
- {
- get
- {
- return m_UpdateInterval;
- }
- set
- {
- if (value <= 0f)
- {
- Log.Error("Update interval is invalid.");
- return;
- }
- m_UpdateInterval = value;
- Reset();
- }
- }
- public float CurrentFps
- {
- get
- {
- return m_CurrentFps;
- }
- }
- public void Update(float elapseSeconds, float realElapseSeconds)
- {
- m_Frames++;
- m_Accumulator += realElapseSeconds;
- m_TimeLeft -= realElapseSeconds;
- if (m_TimeLeft <= 0f)
- {
- m_CurrentFps = m_Accumulator > 0f ? m_Frames / m_Accumulator : 0f;
- m_Frames = 0;
- m_Accumulator = 0f;
- m_TimeLeft += m_UpdateInterval;
- }
- }
- private void Reset()
- {
- m_CurrentFps = 0f;
- m_Frames = 0;
- m_Accumulator = 0f;
- m_TimeLeft = 0f;
- }
- }
- }
- }
|