FPS - Frames Per Second

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

FPS - Frames Per Second

Post by LuMo »

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: Select all

// fps requirements
#include <stdio.h>
#include <stdlib.h>


void initFPS&#40;&#41;
&#123;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFFFF&#41;; // white
    pspDebugScreenSetXY&#40;1,1&#41;;
&#125;

 void drawFPS&#40;&#41;
&#123;
	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&#91;50&#93; = &#123;0&#125;;			// We will store the string here for the window title

    time_t currentTime = time&#40;&lastTime&#41;;				

	// Increase the frame counter
    ++framesPerSecond;

    if&#40; difftime  	&#40;currentTime,lastTime&#41; > 1.0f &#41;
    &#123;
	    lastTime = currentTime;
		
		sprintf&#40;strFrameRate, "Current Frames Per Second&#58; %d", int&#40;framesPerSecond&#41;&#41;;

        pspDebugScreenPrintf&#40;strFrameRate&#41;;
		
		// Reset the frames per second
        framesPerSecond = 0;
    &#125;
&#125;
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

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.
charliex
Posts: 16
Joined: Thu Jan 26, 2006 4:03 pm

Post by charliex »

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: Select all


        pspDebugScreenPrintf&#40;"Current Frames Per Second&#58; %d", int&#40;framesPerSecond&#41;&#41;; 
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

What is the purpose of passing a pointer to lastTime when you retrieve the current time?

Code: Select all

    time_t currentTime = time&#40;&lastTime&#41;;
If this is setting lastTime to the current time, then difftime() will return zero, and your framerate calculation and printf() would never occur.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

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: Select all

time_t currentTime;
time&#40;&currentTime&#41;;
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:

Code: Select all

time&#40;&lastTime&#41;;
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

This should give you an idea.
GE Dominator
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

humm... CHP
i tried your RTC 'sample'
and i am using...

Code: Select all

#include <psprtc.h>
but i still get the error:

Code: Select all

undefined reference to `sceRtcGetTickResolution'
undefined reference to `sceRtcGetCurrentTick'
greets lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
charliex
Posts: 16
Joined: Thu Jan 26, 2006 4:03 pm

Post by charliex »

if i recall properly then you need to add -lpsprtc for those
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

already in the makefile...
btw when do i have to add such a tag? (did not see any infos in the doku...)

Code: Select all

TARGET = pspLoader
OBJS = pspLoader.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
LIBS= -lstdc++ -lpspgum -lpspgu -lm -lpng -lz -lpsprtc

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = FPS-TEST

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
charliex
Posts: 16
Joined: Thu Jan 26, 2006 4:03 pm

Post by charliex »

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
Post Reply