Replay System

Started by
6 comments, last by moucard 20 years ago
Hi to everyone, Does anyone know any resources for designing and implementing a replay system? I''m developing a game for kids and I need to be able to play back the session, so a doctor can later review it. Currently, I''m recording events (every change in mouse coordinates, a left button up, down and some other events that are required) along with a time stamp. The time stamp is in the order of microseconds. This way I get a trace file of about 0.5 MB for a 5 minute session of intense activity. I don''t think I will have as much activity in a normal session. Furthermore I''m considering creating a binary file instead of a text one (I''m only protyping right now). My main problem is how to exactly replay the file. Ok, I open it and read the events, but I''m a little bit worried with the timer. My current thoughts are read a line along with its time stamp. Read the next timestamp as well. Set an on timer event, so each frame we get the time and if it''s bigger than the next time stamp we progress through the list. If it sounds confusing it''s because it is for me as well. So do you know of any resources (on-line tutorials, books, etc.) that might shed some light on how to create such a system? Ideally my system would have video controls as well (play, stop, fast forward-rewind, the works). Thanks in advance!
Advertisement
Gamasutra has an article on replay systems.

-Halo7
Yep, read that already, but what''s more my problem is how to utilize (replay) the stored information. Thanks anyway.
I just want to point out one thing. Be careful if you are storing absolute mouse coordinates, because if the window is moved then all coordinates will be wrong.

So, perhaps it would be better to just store just the buttons that are clicked? But if you want the exact mouse movements, then I would suggest that you store relative coordinates.

For the playback, your idea sounds quite good, if you store all the coordinates. If you store the buttons, do a linear interpolation between the button coordinates instead.
you could flag each item as crucial or not, for example: I assume the path the mouse takes is unimportant, as would be clicks that miss the button or whatever. However, things that change the state would be flagged as crucial. If things are crucial, then even if it slows down you can't just skip. Though you may not need to force a redraw.

So the playback algo:

eventIndex = 0;replayTime = 0;oldClock = clock();while (eventIndex < numEvents){  // where am I?  replayTime += clock() - oldClock;  do   {    oldClock = clock();  } while (Paused);  // sorry if this syntax is wrong  while (event[eventIndex].timeStamp <= replayTime * replaySpeed)    if ((event[eventIndex].Crucial) ||       (event[eventIndex+1].timeStamp > replayTime * replaySpeed)    {      // crucial, or the last event for this timestep      DoEvent(eventIndex++);    }  Redraw();}


BTW, you should probably store the crucial events in absolute coords (by which I mean non-incremental)

lonesock

Piranha are people too.

[edited by - lonesock on March 30, 2004 4:27:28 AM]
Read the first line before the replay starts running.
Start the replay simulation.
When you reach the timestamp of the line you read, process the input and read the next line in.

shmoove
What you need is some message system in your app, so when you click on a button it generates a message which says the button is pressed.
You save these messages along with time stamps.

Then to replay, just send these messages at the appropriate time and your app will respond exactly as if they had been clicked.
Thanks for the responses. I''m just going to try to do it today. I have a general idea, I just wanted to ask first. Though in response to a previous post, yes I need the entire path of the mouse. I''m making a game for autistic children and the doctor needs the entire path saved so he can later examine it (he won''t be present when the child plays the game).
As for the mouse coordinates, I use OpenGL and DirectX, so I''m pretty confident that they won''t change (the coordinates are relative to the window (e.g. 348 569), not to the screen.
I think I know the events that I want to keep, I''m just not confident with the timer class. Will let you know how it turns out. Thanks to everyone again!

This topic is closed to new replies.

Advertisement