Request for help making an ingame Schedule Manager

BlitzMax Forums/BlitzMax Beginners Area/Request for help making an ingame Schedule Manager

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.

Hey all... scroll down a few boxes and you'll see the actual program. Everything is working exquisitely!


Thank you again to Perturbatio who pointed me towards reflection.. what a great module!


Original Post Below...
------------------------------------------------------------------------------------------------------
Hi everyone. I've been playing with a version of blitz3d they gave me at school for awhile now, but finally decided to step it up and buy my own copy of BlitzMax. I'm very glad I did!


I'm currently building a trading game, where the player can navigate his ship through a small solar system, visiting different planets and stations, and buying low/selling high. The main point of the game is to build an entirely dynamic economy. No faking allowed!

Anyway, one of the things I haven't quite figured out is how to implement a 'Schedule'. Here's the example:

Each station/planet is an instantiation of my custom 'TStation' type. Those instantiations have methods such as "produce" or "consume", etc. I would like for some stations to "produce" something every 30 seconds, for example.

So what I need to build is a scheduler, to handle the timing of all these production events. This way, when the appropriate time rolls around for something to be produced, the proper method will be called by the proper object, with the proper parameters.


Now, I've thought of a number of ways to do this. The simplest is to simply compile a list of events and run through them once every second (seconds are the smallest unit of schedulable time). If the system time is greater than the 'scheduled time', then execute the event.

Unfortunately, this would be far too slow. I plan on having at most 1000 stations available, each with multiple future events scheduled at a time. this would result in potentially having to loop through ~4000 scheduled events per tick! No thanks.


So, the current method I'm exploring creates an array - one for every second of time. Of course, I need to limit how far in the future an event can be scheduled, but that's fine. An hour in advance is more than enough - meaning the array only needs to be 3600 seconds (elements) long.

That 'time array' will contain dynamically created TLists of events (so that multiple events can happen at once).

The problem is, with no method pointers available, how in the world can this be done! I suppose I need to somehow pass the 'target' object to the array, along with the 'target' method and parameters. But this is where I'm stuck.

It's probably possible to do this by building another custom type (a "MyEvent" type), which stores the object and the method and the parameters in its fields, all as global objects so I can use a function pointer to that 'MyEvent' object. But how again, how do I point to the particular method I want called?

Perhaps I could make a "TFunctions" type, and store all the methods for my station type in that TFunction type as functions, thus being able to use function pointers to refer to those functions. This way, I'd be able to pass the function pointers to the "MyEvent" object, and separately pass the target object.

If I did this, I wonder if I could even include that "TFunciton" type as a field within my 'station' type.. That's a side question though.


All of these 'options' seem so horribly, unnecessarily complex. All that is needed is a simple method pointer :(

So, are there any suggestions? I'm kinda hoping someone has built something like this Scheduler before and might know of a much simpler way to go about it. Again, it would be easy with method pointers, but as far as I understand we don't have those in BlitzMax.


Thank you for taking the time to read this post!

-NAVY