diff --git a/CommonLibSF/include/SFSE/Utilities.h b/CommonLibSF/include/SFSE/Utilities.h index 0591e415..43d8bb26 100644 --- a/CommonLibSF/include/SFSE/Utilities.h +++ b/CommonLibSF/include/SFSE/Utilities.h @@ -8,8 +8,8 @@ namespace SFSE::stl template constexpr void write_thunk_call(const std::uintptr_t a_address) noexcept { - SFSE::AllocTrampoline(14); - auto& trampoline = SFSE::GetTrampoline(); + AllocTrampoline(14); + auto& trampoline = GetTrampoline(); T::func = trampoline.write_call(a_address, T::thunk); } @@ -35,8 +35,38 @@ namespace SFSE::stl template constexpr void write_thunk_jump(const std::uintptr_t a_src) noexcept { - SFSE::AllocTrampoline(14); - auto& trampoline = SFSE::GetTrampoline(); + AllocTrampoline(14); + auto& trampoline = GetTrampoline(); T::func = trampoline.write_branch(a_src, T::thunk); } + + namespace detail + { + template + struct is_chrono_duration : std::false_type + {}; + + template + struct is_chrono_duration> : std::true_type + {}; + + template + concept is_duration = is_chrono_duration::value; + } + + void add_thread_task(const std::function a_fn, detail::is_duration auto a_wait_for = 0ms) noexcept + { + std::jthread([=] { + std::this_thread::sleep_for(a_wait_for); + GetTaskInterface()->AddTask(a_fn); + }).detach(); + } + + void add_thread_task_permanent(const std::function a_fn, detail::is_duration auto a_wait_for = 0ms) noexcept + { + std::jthread([=] { + std::this_thread::sleep_for(a_wait_for); + GetTaskInterface()->AddPermanentTask(a_fn); + }).detach(); + } }