PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/t_backcompat/MoP/lib/SDL/Tutorial/MoP/Controller/CPUSpinner.pm

http://github.com/PerlGameDev/SDL
Perl | 76 lines | 45 code | 27 blank | 4 comment | 7 complexity | 15e4a53e774c42fd4b0f05ba268ef5f0 MD5 | raw file
 1package SDL::Tutorial::MoP::Controller::CPUSpinner;
 2
 3use strict;
 4use warnings;
 5
 6use base 'SDL::Tutorial::MoP::Base';
 7
 8sub init {
 9	my $self = shift;
10	$self->{keep_going} ||= 1;
11}
12
13sub run {
14	my $self = shift;
15	while ( $self->{keep_going} == 1 ) {
16		$self->evt_manager->post( { name => 'Tick' } );
17	}
18}
19
20sub notify {
21	my ( $self, $event ) = (@_);
22
23	print "Notify in CPU Spinner \n" if $self->{EDEBUG};
24
25	my %event_method = ( 'Quit' => '_quit', );
26
27	my $method = $event_method{ $event->{name} };
28
29	if ( defined $method ) {
30		print "Event: $event->{name}\n" if $self->{EDEBUG};
31
32		# call the corresponding method
33		$self->$method();
34	}
35
36	#if we did not have a tick event then some other controller needs to do
37	#something so game state is still beign process we cannot have new input
38	#now
39}
40
41sub _quit {
42	my $self = shift;
43	$self->{keep_going} = 0;
44}
45
461;
47
48__END__
49
50=head1 NAME
51
52SDL::Tutorial::MoP::Controller::CPUSpinner
53
54=head1 DESCRIPTION
55
56The C<CPUSpinner> controller is the heartbeat of the game.
57
58The game proceeds while C<keep_going> is set. When C<CPUSpinner>
59receives a C<Quit> event, C<keep_going> is set to zero.
60
61=head2 init
62
63C<init> simply initializes C<keep_going>, so the game will start.
64
65=head2 run
66
67Produces a C<Tick> event while C<keep_going> is set.
68
69=head2 notify
70
71If this controller receives a C<Quit> event, C<keep_going> is
72set to zero, stopping the game.
73
74=head1 SEE ALSO
75
76L<SDL::Tutorial::MoP::Controller>