• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Taphreek

FPS Counter

10 posts in this topic

I didn''t know whether this is considered graphics, or general programming, so if this doesn''t belong here, apologize. Anyway, I was wondering if anyone has the code to a simple FPS counter, it sucks not knowing if anything you are doing is improving the framerate. Even if the framerate is output to a text file every update it would be fine. Thanks! -Taphreek Not a n00b, even if can''t write a basic FPS counter
0

Share this post


Link to post
Share on other sites
HEHE Well i will give you a VB Sample

Private FPS as single
Private Time1 as long
Private P as byte

Private Sub Form_Load()
Time1 = getTickCount
do
DoEvents

.....
do your stuff here
.....

if p = 9 then
p=0
FPS = 10000/(getTickCount-Time1)
Time1 = getTickCount
debug.print FPS
end if
p=p+1
loop
End Sub



-VBLimits
Sorry about the Spelling..
0

Share this post


Link to post
Share on other sites
Uh, vb sucks, get out of here w/ that code.

Tap, search the forums for "fps counter" or something like that, the question has been asked alot, you should find it in no time

0

Share this post


Link to post
Share on other sites
yeah, some details about what your using would be nice...
Windows/Linux/Ect...
What windowing system(glut?), ect...
0

Share this post


Link to post
Share on other sites
  
float CGameEngine::CalcFrameRate(LARGE_INTEGER liNow_us)
{
//Original framerate calculation had really crappy twiddle

//framerate = 1000.0f / (float)elapsed;


const float e = 2.718281828f;

//0.5Hz filter, time in ms, so /1000.0

static float filter = (float)pow(e, -2.0f * 0.5f / 1000.0f);

static LARGE_INTEGER liTimeSnap_us;

//guess at initial framerate, so it doesn''t lag so bad on init

static float fFrameRate_fps = 33.3f;

float fElapsed_ms = (liNow_us.QuadPart - liTimeSnap_us.QuadPart) /1000.0f; //convert us to ms

liTimeSnap_us = liNow_us;

float factor = (float)pow(filter, fElapsed_ms);
float ifactor = 1.0f - factor;

if(fElapsed_ms<=0.0f)
//if the elasped time is 0, it took less than 5us to render the frame!

fFrameRate_fps = 200000.0f;
else
//filter, *1000.0f to convert ms to sec (again)

fFrameRate_fps = fFrameRate_fps * factor + ifactor * 1000.0f / fElapsed_ms;

return(fFrameRate_fps);
}

Single-pole, digitally filtered Frame Rate.

Magmai Kai Holmlor
- The disgruntled & disillusioned
0

Share this post


Link to post
Share on other sites
I give you a simple (however not quite as accurate) example in Allegro.

  
// Lions and tigers and global variables, oh my! :^)

volatile unsigned long fps = 0, framecount = 0, total_frames = 0;

void fps_proc()
{
fps = framecount;
total_frames += framecount;
framecount = 0;
}
END_OF_FUNCTION(fps_proc);

int GameLoop()
{
// Some stuff here

......
LOCK_VARIABLE(fps);
LOCK_VARIABLE(framecount);
LOCK_VARIABLE(total_frames);
LOCK_FUNCTION(fps_proc);
// Execute fps_proc once per second

install_int_ex(fps_proc, BPS_TO_TIMER(1));

do {
move_stuff();
draw_screen();
framecount++;
} while( !(want_exit) );
......
}

0

Share this post


Link to post
Share on other sites
Ok here''s a simple way to do it, but it''s not that accurate:

int Get_FPS(void)
{
static DWORD fps_time1=GetTickCount();
static int fps_count, fps;
DWORD fps_time2 = GetTickCount();

fps_count++;
if(fps_time2-fps_time1 >= 1000)
{
fps_time1=GetTickCount();
fps=fps_count;
fps_count=0;
}

return fps;
}


You call this function at the end of every frame.

There is also the more accurate way which is done in the VB Sample. In C it would be similar something like...

DWORD Time1 = GetTickCount();

...Render Frame...

FPS = 10000/(GetTickCount()-Time1);
Time1 = GetTickCount();




Digital Radiation
0

Share this post


Link to post
Share on other sites
Well, if you''re using a Windows based system....

  

//DEBUG FILE STUFF

FILE *OutputFile;

//DEBUG************************************************************************

//Open Debug File

OutputFile = fopen("log.txt", "w+");
_LARGE_INTEGER PerfStart, PerfEnd, Freq;
unsigned long cyclespermilli;
char OutStr[100];
QueryPerformanceFrequency(&Freq);
cyclespermilli = Freq.QuadPart / 1000;
//DEBUG************************************************************************


//DEBUG**********************************************************************

QueryPerformanceCounter(&PerfStart);
//DEBUG**********************************************************************


//Do rendering functions and stuff here...


//DEBUG**********************************************************************

QueryPerformanceCounter(&PerfEnd);
//DEBUG**********************************************************************


//DEBUG**********************************************************************

long Time = (PerfEnd.QuadPart-PerfStart.QuadPart) / cyclespermilli;
memset(&OutStr, ''\0'', sizeof(OutStr));
sprintf(OutStr, "Milliseconds: %d\n", Time);
fwrite(&OutStr, strlen(OutStr), 1, OutputFile);
//DEBUG**********************************************************************






I hope that all looks good. Anyway. There are plenty of examples of using the Performance timer in the MSDN help at http://msdn.microsoft.com

Sorry it looks so bad. I cut out the rest of the engine and we plan on cutting anything with //DEBUG out of the code. =)

E.D.
0

Share this post


Link to post
Share on other sites
Sorry that was me in that last post. It doesn''t look quite the way I wanted it to but oh well.

Its really accurate, pretty fast, and down to millisecond level. (in case you don''t know your FPS is equal to 1/ms where ms is the milliseconds. So for example, my engine takes 9 milliseconds to do its rendering, therefore, I''m running at about 111 FPS. When I include data processing in the loop, it takes about 15 milliseconds which is 66 FPS. Etc... you get the point.)

E.D.
0

Share this post


Link to post
Share on other sites
Thanks for all the help. My only question left is I am using NeHe''s OpenGL text output and its kind of crappy. Anyone know anything better. Thanks again!
0

Share this post


Link to post
Share on other sites
I think that''s one of the better ones, actually.

Magmai Kai Holmlor
- The disgruntled & disillusioned
0

Share this post


Link to post
Share on other sites