Record / replay |
Top Previous Next |
This month I have decided to code a record / replay system that can store and play back the movement of up to 50 different entities.
Start the demo, and then press the "R" key to start recording; you will see a red flashing dot in the upper right corner of the screen. Move the camera around for as long as you want (or don't move it at all) and then press "R" again to stop the recording. Press "P" to enable the playback of the movement that was recorded; you will now see a green, flashing dot in the upper right corner of the screen.
Use the mouse pointer to access the panel in the upper right corner of the screen: you can now pause, move forward, fast forward, rewind or fast rewind the action. You can still move backward and forward even if the "pause" button is pressed; this allows you to examine the (let's say) fantastic goal you've just scored without problems.
All the recorded data is stored inside a recorded_position[70000][50] array; the array can store the x, y, z, pan, tilt, roll and frame number for up to 10,000 frames (10000 x 7 = 70,000) and up to 50 entities. Of course that you can increase the size of this array if you want to record even more frame and / or more entities; you will have to make a few minor changes to the code as well. And since we are here, if the entire array is filled with data the recording will stop automatically.
The recorded data will be stored inside the 1.txt... 50.txt files; if you are using fewer entities only the needed data files will be created. The size of the data files is about 150Kb / minute / entity; if you think that this is too much, you can compress the data before saving it or you can record the game at a smaller frame rate. The action from my project is recorded at 70 fps, the same frame rate at which the demo is run. This might be too much for most of your needs, so feel free to record at a smaller frame rate if you want to (use something like total_frames % 2 to record at 35 fps or decrease fps_max, etc);
The recorded data files are deleted on exit; if you comment a line of code (indicated in the recreplay.c file) you can keep them all. In fact, the system was designed in such a way that the data files can be kept and reused even after the engine is shut down; if you don't plan to use them that way, you can bypass the code that writes / reads data to / from the text files and simply use the data stored inside the recorded_position[70000][50] array for recording / replaying.
The demo comes with 2 different example actions (player / camera and car movement) that should help you implement the record / replay system in your games without any problems. My demo allows you to move the player around and records its movement, as well as the movement of 5 different, randomly moving cars.
The code is very well commented, so you shouldn't have any problems with it.
|