114 lines
2.7 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://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #include "core.h"
  15. #include "loldebug.h"
  16. using namespace std;
  17. namespace lol
  18. {
  19. /*
  20. * DebugFps implementation class
  21. */
  22. class DebugFpsData
  23. {
  24. friend class DebugFps;
  25. private:
  26. Text *lines[5];
  27. };
  28. /*
  29. * Public DebugFps class
  30. */
  31. DebugFps::DebugFps(int x, int y)
  32. : data(new DebugFpsData())
  33. {
  34. #if 0
  35. for (int i = 0; i < 5; i ++)
  36. {
  37. data->lines[i] = new Text(NULL, "gfx/font/ascii.png");
  38. data->lines[i]->SetPos(ivec3(x, y + (i ? 8 : 0) + 16 * i, 0));
  39. Ticker::Ref(data->lines[i]);
  40. }
  41. #else
  42. data->lines[0] = new Text(NULL, "gfx/font/ascii.png");
  43. data->lines[0]->SetPos(ivec3(x, y, 100));
  44. Ticker::Ref(data->lines[0]);
  45. #endif
  46. }
  47. void DebugFps::TickGame(float deltams)
  48. {
  49. Entity::TickGame(deltams);
  50. char buf[1024];
  51. #if 0
  52. sprintf(buf, "%2.2f fps (%i)",
  53. 1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  54. Ticker::GetFrameNum());
  55. data->lines[0]->SetText(buf);
  56. sprintf(buf, "Game % 7.2f % 7.2f",
  57. Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  58. Profiler::GetMax(Profiler::STAT_TICK_GAME));
  59. data->lines[1]->SetText(buf);
  60. sprintf(buf, "Draw % 7.2f % 7.2f",
  61. Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  62. Profiler::GetMax(Profiler::STAT_TICK_DRAW));
  63. data->lines[2]->SetText(buf);
  64. sprintf(buf, "Blit % 7.2f % 7.2f",
  65. Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  66. Profiler::GetMax(Profiler::STAT_TICK_BLIT));
  67. data->lines[3]->SetText(buf);
  68. sprintf(buf, "Frame % 7.2f % 7.2f",
  69. Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  70. Profiler::GetMax(Profiler::STAT_TICK_FRAME));
  71. data->lines[4]->SetText(buf);
  72. #else
  73. sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)",
  74. Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  75. Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  76. Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  77. Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  78. 1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  79. Ticker::GetFrameNum());
  80. data->lines[0]->SetText(buf);
  81. #endif
  82. }
  83. DebugFps::~DebugFps()
  84. {
  85. #if 0
  86. for (int i = 0; i < 5; i ++)
  87. Ticker::Unref(data->lines[i]);
  88. #else
  89. Ticker::Unref(data->lines[0]);
  90. #endif
  91. delete data;
  92. }
  93. } /* namespace lol */