Game Development Community

Engine schedules?

by Sam Guffey · in Torque Game Engine · 09/19/2003 (7:24 pm) · 5 replies

Is there a way to schedule a function in the engine like the way its done in the scripts?

#1
09/20/2003 (3:18 am)
Yes. You can use the SimEvent to do something similar.
#2
09/20/2003 (4:25 pm)
The SimEvent I cant seem to get working. Maybe a lack of understanding.
#3
09/20/2003 (9:13 pm)
Basically you would construct your own subclass of SimEvent, overriding the process method with the code you want executed at a future time like:
class MyKewlEvent : public SimEvent
{
public:
   void process(SimObject *refObject)
   {
      Con::printf("Whee!  What fun!");
   }
};
Then you would post the event to some reference object, which could be an object in the simulation, or the global root group (an object you know will exist for the duration of the simulation). If the object that you use as a reference object is deleted before the event's process time comes, the event will be deleted and never processed.
...
   Sim::postEvent(Sim::getRootGroup(), // post to the root group 
                  new MyKewlEvent,  // a new MyKewlEvent
                  Sim::getCurrentTime() + 100); // 100 ms in the future
   ...
You can do a global search for SimEvent to find more examples.
#4
09/20/2003 (10:24 pm)
How does the engine know what the "SimObject *refObject" is?

What im doing is adding a light on every lightning strike, then trying to delete it 500ms later but no can do.

I need to call the Lightning class and the LightManager class from new SimEvent class and get the light or mLight passes to the Lightning class and remove it with the LightManager class.
#5
09/20/2003 (11:09 pm)
Couldnt you just make a constructor that passes in the appropriate information?