pingus-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pingus runs too fast/clock runs too fast/solution


From: Peter van Rossum
Subject: pingus runs too fast/clock runs too fast/solution
Date: Tue, 8 Apr 2003 09:29:57 -0600
User-agent: Mutt/1.5.4i

On my computer, pingus runs much too fast. Trying to slow pingus down with
-t <some large number> has no effect at all on the speed. 

I've tried to track down the problem and I believe I have found the cause. 
(Well,
I changed something in the source and now it runs ok...). Here are some code
snippets (from game_session.cxx and game_time.cxx) with some comments of what I 
think 
is happening.

Cheers, Peter van Rossum

PS: Great game!

//  $Id: game_session.cxx,v 1.38 2003/04/01 16:00:08 grumbel Exp $

//** ... snip ...

void
PingusGameSession::update (const GameDelta& delta)
{

//** ... snip ... 
//**
//** This following code should make sure that server->update()  -- a tick in 
the 
//**  game -- gets called for every game_speed (= 25) ms of real time that 
passes. 
//**  client->update() -- drawing the screen -- should get called as often as 
reasonable
//**  possible, but it is useless to call it more than once per call to 
server->update().
//**  
//**  Now imagine that the computer is fast -- fast enough that a whole tick 
(including
//**  drawing the screen) happens in (much) less than 25 ms.

  int time_passed = int(delta.get_time() * 1000) + left_over_time;
  int update_time = game_speed;

  left_over_time = 0;

  {
    int i;
    for (i = 0; 
         ((i * update_time < time_passed)
          || i < min_frame_skip)
           && !(i > max_frame_skip);
         ++i)
      {
        // This updates the world and all objects
        server->update ();
        ++number_of_updates;
      }

//**  Then this loop gets executed once.
      
    // Time that got not used for updates
    left_over_time = time_passed - (i * update_time);
  }

//**  left_over_time will be negative.

  if (!max_cpu_usage && left_over_time < 0)
    {
      // FIXME: This doesn't really belong here
      CL_System::sleep(-left_over_time);
    }

//**  And if you haven't called pingus with --min-cpu-usage, you will never 
sleep here.
//**  This causes a game tick to last much less than 25 ms.
  
  // Client is independend of the update limit, well, not completly...
  client->update (delta);

#if 0
  // Move the game one loop further
  server->update ();
  client->update (delta);
#endif
}

//**  Ok, the solution to this is easy. Just call pingus with --min-cpu-usage or
//**  just remove the !max_cpu_usage from the code above. Then the pingus move 
at
//**  the right speed, which you can check by just printing out the game_ticks
//**  (--debug gametime will do this, I think) and seeing that they last, on 
average,
//**  25 ms.

//**  However, there still is a problem: the clock runs too fast. This is just a
//**  bug in game_time.cxx

//  $Id: game_time.cxx,v 1.5 2003/04/06 14:37:07 grumbel Exp $

//** [ ... snip ... ]

std::string
GameTime::ticks_to_realtime_string(int ticks)
{
//** [ ... snip ... ]
  else
    {
      int seconds   = (ticks / game_speed % 60);
      int minutes   = (ticks / (60 * game_speed));

//** This is wrong. ticks is the number of game tick left to play and they are 
//** game_speed ms each. So this should be something like
//**
//** int total_seconds = (ticks * game_speed) / 1000;
//** int seconds = total_seconds % 60;
//** int minutes = total_seconds / 60;
  
      // Stop displaying negative seconds, which can happen if armageddon is
      // clicked with 1 second left.
      if (seconds < 0)
        seconds = 0;
  
      snprintf(time_str, 10, "%2d:%02d", minutes, seconds);
    }
  return time_str;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]