summaryrefslogtreecommitdiffstats
path: root/frozen-bubble/build/frozen-bubble-sdl_perl.patch
blob: be3afe4dfcf52497efbb2ec6c2c215d26ea42076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;