forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FPS - Frames Per Second

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri Jan 27, 2006 3:21 am    Post subject: FPS - Frames Per Second Reply with quote

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
View user's profile Send private message Visit poster's website
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Fri Jan 27, 2006 3:59 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Fri Jan 27, 2006 5:57 am    Post subject: Reply with quote

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
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri Jan 27, 2006 9:44 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Sat Jan 28, 2006 2:32 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat Jan 28, 2006 2:36 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Sat Jan 28, 2006 2:45 am    Post subject: Reply with quote

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(&currentTime);

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:
time(&lastTime);
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sat Jan 28, 2006 3:26 am    Post subject: Reply with quote

This should give you an idea.
_________________
GE Dominator
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Jan 28, 2006 3:48 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat Jan 28, 2006 4:05 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat Jan 28, 2006 8:54 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Sat Jan 28, 2006 9:52 am    Post subject: Reply with quote

if i recall properly then you need to add -lpsprtc for those
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat Jan 28, 2006 7:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Mon Jan 30, 2006 6:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group