Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

77 righe
1.2 KiB

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #include <stdint.h>
  11. #include "core.h"
  12. /*
  13. * Profiler implementation class
  14. */
  15. static class ProfilerData
  16. {
  17. friend class Profiler;
  18. static int const HISTORY = 32;
  19. public:
  20. ProfilerData()
  21. {
  22. for (int i = 0; i < HISTORY; i++)
  23. history[i] = 0.0f;
  24. avg = max = 0.0f;
  25. }
  26. private:
  27. float history[HISTORY];
  28. Timer timer;
  29. float avg, max;
  30. }
  31. data[Profiler::STAT_COUNT];
  32. /*
  33. * Profiler public class
  34. */
  35. void Profiler::Start(int id)
  36. {
  37. data[id].timer.GetMs();
  38. }
  39. void Profiler::Stop(int id)
  40. {
  41. float deltams = data[id].timer.GetMs();
  42. data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
  43. data[id].avg = 0.0f;
  44. data[id].max = 0.0f;
  45. for (int i = 0; i < ProfilerData::HISTORY; i++)
  46. {
  47. data[id].avg += data[id].history[i];
  48. if (data[id].history[i] > data[id].max)
  49. data[id].max = data[id].history[i];
  50. }
  51. data[id].avg /= ProfilerData::HISTORY;
  52. }
  53. float Profiler::GetAvg(int id)
  54. {
  55. return data[id].avg;
  56. }
  57. float Profiler::GetMax(int id)
  58. {
  59. return data[id].max;
  60. }