-
-
Save james4k/cdb71d9d64cac42e4a78ea96b2064f94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static var runNextFrameMutex = new Mutex(); | |
private static var runNextFrameQueue0 = new Array<Void->Void>(); | |
private static var runNextFrameQueue1 = new Array<Void->Void>(); | |
private static var runOnExitFrameMutex = new Mutex(); | |
private static var runOnExitFrameQueue0 = new Array<Void->Void>(); | |
private static var runOnExitFrameQueue1 = new Array<Void->Void>(); | |
// runNextFrame calls func at the beginning of the next ENTER_FRAME event. | |
// Can be used in a job to synchronize by writing data on the next frame. | |
public static function runNextFrame(func:Void->Void):Void | |
{ | |
runNextFrameMutex.acquire(); | |
runNextFrameQueue0.push(func); | |
runNextFrameMutex.release(); | |
} | |
// runOnExitFrame calls func at the beginning of the next EXIT_FRAME event. | |
public static function runOnExitFrame(func:Void->Void):Void | |
{ | |
runOnExitFrameMutex.acquire(); | |
runOnExitFrameQueue0.push(func); | |
runOnExitFrameMutex.release(); | |
} | |
public static function onEnterFrame():Void | |
{ | |
runNextFrameMutex.acquire(); | |
var tmp = runNextFrameQueue0; | |
runNextFrameQueue0 = runNextFrameQueue1; | |
runNextFrameQueue1 = tmp; | |
runNextFrameMutex.release(); | |
if (runNextFrameQueue1.length > 0) | |
{ | |
for (func in runNextFrameQueue1) | |
{ | |
func(); | |
} | |
cpp.NativeArray.setSize(runNextFrameQueue1, 0); | |
} | |
} | |
public static function onExitFrame():Void | |
{ | |
runOnExitFrameMutex.acquire(); | |
var tmp = runOnExitFrameQueue0; | |
runOnExitFrameQueue0 = runOnExitFrameQueue1; | |
runOnExitFrameQueue1 = tmp; | |
runOnExitFrameMutex.release(); | |
if (runOnExitFrameQueue1.length > 0) | |
{ | |
for (func in runOnExitFrameQueue1) | |
{ | |
func(); | |
} | |
cpp.NativeArray.setSize(runOnExitFrameQueue1, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment