Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event macro slot system #2781

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Event macro slot system #2781

wants to merge 17 commits into from

Conversation

Henrybk
Copy link
Contributor

@Henrybk Henrybk commented Jun 2, 2019

Adding a way for eventMacro to run multiple macros at the same time has always been something I wanted but I never made. Today I decided to come up with a simple system to make it work, this is still very much a work is progress (as the many "TODO" messages may indicate).

There are some design decisions I have want/need help with.

How should we handle the AI queue while we have 1 or more macros running? What if one is overrideAI 1 and the others are not? What if they all are overrideAI 0 or 1?

How should the commands be changed to accompany these changes?

The code as it is now only supports multiple macros if they are all "overrideAI 1".

Example:

@edit:

Well, I guess the code is now working nicely, I fixed all the bugs I could find, fixed the command and the overrideAI problem.

@ya4ept
Copy link
Contributor

ya4ept commented Jun 3, 2019

what is the difference between options "priority" and "slot"?

@Henrybk
Copy link
Contributor Author

Henrybk commented Jun 3, 2019

@ya4ept Priority hasn`t changed at all.

Slots separate macros and automacros into different "instances", as is all macros and automacros using slot 1 will be totally independent from those using slot 2 or 3 or etc.

While a macro is running at slot 1, in slot 2 there can be a few automacros checking for conditions, and another macro running at the same time in slot 7

This makes it possible to run multiple macros at the same time and to also run automacro checking during macro runtime.

@Nipodemos
Copy link
Contributor

automacro alpha {
    BaseLevel > 0
    exclusive 1
    slot 1
    call {
        $i = 0
        while ($i < 10) {
            pause 2
            $i++
            log alpha automacro running on slot 1 for &eval(2*$i) seconds
        }
    }
}

automacro beta {
    BaseLevel > 0
    exclusive 1
    slot 2
    timeout 3
    call {
        log beta automacro running on slot 2
    }
}

image
worked here with overrideAI 0 on both

@marchewka997
Copy link

great update!

@@ -132,6 +132,9 @@ sub set_parameters {
if (!defined $self->{parameters}{'repeat'}) {
$self->{parameters}{'repeat'} = 1;
}
if (!defined $self->{parameters}{'slot'}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a 1-based counting system (ie, there's no slot zero), you could do:

$self->{parameters}{'slot'} ||= 1;

@@ -67,6 +67,12 @@ sub new {
$self->repeat(1);
}

if (defined $slot && $slot =~ /^\d+$/) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should slot 0 be allowed?

# Adds the current macro to the already existent eventMacro sequence in AI queue
sub register_add {
my ($self, $macro_args) = @_;
debug "[eventMacro] Macro '".$self->{name}."' is now adding itself to the eventMacro sequente in AI queue.\n", "eventMacro", 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequente => sequence

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this message match the phrasing in register_new? Same for unregister and register_remove.

"eventMacro check force_start: forces the start of automacros checking\n".
"eventMacro check resume: return automacros checking to the normal state\n";
return;
if (!defined $params[0] || (defined $params[0] && $params[0] ne 'force_stop' && $params[0] ne 'force_start' && $params[0] ne 'resume')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs vs spaces.

my $slot = $params[1];

if ($slot !~ /^\d+$/) {
message "[eventMacro] '".$slot."' is not a valid option\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allow people to target macros by the name of the running routine? So slot could be foo if the running macro's name is foo. Targeting by slots could be hard, since slots are allocated automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slots are not allocated automatically, they are defined in the automacro or in the plugin command.

@Nipodemos
Copy link
Contributor

bug report:

sometimes eventMacro is not removing itself from AI queue, making bot simply doing anything. Despite that, all automacros triggers normally.

The only solution i've found is to run ai clear, when immediately go back to work properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants