Is there a simpler way to do a series of events that occurs without using many different timer events? Like for example, there is a gun fight going on as the player is supposed to be doing other actions to get away. There are many (20+) events that need to happen at different times but the player also needs to be able to move around and interact during this fight, so I can't have blocking or waiting.
Is there a way to do this without a lot of timer checks in the repeatedly_execute functions? If not I can probably manage but if so, thanks!
You can use normal int variables in r_e_a as a clock (iterating a "i++;" command. Each iteration equals 1 game cycle) and let the game check its value like some stop watch to ccordinate the events you want to happen. I used this to have a blinking effect that ends when the counter hits a value. I am sure you could use it for gunshots and stuff too.
I guess doing checks in rep_exec is inevitable but you can organise them using a struct:
enum TimerEventType
{
eEvtGunBlast1,
eEvtGunBlast2,
eEvtExplosion,
// ...
}
struct TimerEvent
{
int delay;
TimerEventType type;
};
#define MAX_EVENTS 100
TimerEvent events[MAX_EVENTS];
int event_count;
int last_event;
int time_elapsed;
And a couple of functions like this:
void OnEvent(TimerEventType event)
{
if (event == eEvtGunBlast1)
{
// Do something
}
else if (event == eEvtGunBlast2)
{
// Do something else
}
// ...
}
void CheckEvents()
{
if (last_event == event_count - 1) // Last event already happened
return;
if (time_elapsed >= events[last_event].delay) // Next event should happen
{
OnEvent(events[last_event].type);
last_event++;
time_elapsed = 0; // Reset timer
}
else
time_elapsed++; // Update timer
}
void AddEvent(int delay, TimerEventType type)
{
if (event_count == MAX_EVENTS) return; // Error here, increase the maximum
events[event_count].delay = delay;
events[event_count].type = type;
event_count++;
}
At another place you would like to call CheckEvents in a rep_exec function and add events something like this:
void SetupEvents()
{
AddEvent(30, eEvtGunBlast1);
AddEvent(10, eEvtExplosion);
AddEvent(120, eEvtGunBlast2);
AddEvent(10, eEvtExplosion);
}
A bit long but if you have many complicated events it might work for you. Hope it helps :)
Ok, thanks for the tips, Wyz and Kumpel! I think this will help out a lot.