Fps.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "Fps.h"
  2. #include <Bild.h>
  3. #include <Prozess.h>
  4. #include <Schrift.h>
  5. #include <Text.h>
  6. using namespace Framework;
  7. // Inhalt der Fps Klasse aus Fps.h
  8. // Konstruktor
  9. Fps::Fps()
  10. : Zeichnung()
  11. {
  12. pr = new Prozess();
  13. i = 0;
  14. fpsCount = 0;
  15. nowFps = 0;
  16. nowCpu = 0;
  17. nowMem = 0;
  18. textRd = 0;
  19. sFarbe = 0;
  20. }
  21. // Destruktor
  22. Fps::~Fps()
  23. {
  24. delete pr;
  25. if( textRd )
  26. textRd->release();
  27. }
  28. // nicht constant
  29. void Fps::setSchriftZ( Schrift *schrift ) // setzt die Schrift
  30. {
  31. if( !this->textRd )
  32. textRd = new TextRenderer( schrift );
  33. else
  34. textRd->setSchriftZ( schrift );
  35. textRd->setSchriftSize( 12 );
  36. rend = 1;
  37. }
  38. void Fps::setSFarbe( int f ) // setzt die Schrift Farbe
  39. {
  40. sFarbe = f;
  41. rend = 1;
  42. }
  43. bool Fps::tick( double tickval ) // tick
  44. {
  45. i += tickval * 60;
  46. if( i >= 60 )
  47. {
  48. nowFps = fpsCount;
  49. nowCpu = (int)pr->getCPU();
  50. nowMem = (int)(pr->getMem() / 1024);
  51. fpsCount = 0;
  52. i -= 60;
  53. rend = 1;
  54. }
  55. bool ret = rend;
  56. rend = 0;
  57. return ret;
  58. }
  59. void Fps::render( Bild &zrObj ) // zeichnet nach zrObj
  60. {
  61. fpsCount++;
  62. if( textRd && sFarbe )
  63. {
  64. Text renderT( "FPS: " );
  65. renderT.append( nowFps );
  66. renderT.append( "\nCPU: " );
  67. renderT.append( nowCpu );
  68. renderT.append( "%\nMem: " );
  69. renderT.append( nowMem );
  70. renderT.append( "kb" );
  71. textRd->renderText( 10, 10, renderT, zrObj, sFarbe );
  72. }
  73. }
  74. // constant
  75. int Fps::getFps() const // gibt fps zurück
  76. {
  77. return nowFps;
  78. }
  79. int Fps::getCpu() const // gibt die Cpu zurück
  80. {
  81. return nowCpu;
  82. }
  83. int Fps::getMem() const // gibt den Arbeitsspeicher zurück
  84. {
  85. return nowMem;
  86. }
  87. Schrift *Fps::getSchrift() const // gibt die Schrift zurück
  88. {
  89. return textRd ? textRd->getSchrift() : 0;
  90. }
  91. Schrift *Fps::zSchrift() const
  92. {
  93. return textRd ? textRd->zSchrift() : 0;
  94. }
  95. int Fps::getFarbe() const // gibt die Farbe zurück
  96. {
  97. return sFarbe;
  98. }