Hi, first thanks for the reply of my mail about printing. Now I have
another problem.
Recently, my project’s event handler is a little lagging, even in
fullscreen mode. If I clicked the mouse button sequentially, sometimes it
wouldn’t be catched by the handler. So I decided to make the event handler
and image drawing sequences into different threads. I’m confused about how
should I implement the threading. I’ve looked at several tutorials about
SDL_thread, but they didn’t work. You see, in my projects all was handled
by one universal singleton object. That object will handle everything from
other objects’ creations, accessing the objects, freeing the objects,
drawing, event handler, etc. Thus the main function will only consist of:
void main()
{
CMainApp *mMainApp; //The universal object
mMainApp = new CMainApp;
mMainApp->start();
}
So, I implemented the thread function and creation in the object:
The declarations:
class CMainApp
{
Public:
CMainApp();
~CMainApp();
int drawThreadFunc(void *data);
void start();
void draw();
//Variables
Private:
bool done;
SDL_Thread *mThread;
//Other functions&variables
…
};
The implementations:
CMainApp::CMainApp()
{
done=false;
…
}
CMainApp::~CMainApp()
{
…
}
int CMainApp::drawThreadFunc(void *data)
{
while(!done)
{
draw(); //Drawing the surface
}
}
void CMainApp::start()
{
mThread = SDL_CreateThread(drawThreadFunc, NULL );
while(!done)
{
eventHandling(); //Catch and handle events
}
SDL_KillThread(mThread);
}
But when I compiled the code, it show this error message (FYI I used
Kdevelop):
/home/benang/mattinggame/src/MainApp.cpp:129: error: argument of type ?int
(CMainApp::)(void*)? does not match ?int ()(void)?
Why does this happen? Is my threading code above correct?