scheduling events

J

Joe, G.I.

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top