115 行
2.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 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. #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("", "data/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("", "data/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 seconds)
  48. {
  49. Entity::TickGame(seconds);
  50. char buf[1024];
  51. #if 0
  52. sprintf(buf, "%2.2f fps (%i)",
  53. 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  54. Ticker::GetFrameNum());
  55. data->lines[0]->SetText(buf);
  56. sprintf(buf, "Game % 7.2f % 7.2f",
  57. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  58. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
  59. data->lines[1]->SetText(buf);
  60. sprintf(buf, "Draw % 7.2f % 7.2f",
  61. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  62. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_DRAW));
  63. data->lines[2]->SetText(buf);
  64. sprintf(buf, "Blit % 7.2f % 7.2f",
  65. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  66. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
  67. data->lines[3]->SetText(buf);
  68. sprintf(buf, "Frame % 7.2f % 7.2f",
  69. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  70. 1e3f * 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) %2.2f",
  74. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  75. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  76. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  77. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  78. 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  79. 1e3f * Profiler::GetAvg(Profiler::STAT_USER_00),
  80. Ticker::GetFrameNum());
  81. data->lines[0]->SetText(buf);
  82. #endif
  83. }
  84. DebugFps::~DebugFps()
  85. {
  86. #if 0
  87. for (int i = 0; i < 5; i ++)
  88. Ticker::Unref(data->lines[i]);
  89. #else
  90. Ticker::Unref(data->lines[0]);
  91. #endif
  92. delete data;
  93. }
  94. } /* namespace lol */