diff --git a/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h b/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h index 6e83ebde75..e797904803 100644 --- a/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h +++ b/Common/Cpp/Concurrency/Backends/AsyncTask_Default.h @@ -7,9 +7,9 @@ #ifndef PokemonAutomation_AsyncTask_Default_H #define PokemonAutomation_AsyncTask_Default_H -#include #include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/SpinPause.h" #include "Common/Cpp/Concurrency/Mutex.h" #include "Common/Cpp/Concurrency/ConditionVariable.h" @@ -50,7 +50,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{ pause(); } } - AsyncTask_Cpp(std::function task) + AsyncTask_Cpp(MoveOnlyFunction task) : m_task(std::move(task)) , m_state(State::NOT_STARTED) {} @@ -102,7 +102,7 @@ class AsyncTask_Cpp : public AsyncTaskCore{ private: - std::function m_task; + MoveOnlyFunction m_task; std::atomic m_state; std::exception_ptr m_exception; diff --git a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp index 297ba275cb..bf5ed9ce7a 100644 --- a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp +++ b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.cpp @@ -90,7 +90,7 @@ WallDuration ThreadPool_Default::cpu_time() const{ return ret; } -AsyncTask ThreadPool_Default::dispatch(std::function&& func){ +AsyncTask ThreadPool_Default::dispatch(MoveOnlyFunction&& func){ AsyncTask task; { std::unique_lock lg(m_lock); @@ -114,7 +114,7 @@ AsyncTask ThreadPool_Default::dispatch(std::function&& func){ m_thread_cv.notify_one(); return task; } -AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function&& func){ +AsyncTask ThreadPool_Default::dispatch_now_blocking(MoveOnlyFunction&& func){ AsyncTask task; { std::unique_lock lg(m_lock); @@ -138,7 +138,7 @@ AsyncTask ThreadPool_Default::dispatch_now_blocking(std::function&& func m_thread_cv.notify_one(); return task; } -AsyncTask ThreadPool_Default::try_dispatch_now(std::function& func){ +AsyncTask ThreadPool_Default::try_dispatch_now(MoveOnlyFunction& func){ AsyncTask task; { std::lock_guard lg(m_lock); diff --git a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h index b2944c630f..d60a7378bb 100644 --- a/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h +++ b/Common/Cpp/Concurrency/Backends/ThreadPool_Default.h @@ -49,9 +49,9 @@ class ThreadPool_Default final : public ThreadPool{ public: - [[nodiscard]] virtual AsyncTask dispatch(std::function&& func) override; - [[nodiscard]] virtual AsyncTask dispatch_now_blocking(std::function&& func) override; - [[nodiscard]] virtual AsyncTask try_dispatch_now(std::function& func) override; + [[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction&& func) override; + [[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction&& func) override; + [[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction& func) override; virtual void run_in_parallel( const std::function& func, diff --git a/Common/Cpp/Concurrency/Backends/Thread_Qt.tpp b/Common/Cpp/Concurrency/Backends/Thread_Qt.tpp index 860c4505c7..3117d8a7b3 100644 --- a/Common/Cpp/Concurrency/Backends/Thread_Qt.tpp +++ b/Common/Cpp/Concurrency/Backends/Thread_Qt.tpp @@ -21,7 +21,7 @@ namespace PokemonAutomation{ // PIMPL implementation - hides std::thread from header struct Thread::Data : public QThread{ - Data(std::function&& function) + Data(MoveOnlyFunction&& function) : m_function(std::move(function)) // , m_finished(false) { @@ -69,7 +69,7 @@ struct Thread::Data : public QThread{ // cout << "exiting: " << this << endl; } - std::function m_function; + MoveOnlyFunction m_function; std::atomic m_finished; }; @@ -95,7 +95,7 @@ Thread::Thread() = default; // Main constructor - starts thread immediately with given function // - Uses CONSTRUCT_TOKEN to construct Pimpl with Data constructor // - Thread starts running immediately (same as std::thread behavior) -Thread::Thread(std::function&& function) +Thread::Thread(MoveOnlyFunction&& function) : m_data(CONSTRUCT_TOKEN, std::move(function)) {} diff --git a/Common/Cpp/Concurrency/Backends/Thread_StdThread.tpp b/Common/Cpp/Concurrency/Backends/Thread_StdThread.tpp index b3e42146f8..9fb090098a 100644 --- a/Common/Cpp/Concurrency/Backends/Thread_StdThread.tpp +++ b/Common/Cpp/Concurrency/Backends/Thread_StdThread.tpp @@ -19,7 +19,7 @@ namespace PokemonAutomation{ struct Thread::Data{ std::thread m_thread; - Data(std::function&& function) + Data(MoveOnlyFunction&& function) : m_thread(std::move(function)) {} }; @@ -45,7 +45,7 @@ Thread::Thread() = default; // Main constructor - starts thread immediately with given function // - Uses CONSTRUCT_TOKEN to construct Pimpl with Data constructor // - Thread starts running immediately (same as std::thread behavior) -Thread::Thread(std::function&& function) +Thread::Thread(MoveOnlyFunction&& function) : m_data(CONSTRUCT_TOKEN, std::move(function)) {} diff --git a/Common/Cpp/Concurrency/Backends/Thread_StdThreadDetach.tpp b/Common/Cpp/Concurrency/Backends/Thread_StdThreadDetach.tpp index 4f78e38949..02c3bcd8fb 100644 --- a/Common/Cpp/Concurrency/Backends/Thread_StdThreadDetach.tpp +++ b/Common/Cpp/Concurrency/Backends/Thread_StdThreadDetach.tpp @@ -25,10 +25,10 @@ struct Thread::Data{ std::thread m_thread; - Data(std::function&& function) + Data(MoveOnlyFunction&& function) : m_stopped(false) , m_thread( - [this, function = std::move(function)]{ + [this, function = std::move(function)]() mutable{ function(); // std::lock_guard lg(m_lock); // m_stopped = true; @@ -60,7 +60,7 @@ Thread::Thread() = default; // Main constructor - starts thread immediately with given function // - Uses CONSTRUCT_TOKEN to construct Pimpl with Data constructor // - Thread starts running immediately (same as std::thread behavior) -Thread::Thread(std::function&& function) +Thread::Thread(MoveOnlyFunction&& function) : m_data(CONSTRUCT_TOKEN, std::move(function)) {} diff --git a/Common/Cpp/Concurrency/FireForgetDispatcher.cpp b/Common/Cpp/Concurrency/FireForgetDispatcher.cpp index 10e1a8a0cb..df021077c3 100644 --- a/Common/Cpp/Concurrency/FireForgetDispatcher.cpp +++ b/Common/Cpp/Concurrency/FireForgetDispatcher.cpp @@ -38,7 +38,7 @@ FireForgetDispatcher::~FireForgetDispatcher(){ stop(); } -void FireForgetDispatcher::dispatch(std::function&& func){ +void FireForgetDispatcher::dispatch(MoveOnlyFunction&& func){ std::lock_guard lg(m_lock); m_queue.emplace_back(std::move(func)); m_cv.notify_one(); @@ -58,7 +58,7 @@ void FireForgetDispatcher::dispatch(std::function&& func){ void FireForgetDispatcher::thread_loop(){ while (true){ - std::function task; + MoveOnlyFunction task; { std::unique_lock lg(m_lock); if (m_stopping){ diff --git a/Common/Cpp/Concurrency/FireForgetDispatcher.h b/Common/Cpp/Concurrency/FireForgetDispatcher.h index 3364284ad7..cb18cc49bc 100644 --- a/Common/Cpp/Concurrency/FireForgetDispatcher.h +++ b/Common/Cpp/Concurrency/FireForgetDispatcher.h @@ -8,7 +8,7 @@ #define PokemonAutomation_FireForgetDispatcher_H #include -#include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Mutex.h" #include "ConditionVariable.h" #include "Thread.h" @@ -23,7 +23,7 @@ class FireForgetDispatcher{ // Dispatch the specified task and return a handle to it. // Call "handle->wait()" to wait for the task to finish. - void dispatch(std::function&& func); + void dispatch(MoveOnlyFunction&& func); void stop(); @@ -32,7 +32,7 @@ class FireForgetDispatcher{ void thread_loop(); private: - std::deque> m_queue; + std::deque> m_queue; Thread m_thread; bool m_stopping; Mutex m_lock; diff --git a/Common/Cpp/Concurrency/ScheduledTaskRunner.cpp b/Common/Cpp/Concurrency/ScheduledTaskRunner.cpp index 488d95bac7..a3378a67e4 100644 --- a/Common/Cpp/Concurrency/ScheduledTaskRunner.cpp +++ b/Common/Cpp/Concurrency/ScheduledTaskRunner.cpp @@ -52,7 +52,7 @@ WallClock ScheduledTaskRunner::next_event() const{ } return m_schedule.begin()->first; } -void ScheduledTaskRunner::add_event(WallClock time, std::function callback){ +void ScheduledTaskRunner::add_event(WallClock time, MoveOnlyFunction callback){ std::lock_guard lg(m_lock); if (m_stopped){ return; @@ -60,7 +60,7 @@ void ScheduledTaskRunner::add_event(WallClock time, std::function callba m_schedule.emplace(time, std::move(callback)); m_cv.notify_all(); } -void ScheduledTaskRunner::add_event(std::chrono::milliseconds time_from_now, std::function callback){ +void ScheduledTaskRunner::add_event(std::chrono::milliseconds time_from_now, MoveOnlyFunction callback){ std::lock_guard lg(m_lock); if (m_stopped){ return; diff --git a/Common/Cpp/Concurrency/ScheduledTaskRunner.h b/Common/Cpp/Concurrency/ScheduledTaskRunner.h index 45b4bc19a0..c7b10f7dae 100644 --- a/Common/Cpp/Concurrency/ScheduledTaskRunner.h +++ b/Common/Cpp/Concurrency/ScheduledTaskRunner.h @@ -10,6 +10,7 @@ #define PokemonAutomation_ScheduledTaskRunner_H #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" //#include "Common/Cpp/CancellableScope.h" #include "Common/Cpp/Concurrency/Mutex.h" @@ -33,8 +34,8 @@ class ScheduledTaskRunner{ // events are scheduled. WallClock next_event() const; - void add_event(WallClock time, std::function callback); - void add_event(std::chrono::milliseconds time_from_now, std::function callback); + void add_event(WallClock time, MoveOnlyFunction callback); + void add_event(std::chrono::milliseconds time_from_now, MoveOnlyFunction callback); // virtual bool cancel(std::exception_ptr exception) noexcept override; @@ -46,7 +47,7 @@ class ScheduledTaskRunner{ ConditionVariable m_cv; bool m_stopped; - std::multimap> m_schedule; + std::multimap> m_schedule; AsyncTask m_runner; }; diff --git a/Common/Cpp/Concurrency/Thread.h b/Common/Cpp/Concurrency/Thread.h index 759d8b3707..97bede7d39 100644 --- a/Common/Cpp/Concurrency/Thread.h +++ b/Common/Cpp/Concurrency/Thread.h @@ -21,7 +21,7 @@ #ifndef PokemonAutomation_Concurrency_Thread_H #define PokemonAutomation_Concurrency_Thread_H -#include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Containers/Pimpl.h" namespace PokemonAutomation{ @@ -42,7 +42,7 @@ class Thread{ // Constructor - starts thread immediately with given function like std::thread // Function is moved (not copied) for efficiency - Thread(std::function&& function); + Thread(MoveOnlyFunction&& function); // Returns true if Thread has valid data (not default-constructed or moved-from) // and not joined. diff --git a/Common/Cpp/Concurrency/ThreadPool.h b/Common/Cpp/Concurrency/ThreadPool.h index 29ea2cf01c..6a47ab3337 100644 --- a/Common/Cpp/Concurrency/ThreadPool.h +++ b/Common/Cpp/Concurrency/ThreadPool.h @@ -17,6 +17,7 @@ #define PokemonAutomation_ThreadPool_H #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" namespace PokemonAutomation{ @@ -40,17 +41,17 @@ class ThreadPool{ // Dispatch the function and return immediately. // The function is not guaranteed to begin running immediately. - [[nodiscard]] virtual AsyncTask dispatch(std::function&& func) = 0; + [[nodiscard]] virtual AsyncTask dispatch(MoveOnlyFunction&& func) = 0; // Dispatch the function and begin running now. // If there are no threads available, it waits until there are. // This function will not return until the function has begin running. - [[nodiscard]] virtual AsyncTask dispatch_now_blocking(std::function&& func) = 0; + [[nodiscard]] virtual AsyncTask dispatch_now_blocking(MoveOnlyFunction&& func) = 0; // Try to dispatch the function and begin running now. // Returns null if no threads are available. "func" will be moved-from only on success. // This function returns immediately. - [[nodiscard]] virtual AsyncTask try_dispatch_now(std::function& func) = 0; + [[nodiscard]] virtual AsyncTask try_dispatch_now(MoveOnlyFunction& func) = 0; // Run function for all the indices [start, end). // Lower indices are not allowed to block on higher indices. diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp b/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp index 068d6ec418..1f5369a0ab 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/SnapshotManager.cpp @@ -5,6 +5,7 @@ */ //#include "Common/Cpp/Concurrency/ReverseLockGuard.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/AsyncTask.h" #include "CommonFramework/ImageTypes/ImageRGB32_Qt.h" #include "CommonFramework/Tools/GlobalThreadPools.h" @@ -100,7 +101,7 @@ bool SnapshotManager::try_dispatch_conversion(uint64_t seqnum, QVideoFrame frame } try{ - std::function lambda = [=, this, frame = std::move(frame)](){ + MoveOnlyFunction lambda = [=, this, frame = std::move(frame)](){ convert(seqnum, std::move(frame), timestamp); }; diff --git a/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.h b/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.h index f0cab8171e..86d360c23e 100644 --- a/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.h +++ b/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.h @@ -7,7 +7,7 @@ #ifndef PokemonAutomation_CommonTools_InterruptableCommands_H #define PokemonAutomation_CommonTools_InterruptableCommands_H -#include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/Mutex.h" #include "Common/Cpp/Concurrency/ConditionVariable.h" #include "Common/Cpp/Concurrency/AsyncTask.h" @@ -44,7 +44,7 @@ class AsyncCommandSession final : private Cancellable{ // previous `dispatch()` while a new `dispatch()` presses button A and button B // at the same time, button A is not released during the transition. // You can use it to adjust button state continuously without interruption. - void dispatch(std::function&& lambda); + void dispatch(MoveOnlyFunction&& lambda); // Wait for currently running command to finish. void wait(); diff --git a/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp b/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp index 193dad2d9b..bc96bbc675 100644 --- a/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp +++ b/SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp @@ -21,11 +21,11 @@ template struct AsyncCommandSession::CommandSet{ CommandSet( CancellableScope& parent, ControllerType& controller, - std::function&& lambda + MoveOnlyFunction&& lambda ); CancellableHolder scope; ControllerContextType context; - std::function commands; + MoveOnlyFunction commands; }; @@ -33,7 +33,7 @@ struct AsyncCommandSession::CommandSet{ template AsyncCommandSession::CommandSet::CommandSet( CancellableScope& parent, ControllerType& controller, - std::function&& lambda + MoveOnlyFunction&& lambda ) : scope(parent) , context(scope, controller) @@ -97,7 +97,7 @@ void AsyncCommandSession::stop_command(){ } } template -void AsyncCommandSession::dispatch(std::function&& lambda){ +void AsyncCommandSession::dispatch(MoveOnlyFunction&& lambda){ auto scope_check = m_sanitizer.check_scope(); // Construct the CommandSet outside the lock. diff --git a/SerialPrograms/Source/CommonTools/Async/SuperControlSession.h b/SerialPrograms/Source/CommonTools/Async/SuperControlSession.h index 62d5ec99e3..b13532bf23 100644 --- a/SerialPrograms/Source/CommonTools/Async/SuperControlSession.h +++ b/SerialPrograms/Source/CommonTools/Async/SuperControlSession.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" namespace PokemonAutomation{ @@ -58,7 +58,7 @@ class SuperControlSession{ void operator+=(VisualInferenceCallback& callback); void operator+=(AudioInferenceCallback& callback); - void register_state_command(size_t state, std::function&& action); + void register_state_command(size_t state, MoveOnlyFunction&& action); protected: @@ -91,7 +91,7 @@ class SuperControlSession{ std::vector m_audio_callbacks; // These are actions - std::map> m_state_actions; + std::map> m_state_actions; private: // Run-time state. diff --git a/SerialPrograms/Source/CommonTools/Async/SuperControlSession.tpp b/SerialPrograms/Source/CommonTools/Async/SuperControlSession.tpp index c8343ecf0e..a5fae0b94e 100644 --- a/SerialPrograms/Source/CommonTools/Async/SuperControlSession.tpp +++ b/SerialPrograms/Source/CommonTools/Async/SuperControlSession.tpp @@ -49,7 +49,7 @@ void SuperControlSession::operator+=(AudioInferenceCallback& cal m_audio_callbacks.emplace_back(&callback); } template -void SuperControlSession::register_state_command(size_t state, std::function&& action){ +void SuperControlSession::register_state_command(size_t state, MoveOnlyFunction&& action){ auto iter = m_state_actions.find(state); if (iter != m_state_actions.end()){ throw InternalProgramError(&m_stream.logger(), PA_CURRENT_FUNCTION, "Duplicate State Enum: " + std::to_string(state)); diff --git a/SerialPrograms/Source/CommonTools/DetectionDebouncer.h b/SerialPrograms/Source/CommonTools/DetectionDebouncer.h index ee4f41cf24..6b071efe88 100644 --- a/SerialPrograms/Source/CommonTools/DetectionDebouncer.h +++ b/SerialPrograms/Source/CommonTools/DetectionDebouncer.h @@ -7,8 +7,8 @@ #ifndef PokemonAutomation_CommonTools_DetectionDebouncer_H #define PokemonAutomation_CommonTools_DetectionDebouncer_H -#include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" namespace PokemonAutomation{ @@ -20,7 +20,7 @@ class DetectionDebouncer{ DetectionDebouncer( Type initial_state, std::chrono::milliseconds min_streak, - std::function&& state_reporter + MoveOnlyFunction&& state_reporter ) : m_min_streak(min_streak) , m_state_reporter(std::move(state_reporter)) @@ -57,7 +57,7 @@ class DetectionDebouncer{ private: std::chrono::milliseconds m_min_streak; - std::function m_state_reporter; + MoveOnlyFunction m_state_reporter; std::atomic m_current_reported; WallClock m_last_match; diff --git a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp index 27142afdf0..af7338714c 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp @@ -79,7 +79,7 @@ DeviceHandle::~DeviceHandle(){ void DeviceHandle::add_message_handler( uint8_t opcode, - std::function handler + MoveOnlyFunction handler ){ auto ret = m_message_handlers.emplace(opcode, std::move(handler)); if (!ret.second){ diff --git a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h index ffbee53f0a..7da7a0bc20 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h +++ b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.h @@ -11,6 +11,7 @@ #include #include #include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/Concurrency/Mutex.h" @@ -38,7 +39,7 @@ class DeviceHandle final : public CancellableScope, private StreamListener{ virtual ~DeviceHandle(); void add_message_handler( uint8_t opcode, - std::function handler + MoveOnlyFunction handler ); virtual bool cancel(std::exception_ptr exception) noexcept override; @@ -196,7 +197,7 @@ class DeviceHandle final : public CancellableScope, private StreamListener{ std::deque m_buffer; MessageLogger m_message_loggers; - std::map> m_message_handlers; + std::map> m_message_handlers; }; diff --git a/SerialPrograms/Source/Integrations/DiscordWebhook.cpp b/SerialPrograms/Source/Integrations/DiscordWebhook.cpp index 30e58621a6..fe7b187e5b 100644 --- a/SerialPrograms/Source/Integrations/DiscordWebhook.cpp +++ b/SerialPrograms/Source/Integrations/DiscordWebhook.cpp @@ -62,7 +62,7 @@ void DiscordWebhookSender::send( const QUrl& url, std::chrono::milliseconds delay, const JsonObject& obj, std::shared_ptr file, - std::function finish_callback + MoveOnlyFunction finish_callback ){ cleanup_stuck_requests(); std::shared_ptr json(new JsonValue(obj.clone())); @@ -75,7 +75,7 @@ void DiscordWebhookSender::send( json = std::move(json), file = std::move(file), finish_callback = std::move(finish_callback) - ]{ + ]() mutable{ throttle(); std::vector attachments; if (file){ @@ -95,7 +95,7 @@ void DiscordWebhookSender::send( const QUrl& url, std::chrono::milliseconds delay, const JsonObject& obj, std::vector> files, - std::function finish_callback + MoveOnlyFunction finish_callback ){ cleanup_stuck_requests(); std::shared_ptr json(new JsonValue(obj.clone())); @@ -108,7 +108,7 @@ void DiscordWebhookSender::send( json = std::move(json), files = std::move(files), finish_callback = std::move(finish_callback) - ]{ + ]() mutable{ throttle(); std::vector attachments; for (auto& file : files){ diff --git a/SerialPrograms/Source/Integrations/DiscordWebhook.h b/SerialPrograms/Source/Integrations/DiscordWebhook.h index 425d3ac7f3..c380e6a172 100644 --- a/SerialPrograms/Source/Integrations/DiscordWebhook.h +++ b/SerialPrograms/Source/Integrations/DiscordWebhook.h @@ -9,6 +9,7 @@ #include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Time.h" #include "Common/Cpp/Concurrency/Mutex.h" #include "Common/Cpp/Concurrency/ConditionVariable.h" @@ -52,14 +53,14 @@ class DiscordWebhookSender : public QObject{ const QUrl& url, std::chrono::milliseconds delay, const JsonObject& obj, std::shared_ptr file, - std::function finish_callback = nullptr + MoveOnlyFunction finish_callback = nullptr ); void send( Logger& logger, const QUrl& url, std::chrono::milliseconds delay, const JsonObject& obj, std::vector> files, - std::function finish_callback = nullptr + MoveOnlyFunction finish_callback = nullptr ); static DiscordWebhookSender& instance(); diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h index f722b93909..90caef4a51 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_Joycon.h @@ -30,7 +30,7 @@ class PABotBase2_JoyCon : PABotBase2::Connection& connection, ControllerClass controller_class, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ) : JoyconType(logger, controller_class) , PABotBase2_OemController( diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp index 4ba3cface9..fa537b9a70 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp @@ -122,7 +122,7 @@ PABotBase2_OemController::PABotBase2_OemController( RecursiveThrottler& logging_throttler, PABotBase2::Connection& connection, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ) : PABotBase2_Controller(logger, logging_throttler, connection) , m_controller_type(controller_type) diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h index f586f83cc4..28bdd3be0d 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.h @@ -8,6 +8,7 @@ #define PokemonAutomation_NintendoSwitch_PABotBase2_OemController_H #include "Common/ControllerStates/NintendoSwitch_OemController_State.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Controllers/ControllerStatusThread.h" #include "Controllers/JoystickTools.h" //#include "NintendoSwitch/NintendoSwitch_Settings.h" @@ -36,7 +37,7 @@ class PABotBase2_OemController : RecursiveThrottler& logging_throttler, PABotBase2::Connection& connection, ControllerType controller_type, - std::function on_rumble + MoveOnlyFunction on_rumble ); ~PABotBase2_OemController(); void stop(); @@ -166,7 +167,7 @@ class PABotBase2_OemController : Milliseconds m_cooldown; Milliseconds m_timing_variation; - std::function m_on_rumble; + MoveOnlyFunction m_on_rumble; std::unique_ptr m_status_thread; diff --git a/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_EscapeFromAttack.h b/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_EscapeFromAttack.h index 370b76c572..d3fe64694e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_EscapeFromAttack.h +++ b/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_EscapeFromAttack.h @@ -46,7 +46,7 @@ class EscapeFromAttack : public SuperControlSession{ GET_ON_SNEASLER, CLIMBING, }; - void register_state_command(State state, std::function&& action){ + void register_state_command(State state, MoveOnlyFunction&& action){ SuperControlSession::register_state_command((size_t)state, std::move(action)); } bool run_state_action(State state){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_FlagNavigationAir.h b/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_FlagNavigationAir.h index 3a5c1ddd8e..8c2d10cd60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_FlagNavigationAir.h +++ b/SerialPrograms/Source/VideoGames/PokemonLA/Programs/PokemonLA_FlagNavigationAir.h @@ -62,7 +62,7 @@ class FlagNavigationAir : public SuperControlSession{ TURN_RIGHT, FIND_FLAG, }; - void register_state_command(State state, std::function&& action){ + void register_state_command(State state, MoveOnlyFunction&& action){ SuperControlSession::register_state_command((size_t)state, std::move(action)); } bool run_state_action(State state){ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.cpp index 2ca84ccb49..adabbccbf2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.cpp @@ -181,13 +181,13 @@ LetsGoKillWatcher::LetsGoKillWatcher( Logger& logger, Color color, bool trigger_if_detected, const ImageFloatBox& box, - std::function on_kill_callback, + MoveOnlyFunction on_kill_callback, std::chrono::milliseconds duration ) : DetectorToFinder("LetsGoKillWatcher", duration, color, box) , m_logger(logger) , m_trigger_if_detected(trigger_if_detected) - , m_on_kill_callback(on_kill_callback) + , m_on_kill_callback(std::move(on_kill_callback)) , m_last_detection(false) , m_last_detected(WallClock::min()) {} diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h b/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h index dde7152198..985e0f4359 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h @@ -7,9 +7,9 @@ #ifndef PokemonAutomation_PokemonSV_LetsGoKillDetector_H #define PokemonAutomation_PokemonSV_LetsGoKillDetector_H -#include #include #include "Common/Cpp/Color.h" +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonTools/Audio/AudioPerSpectrumDetectorBase.h" @@ -39,7 +39,7 @@ class LetsGoKillWatcher : public DetectorToFinder{ Logger& logger, Color color, bool trigger_if_detected = true, const ImageFloatBox& box = {0.71, 0.15, 0.04, 0.08}, - std::function on_kill_callback = nullptr, + MoveOnlyFunction on_kill_callback = nullptr, std::chrono::milliseconds duration = std::chrono::milliseconds(250) ); @@ -52,7 +52,7 @@ class LetsGoKillWatcher : public DetectorToFinder{ private: Logger& m_logger; bool m_trigger_if_detected; - std::function m_on_kill_callback; + MoveOnlyFunction m_on_kill_callback; bool m_last_detection; std::atomic m_last_detected; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp index ed375c9948..c3b2ae25f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp @@ -6,6 +6,7 @@ #include #include +#include "Common/Cpp/MoveOnlyFunction.h" #include "Common/Cpp/Concurrency/SpinLock.h" #include "Common/Cpp/Concurrency/AsyncTask.h" #include "Kernels/Waterfill/Kernels_Waterfill_Session.h" @@ -134,7 +135,7 @@ ShinySparkleSetSwSh find_sparkles(size_t screen_area, WaterfillSession& session) auto finder = session.make_iterator(20); WaterfillObject object; while (finder->find_next(object, true)){ - std::function func = [&, screen_area, object = std::move(object)]{ + MoveOnlyFunction func = [&, screen_area, object = std::move(object)]{ find_sparkles( screen_area, lock,