/[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 152 by dpavlin, Sun Aug 5 15:24:22 2007 UTC revision 165 by dpavlin, Mon Aug 6 07:04:40 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 23  __PACKAGE__->mk_accessors(qw(app event)) Line 23  __PACKAGE__->mk_accessors(qw(app event))
23    
24  Screen - simulated 256*256 pixels monochrome screen using SDL  Screen - simulated 256*256 pixels monochrome screen using SDL
25    
26    =head1 Architecture dependent
27    
28    You may override following methods if you want to implement keyboard on each
29    keypress event. Alternative is to use <read> hook and trap memory access.
30    
31    =head2 key_down
32    
33      $self->key_down( 'a' );
34    
35    =cut
36    
37    sub key_down {}
38    
39    =head2 key_up
40    
41      $self->key_up( 'a' );
42    
43    =cut
44    
45    sub key_up {}
46    
47    
48    =head1 Architecture independent
49    
50    You don't need to override any of following function in your architecture,
51    but you might want to call them.
52    
53  =head2 open_screen  =head2 open_screen
54    
55  Open simulated screen  Open simulated screen
# Line 49  sub open_screen { Line 76  sub open_screen {
76          );          );
77          #$app->grab_input( SDL_GRAB_QUERY );          #$app->grab_input( SDL_GRAB_QUERY );
78          $app->grab_input( SDL_GRAB_OFF );          $app->grab_input( SDL_GRAB_OFF );
79          $app->title( ref($self) . ' ' . $self::VERSION );          $app->title( ref($self) );
80    
81          $self->app( $app );          $self->app( $app );
82    
# Line 220  Check SDL event loop if there are any pe Line 247  Check SDL event loop if there are any pe
247  my $pending_key;  my $pending_key;
248  my $run_for = 2000;  my $run_for = 2000;
249    
 my $key_down;  
   
 sub key_down {  
         my $self = shift;  
         my $key = shift;  
         warn "key_down($key) = ",$key_down->{$key}, "\n" if $self->debug;  
         return $key_down->{$key};  
 }  
   
250  sub key_pressed {  sub key_pressed {
251          my $self = shift;          my $self = shift;
252    
# Line 238  sub key_pressed { Line 256  sub key_pressed {
256          my $event = $self->event || confess "no event?";          my $event = $self->event || confess "no event?";
257    
258          if ( ! $event->poll ) {          if ( ! $event->poll ) {
259                    return $pending_key unless $self->can('session_event');
260                  if ( my $h = $self->session_event('key_pressed') ) {                  if ( my $h = $self->session_event('key_pressed') ) {
261                          my ( $key, $state ) = %$h;                          my ( $key, $state ) = %$h;
262                          if ( $state ) {                          if ( $state ) {
263                                  $pending_key = $key;                                  $pending_key = $key;
264                                  $key_down->{$key}++;                                  $self->key_down( $key );
265                          } else {                          } else {
266                                  undef $pending_key;                                  undef $pending_key;
267                                  $key_down->{$key} = 0;                                  $self->key_up( $key );
268                          }                          }
269                  }                  }
270                  return $pending_key;                  return $pending_key;
# Line 259  sub key_pressed { Line 278  sub key_pressed {
278    
279          if ($type == SDL_KEYDOWN) {          if ($type == SDL_KEYDOWN) {
280                  $k = $event->key_name();                  $k = $event->key_name();
                 $key_down->{$k}++;  
281                  if ( $k eq 'escape' ) {                  if ( $k eq 'escape' ) {
282                          $run_for = $self->cli;                          $run_for = $self->cli;
283                          warn "will check event loop every $run_for cycles\n";                          warn "will check event loop every $run_for cycles\n";
# Line 267  sub key_pressed { Line 285  sub key_pressed {
285                  } else {                  } else {
286                          warn "SDL_KEYDOWN ($type) = '$k'", $just_checking ? ' fake' : '', "\n";                          warn "SDL_KEYDOWN ($type) = '$k'", $just_checking ? ' fake' : '', "\n";
287                          $pending_key = $k;                          $pending_key = $k;
288                            $self->key_down( $k );
289                          $self->record_session('key_pressed', { $k => 1 });                          $self->record_session('key_pressed', { $k => 1 });
290                  }                  }
291          } elsif ( $type == SDL_KEYUP ) {          } elsif ( $type == SDL_KEYUP ) {
292                  my $up = $event->key_name();                  my $up = $event->key_name();
293                  warn "SDL_KEYUP ($type) = '$up'", $just_checking ? ' fake' : '', "\n";                  warn "SDL_KEYUP ($type) = '$up'", $just_checking ? ' fake' : '', "\n";
294                    $self->key_up( $up );
295                  $self->record_session('key_pressed', { $up => 0 });                  $self->record_session('key_pressed', { $up => 0 });
                 $key_down->{$up} = 0;  
296                  undef $pending_key;                  undef $pending_key;
297          }          }
298    
# Line 307  sub loop { Line 326  sub loop {
326          }          }
327  }  }
328    
329    # helper array to flip bytes for display
330    our @flip;
331    
332    foreach my $i ( 0 .. 255 ) {
333            my $t = 0;
334            $i & 0b00000001 and $t = $t | 0b10000000;
335            $i & 0b00000010 and $t = $t | 0b01000000;
336            $i & 0b00000100 and $t = $t | 0b00100000;
337            $i & 0b00001000 and $t = $t | 0b00010000;
338            $i & 0b00010000 and $t = $t | 0b00001000;
339            $i & 0b00100000 and $t = $t | 0b00000100;
340            $i & 0b01000000 and $t = $t | 0b00000010;
341            $i & 0b10000000 and $t = $t | 0b00000001;
342            #warn "$i = $t\n";
343            $flip[$i] = $t;
344    }
345    
346  =head1 SEE ALSO  =head1 SEE ALSO
347    
348  L<Orao> is sample implementation using this module  L<Orao> is sample implementation using this module

Legend:
Removed from v.152  
changed lines
  Added in v.165

  ViewVC Help
Powered by ViewVC 1.1.26