Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef PokemonAutomation_CommonTools_InterruptableCommands_H
#define PokemonAutomation_CommonTools_InterruptableCommands_H

#include <functional>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Concurrency/Mutex.h"
#include "Common/Cpp/Concurrency/ConditionVariable.h"
#include "Common/Cpp/Concurrency/AsyncTask.h"
Expand Down Expand Up @@ -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<void(ControllerContextType&)>&& lambda);
void dispatch(MoveOnlyFunction<void(ControllerContextType&)>&& lambda);

// Wait for currently running command to finish.
void wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ template <typename ControllerType>
struct AsyncCommandSession<ControllerType>::CommandSet{
CommandSet(
CancellableScope& parent, ControllerType& controller,
std::function<void(ControllerContextType&)>&& lambda
MoveOnlyFunction<void(ControllerContextType&)>&& lambda
);
CancellableHolder<CancellableScope> scope;
ControllerContextType context;
std::function<void(ControllerContextType&)> commands;
MoveOnlyFunction<void(ControllerContextType&)> commands;
};



template <typename ControllerType>
AsyncCommandSession<ControllerType>::CommandSet::CommandSet(
CancellableScope& parent, ControllerType& controller,
std::function<void(ControllerContextType&)>&& lambda
MoveOnlyFunction<void(ControllerContextType&)>&& lambda
)
: scope(parent)
, context(scope, controller)
Expand Down Expand Up @@ -97,7 +97,7 @@ void AsyncCommandSession<ControllerType>::stop_command(){
}
}
template <typename ControllerType>
void AsyncCommandSession<ControllerType>::dispatch(std::function<void(ControllerContextType&)>&& lambda){
void AsyncCommandSession<ControllerType>::dispatch(MoveOnlyFunction<void(ControllerContextType&)>&& lambda){
auto scope_check = m_sanitizer.check_scope();

// Construct the CommandSet outside the lock.
Expand Down
6 changes: 3 additions & 3 deletions SerialPrograms/Source/CommonTools/Async/SuperControlSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <vector>
#include <map>
#include <chrono>
#include <functional>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Time.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -58,7 +58,7 @@ class SuperControlSession{
void operator+=(VisualInferenceCallback& callback);
void operator+=(AudioInferenceCallback& callback);

void register_state_command(size_t state, std::function<bool()>&& action);
void register_state_command(size_t state, MoveOnlyFunction<bool()>&& action);


protected:
Expand Down Expand Up @@ -91,7 +91,7 @@ class SuperControlSession{
std::vector<AudioInferenceCallback*> m_audio_callbacks;

// These are actions
std::map<size_t, std::function<bool()>> m_state_actions;
std::map<size_t, MoveOnlyFunction<bool()>> m_state_actions;

private:
// Run-time state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void SuperControlSession<ControllerType>::operator+=(AudioInferenceCallback& cal
m_audio_callbacks.emplace_back(&callback);
}
template <typename ControllerType>
void SuperControlSession<ControllerType>::register_state_command(size_t state, std::function<bool()>&& action){
void SuperControlSession<ControllerType>::register_state_command(size_t state, MoveOnlyFunction<bool()>&& 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));
Expand Down
6 changes: 3 additions & 3 deletions SerialPrograms/Source/CommonTools/DetectionDebouncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef PokemonAutomation_CommonTools_DetectionDebouncer_H
#define PokemonAutomation_CommonTools_DetectionDebouncer_H

#include <functional>
#include <atomic>
#include "Common/Cpp/MoveOnlyFunction.h"
#include "Common/Cpp/Time.h"

namespace PokemonAutomation{
Expand All @@ -20,7 +20,7 @@ class DetectionDebouncer{
DetectionDebouncer(
Type initial_state,
std::chrono::milliseconds min_streak,
std::function<void(Type)>&& state_reporter
MoveOnlyFunction<void(Type)>&& state_reporter
)
: m_min_streak(min_streak)
, m_state_reporter(std::move(state_reporter))
Expand Down Expand Up @@ -57,7 +57,7 @@ class DetectionDebouncer{

private:
std::chrono::milliseconds m_min_streak;
std::function<void(Type)> m_state_reporter;
MoveOnlyFunction<void(Type)> m_state_reporter;

std::atomic<Type> m_current_reported;
WallClock m_last_match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EscapeFromAttack : public SuperControlSession<ProController>{
GET_ON_SNEASLER,
CLIMBING,
};
void register_state_command(State state, std::function<bool()>&& action){
void register_state_command(State state, MoveOnlyFunction<bool()>&& action){
SuperControlSession::register_state_command((size_t)state, std::move(action));
}
bool run_state_action(State state){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FlagNavigationAir : public SuperControlSession<ProController>{
TURN_RIGHT,
FIND_FLAG,
};
void register_state_command(State state, std::function<bool()>&& action){
void register_state_command(State state, MoveOnlyFunction<bool()>&& action){
SuperControlSession::register_state_command((size_t)state, std::move(action));
}
bool run_state_action(State state){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ LetsGoKillWatcher::LetsGoKillWatcher(
Logger& logger,
Color color, bool trigger_if_detected,
const ImageFloatBox& box,
std::function<void()> on_kill_callback,
MoveOnlyFunction<void()> 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())
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#ifndef PokemonAutomation_PokemonSV_LetsGoKillDetector_H
#define PokemonAutomation_PokemonSV_LetsGoKillDetector_H

#include <functional>
#include <atomic>
#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"
Expand Down Expand Up @@ -39,7 +39,7 @@ class LetsGoKillWatcher : public DetectorToFinder<LetsGoKillDetector>{
Logger& logger,
Color color, bool trigger_if_detected = true,
const ImageFloatBox& box = {0.71, 0.15, 0.04, 0.08},
std::function<void()> on_kill_callback = nullptr,
MoveOnlyFunction<void()> on_kill_callback = nullptr,
std::chrono::milliseconds duration = std::chrono::milliseconds(250)
);

Expand All @@ -52,7 +52,7 @@ class LetsGoKillWatcher : public DetectorToFinder<LetsGoKillDetector>{
private:
Logger& m_logger;
bool m_trigger_if_detected;
std::function<void()> m_on_kill_callback;
MoveOnlyFunction<void()> m_on_kill_callback;

bool m_last_detection;
std::atomic<WallClock> m_last_detected;
Expand Down
Loading