X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSDL%2FApp.pm;h=86e4ea4e2e9158849bf7ee44894dacd9bbb04b9d;hb=bd607ddd553e47f74c6fc157316752d9adab9a13;hp=1fd0b5b39b950a2de3bbb6355df9032098138779;hpb=bfd90409c307d445ed6fec5cce6344b1e3d1be05;p=sdlgit%2FSDL_perl.git diff --git a/lib/SDL/App.pm b/lib/SDL/App.pm index 1fd0b5b..86e4ea4 100644 --- a/lib/SDL/App.pm +++ b/lib/SDL/App.pm @@ -31,13 +31,14 @@ package SDL::App; use strict; +use warnings; +use Carp; use SDL; use SDL::Event; use SDL::Surface; use SDL::Rect; our @ISA = qw(SDL::Surface); - sub DESTROY { } @@ -54,10 +55,16 @@ sub new { -red_accum_size -ras -blue_accum_size -bas -green_accum_sizee -gas -alpha_accum_size -aas -double_buffer -db -buffer_size -bs -stencil_size -st - -asyncblit + -asyncblit -init / ) if ($SDL::DEBUG); - SDL::Init(SDL::SDL_INIT_EVERYTHING()); + # SDL_INIT_VIDEO() is 0, so check defined instead of truth. + my $init = defined $options{-init} ? $options{-init} : + SDL_INIT_EVERYTHING(); + + SDL::Init($init); + + #SDL::Init(SDL::SDL_INIT_EVERYTHING()); my $t = $options{-title} || $options{-t} || $0; my $it = $options{-icon_title} || $options{-it} || $t; @@ -105,8 +112,8 @@ sub new { $SDL::App::USING_OPENGL = 0; } - my $self = \SDL::SetVideoMode($w,$h,$d,$f) - or die SDL::GetError(); + my $self = SDL::SetVideoMode($w,$h,$d,$f) + or croak SDL::GetError(); if ($ic and -e $ic) { my $icon = new SDL::Surface -name => $ic; @@ -178,8 +185,7 @@ sub loop ($$) { my $event = new SDL::Event; while ( $event->wait() ) { if ( ref($$href{$event->type()}) eq "CODE" ) { - &{$$href{$event->type()}}($event); - $self->sync(); + &{$$href{$event->type()}}($event); } } } @@ -189,7 +195,7 @@ sub sync ($) { if ($SDL::App::USING_OPENGL) { SDL::GLSwapBuffers() } else { - $self->flip(); + SDL::Flip($self); } } @@ -200,7 +206,7 @@ sub attribute ($$;$) { SDL::GLSetAttribute($mode,$value); } my $returns = SDL::GLGetAttribute($mode); - die "SDL::App::attribute failed to get GL attribute" if ($$returns[0] < 0); + croak "SDL::App::attribute failed to get GL attribute" if ($$returns[0] < 0); $$returns[1]; } @@ -215,17 +221,35 @@ __END__; SDL::App - a SDL perl extension =head1 SYNOPSIS - - my $app = new SDL::App ( - -title => 'Application Title', - -width => 640, - -height => 480, - -depth => 32 ); + + use SDL; + use SDL::Event; + use SDL::App; + + my $app = new SDL::App ( + -title => 'Application Title', + -width => 640, + -height => 480, + -depth => 32 ); + +This is the manual way of doing things + + my $event = new SDL::Event; # create a new event + + $event->pump(); + $event->poll(); + + while ($event->wait()) { + my $type = $event->type(); # get event type + print $type; + exit if $type == SDL_QUIT; + } +An alternative to the manual Event processing is the L . =head1 DESCRIPTION L controls the root window of the of your SDL based application. -It extends the L class, and provides an interface to the window +It extends the L class, and provides an interface to the window manager oriented functions. =head1 METHODS @@ -355,11 +379,12 @@ or OpenGL buffer if applicable. This is prefered to calling flip on the applica C allows one to set and get GL attributes. By passing a value in addition to the attribute selector, the value will be set. C -always returns the current value of the given attribute, or dies on failure. +always returns the current value of the given attribute, or croaks on failure. =head1 AUTHOR David J. Goehrig +Kartik Thakore =head1 SEE ALSO