Thread Questions
by Alex Poli · in Torque 2D Professional · 06/04/2014 (3:51 pm) · 5 replies
Hello,
I have been playing around with threads, and I can't seem to get a simple test working. I have a custom C++ object that I am working with called Island, and in that I want to add a simple threading test. What I did was add a threadTest and a printMessage function to the Island class, which are as follows:
When I try to compile this it says:
Error 2 error C3867: 'Island::printMessage': function call missing argument list; use '&Island::printMessage' to create a pointer to member c:usersalextorque2dlighttorque2denginesourcemapgenerationmapgeneration.h 271 1 Torque2D
Error 3 error C2664: 'Thread::Thread(const Thread &)' : cannot convert argument 1 from 'const char *' to 'ThreadRunFunction' c:usersalextorque2dlighttorque2denginesourcemapgenerationmapgeneration.h 271 1 Torque2D
I am assuming this is not how threads are constructed, but I can't figure out how I should be doing it.
Are there any examples of how to create threads in T2D?
Thanks!
I have been playing around with threads, and I can't seem to get a simple test working. I have a custom C++ object that I am working with called Island, and in that I want to add a simple threading test. What I did was add a threadTest and a printMessage function to the Island class, which are as follows:
void threadTest(const char* text){
Thread t(printMessage, text, true, true);
};
static void printMessage(const char* msg){
Con::printf("Message: %s", msg);
};When I try to compile this it says:
Error 2 error C3867: 'Island::printMessage': function call missing argument list; use '&Island::printMessage' to create a pointer to member c:usersalextorque2dlighttorque2denginesourcemapgenerationmapgeneration.h 271 1 Torque2D
Error 3 error C2664: 'Thread::Thread(const Thread &)' : cannot convert argument 1 from 'const char *' to 'ThreadRunFunction' c:usersalextorque2dlighttorque2denginesourcemapgenerationmapgeneration.h 271 1 Torque2D
I am assuming this is not how threads are constructed, but I can't figure out how I should be doing it.
Are there any examples of how to create threads in T2D?
Thanks!
#3
06/14/2014 (7:22 pm)
Thanks Daniel! I will definitely take a look at that. After a cursory glance it looks like T2D and T3D use the same thread class so that example should work.
#4
Did you get the threading and Torque 2d to work? I personally am looking into using threads to aid in heavy computational algorithms without interrupting the main game flow such as the player controls and image rendering.
Any experience/tips would help.
05/07/2015 (6:07 am)
@AlexDid you get the threading and Torque 2d to work? I personally am looking into using threads to aid in heavy computational algorithms without interrupting the main game flow such as the player controls and image rendering.
Any experience/tips would help.
#5
Sorry I couldn't be more help. :(
05/07/2015 (2:41 pm)
Chris, it's been a while since I experimented with threads so I don't really remember if I was ever able to get it working. I think I was able to implement them, but that I was still getting spikes of lag when loading files and such. I used the example that Daniel linked to get it somewhat working, but eventually gave up.Sorry I couldn't be more help. :(
Torque Owner Richard Ranft
Roostertail Games
As far as how to use threads in general, my advice is to buy a good book on the subject (or maybe five, so you can compare notes - it's a complex subject and I own seven or eight myself). And also realize that with C++ 11 things on the threading front have gotten easier, but there is another learning curve....