Event system ideas

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Nectar
Posts: 6
Joined: Thu Feb 10, 2005 8:02 pm

Event system ideas

Post by Nectar »

So i've finished my event system for my project, and it works fine..

There are two basic methods for injecting events into the sytem, timed events (that happen based on a timer), or static events (ie, software generated events for spawning NPCs, or keyboard events that kind of thing).

The static event system I think is fine, but I'm hung up on the timed system.. Currently, it runs through every second, and all the events have a second accuracy as well. Basically, I'm undecided on if the timer should have better accuracy or not..

But if it has better accuracy, say every half second, that means that the system will be processing through the events twice a second. With say 100 events, that could chew alot of time i think.
But with less accuracy, it means that the event system is limited in what it can do.

Any ideas? Which is better, accuracy or speed?
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

In my opinion, standardizing timed events to a fixed interval is a bad move. Maybe you should look into a way to use arbitrary time intervals. I don't know how your event system works so there is little advice I can give about the actual implementation.
Kidinnu
Posts: 10
Joined: Fri Jun 02, 2006 6:54 pm
Location: North Carolina, USA

Post by Kidinnu »

Umm, one of the classic ways to do this would be closer to:

* keep the list of events sorted for which comes soonest; this is O(nlogn) and probably performs much better than that, depending on the exact distribution of event times you've got.

* you're probably not going to want to set an interrupt timer, so just check once per frame to see if the first event in the queue is due. if it is, execute it and check the next.

This ties the variable overhead to the event *generation*, not the event handling.

The accuracy/speed tradeoff really depends on the kinds of events you're using in your system, but I think you're making a much coarser-granularity system than you need to.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think your style of processing timed events is not good at all. Why do you poll all events just to see that every some seconds just one of the events happens? Polling is only good if most of the events happen all the time.
A typical way of processing timed events is to store the events on a time line. Then you just have to check whether the first event happened. Insertion can be done with binary search so it shoudl be quite fast. And inserting periodical events can be done just after processing the last (and only) event of that type in the queue.
Nectar
Posts: 6
Joined: Thu Feb 10, 2005 8:02 pm

Post by Nectar »

hmm,
I think the best way to go would be to use the time line idea, i'm a little concerned though that the tree would become side heavy, in that if I add events linearly (ie, first event is 5 seconds, second is 7, etc) then it looses efficency, but I doubt it would be worse than the current implementation

To be honest, i'm not sure if I need timed events much so I'll probably only have 10 or so active at any one point, compared to the static events.

I'll have to see what kind of tasks i'm using this for. Mabye then I can see the best route to go
stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

Set a bunch of timers, and only decrement the one that is due to expire first. When it expires check for any others that have expired. Action them.

When you schedule a new timer, if it's due to expire before the one you're currently decrementing, replace it with the new one.
Post Reply