82 行
1.6 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 <cstdio>
  9. #include "core.h"
  10. #include "debugfps.h"
  11. /*
  12. * DebugFps implementation class
  13. */
  14. class DebugFpsData
  15. {
  16. friend class DebugFps;
  17. private:
  18. int fontid;
  19. };
  20. /*
  21. * Public DebugFps class
  22. */
  23. DebugFps::DebugFps()
  24. {
  25. data = new DebugFpsData();
  26. data->fontid = Forge::Register("gfx/font/ascii.png");
  27. }
  28. Entity::Group DebugFps::GetGroup()
  29. {
  30. return GROUP_AFTER;
  31. }
  32. void DebugFps::TickDraw(float deltams)
  33. {
  34. Entity::TickDraw(deltams);
  35. char buf[1024];
  36. Font *font = Forge::GetFont(data->fontid);
  37. sprintf(buf, "%2.2f fps (%i)",
  38. 1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  39. Ticker::GetFrameNum());
  40. font->PrintBold(10, 10, buf);
  41. sprintf(buf, "Game % 7.2f % 7.2f",
  42. Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  43. Profiler::GetMax(Profiler::STAT_TICK_GAME));
  44. font->PrintBold(10, 34, buf);
  45. sprintf(buf, "Draw % 7.2f % 7.2f",
  46. Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  47. Profiler::GetMax(Profiler::STAT_TICK_DRAW));
  48. font->PrintBold(10, 50, buf);
  49. sprintf(buf, "Blit % 7.2f % 7.2f",
  50. Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  51. Profiler::GetMax(Profiler::STAT_TICK_BLIT));
  52. font->PrintBold(10, 66, buf);
  53. sprintf(buf, "Frame % 7.2f % 7.2f",
  54. Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  55. Profiler::GetMax(Profiler::STAT_TICK_FRAME));
  56. font->PrintBold(10, 82, buf);
  57. }
  58. DebugFps::~DebugFps()
  59. {
  60. Forge::Deregister(data->fontid);
  61. delete data;
  62. }