• 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.
Sign in to follow this  
Followers 0
pixeltasim

Finding out FPS

7 posts in this topic

I just started working with SDL and with some help from the internet got deWitter's game loop working, but I want to find out what my fps is. I'm not exactly sure how to go about doing this, and I haven't really understood any answer I have found on the internet. Any answers would be appreciated. 

#include <SDL.h>

int main( int argc, char *argv[] )
{
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;

float interpolation;
int loops;
int fps;

SDL_Event event;
SDL_Surface *screen = NULL;
screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE);

SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
SDL_Rect source;
source.x = 0;
source.y = 0;
source.h = 150;
source.w = 120;

SDL_Rect dest;
dest.x = 120;
dest.y = 120;
dest.h = 150;
dest.w = 120;

bool running = true;
unsigned int next_game_tick = SDL_GetTicks();

while ( running )
{

while( SDL_PollEvent( &event ) )
{
if ( event.type == SDL_QUIT )
running = false;
}
if (event.type == SDL_KEYDOWN)
         {
            SDLKey keyPressed = event.key.keysym.sym;

            switch (keyPressed)
            {
               case SDLK_ESCAPE:
                  running = false;
                  break;
            }
         }


loops = 0;
while( SDL_GetTicks() > next_game_tick && loops < MAX_FRAMESKIP )
{


// update_game();

next_game_tick += SKIP_TICKS;
loops ++;
}

interpolation = float( SDL_GetTicks() + SKIP_TICKS - next_game_tick ) / float( SKIP_TICKS );

// display_game( interpolation );
SDL_BlitSurface(bmp,&source,screen,&dest);
SDL_Flip(screen);

}

return 0;
}

 

 

0

Share this post


Link to post
Share on other sites

Also note that much better measure than frames/s is ms/frame. This gives you information how long in miliseconds it takes to generate one frame on average. There is great explanation of why FPS sucks as a measure for programmers: http://www.mvps.org/directx/articles/fps_versus_frame_time.htm.

 

Especially the part comparing non-linear FPS vs linear ms/frame - you can see how bad of a measure FPS is and that it doesn't really tell you anything. Leave it to GPU marketers and sellers trying to impress customers with something that doesn't make sense to measure changes in performance on per frame basis.

Edited by noizex
0

Share this post


Link to post
Share on other sites

I followed the tutorial and used their timer class, but I have an absolutely massive fps, and I'm not sure if that is correct.

#include <SDL.h>
#include "Timer.h"
int main( int argc, char *argv[] )
{
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;

float interpolation;
int loops;
int frame;
Timer fps;
Timer update;

SDL_Event event;
SDL_Surface *screen = NULL;
screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);

SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
SDL_Rect source;
source.x = 0;
source.y = 0;
source.h = 150;
source.w = 120;

SDL_Rect dest;
dest.x = 120;
dest.y = 120;
dest.h = 150;
dest.w = 120;

bool running = true;
unsigned int next_game_tick = SDL_GetTicks();
fps.start();
update.start();
while ( running )
{

while( SDL_PollEvent( &event ) )
{
if ( event.type == SDL_QUIT )
running = false;
}
if (event.type == SDL_KEYDOWN)
         {
            SDLKey keyPressed = event.key.keysym.sym;

            switch (keyPressed)
            {
               case SDLK_ESCAPE:
                  running = false;
                  break;
            }
         }


loops = 0;
while( SDL_GetTicks() > next_game_tick && loops < MAX_FRAMESKIP )
{


// update_game();

next_game_tick += SKIP_TICKS;
loops ++;
}

interpolation = float( SDL_GetTicks() + SKIP_TICKS - next_game_tick ) / float( SKIP_TICKS );

// display_game( interpolation );
SDL_BlitSurface(bmp,&source,screen,&dest);
SDL_Flip(screen);
frame++;
if(update.get_ticks()>1000){
    int fpsnum = frame/(fps.get_ticks()/1000.f);
    printf("Rendering at %u frames per second\n", fpsnum);
    update.start();
}

}

return 0;
}

Standard output:
Rendering at 2683765 frames per second
Rendering at 895185 frames per second
Rendering at 537183 frames per second
Rendering at 383724 frames per second
Rendering at 298462 frames per second
Rendering at 244201 frames per second
Rendering at 223834 frames per second
Should that be normal?

Edited by pixeltasim
0

Share this post


Link to post
Share on other sites

Alright, so I figured out how to display FPS properly, but I am now having an issue with SDL_GetTicks(), whenever I try to assign a variable to it, the variable's value remains zero, while when I check SDL_GetTicks() directly, it works fine. 

float Timer::timeSinceCreation()//calling this method returns zero as well
{
   return SDL_GetTicks(); 
}

float Timer::timeSinceLastFrame()
{
   float thisTime = SDL_GetTicks();//thistime is always zero
   float deltaTime = thisTime - m_timeOfLastCall;//, thus every other value remains zero
   m_timeOfLastCall = thisTime;
   printf("%u ms \n",thisTime );
   return deltaTime;
}

 

The program ran fine once, but then it stopped working. 

 

Just realized, this seems to be part of a larger problem in this class, all of the variables don't get assigned, so when I changed deltaTime to 5, it stayed at zero.

Edited by pixeltasim
0

Share this post


Link to post
Share on other sites
SDL_GetTicks returns an unsigned integer (number of milliseconds), so you shouldn't assign it to a float or return it as a float either. I can't say if that is the cause of your problem though. Edited by ultramailman
0

Share this post


Link to post
Share on other sites

Thank You! It was part of the problem actually, I was assigned %u when I should have been doing %f. I've switched my variables over to uint32 though, because that's what SDL_GetTicks() returns in. I've got my FPS working now with a modified timer and Min/Avg/Max framerate system going. 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0