[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

scheduling events

Joe, G.I.

10/22/2008 7:55:00 PM

Trying a new approach that I think might work out better than my old
approach. And this turns out to be a really good reason for me to learn
boost. Someone else lead me onto this path that I don't fully understand.

So I'm trying to create 10 events that will start from a random amount
of time between now and 10 seconds. I have the random generating code
function that works. And I'm trying to have a scheduler execute my
events at *that* randomly generated time.

I have this at the top of one of my *.cpp files

typedef boost::function<void ()> event;

Then here I create the event which I think binds the die function of the
Monster class to this void function called 'killMonster'. What does the
second argument do? This just creates the event and schedules it? Is
this context.scheduler a part of boost or ... where can I find more
about creating a scheduler?

event killMonster = boost::bind(&Monster::die, this -> target);
this -> context.scheduler.at(NOW + 3.0, killMonster);

Then I have a function that is called between every frame of my game, so
that's where I planned on checking the time of the event to see if it
had expired. Can someone elaborate as to this ... I don't understand how
that fits in with step_length.

time += step_length;
this -> context.scheduler.run(time);