Archived

This topic is now archived and is closed to further replies.

moucard

using a replay system

Recommended Posts

Hello to everyone. I've build a replay system of a small game, where I record mostly the mouse events (mouse move, left mouse button up, down, etc) I save these events in a binary trace file. I later replay this file, but I seem to have some speed problems. The replay runs a bit slower than the real thing. To give an example, for a 20 second session, the replay lasted about 50 seconds. For recording the events I use a timestamp of the time difference. A small text sample is: Event Type Time Difference Data (mouse coordinates) Mouse : 0.02 : 432-451 Mouse : 0.03 : 442-460 Mouse : 0.02 : 450-470 Mouse : 0.031 : 456-480 The way I go about recreating the trace is: Open the file Read a header and re-set the level Then on glut's idle event:
if ((g_cTimer->ElapsedTime() - g_dTimeOfLastEvent) >= dEventTime)) {
g_dTimeOfLastEvent = g_cTimer->ElapsedTime();
g_TraceFile.read((char*)&ucEventType, sizeof(unsigned char));
g_TraceFile.read((char*)&dEventTime, sizeof(double));
// Then a switch statement according to the event type.
// In case of a mouse move I use gluUnproject to change the mouse
// coordinates to world coordinates.
   
Do you believe that the slow-down problem is because I read constantly the file from disk? Should I load the whole file to memory first? To hold the file in memory (as it is a binary file) can I use a vector? Is there a better method? Thank you for your time. [edited by - moucard on May 27, 2004 3:23:14 AM] [edited by - moucard on May 27, 2004 4:08:07 AM]

Share this post


Link to post
Share on other sites
a little bit less than 300 kb.
The other thing I''m thinking is about storing absolute time values instead of the time difference. But then I have the problem that if a frame takes too long to render, there goes my whole timer. The cursor starts jumping around, trying to catch up the lost time. I''ve used the later method before and know this for sure. This is why I wanted to store the time difference. With this method I don''t loose track of time no matter how long the frame takes to render.

Share this post


Link to post
Share on other sites