Game Development Reference
In-Depth Information
With those tools, you have everything you need to write your own real-time pro-
cesses, including having them send and receive events from other threads and game
subsystems.
Background Decompression of a Zip File
One classic problem in game software is how to decompress a stream without halting
the game. The stream could be anything from a portion of a music file to a movie to
level data. The following class and code show how you can set up a background pro-
cess to receive requests from the game to decompress something in the background
and send an event when the decompression is complete.
class DecompressionProcess : public RealtimeProcess
{
public:
EventListenerPtr m_pListener;
static void Callback(int progress, bool &cancel);
DecompressionProcess() : RealtimeProcess(ThreadProc)
{
IEventManager::Get()->VAddListener(
MakeDelegate(this, &DecompressionProcess::DecompressRequestDelegate),
EvtData_Decompress_Request::sk_EventType);
}
virtual
DecompressionProcess()
˜
{
IEventManager::Get()->VRemoveListener(
MakeDelegate(this, &DecompressionProcess::DecompressRequestDelegate),
EvtData_Decompress_Request::sk_EventType);
}
virtual void VThreadProc(void);
ThreadSafeEventQueue m_RealtimeEventQueue;
// event delegates
void DecompressRequestDelegate(IEventDataPtr pEventData)
{
IEventDataPtr pEventClone = pEventData->VCopy();
m_RealtimeEventQueue.push(pEventClone);
}
};
The DecompressionProcess class is a real-time process that registers to listen for
an event, the EvtData_Decompress_Request event, which simply stores the name
 
 
Search WWH ::




Custom Search