Tue, 10 Aug 2021 09:31:50 +0300
* Run once is now guarded and allows any function with any number of parameters
Source/Gorgon/Main.cpp | file | annotate | diff | comparison | revisions | |
Source/Gorgon/Main.h | file | annotate | diff | comparison | revisions |
--- 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<std::function<void()>> once; bool exiting = false; @@ -146,6 +147,9 @@ } void RegisterOnce(std::function<void()> fn) { + std::lock_guard<std::mutex> grd(once_mtx); + once.push_back(fn); } + }
--- 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<void()> fn); + + /// Registers a function to be run at the start of the next frame. + template<class F_, class ...A_> + void RegisterOnce(F_ fn, A_ && ...args) { + RegisterOnce(std::function<void()>(std::bind(fn, std::forward<A_>(args)...))); + } + extern Event<> BeforeFrameEvent; }