The Scheduler (schedule) provides timed events and timed call services for the game.
The function of the Scheduler (schedule) and the function of the event listener (EventListener) are somewhat similar: they invoke a pre-prepared callback function in a particular case.
The difference is that the event listener needs to invoke this prepared callback function by a manual trigger (Trigger), and the scheduler needs to wait until the game has run for a time period (delta_time) and then call the callback function.
The scheduler is typically packaged as a class:
One, need a registration callback function interface, the parameters of this interface may include 1:time, refers to how long it takes to call the registered callback function 2, the callback function needs to call the relevant information
Second, we need to define a struct to hold the whole information of the registered callback function. May include: Timing of the callback, function itself, parameters to be passed, etc.
Third, the above structure is stored in a container, and then in an update to traverse the container, once the time is up, call immediately.
This is probably the case, the specific code I will not post.
Add:
The third step, in fact, if the elements in the container by the callback time to sort, actually do not need to traverse the entire container, each time as long as access to the container's first or tail elements, compare whether to a callable point in time. After that, delete the first or the tail element. This ensures that the first or the trailing element of the container is the first callback function to be called at a time. Without having to traverse the entire container.
Scheduler (Scheduler)