mirror of
https://github.com/pragma-/pbot.git
synced 2025-05-03 13:17:33 +02:00
Rename pbot.output_queue_flushed
to pbot.output_queue_empty
This commit is contained in:
parent
7fb48f9b5d
commit
acd9570947
@ -34,6 +34,11 @@ $VERSION = "0.79";
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $proto = shift;
|
my $proto = shift;
|
||||||
|
my %args = @_;
|
||||||
|
|
||||||
|
if (not $args{pbot}) {
|
||||||
|
Carp::croak("Missing pbot reference to " . __PACKAGE__);
|
||||||
|
}
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
'_conn' => [],
|
'_conn' => [],
|
||||||
@ -45,6 +50,7 @@ sub new {
|
|||||||
'_read' => IO::Select->new(),
|
'_read' => IO::Select->new(),
|
||||||
'_timeout' => 0,
|
'_timeout' => 0,
|
||||||
'_write' => IO::Select->new(),
|
'_write' => IO::Select->new(),
|
||||||
|
'_pbot' => $args{pbot},
|
||||||
};
|
};
|
||||||
|
|
||||||
bless $self, $proto;
|
bless $self, $proto;
|
||||||
@ -123,6 +129,8 @@ sub do_one_loop {
|
|||||||
$outputevent->content->{coderef}->(@{$outputevent->content->{args}});
|
$outputevent->content->{coderef}->(@{$outputevent->content->{args}});
|
||||||
}
|
}
|
||||||
$nexttimer = $self->outputqueue->head->time if !$self->outputqueue->is_empty();
|
$nexttimer = $self->outputqueue->head->time if !$self->outputqueue->is_empty();
|
||||||
|
} else {
|
||||||
|
$self->{_pbot}->{event_dispatcher}->dispatch_event('pbot.output_queue_empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
# we don't want to bother waiting on input or running
|
# we don't want to bother waiting on input or running
|
||||||
|
@ -1382,7 +1382,6 @@ sub sl {
|
|||||||
|
|
||||||
if ($seconds == 0) {
|
if ($seconds == 0) {
|
||||||
$self->{_slcount} = 0;
|
$self->{_slcount} = 0;
|
||||||
$self->pbot->{event_dispatcher}->dispatch_event('pbot.output_queue_flushed');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### DEBUG DEBUG DEBUG
|
### DEBUG DEBUG DEBUG
|
||||||
|
@ -172,7 +172,7 @@ sub initialize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# prepare the IRC engine
|
# prepare the IRC engine
|
||||||
$self->{irc} = PBot::IRC->new;
|
$self->{irc} = PBot::IRC->new(pbot => $self);
|
||||||
|
|
||||||
# prepare remaining core PBot modules -- do not change this order
|
# prepare remaining core PBot modules -- do not change this order
|
||||||
$self->{event_queue} = PBot::EventQueue->new(pbot => $self, name => 'PBot event queue', %conf);
|
$self->{event_queue} = PBot::EventQueue->new(pbot => $self, name => 'PBot event queue', %conf);
|
||||||
|
@ -117,7 +117,7 @@ sub initialize {
|
|||||||
|
|
||||||
# receive notification when all messages in IRC output queue have been sent
|
# receive notification when all messages in IRC output queue have been sent
|
||||||
$self->{pbot}->{event_dispatcher}->register_handler(
|
$self->{pbot}->{event_dispatcher}->register_handler(
|
||||||
'pbot.output_queue_flushed', sub { $self->on_output_queue_flushed(@_) }
|
'pbot.output_queue_empty', sub { $self->on_output_queue_empty(@_) }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +129,9 @@ sub unload {
|
|||||||
|
|
||||||
# remove battleship loop event from event queue
|
# remove battleship loop event from event queue
|
||||||
$self->end_game_loop;
|
$self->end_game_loop;
|
||||||
|
|
||||||
|
# remove event handler
|
||||||
|
$self->{pbot}->{event_dispatcher}->remove_handler('pbot.output_queue_empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
# the game is paused at the beginning when sending the player boards to all
|
# the game is paused at the beginning when sending the player boards to all
|
||||||
@ -138,7 +141,7 @@ sub unload {
|
|||||||
# disconnected with 'excess flood'). this event handler resumes the game once
|
# disconnected with 'excess flood'). this event handler resumes the game once
|
||||||
# the boards have finished transmitting, unless the game was manually paused
|
# the boards have finished transmitting, unless the game was manually paused
|
||||||
# by a player.
|
# by a player.
|
||||||
sub on_output_queue_flushed {
|
sub on_output_queue_empty {
|
||||||
my ($self) = @_; # we don't care about the other event arguments
|
my ($self) = @_; # we don't care about the other event arguments
|
||||||
|
|
||||||
# unless paused by a player, resume the game
|
# unless paused by a player, resume the game
|
||||||
@ -312,7 +315,7 @@ sub cmd_battleship {
|
|||||||
$self->{state_data}->{paused} = 1;
|
$self->{state_data}->{paused} = 1;
|
||||||
|
|
||||||
# this pause was set by a player.
|
# this pause was set by a player.
|
||||||
# this is used by on_output_queue_flushed() to know if it's okay to unpause automatically
|
# this is used by on_output_queue_empty() to know if it's okay to unpause automatically
|
||||||
$self->{state_data}->{paused_by_player} = 1;
|
$self->{state_data}->{paused_by_player} = 1;
|
||||||
} else {
|
} else {
|
||||||
$self->{state_data}->{paused} = 0;
|
$self->{state_data}->{paused} = 0;
|
||||||
@ -1394,7 +1397,7 @@ sub state_showboard {
|
|||||||
# this is due to output pacing; the messages are trickled out slowly
|
# this is due to output pacing; the messages are trickled out slowly
|
||||||
# to avoid overflowing the ircd's receive queue. we do not want the
|
# to avoid overflowing the ircd's receive queue. we do not want the
|
||||||
# game state to advance while the messages are being sent out. the
|
# game state to advance while the messages are being sent out. the
|
||||||
# game will resume when the `pbot.output_queue_flushed` notification
|
# game will resume when the `pbot.output_queue_empty` notification
|
||||||
# is received.
|
# is received.
|
||||||
$state->{paused} = 1;
|
$state->{paused} = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user