/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

  1. package SDL::Tutorial::MoP::Controller::CPUSpinner;
  2. use strict;
  3. use warnings;
  4. use base 'SDL::Tutorial::MoP::Base';
  5. sub init {
  6. my $self = shift;
  7. $self->{keep_going} ||= 1;
  8. }
  9. sub run {
  10. my $self = shift;
  11. while ( $self->{keep_going} == 1 ) {
  12. $self->evt_manager->post( { name => 'Tick' } );
  13. }
  14. }
  15. sub notify {
  16. my ( $self, $event ) = (@_);
  17. print "Notify in CPU Spinner \n" if $self->{EDEBUG};
  18. my %event_method = ( 'Quit' => '_quit', );
  19. my $method = $event_method{ $event->{name} };
  20. if ( defined $method ) {
  21. print "Event: $event->{name}\n" if $self->{EDEBUG};
  22. # call the corresponding method
  23. $self->$method();
  24. }
  25. #if we did not have a tick event then some other controller needs to do
  26. #something so game state is still beign process we cannot have new input
  27. #now
  28. }
  29. sub _quit {
  30. my $self = shift;
  31. $self->{keep_going} = 0;
  32. }
  33. 1;
  34. __END__
  35. =head1 NAME
  36. SDL::Tutorial::MoP::Controller::CPUSpinner
  37. =head1 DESCRIPTION
  38. The C<CPUSpinner> controller is the heartbeat of the game.
  39. The game proceeds while C<keep_going> is set. When C<CPUSpinner>
  40. receives a C<Quit> event, C<keep_going> is set to zero.
  41. =head2 init
  42. C<init> simply initializes C<keep_going>, so the game will start.
  43. =head2 run
  44. Produces a C<Tick> event while C<keep_going> is set.
  45. =head2 notify
  46. If this controller receives a C<Quit> event, C<keep_going> is
  47. set to zero, stopping the game.
  48. =head1 SEE ALSO
  49. L<SDL::Tutorial::MoP::Controller>