Permalink
Browse files

paused method for controller. sdlx music docs. added a few things to …

….gitignore
  • Loading branch information...
Blaizer committed Mar 21, 2011
1 parent b5f2382 commit 0198693ec99783081ac28df0b0dffcbe05d2d6fb
Showing with 350 additions and 23 deletions.
  1. +6 −0 .gitignore
  2. +20 −20 lib/SDLx/Controller.pm
  3. +2 −3 lib/pods/SDLx/Controller.pod
  4. +322 −0 lib/pods/SDLx/Music.pod
View
@@ -32,3 +32,9 @@ MANIFEST
*.bak
*_def.old
*.ERR
+*Thumbs.db
+Build.bat
+*.base
+*.def
+*.exp
+*.lds
View
@@ -34,9 +34,9 @@ sub new {
my $a;
$self = bless \$a, $self;
}
-
+
my $ref = refaddr $self;
-
+
$_dt{ $ref } = defined $args{dt} ? $args{dt} : 0.1;
$_min_t{ $ref } = defined $args{min_t} ? $args{min_t} : 1 / 60;
# $_current_time{ $ref } = $args{current_time} || 0; #no point
@@ -47,6 +47,7 @@ sub new {
$_show_handlers{ $ref } = $args{show_handlers} || [];
$_sleep_cycle{ $ref } = $args{delay};
$_eoq{$ref} = $args{exit_on_quit} || $args{eoq} || 0;
+# $_paused{ $ref } = $args{paused}; #read only
return $self;
}
@@ -70,13 +71,13 @@ sub DESTROY {
sub run {
my ($self) = @_;
- my $ref = refaddr $self;
+ my $ref = refaddr $self;
my $dt = $_dt{ $ref };
my $min_t = $_min_t{ $ref };
my $t = 0.0;
- #Allows us to do stop and run
- $_stop{ $ref } = 0;
+ #Allows us to do stop and run
+ $_stop{ $ref } = 0;
$_current_time{ $ref } = Time::HiRes::time;
while ( !$_stop{ $ref } ) {
@@ -96,17 +97,16 @@ sub run {
my $step = $delta_copy / $dt;
$self->_move( $ref, $step, $t ); #a partial move
$t += $dt * $step;
-
+
$self->_show( $ref, $delta_time );
-
+
$dt = $_dt{ $ref}; #these can change
$min_t = $_min_t{ $ref}; #during the cycle
SDL::delay( $_sleep_cycle{ $ref } ) if $_sleep_cycle{ $ref };
}
}
-*eoq = \&exit_on_quit; # alias
sub exit_on_quit {
my ($self, $value) = @_;
@@ -117,22 +117,22 @@ sub exit_on_quit {
return $_eoq{$ref};
}
+*eoq = \&exit_on_quit; # alias
sub pause {
my ($self, $callback) = @_;
my $ref = refaddr $self;
$callback ||= sub {1};
my $event = SDL::Event->new();
- $_paused{ $ref } = 1;
+ $_paused{ $ref} = 1;
while(1) {
SDL::Events::wait_event($event) or Carp::confess("pause failed waiting for an event");
if($callback->($event, $self)) {
$_current_time{ $ref} = Time::HiRes::time; #so run doesn't catch up with the time paused
last;
}
}
-
- delete $_paused{$ref};
+ delete $_paused{ $ref};
}
sub _event {
@@ -191,10 +191,10 @@ sub add_show_handler {
sub _remove_handler {
my ( $arr_ref, $id ) = @_;
if ( ref $id ) {
- ($id) = grep {
+ ($id) = grep {
$id eq $arr_ref->[$_]
} 0..$#{$arr_ref};
-
+
if ( !defined $id ) {
Carp::cluck("$id is not currently a handler of this type");
return;
@@ -243,25 +243,25 @@ sub show_handlers { $_show_handlers{ refaddr $_[0] } }
sub dt {
my ($self, $arg) = @_;
- my $ref = refaddr $self;
+ my $ref = refaddr $self;
$_dt{ $ref} = $arg if defined $arg;
-
+
$_dt{ $ref};
}
sub min_t {
my ($self, $arg) = @_;
- my $ref = refaddr $self;
+ my $ref = refaddr $self;
$_min_t{ $ref} = $arg if defined $arg;
-
+
$_min_t{ $ref};
}
sub current_time {
my ($self, $arg) = @_;
- my $ref = refaddr $self;
+ my $ref = refaddr $self;
$_current_time{ $ref} = $arg if defined $arg;
-
+
$_current_time{ $ref};
}
@@ -275,7 +275,7 @@ sub _exit_on_quit {
$self->stop() if $event->type == SDL_QUIT;
}
-1; #not 42 man!
+1;
__END__
@@ -117,7 +117,7 @@ This can be used to easily implement a pause when the app loses focus:
sub window {
my ($e, $app) = @_;
if($e->type == SDL_QUIT) {
- $app->stop;
+ $app->stop;
# quit handling is here so that the app
# can be stopped while paused
}
@@ -129,7 +129,7 @@ This can be used to easily implement a pause when the app loses focus:
else {
$app->pause(\&window);
# recursive, but only once since the window
- # can't lose focus again without gaining is first
+ # can't lose focus again without gaining it first
}
}
}
@@ -168,7 +168,6 @@ This is only useful when used within code that will be run by C<pause>:
return 0;
}
-
=head2 add_event_handler
Register a callback to handle events. You can add as many subs as you need.
Oops, something went wrong.

0 comments on commit 0198693

Please sign in to comment.