diff --git a/CommonLibSF/include/SFSE/Utilities.h b/CommonLibSF/include/SFSE/Utilities.h index 034b2b75..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,24 +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); } - void add_thread_task(std::function a_fn, std::chrono::milliseconds a_wait_for_ms = 0ms) noexcept + 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_ms); - SFSE::GetTaskInterface()->AddTask(a_fn); + std::this_thread::sleep_for(a_wait_for); + GetTaskInterface()->AddTask(a_fn); }).detach(); } - void add_thread_task_permanent(std::function a_fn, std::chrono::milliseconds a_wait_for_ms = 0ms) noexcept + 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_ms); - SFSE::GetTaskInterface()->AddPermanentTask(a_fn); + std::this_thread::sleep_for(a_wait_for); + GetTaskInterface()->AddPermanentTask(a_fn); }).detach(); } }