willox / auxtools

Rust library for low-level interfacing with BYOND's virtual machine. Includes a remote debugger for the BYOND DreamMaker language.
MIT License
27 stars 32 forks source link

Added a "priority callbacks" feature #8

Closed Putnam3145 closed 3 years ago

Putnam3145 commented 3 years ago

A feature I've kinda been jonesin' for. I'm using callbacks for my threaded atmos, but callbacks are too "high priority" for it: they're always run, each and every one, each and every tick. So I've changed the default to one that allows for the behavior I desire: only runs if there's enough time left in the tick, only runs as long as there's enough time left in the tick. You can make one with the old behavior with the new Callback::new_priority function. Here's an example of usage:

#define TICK_REMAINING_MS ((Master.current_ticklimit - TICK_USAGE) * world.tick_lag)

/datum/controller/subsystem/callbacks/fire()
    _process_callbacks_priority()
    if(TICK_CHECK || _process_callbacks(MC_TICK_REMAINING_MS))
        pause()