#include "Fps.h" #include #include #include #include using namespace Framework; // Inhalt der Fps Klasse aus Fps.h // Konstruktor Fps::Fps() { pr = new Prozess(); i = 0; fpsCount = 0; nowFps = 0; nowCpu = 0; nowMem = 0; schrift = 0; sFarbe = 0; ref = 1; } // Destruktor Fps::~Fps() { delete pr; if( schrift ) schrift = schrift->release(); } // nicht constant void Fps::setSchriftZ( Schrift *schrift ) // setzt die Schrift { if( this->schrift ) this->schrift = this->schrift->release(); this->schrift = schrift; rend = 1; } void Fps::setSFarbe( int f ) // setzt die Schrift Farbe { sFarbe = f; rend = 1; } bool Fps::tick( double tickval ) // tick { i += tickval * 60; if( i >= 60 ) { nowFps = fpsCount; nowCpu = (int)pr->getCPU(); nowMem = (int)(pr->getMem() / 1024); fpsCount = 0; i -= 60; rend = 1; } bool ret = rend; rend = 0; return ret; } void Fps::render( Bild &zrObj ) // zeichnet nach zrObj { fpsCount++; if( schrift && sFarbe ) { Text renderT( "FPS: " ); renderT.append( nowFps ); renderT.append( "\nCPU: " ); renderT.append( nowCpu ); renderT.append( "%\nMem: " ); renderT.append( nowMem ); renderT.append( "kb" ); schrift->setDrawPosition( 10, 10 ); schrift->setSchriftSize( 12 ); schrift->renderText( &renderT, zrObj, sFarbe ); } } // constant int Fps::getFps() const // gibt fps zurück { return nowFps; } int Fps::getCpu() const // gibt die Cpu zurück { return nowCpu; } int Fps::getMem() const // gibt den Arbeitsspeicher zurück { return nowMem; } Schrift *Fps::getSchrift() const // gibt die Schrift zurück { return schrift ? schrift->getThis() : 0; } Schrift *Fps::zSchrift() const { return schrift; } int Fps::getFarbe() const // gibt die Farbe zurück { return sFarbe; } // Reference Counting Fps *Fps::getThis() { ref++; return this; } Fps *Fps::release() { ref--; if( !ref ) delete this; return 0; }