Game Development Reference
In-Depth Information
Communication between real-time processes and the rest of the game happens
exactly where you might expect in the Event Manager. A little bit of code has to
be written to manage the problem of events being sent to or from real-time processes,
but you
ll be surprised how little. Passing messages is a great way to synchronize pro-
cesses running in different threads, and it also avoids problems that arise with shared
data.
After the basic classes are written, you
'
ll see how you can write a background real-
time process to handle decompression of part of a Zip file.
'
The RealtimeProcess Class
The goal with the RealtimeProcess class is to make it really easy to create real-
time processes. Here
'
s the class definition:
class RealtimeProcess : public Process
{
protected:
HANDLE m_hThread;
DWORD m_ThreadID;
int m_ThreadPriority;
public:
// Other prioities can be:
// THREAD_PRIORITY_ABOVE_NORMAL
// THREAD_PRIORITY_BELOW_NORMAL
// THREAD_PRIORITY_HIGHEST
// THREAD_PRIORITY_TIME_CRITICAL
// THREAD_PRIORITY_LOWEST
// THREAD_PRIORITY_IDLE
//
RealtimeProcess( int priority = THREAD_PRIORITY_NORMAL )
: Process(PROC_REALTIME)
{
m_ThreadID = 0;
m_ThreadPriority = priority;
}
virtual ~RealtimeProcess() { CloseHandle(m_hThread); }
static DWORD WINAPI ThreadProc ( LPVOID lpParam );
protected:
virtual void VOnInit();
virtual void VOnUpdate(unsigned long deltaMs) { }
virtual void VThreadProc(void) = 0;
};
 
 
Search WWH ::




Custom Search