Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

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