# HG changeset patch # User cemkalyoncu # Date 1628577110 -10800 # Node ID 92bb193f0a6e1c73f9eb3cef72caba03f463c3af # Parent 20deab12df40516749123d63ddacaedab749b370 * Run once is now guarded and allows any function with any number of parameters diff -r 20deab12df40 -r 92bb193f0a6e Source/Gorgon/Main.cpp --- a/Source/Gorgon/Main.cpp Sun Aug 01 13:04:07 2021 +0300 +++ b/Source/Gorgon/Main.cpp Tue Aug 10 09:31:50 2021 +0300 @@ -58,6 +58,7 @@ Event<> BeforeFrameEvent; + std::mutex once_mtx; std::vector> once; bool exiting = false; @@ -146,6 +147,9 @@ } void RegisterOnce(std::function fn) { + std::lock_guard grd(once_mtx); + once.push_back(fn); } + } diff -r 20deab12df40 -r 92bb193f0a6e Source/Gorgon/Main.h --- a/Source/Gorgon/Main.h Sun Aug 01 13:04:07 2021 +0300 +++ b/Source/Gorgon/Main.h Tue Aug 10 09:31:50 2021 +0300 @@ -60,6 +60,13 @@ /// Registers a function to be run at the start of the next frame. void RegisterOnce(std::function fn); + + /// Registers a function to be run at the start of the next frame. + template + void RegisterOnce(F_ fn, A_ && ...args) { + RegisterOnce(std::function(std::bind(fn, std::forward(args)...))); + } + extern Event<> BeforeFrameEvent; }