| View previous topic :: View next topic |
| Author |
Message |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri Jan 27, 2006 3:21 am Post subject: FPS - Frames Per Second |
|
|
hi
i just tried to write a fps viewer function
(i already implemented it for OGL in windows)
here is my modded file (does not show anythin on psp, why?)
| Code: | // 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 |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Fri Jan 27, 2006 3:59 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
charliex
Joined: 26 Jan 2006 Posts: 16
|
Posted: Fri Jan 27, 2006 5:57 am Post subject: |
|
|
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.
| Code: |
pspDebugScreenPrintf("Current Frames Per Second: %d", int(framesPerSecond));
|
|
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri Jan 27, 2006 9:44 pm Post subject: |
|
|
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 _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
Dr. Vegetable
Joined: 14 Nov 2005 Posts: 171 Location: Boston, Massachusetts
|
Posted: Sat Jan 28, 2006 2:32 am Post subject: |
|
|
What is the purpose of passing a pointer to lastTime when you retrieve the current time?
| Code: | | time_t currentTime = time(&lastTime); |
If this is setting lastTime to the current time, then difftime() will return zero, and your framerate calculation and printf() would never occur. |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 28, 2006 2:36 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Dr. Vegetable
Joined: 14 Nov 2005 Posts: 171 Location: Boston, Massachusetts
|
Posted: Sat Jan 28, 2006 2:45 am Post subject: |
|
|
According to this reference, the time() function will store the current time in the time_t that you pass to it. So why not use:
| Code: | time_t currentTime;
time(¤tTime); |
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:
|
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Sat Jan 28, 2006 3:26 am Post subject: |
|
|
This should give you an idea. _________________ GE Dominator |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sat Jan 28, 2006 3:48 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 28, 2006 4:05 am Post subject: |
|
|
yeah, noticed that.. i set pos to 1,1 now every time. works fine (120fps)
will check chp's stuff soon
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 28, 2006 8:54 am Post subject: |
|
|
humm... CHP
i tried your RTC 'sample'
and i am using...
| Code: | | #include <psprtc.h> |
but i still get the error:
| Code: | undefined reference to `sceRtcGetTickResolution'
undefined reference to `sceRtcGetCurrentTick' |
greets lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
charliex
Joined: 26 Jan 2006 Posts: 16
|
Posted: Sat Jan 28, 2006 9:52 am Post subject: |
|
|
| if i recall properly then you need to add -lpsprtc for those |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 28, 2006 7:01 pm Post subject: |
|
|
already in the makefile...
btw when do i have to add such a tag? (did not see any infos in the doku...)
| Code: |
TARGET = pspLoader
OBJS = pspLoader.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lstdc++ -lpspgum -lpspgu -lm -lpng -lz -lpsprtc
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = FPS-TEST
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
_________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
charliex
Joined: 26 Jan 2006 Posts: 16
|
Posted: Mon Jan 30, 2006 6:24 am Post subject: |
|
|
to add it you'd just add -lpsprtc to LIBS
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
also make sure psptrc.h is included |
|
| Back to top |
|
 |
|