[SDL] stuck with multiplayer and some segfaults

Olof Bjarnason olof.bjarnason at gmail.com
Fri Mar 11 04:14:59 PST 2005


Say you fix your logic rate to 100 Hz, that is 10 ms per frame. Try to
find as accurate as possible a time measurement, SDL_GetTicks() has 10
ms granularity so it is not ideal but might prove good enough at least
it won't "drift" as time goes by. The trick is to keep a variable for
your current "logic time" or "game time", which tries to "follow" the
computer time / real time as good as possible. Call it gameTime_ms, ms
for milliseconds:

In the main loop:

 1. process events,
 2. int computerTime_ms = getCurrentTime_ms(); // or whatever you call
your routine
 3. // Now bring gameTime_ms up to the actual time!
   while(computerTime_ms-gameTime_ms > 0) {
     take a 10ms physic step
     gameTime_ms += 10;
   }
 4.draw graphics (a snapshot of the game state at gameTime_ms!)

So after the while-loop gameTime_ms will be 0-9 ms "before" the
computers actual time, but this is unnoticible for a human eye and
makes no physical difference AFAICS.

The processing of the events might be done in a separate thread to
enable granularity higher than the FPS rate! It might be a bit tricky
though maybe someone can fill up on this.

Another issue is the limited size of the gameTime_ms. If it is
unsigned 32bit, we get approx. 4*10^9 ms = 4*10^6 s = 4*10 / (60*60) h
~= 4.400 hrs ~= 180 days. How long can a pong game get? :) Anyway you
must make sure getCurrentTime_ms() starts counting at 0 when the
program boots..

/Olof

On Fri, 11 Mar 2005 12:23:09 +0100, Jonas Huckestein
<jonas.huckestein at web.de> wrote:
> thanks david :)
> 
> On Friday 11 March 2005 09:02, David Olofson wrote:
> > Because of the complexity that adds, and other, more serious issues
> > (collision detection and event handling), I generally prefer to use a
> > fixed logic frame rate for totally concistent behavior.
> yea, that's what i was thinking. so how would i do that then?
> simply skip a few rounds on my game-loop or do any problems come with that?
> (theres this sdl_framerate thingy from the sdl_gfx package and i was
> wondering why that is necessary at all)
> 
> > Faster...? It's usually the client that burns more cycles, due to the
> > graphics - except when one client is also the server, of course.
> that's the case :)
> 
> > Anyway, in most cases, one should probably just try to keep it as
> > clean and simple as possible. Try to design a GUI that does what you
> > need with a minimum of confusing "bonus features".
> i'll do my best, thanks
> 
> 
> take care ...
> --
> Jonas Huckestein
> 
> Pub. PGP Key: http://pgp.upb.de:11371/pks/lookup?op=get&search=0xD2BAE645
> 
> "There was once a cross-eyed teacher who couldn't control his pupils."
> Another one: "I was wondering why the baseball kept getting bigger. Then it
> hit me." and "A bicycle can't stand on its own. It's two-tired."
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
> 
> 
> 
>




More information about the SDL mailing list