Game Development Reference
In-Depth Information
The members of this class include a Windows HANDLE to the thread, the thread ID,
and the current thread priority. This is set to THREAD_PRIORITY_NORMAL , but
depending on what the process needs to do, you might increase or decrease the pri-
ority. Note that if you set it to THREAD_PRIORITY_TIME_CRITICAL , you
ll likely
notice a serious sluggishness of the user interface, particularly the mouse pointer.
It
'
s a good idea to play nice and leave it at the default or even put it at a lower
priority.
'
Thread Priority Shuffle
While working on Barbie, one of the engineers built a multithreaded loader
that would load the data needed for the game in the background while the
intro movie played. Unfortunately, on single-core machines, the intro movie
got really choppy and would cut in and out. We considered delaying the
start of the background loading until after the movie, although that would
defeat the purpose. On a whim, one engineer tried lowering the priority of
the loader thread.
It worked perfectly, and the choppiness was completely
gone.
The thread process is defined by ThreadProc , which is called by the operating sys-
tem when the thread is created. That, in turn, will call VThreadProc , which will be
defined by an inherited class. The RealtimeProcess class is meant to be a base
class. Child classes will write their own thread process and send a pointer to it in the
constructor.
Notice that the class does implement a VOnUpdate() method, but it is just a stub.
All of the real processing in this class will be done by a thread function pointed to by
m_lpRoutine .
VOnInit() is where the call to CreateThread() happens:
void RealtimeProcess::VOnInit(void)
{
Process::VOnInit();
m_hThread = CreateThread(
NULL, // default security attributes
0, // default stack size
ThreadProc, // thread process
this, // thread parameter is a pointer to the process
0, // default creation flags
&m_ThreadID); // receive thread identifier
if( m_hThread == NULL )
{
 
Search WWH ::




Custom Search