Game Development Reference
In-Depth Information
// Create our log data.
LogDataForPlayingASound new_log_data;
StringCopy( new_log_data.m_event_name , event->m_name );
new_log_data.m_params = params;
new_log_data.m_owner_id = owner_id;
new_log_data.m_instance_id = *(unsigned int*)inst;
writeData( &LogDataForPlayingASound, data_size );
}
Listing 11.9. Pseudocode sample of sound command log structure.
As the command log file may end up getting quite large if the replay data are
logged for an extended period of game play, it may be worth investigating options
to stream this file into memory. This way, we only store the commands for the
next few seconds of game play, rather than have the log fill up our, almost certainly
restricted, memory pool.
Replaying the sound log. We need a method to play the log file generated by
running the game. The easiest method to do this is to run the game in a special
sound replay mode. When in this mode, the game will only play sound commands
from the log file and not those generated by the game itself. This is easily done by
adding a flag to your game, which is set when booting up in replay mode. This flag
is used to make sure we only process sound commands retrieved from the log file.
Our SoundReplay class manages loading in the file, potentially streaming it in
if the file is too large to fit into memory. The SoundReplay class has to mimic the
behavior of the actively playing sounds from the game. Therefore, when creating
our log, we note down the address of the SoundInstance pointer used in our sound
commands. We must store these addresses so that logged commands that affected
a sound instance can be mapped to a new sound instance when we replay them in
order to correctly to reproduce the soundscape.
Within our SoundReplay class, we should have a linked list, or an array of
LoggedSoundInstances, as described in Listing 11.10. This class allows us to map
struct LoggedSoundInstance
{
unsigned int m_assumed_identity;
SoundInstance * m_instance;
};
Listing 11.10. Sample logged sound instance.
Search WWH ::




Custom Search