You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
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 <lol/main.h>
  15. #include "loldebug.h"
  16. namespace lol
  17. {
  18. /*
  19. * DebugFps implementation class
  20. */
  21. class DebugFpsData
  22. {
  23. friend class DebugFps;
  24. private:
  25. Text *lines[5];
  26. };
  27. /*
  28. * Public DebugFps class
  29. */
  30. DebugFps::DebugFps(int x, int y)
  31. : data(new DebugFpsData())
  32. {
  33. #if 0
  34. for (int i = 0; i < 5; i ++)
  35. {
  36. data->lines[i] = new Text("", "data/font/ascii.png");
  37. data->lines[i]->SetPos(ivec3(x, y + (i ? 8 : 0) + 16 * i, 0));
  38. Ticker::Ref(data->lines[i]);
  39. }
  40. #else
  41. data->lines[0] = new Text("", "data/font/ascii.png");
  42. data->lines[0]->SetPos(vec3(x, y, 100));
  43. Ticker::Ref(data->lines[0]);
  44. #endif
  45. }
  46. void DebugFps::TickGame(float seconds)
  47. {
  48. Entity::TickGame(seconds);
  49. char buf[1024];
  50. #if 0
  51. sprintf(buf, "%2.2f fps (%i)",
  52. 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  53. Ticker::GetFrameNum());
  54. data->lines[0]->SetText(buf);
  55. sprintf(buf, "Game % 7.2f % 7.2f",
  56. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  57. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
  58. data->lines[1]->SetText(buf);
  59. sprintf(buf, "Draw % 7.2f % 7.2f",
  60. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  61. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_DRAW));
  62. data->lines[2]->SetText(buf);
  63. sprintf(buf, "Blit % 7.2f % 7.2f",
  64. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  65. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
  66. data->lines[3]->SetText(buf);
  67. sprintf(buf, "Frame % 7.2f % 7.2f",
  68. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  69. 1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME));
  70. data->lines[4]->SetText(buf);
  71. #else
  72. sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i) %2.2f",
  73. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
  74. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
  75. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
  76. 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  77. 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
  78. 1e3f * Profiler::GetAvg(Profiler::STAT_USER_00),
  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 */