LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2004, 03:37 AM   #1
markelo
Member
 
Registered: Mar 2004
Distribution: Red hat 9 -> 64bit fedora
Posts: 190

Rep: Reputation: 30
SDL_GetTicks() troubles


Once again hitting on troubles.
SDL_GetTicks(); returns same time when I last called it very often.

This causes troubles that in my 3D program framerate jumps between 1000 and 55 ( real value )
Animations and self moving objects seems to move okay. But why so erraric framerates ?

I have something like this at the beginning ( global variables )

Uint32 newtime=0;

Uint32 oldtime=0;
Uint32 passedtime=0;



Then in my code
newtime=SDL_GetTicks();
passedtime=newtime-oldtime;
cout<<"Framerate="<<( float ) ( ( float ) passedtime / 1000.0f )<<endl;
oldtime=newtime;
updateScreen (); //Draws the scene.

My platform is A64 3000+ with nfoce3 board.
My kernel is Red hat 9 with custom build 2.6.7 kernel. SDL version is same as came with RH9.
 
Old 08-05-2004, 08:00 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try something like this. It's complete SDL program with frame-delay, but it does not draw anything.
I use it as a starting piont for an SDL-program. I took the frame-delay function from Sam Lantinga's example SDL-program "aliens". See http://www.libsdl.org/projects/aliens/
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#include "SDL.h"

#define FRAMES_PER_SEC  50

SDL_Surface *screen;

void updatescreen (void)
{
     /* Draw your frame here */
}

void init (void)
{
     srand (time (NULL));
     if (SDL_Init (SDL_INIT_VIDEO) < 0) {
          fprintf (stderr, "Unable to init SDL: %s\n", SDL_GetError ());
          exit (1);
     }
     atexit (SDL_Quit);

     screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE);
     if (screen == NULL) {
          fprintf (stderr, "Unable to set 640x480x16 video mode: %s\n",
                   SDL_GetError ());
          exit (1);
     }
}

void framedelay (void)
{
     static Uint32 next_tick = 0;
     Uint32 this_tick;

     this_tick = SDL_GetTicks ();
     if (this_tick < next_tick) {
          SDL_Delay (next_tick - this_tick);
     }
     next_tick = this_tick + (1000 / FRAMES_PER_SEC);
}


void run (void)
{
     int done;
     SDL_Event event;

     done = 0;
     while (1) {
          framedelay ();
          while (SDL_PollEvent (&event)) {
               switch (event.type) {
               case SDL_QUIT:
                    return;
               }
          }
          updatescreen ();
     }
}


int main (int argc, char *argv[])
{
     init ();
     updatescreen ();
     run ();
     return 0;
}
Compile and link with:
Code:
gcc -g -Wall `sdl-config --cflags` `sdl-config --libs` -o progname progname.c

Last edited by Hko; 08-05-2004 at 08:16 AM.
 
Old 08-05-2004, 01:12 PM   #3
markelo
Member
 
Registered: Mar 2004
Distribution: Red hat 9 -> 64bit fedora
Posts: 190

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Hko
Try something like this. It's complete SDL program with frame-delay, but it does not draw anything.
I use it as a starting piont for an SDL-program. I took the frame-delay function from Sam Lantinga's example SDL-program "aliens". See http://www.libsdl.org/projects/aliens/
That code could be fine but I want to measure framerates in different situations like when there are lots of objects and when there are only few and so on.
Example code you posted restricts framerates to pass certain value and I don't want that.

So my real question is is this SDL_GetTicks() so erratic with high update rate or do I have an another problem ?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
troubles with SATA, troubles with NVIDIA aevangelica Linux - Hardware 6 10-17-2005 02:39 AM
g++ troubles GlassEyeSlim Linux - Newbie 6 02-15-2005 10:51 AM
X Troubles robza Mandriva 2 08-25-2003 04:28 AM
Troubles tryinglinux Linux - Newbie 6 05-06-2003 10:19 AM
Have some troubles vnpcg Linux - Software 1 02-20-2003 08:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration