1 decade ago by FelipeBudinich
I've been trying without luck to implement debouncing on Impact in order to lighten the load of my AI (for a clear explanation and the place I got this idea and code snippet from: click here )
The idea is that I don't need each entity to know if it's on-screen every frame, or if the mouse is over it every frame, or if the win condition was met every frame, etc
Any ideas would be welcome ;)
Function.prototype.debounce = function (threshold, execAsap) { var func = this, // reference to original function timeout; // handle to setTimeout async task (detection period) // return the new debounced function which executes the original function only once // until the detection period expires return function debounced() { var obj = this, // reference to original context object args = arguments; // arguments at execution time // this is the detection function. it will be executed if/when the threshold expires function delayed() { // if we're executing at the end of the detection period if (!execAsap) { // execute now func.apply(obj, args); } // clear timeout handle timeout = null; } // stop any current detection period if (timeout) { // otherwise, if we're not already waiting and we're executing at the beginning of the waiting period clearTimeout(timeout); } else if (execAsap) { // execute now func.apply(obj, args); } // reset the waiting period timeout = setTimeout(delayed, threshold || 100); }; };
The idea is that I don't need each entity to know if it's on-screen every frame, or if the mouse is over it every frame, or if the win condition was met every frame, etc
Any ideas would be welcome ;)