// fps requirements
#include <stdio.h>
#include <stdlib.h>
void initFPS()
{
pspDebugScreenInit();
pspDebugScreenSetTextColor(0xFFFFFFFF); // white
pspDebugScreenSetXY(1,1);
}
void drawFPS()
{
static float framesPerSecond = 0.0f; // This will store our fps
time_t lastTime; // This will hold the time from the last frame
static char strFrameRate[50] = {0}; // We will store the string here for the window title
time_t currentTime = time(&lastTime);
// Increase the frame counter
++framesPerSecond;
if( difftime (currentTime,lastTime) > 1.0f )
{
lastTime = currentTime;
sprintf(strFrameRate, "Current Frames Per Second: %d", int(framesPerSecond));
pspDebugScreenPrintf(strFrameRate);
// Reset the frames per second
framesPerSecond = 0;
}
}
"Good artists copy, great artists steal." Pablo Picasso go2lumo.com
Simple. You made your lastTime variable local for the drawFPS function, thus it get's allocated and initialized everytime the drawFPS function is called and therefore you never (or most likely only once every XXX calls) will get the difftime(...) > 1.0f tu be true.
Put the declaration of lastTime outside the function to make it global.
make lasttime static too, then it won't get reinitialised , you don't need the sprintf or strFrameRate either,unless you plan to extend the function and use the results elsewhere, the pspDebugScreenPrintf works just like printf too.
time(); does not work, have to pass something...
i am using getCurrentTickCount in windows... not accessable on psp...
how can i get current time (t_time? / ticks...) without passing somethign?
greets
lumo
"Good artists copy, great artists steal." Pablo Picasso go2lumo.com
Of course, you also need to make sure that you properly initialize your static lastTime timer to some "pre-historic" value when your program first starts. You could handle this by calling time() from your initFPS() function:
LuMo wrote:hmm ok, changed those two things...
still does not show anything on screen.
i use the function while showing GU/GUM stuff
any ideas?
thanks in advance
lumo
Did you set the debugScreen offset to where your drawingbuffer is with pspDebugScreenSetOffset((int)framebuffer);? you have to do this everytime the framebuffer changes after a swap and you want to print out something, or else the print will go to somewhere else that you most likely won't see.
does blit from the samples/gu/blit compile and link ok?
if so, try putting -lpsprtc first in the LIBS list, i seem to recall seeing something like that being mentioned once before, it shouldn't affect it though
ie like
LIBS= -lpsprtc -lstdc++ -lpspgum -lpspgu -lm -lpng -lz