Skip to content

Commit

Permalink
SDL::Deprecated updated. quit is now stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaizer committed Oct 3, 2010
1 parent dbf726d commit f23b4c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/SDLx/Controller.pm
Expand Up @@ -16,7 +16,7 @@ use Scalar::Util 'refaddr';
my %_dt; my %_dt;
my %_min_t; my %_min_t;
my %_current_time; my %_current_time;
my %_quit; my %_stop;
my %_event; my %_event;
my %_event_handlers; my %_event_handlers;
my %_move_handlers; my %_move_handlers;
Expand All @@ -38,7 +38,7 @@ sub new {
$_dt{ refaddr $self} = defined $args{dt} ? $args{dt} : 0.1; $_dt{ refaddr $self} = defined $args{dt} ? $args{dt} : 0.1;
$_min_t{ refaddr $self} = defined $args{min_t} ? $args{min_t} : 1 / 60; $_min_t{ refaddr $self} = defined $args{min_t} ? $args{min_t} : 1 / 60;
# $_current_time{ refaddr $self} = $args{current_time} || 0; #no point # $_current_time{ refaddr $self} = $args{current_time} || 0; #no point
$_quit{ refaddr $self} = $args{quit}; $_stop{ refaddr $self} = $args{stop};
$_event{ refaddr $self} = $args{event} || SDL::Event->new(); $_event{ refaddr $self} = $args{event} || SDL::Event->new();
$_event_handlers{ refaddr $self} = $args{event_handlers}; $_event_handlers{ refaddr $self} = $args{event_handlers};
$_move_handlers{ refaddr $self} = $args{move_handlers}; $_move_handlers{ refaddr $self} = $args{move_handlers};
Expand All @@ -56,7 +56,7 @@ sub DESTROY {
delete $_dt{ refaddr $self}; delete $_dt{ refaddr $self};
delete $_min_t{ refaddr $self}; delete $_min_t{ refaddr $self};
delete $_current_time{ refaddr $self}; delete $_current_time{ refaddr $self};
delete $_quit{ refaddr $self}; delete $_stop{ refaddr $self};
delete $_event{ refaddr $self}; delete $_event{ refaddr $self};
delete $_event_handlers{ refaddr $self}; delete $_event_handlers{ refaddr $self};
delete $_move_handlers{ refaddr $self}; delete $_move_handlers{ refaddr $self};
Expand All @@ -72,7 +72,7 @@ sub run {
my $min_t = $_min_t{ refaddr $self}; my $min_t = $_min_t{ refaddr $self};
my $t = 0.0; my $t = 0.0;
$_current_time{ refaddr $self} = Time::HiRes::time; $_current_time{ refaddr $self} = Time::HiRes::time;
while ( !$_quit{ refaddr $self} ) { while ( !$_stop{ refaddr $self} ) {
$self->_event; $self->_event;


my $new_time = Time::HiRes::time; my $new_time = Time::HiRes::time;
Expand Down Expand Up @@ -135,7 +135,7 @@ sub _show {
} }
} }


sub quit { $_quit{ refaddr $_[0] } = 1 } sub stop { $_stop{ refaddr $_[0] } = 1 }


sub _add_handler { sub _add_handler {
my ( $hash_ref, $num_ref, $handler ) = @_; my ( $hash_ref, $num_ref, $handler ) = @_;
Expand Down
13 changes: 13 additions & 0 deletions lib/pods/SDL/Deprecated.pod
Expand Up @@ -11,6 +11,19 @@ Core


=head1 RELEASES =head1 RELEASES


=head2 2.5xx

Major changes to C<SDLx::Controller>.

C<quit> is now C<stop>. Event handlers no longer end C<run> on returning false. Call C<stop> explicitly instead.

The first argument to move handlers is the step portion instead of C<dt>.
The second argument to move handlers, the C<t> value, is now the third argument.

The handle holders are now hashes instead of arrays.

C<min_t> will limit apps to a framerate of 60 by default.

=head2 2.513 =head2 2.513


=over =over
Expand Down
10 changes: 5 additions & 5 deletions lib/pods/SDLx/Controller.pod
Expand Up @@ -73,7 +73,7 @@ Returns the new object.
=head2 run =head2 run


After creating and setting up your handlers (see below), call this method to After creating and setting up your handlers (see below), call this method to
activate the main loop. The main loop will run until C<quit> is called. activate the main loop. The main loop will run until C<stop> is called.


All hooked functions will be called during the main loop, in this order: All hooked functions will be called during the main loop, in this order:


Expand All @@ -90,7 +90,7 @@ All hooked functions will be called during the main loop, in this order:
Please refer to each handler below for information on received arguments. Please refer to each handler below for information on received arguments.
Note that the second argument every callback recieves is the C<SDLx::Controller> object. Note that the second argument every callback recieves is the C<SDLx::Controller> object.


=head2 quit =head2 stop


Returns from the C<run> loop. Returns from the C<run> loop.


Expand Down Expand Up @@ -137,13 +137,13 @@ order. Returns the order queue number of the added callback.
The first argument passed to registered callbacks is the L<< SDL::Event >> object. The first argument passed to registered callbacks is the L<< SDL::Event >> object.
The second is the C<SDLx::Controller> object. The second is the C<SDLx::Controller> object.


sub quit { sub stop {
my ($event, $app) = @_; my ($event, $app) = @_;
if($event->type == SDL_QUIT) { if($event->type == SDL_QUIT) {
$controller->quit; $controller->stop;
} }
} }
$controller->add_event_handler(\&quit); $controller->add_event_handler(\&stop);


=head2 add_move_handler =head2 add_move_handler


Expand Down
4 changes: 2 additions & 2 deletions t/sdlx_controller.t
Expand Up @@ -12,7 +12,7 @@ use lib 't/lib';
can_ok( can_ok(
'SDLx::Controller', 'SDLx::Controller',
qw( qw(
new quit dt min_t new run stop pause dt min_t current_time
add_move_handler add_event_handler add_show_handler add_move_handler add_event_handler add_show_handler
remove_move_handler remove_event_handler remove_show_handler remove_move_handler remove_event_handler remove_show_handler
remove_all_move_handlers remove_all_event_handlers remove_all_show_handlers remove_all_move_handlers remove_all_event_handlers remove_all_show_handlers
Expand Down Expand Up @@ -57,7 +57,7 @@ sub test_move {
sub test_show { sub test_show {
my $ticks = shift; my $ticks = shift;
ok( $ticks >= 0.5, "show handle \$_[0] of $ticks was >= 0.5" ); ok( $ticks >= 0.5, "show handle \$_[0] of $ticks was >= 0.5" );
$app->quit(); $app->stop();
} }


$app->add_move_handler(\&test_move); $app->add_move_handler(\&test_move);
Expand Down
2 changes: 1 addition & 1 deletion t/sdlx_controller_interface.t
Expand Up @@ -88,7 +88,7 @@ $controller->add_event_handler( sub { $counts->[0]++; return 0 if $interface->cu


$interface->set_acceleration( $interface->set_acceleration(
sub { sub {
$controller->quit() if $counts->[1] > 100; $controller->stop() if $counts->[1] > 100;
$counts->[1]++; $counts->[1]++;
isa_ok( $_[1], 'SDLx::Controller::State', '[Controller] called acceleration and gave us a state' ), isa_ok( $_[1], 'SDLx::Controller::State', '[Controller] called acceleration and gave us a state' ),
return ( 10, 10, 10 ); return ( 10, 10, 10 );
Expand Down

0 comments on commit f23b4c9

Please sign in to comment.