/[VRac]/Screen.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 161 by dpavlin, Sun Aug 5 19:44:20 2007 UTC revision 171 by dpavlin, Mon Aug 6 11:40:21 2007 UTC
# Line 14  use Carp qw/confess/; Line 14  use Carp qw/confess/;
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15    
16  use Exporter 'import';  use Exporter 'import';
17  our @EXPORT = qw'$white $black';  our @EXPORT = qw'$white $black @flip';
18    
19  use base qw(Class::Accessor Prefs);  use base qw(Class::Accessor Prefs);
20  __PACKAGE__->mk_accessors(qw(app event));  __PACKAGE__->mk_accessors(qw(app event));
# Line 245  Check SDL event loop if there are any pe Line 245  Check SDL event loop if there are any pe
245  =cut  =cut
246    
247  my $pending_key;  my $pending_key;
248    my $key_active;
249  my $run_for = 2000;  my $run_for = 2000;
250    
251  sub key_pressed {  sub key_pressed {
# Line 262  sub key_pressed { Line 263  sub key_pressed {
263                          if ( $state ) {                          if ( $state ) {
264                                  $pending_key = $key;                                  $pending_key = $key;
265                                  $self->key_down( $key );                                  $self->key_down( $key );
266                                    $key_active->{$key} = 1;
267                          } else {                          } else {
268                                  undef $pending_key;                                  undef $pending_key;
269                                  $self->key_up( $key );                                  $self->key_up( $key );
270                                    $key_active->{$key} = 0;
271                          }                          }
272                  }                  }
273                  return $pending_key;                  return $pending_key;
# Line 286  sub key_pressed { Line 289  sub key_pressed {
289                          warn "SDL_KEYDOWN ($type) = '$k'", $just_checking ? ' fake' : '', "\n";                          warn "SDL_KEYDOWN ($type) = '$k'", $just_checking ? ' fake' : '', "\n";
290                          $pending_key = $k;                          $pending_key = $k;
291                          $self->key_down( $k );                          $self->key_down( $k );
292                            $key_active->{$k} = 1;
293                          $self->record_session('key_pressed', { $k => 1 });                          $self->record_session('key_pressed', { $k => 1 });
294                  }                  }
295          } elsif ( $type == SDL_KEYUP ) {          } elsif ( $type == SDL_KEYUP ) {
296                  my $up = $event->key_name();                  my $up = $event->key_name();
297                  warn "SDL_KEYUP ($type) = '$up'", $just_checking ? ' fake' : '', "\n";                  warn "SDL_KEYUP ($type) = '$up'", $just_checking ? ' fake' : '', "\n";
298                  $self->key_up( $up );                  $self->key_up( $up );
299                    $key_active->{$up} = 0;
300                  $self->record_session('key_pressed', { $up => 0 });                  $self->record_session('key_pressed', { $up => 0 });
301                  undef $pending_key;                  undef $pending_key;
302          }          }
# Line 301  sub key_pressed { Line 306  sub key_pressed {
306          return $pending_key;          return $pending_key;
307  }  }
308    
309    =head2 key_active
310    
311    Is key currently pressed on keyboard or in session?
312    
313      $self->key_active( 'left shift', 'right shift', 'a' );
314    
315    =cut
316    
317    sub key_active {
318            my $self = shift;
319            my @keys = @_;
320            confess "Regexp is no longer supported" if ref($_[0]) eq 'Regexp';
321    
322            my $active = 0;
323            foreach my $key ( @keys ) {
324                    $active++ if $key_active->{$key};
325            }
326    
327            warn "## key_active(",dump(@keys),") = $active\n" if $active;
328            return $active;
329    }
330    
331  =head2 loop  =head2 loop
332    
333  Implement CPU run for C<$run_run> cycles inside SDL event loop  Implement CPU run for C<$run_run> cycles inside SDL event loop
# Line 326  sub loop { Line 353  sub loop {
353          }          }
354  }  }
355    
356    # helper array to flip bytes for display
357    our @flip;
358    
359    foreach my $i ( 0 .. 255 ) {
360            my $t = 0;
361            $i & 0b00000001 and $t = $t | 0b10000000;
362            $i & 0b00000010 and $t = $t | 0b01000000;
363            $i & 0b00000100 and $t = $t | 0b00100000;
364            $i & 0b00001000 and $t = $t | 0b00010000;
365            $i & 0b00010000 and $t = $t | 0b00001000;
366            $i & 0b00100000 and $t = $t | 0b00000100;
367            $i & 0b01000000 and $t = $t | 0b00000010;
368            $i & 0b10000000 and $t = $t | 0b00000001;
369            #warn "$i = $t\n";
370            $flip[$i] = $t;
371    }
372    
373  =head1 SEE ALSO  =head1 SEE ALSO
374    
375  L<Orao> is sample implementation using this module  L<Orao> is sample implementation using this module

Legend:
Removed from v.161  
changed lines
  Added in v.171

  ViewVC Help
Powered by ViewVC 1.1.26