Recording/Playback player input, how to handle desync?

A place for people with an interest in developing new shmups.
Post Reply
User avatar
Dave_K.
Posts: 4570
Joined: Wed Jan 26, 2005 5:43 am
Location: SF Bay Area
Contact:

Recording/Playback player input, how to handle desync?

Post by Dave_K. »

Got some questions for those of you that handle recording player input and playing it back, be it either as a demo sequence, or a high score replay.

1) What additional data do you save other than the players input and the frame number / timestamp?
2) How do you handle desync'ing situations when played back on a client that runs at a different FPS?
Ixmucane2
Posts: 773
Joined: Mon Jan 19, 2009 3:26 pm
Location: stuck at the continue prompt

Re: Recording/Playback player input, how to handle desync?

Post by Ixmucane2 »

What do you mean by "different FPS"? If you want reliable input playback, you need a fixed simulation time step that doesn't depend on rendering time steps.
User avatar
ciox
Posts: 1008
Joined: Sun Feb 12, 2012 5:29 pm
Location: Romania

Re: Recording/Playback player input, how to handle desync?

Post by ciox »

1. You don't need to save the frame number or a timestamp, just make sure you start recording (if recording) and playing back (if playing back) in the same part of your code. If you have randomness you need to initialize and store the random seed in your replay and then load it from the replay when playing back.

2. Make sure everything uses a fixed time step, for example everything that moves in the game has its movement handled by you with simple code like "location += normal(direction)*speed" and doesn't rely on built-in functions that could sneak variable time step logic into your game. Stuff that is just eye candy can't desync the replay so built-in functions are fine for those.
User avatar
mice
Posts: 829
Joined: Tue Apr 26, 2005 2:50 pm
Location: Sweden
Contact:

Re: Recording/Playback player input, how to handle desync?

Post by mice »

ciox wrote:just make sure you start recording (if recording) a
If you don't want 60 entries per second, you need a timestamp (or rather a framestamp).
Dave_K. wrote:What additional data do you save other than the players input and the frame number / timestamp?
The eventual difficulty setting.

And yes, a constant time frame step is a lot easier than trying to do variable FPS input playback. I haven't tried it myself, but it feels like it could be really hard to get it working properly.
User avatar
Dave_K.
Posts: 4570
Joined: Wed Jan 26, 2005 5:43 am
Location: SF Bay Area
Contact:

Re: Recording/Playback player input, how to handle desync?

Post by Dave_K. »

Thanks for the advice guys! I need to think about this some more, as currently my game (written in AS3/Flash) is based around a frame counter. I do have access to the frame delay upon exiting a frame, so maybe I should be using this to adjust the replay?
Ixmucane2
Posts: 773
Joined: Mon Jan 19, 2009 3:26 pm
Location: stuck at the continue prompt

Re: Recording/Playback player input, how to handle desync?

Post by Ixmucane2 »

Dave_K. wrote:Thanks for the advice guys! I need to think about this some more, as currently my game (written in AS3/Flash) is based around a frame counter. I do have access to the frame delay upon exiting a frame, so maybe I should be using this to adjust the replay?
Not at all. Adjust nothing to compensate for real-time delays; just render new frames.
It might help to think of the game as a turn based one: every turn you collect the player's input for that turn (presumably by polling, only once per turn, which buttons are down) and then you update the game state.
Rendering frames to the screen and playing music and sound effects is a completely accessory and optional activity; when you reproduce a recorded game you can render something different from the first time (different screen size, more frames, increased quality, added or removed text, etc.) and change speed (particularly to compensate any involuntary slowdown).
User avatar
Dave_K.
Posts: 4570
Joined: Wed Jan 26, 2005 5:43 am
Location: SF Bay Area
Contact:

Re: Recording/Playback player input, how to handle desync?

Post by Dave_K. »

This makes a lot of sense. Thanks again for the help!
Post Reply