mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 16:18:19 -10:00
This adds a mechanism for running generic operations at specific points of the frame execution. This can be used by any part of the code an not just Lua since it simply executes std::functions. It also adds an "execution context" concept that specifies in which situation an operation should be executed. This is then used by the Lua Coroutines code for resuming coroutines at specific points instead of always when the awaited promise resolves.
32 lines
455 B
C++
32 lines
455 B
C++
#pragma once
|
|
|
|
#include <utility>
|
|
|
|
namespace util {
|
|
namespace detail {
|
|
template <typename F>
|
|
struct FinalAction {
|
|
FinalAction(F f) : m_finally{std::move(f)} {}
|
|
~FinalAction()
|
|
{
|
|
if (m_enabled) {
|
|
m_finally();
|
|
}
|
|
}
|
|
|
|
void disable() { m_enabled = false; };
|
|
|
|
private:
|
|
F m_finally;
|
|
bool m_enabled{true};
|
|
};
|
|
} // namespace detail
|
|
|
|
template <typename F>
|
|
detail::FinalAction<F> finally(F f)
|
|
{
|
|
return detail::FinalAction<F>(f);
|
|
}
|
|
|
|
} // namespace util
|