/[VRac]/Session.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 /Session.pm

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

revision 149 by dpavlin, Sun Aug 5 13:27:27 2007 UTC revision 150 by dpavlin, Sun Aug 5 15:16:10 2007 UTC
# Line 23  Session - save or load emulator interact Line 23  Session - save or load emulator interact
23    
24  =head2 record_session  =head2 record_session
25    
26    $self->record_session( 'name', $values );    $self->record_session( 'name', $value );
27    
28  =cut  =cut
29    
 my $last_tick = 0;  
   
30  sub record_session {  sub record_session {
31          my $self = shift;          my $self = shift;
32          my $name = shift || confess "no name?";          my $name = shift || confess "need name";
33    
34          my $t = $self->app->ticks;          my $t = $self->app->ticks;
         my $dt = $t - $last_tick;  
         $last_tick = $t;  
35    
36          $self->append_to_file('session.pl', "\$s->{$t}->{$name} = ", dump( @_ ),";\n");          $self->append_to_file('session.pl', "\$s->{$t}->{'$name'} = ", dump( @_ ),";\n");
37    
38  }  }
39    
# Line 47  sub record_session { Line 43  sub record_session {
43    
44  =cut  =cut
45    
46    my $s;
47    my @timeline;
48    
49  sub load_session {  sub load_session {
50          my $self = shift;          my $self = shift;
51          my $path = shift || confess "no path?";          my $path = shift || confess "no path?";
52    
53          my $s;          if ( ! -r $path ) {
54                    warn "WARNING: can't open session $path: $!\n";
55                    return;
56            }
57    
58          eval read_file( $path );          eval read_file( $path );
59          warn "s = ",dump( $s );          warn "session = ",dump( $s );
60    
61          my @timeline = sort { $a <=> $b } keys %$s;          @timeline = sort { $a <=> $b } keys %$s;
62    
63          my ( $from, $to ) = @timeline[0,-1];          my ( $from, $to ) = @timeline[0,-1];
64          printf "loaded session %.2f-%.2fs with %d events\n", $from / 1000, $to / 1000, $#timeline + 1;          printf "loaded session %.2f-%.2fs with %d events\n", $from / 1000, $to / 1000, $#timeline + 1;
65  }  }
66    
67    =head2 session_event
68    
69      my $v = $self->session_event('key_pressed');
70    
71    =cut
72    
73    sub session_event {
74            my $self = shift;
75    
76            return unless @timeline;
77    
78            my $name = shift || confess "no name?";
79    
80            my $t = $self->app->ticks;
81    
82            # do we have events to trigger?
83            return if ( $t < $timeline[0] );
84    
85            my $e_t = $timeline[0];
86    
87            # do we have next event and should we take it?
88            if ( $#timeline > 0 && $t > $timeline[1] ) {
89                    shift @timeline;
90                    $e_t = $timeline[0];
91                    warn "session_event $e_t $name ",dump( $s->{$e_t}->{$name} )," left ", $#timeline+1, " events\n";
92            }
93    
94            return $s->{$e_t}->{$name};
95    }
96    
97  =head1 SEE ALSO  =head1 SEE ALSO
98    
99  L<VRac>  L<VRac>

Legend:
Removed from v.149  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26