*RealTime Revisited

14. April 2010 09:27 by Jeromy Walsh in Analysis  //  Tags: ,   //   Comments (2)

During my previous post I made the observation that the ElapsedRealTime and TotalRealTime methods were noticeably absent from the GameTime object which is provided to the Update and Draw methods. In my post I said this was presumably because the difference between game time and real time was confusing to developers. And given that there are alternate methods to obtain wall-clock time, they probably just disposed of it.

It turns out...I was spot on! About four hours after I posted my tutorial, Shawn Hargreaves, one of the XNA developers, posted to Shawn Hargreaves' Blog precisely that. In specific, he provided four reasons for why it was removed.

  1. "The data was rarely used..."
  2. "For the ... handful of cases people need this data they can get it from any other .NET timer..."
  3. "... is confusing for our customers"
  4. ElapsedRealTime is not well defined within the Draw method.
 
One thing I did want to comment on though is his first assumption. Shawn said:
 
"This data is rarely useful. Most often, people who think they need it would really be better off just setting their game to variable timestep mode, in which case *GameTime and *RealTime collapse and become the same thing."
 
This isn't entirely true. In a variable timestep game, the API makes no effort to throttle or stabilize the execution of the main game loop, so there's no sleeping and no iterative calls to Update in order to maintain a steady interval. However, there's still a subtle difference between Game Time and Wall-Clock Time. In specific, game time represents the amount of time spent processing the application logic, while wall-clock time represents the actual amount of elapsed time. On the Zune, Xbox 360, and WinPhone these are likely going to be the same thing most of the time. However on the PC (and at certain points on other platforms) the application is forced to block processing. A common example is when running on the PC in windowed mode. If you grab the window frame the message pump halts, waiting for the user to release the window. During this time the entire application is blocked, so it performs no processing. Consequently, game time never advances. You can hold the window for 30 minutes, whether in fixed-step or variable-step, either way time won't advance 1 millisecond until you release the window. However, wall-clock time would have still advanced 30 minutes.
 
With all that said, aside from network play, it's generally acceptable for game-play to pause while moving the window. I'm not yet familiar enough with network programming to be able to say with any certainty how this will effect multiplayer games.

Comments (2) -

Andres "NEXUS" Chamarra
Andres "NEXUS" Chamarra
1/18/2011 5:35:34 AM #

In networking games the blocking of the application process presents several problems.
If the application instance in question is a client session, once it gets back to processing it will have a LOT of catching up to do, if the app was blocked long enough, KeepAlive packets (empty network packages that tell the server that while the client is not sending any events, it hasn't lost connection) won't be sent and the server is likely to drop the client's connection.
If the app instance is server session, the problem is much worse, if blocked long enough the entire game session will likely drop.
Networking games should run these processes on an alternative background thread that is not dependent on the focus of the game window.
Even so, if the game window is in charge of retrieving packets from the incoming stack, and it doesn't for a long enough time, the stack might have gotten full and failed to receive new packets, thus failing to synchronize the client properly.

All these issues must be addressed somehow for a networked game to work properly.

SJR
SJR
7/15/2011 3:30:22 AM #

It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
You should take part in a contest for one of the best blogs on the web. I will recommend this site!

Pingbacks and trackbacks (1)+

About the author

Jeromy Walsh is a professional game programmer with multiple credited and uncredited AAA game titles. Jeromy's primary area of expertise is in Tools/Engine development, though he likes to fiddle with other areas as well.

Month List