Schedule a task to run
by gamer · in Torque Game Engine · 09/28/2006 (5:49 pm) · 0 replies
I am trying to shedule a thread/task to run from the c++ engine code. basically calling Sim::postEvent over and over again so that the task gets every 100 ms. However, it doesn't work, when I invoke my console command onSchedule2(), the c++ member function onSchedule gets called, but then when it calls Sim::postEvent(), trying to call the console command onSchedule2() again in 100ms, it seems that the event never gets to onSchedule2. any idea how to do the schedulng properly from c++? thanks
in class A
in the script:
$A=new A(AName);
$A.StartCom();
in class A
void A::onSchedule(){
//does some work and then
string tmp("onSchedule2");
const char*argv=tmp.c_str();
util::schedule_task(this,100,1,&argv);
}
ConsoleMethod(A, onSchedule2,void,2,2,""){
Con::printf("consoleMethod onSchedule2 called\n");
object->onSchedule();
}
S32 util::schedule_task(SimObject *refObject, S32 timeDelta, S32 argc, const char **argv ){
if(!refObject)
{
refObject = Sim::getRootGroup();
}
SimConsoleEvent *evt = new SimConsoleEvent(argc, argv, true);
S32 ret = Sim::postEvent(refObject, evt, Sim::getCurrentTime() + timeDelta);
return ret;
}
void A::StartCom(){
string tmp("onSchedule2");
const char*argv=tmp.c_str();
util::schedule_task(this,100,1,&argv);
}in the script:
$A=new A(AName);
$A.StartCom();
About the author