Scheduler (Scheduler)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.