Based on upstream patch: http://www.frozen-bubble.org/perl-SDL.patch This version of the patch works with both sdl-perl-1.x and sdl-perl-2.x --- frozen-bubble +++ frozen-bubble @@ -90,3 +90,4 @@ $version = '1.0.0'; +$SDL_VER = substr($SDL::VERSION, 0, 1); # Extract sdl-perl's major num @@ -161,6 +161,19 @@ #- ----------- sound related stuff ---------------------------------------- +sub get_sound { + my ($sound) = @_; + if ($SDL_VER eq 1) { + if (ref($sound) eq 'SDL::Sound') { + return $sound{$_}{-data}; + } else { + return $sound->{-data}; + } + } else { + return $$sound; + } +} + sub play_sound($) { $mixer_enabled && $mixer && !$sfx_disabled && $sound{$_[0]} and $mixer->play_channel(-1, $sound{$_[0]}, 0); } @@ -179,7 +188,7 @@ $elem or return -1; -f $elem or return 0; $mus = SDL::Music->new($elem); - if ($mus->{-data}) { + if (get_sound($mus)) { print STDERR "[Playlist] playing `$elem'\n"; $mixer->play_music($mus, 0); return 1; @@ -191,9 +200,9 @@ while ($tryanother->() == 0) {}; } else { $mus = SDL::Music->new("$FPATH$musics{$name}"); - $mus->{-data} or print STDERR "Warning, could not create new music from `$FPATH$musics{$name}' (reason: ", $app->error, ").\n"; + get_sound($mus) or print STDERR "Warning, could not create new music from `$FPATH$musics{$name}' (reason: ", $app->error, ").\n"; if ($pos) { - fb_c_stuff::fade_in_music_position($mus->{-data}, -1, 500, $pos); + fb_c_stuff::fade_in_music_position(get_sound($mus), -1, 500, $pos); } else { $mixer->play_music($mus, -1); } @@ -212,7 +221,7 @@ foreach (@sounds) { my $sound_path = "$FPATH/snd/$_.wav"; $sound{$_} = SDL::Sound->new($sound_path); - if ($sound{$_}{-data}) { + if (get_sound($sound{$_})) { $sound{$_}->volume(80); } else { print STDERR "Warning, could not create new sound from `$sound_path'.\n"; @@ -233,6 +233,14 @@ #- ----------- graphics related stuff -------------------------------------- +sub SDL_TEXTWIDTH { + if (defined(&SDL::App::SDL_TEXTWIDTH)) { + SDL::App::SDL_TEXTWIDTH(@_); # perl-sdl-1.x + } else { + SDL::SFont::SDL_TEXTWIDTH(@_); # perl-sdl-2.x + } +} + sub add_default_rect($) { my ($surface) = @_; $rects{$surface} = SDL::Rect->new(-width => $surface->width, -height => $surface->height); @@ -304,10 +304,28 @@ return $save; } +sub surf { + my ($surface) = @_; + if (ref($surface) eq 'HASH') { + return $surface->{-surface}; + } else { + return $$surface; + } +} + +sub rect { + my ($rect) = @_; + if (ref($rect) eq 'HASH') { + return $rect->{-rect}; + } else { + return $$rect; + } +} + sub add_image($) { my $file = "$FPATH/gfx/$_[0]"; my $img = SDL::Surface->new(-name => $file); - $img->{-surface} or die "FATAL: Couldn't load `$file' into a SDL::Surface.\n"; + surf($img) or die "FATAL: Couldn't load `$file' into a SDL::Surface.\n"; add_default_rect($img); return $img; } @@ -1473,7 +1491,7 @@ } put_image($imgbin{hiscore_frame}, $high_posx - 7, $high_posy - 6); - fb_c_stuff::shrink($app->{-surface}, $background->display_format->{-surface}, $high_posx, $high_posy, $high_rect->{-rect}, 4); + fb_c_stuff::shrink(surf($app), surf($background->display_format), $high_posx, $high_posy, rect($high_rect), 4); $centered_print->($high_posx, $high_posy, $high->{name}); $centered_print->($high_posx, $high_posy+20, $high->{level} eq 'WON' ? "WON!" : "LVL-".$high->{level}); my $min = int($high->{time}/60); @@ -1642,7 +1660,7 @@ $background->blit($apprects{main}, $app, $apprects{main}); $app->flip; } else { - fb_c_stuff::effect($app->{-surface}, $background->display_format->{-surface}); + fb_c_stuff::effect(surf($app), surf($background->display_format)); } $display_on_app_disabled = 0;