Event Scheduler

Miscellaneous Forums/Blitz Showcase/Event Scheduler

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

@ ImaginaryHuman:

There is no idle time whatsoever, due to the use of Event Hooks. As soon as the scheduled function is executed, it returns. This is not an eventQueue.


@Paxman:

The solution you mention is equivalent to iterating through every single object each cycle, which requires a ton of overhead.

I'm using this code for a program which contains many hundreds or thousands of objects, each with independent 'schedules', such as "Produce X every 30 seconds" or "Consume X every 25 seconds", etc. Looping through the object list every cycle to check timestamps require hundreds or thousands of conditionals each cycle. Using a master schedule that is time-organized is a slightly better solution, but requires schedule sorting/seeking when an event is scheduled. My solution provides the minimum amount of overhead, because only one cell must be checked each cycle, and inserting new events into the proper location is the matter of a very simple two-operation equation.

Make sense?

EDIT:


I've been improving this code alot, so if anyone's interested I will gladly explain more. The use right now is for a trade simulation in which there are hundreds of trade posts and hundreds of NPC traders simultaneously active. The stations produce and consume commodities as regular intervals - so by using this method I can avoid having to cycle through the entire list of stations once every tick in order to determine whether or not enough time has passed for each station to consume/produce its next commodity.