Hello there,
I had this problem when trying to implement multi-threading system to my game for the "Loading Content" section, so that I can get the progress while the game importing the game contents.
I used this class from CodeProject for the threading:
http://www.codeproject.com/KB/threads/SynchronizedThreadNoMfc.aspx
and here is my code: (simplified)
the multithreading class (please see the article given above as reference):
// ResThread.h
class ResThread : public Thread
{
private:
int ID;
char *ThreadName;
public:
ResThread(int iID, const char *szThreadName)
{
this->ID = iID;
this->ThreadName = szThreadName;
}
void run()
{
//...........other codes
if(this->ID == 1)
{
LoadMainResources(); // this will import all the game resources
}
else
{
// the game draws this fine, but not for the window..
while(!LoadCompleted && LoopGDK())
{
int LoadProgress = GetLoadingProgress();
char loadtxt[100] = "Loading Game Interface... [";
strcat_s(loadtxt, 100, dbStr(LoadProgress));
strcat_s(loadtxt, 100, "%]");
d3dStartText(); // Cloggy's D3DFunc text
d3dText(4, 400, 318, 1, loadtxt, dbRGB(255, 255, 255));
d3dEndText();
dbSync();
}
}
}
};
and my main game code:
//...
#include "ResThread.h"
//...
void DarkGDK()
{
//........other codes
Thread *MainRsrcThread = new ResThread(1, "Thread 01");
Thread *LoadingThread = new ResThread(2, "Thread 02");
// I don't apply Mutex so that it will work asynchronously
MainRsrcThread->start();
LoadingThread->start();
MainRsrcThread->stop();
LoadingThread->stop();
while(LoopGDK())
{
//.....other codes
dbSync();
}
}
And here's a screenshot to show how it looks like:
http://img186.imageshack.us/img186/2578/wdwren.jpg
Am I doing wrong?
Any kind of help would be appreciated!
Thanks.
if(asleep) sheep++;