Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FramesPerSecond.cs 1.3 KiB

8 meses atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. namespace RenderHookAPI.Hook.Common
  3. {
  4. [Serializable]
  5. public class FramesPerSecond: TextElement
  6. {
  7. string _fpsFormat = "{0:N0} fps";
  8. public override string Text
  9. {
  10. get
  11. {
  12. return String.Format(_fpsFormat, GetFPS());
  13. }
  14. set
  15. {
  16. _fpsFormat = value;
  17. }
  18. }
  19. int _frames = 0;
  20. int _lastTickCount = 0;
  21. float _lastFrameRate = 0;
  22. public FramesPerSecond(System.Drawing.Font font)
  23. : base(font)
  24. {
  25. }
  26. /// <summary>
  27. /// Must be called each frame
  28. /// </summary>
  29. public override void Frame()
  30. {
  31. _frames++;
  32. if (Math.Abs(Environment.TickCount - _lastTickCount) > 1000)
  33. {
  34. _lastFrameRate = (float)_frames * 1000 / Math.Abs(Environment.TickCount - _lastTickCount);
  35. _lastTickCount = Environment.TickCount;
  36. _frames = 0;
  37. }
  38. }
  39. /// <summary>
  40. /// Return the current frames per second
  41. /// </summary>
  42. /// <returns></returns>
  43. public float GetFPS()
  44. {
  45. return _lastFrameRate;
  46. }
  47. }
  48. }