Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

77 rader
1.3 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #include <cstdlib>
  12. #include <stdint.h>
  13. namespace lol
  14. {
  15. /*
  16. * Profiler implementation class
  17. */
  18. static class profiler_data
  19. {
  20. friend class Profiler;
  21. void update()
  22. {
  23. history[frame++ % HISTORY] = m_timer.get();
  24. avg = max = 0.0f;
  25. for (int i = 0; i < HISTORY; i++)
  26. {
  27. avg += history[i];
  28. if (history[i] > max)
  29. max = history[i];
  30. }
  31. avg /= HISTORY;
  32. }
  33. static int const HISTORY = 32;
  34. private:
  35. float history[HISTORY] = { 0.0f };
  36. int frame = 0;
  37. timer m_timer;
  38. float avg = 0.0f, max = 0.0f;
  39. }
  40. data[Profiler::STAT_COUNT];
  41. /*
  42. * Profiler public class
  43. */
  44. void Profiler::Start(int id)
  45. {
  46. data[id].m_timer.get();
  47. }
  48. void Profiler::Stop(int id)
  49. {
  50. data[id].update();
  51. }
  52. float Profiler::GetAvg(int id)
  53. {
  54. return data[id].avg;
  55. }
  56. float Profiler::GetMax(int id)
  57. {
  58. return data[id].max;
  59. }
  60. } /* namespace lol */