ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/cfplus
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/cfplus (file contents):
Revision 1.185 by elmex, Tue Jul 24 18:39:39 2007 UTC vs.
Revision 1.192 by root, Mon Jul 30 02:16:16 2007 UTC

71unshift @INC, $ENV{PAR_TEMP} 71unshift @INC, $ENV{PAR_TEMP}
72 if %PAR::LibCache; 72 if %PAR::LibCache;
73 73
74use Time::HiRes 'time'; 74use Time::HiRes 'time';
75use Event; 75use Event;
76use List::Util qw(max min);
76 77
77use Crossfire; 78use Crossfire;
78use Crossfire::Protocol::Constants; 79use Crossfire::Protocol::Constants;
79 80
80use Compress::LZF; 81use Compress::LZF;
162 163
163our $SDL_MIXER; 164our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 165our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT; 166our @MUSIC_WANT;
166our $MUSIC_START; 167our $MUSIC_START;
167our $MUSIC_PLAYING; 168our $MUSIC_PLAYING_DATA;
169our $MUSIC_PLAYING_META;
168our $MUSIC_PLAYER; 170our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 171our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
170our @SOUNDS; # event => file mapping 172our @SOUNDS; # event => file mapping
171our %AUDIO_CHUNKS; # audio files 173our %AUDIO_CHUNKS; # audio files
172 174
177our $INV; 179our $INV;
178our $INVR; 180our $INVR;
179our $INV_RIGHT_HB; 181our $INV_RIGHT_HB;
180 182
181our $PICKUP_CFG; 183our $PICKUP_CFG;
182
183our $IN_BUILD_MODE;
184our $BUILD_BUTTON;
185 184
186sub status { 185sub status {
187 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 186 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
188} 187}
189 188
462 query => \&server_query, 461 query => \&server_query,
463 462
464 setup_req => { 463 setup_req => {
465 smoothing => $CFG->{map_smoothing}*1, 464 smoothing => $CFG->{map_smoothing}*1,
466 }, 465 },
467
468 sound_play => sub {
469 my ($x, $y, $soundnum, $type) = @_;
470
471 $SDL_MIXER
472 or return;
473
474 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
475 or return;
476
477 $chunk->play;
478 },
479 }; 466 };
480 467
481 if ($CONN) { 468 if ($CONN) {
482 CFPlus::lowdelay fileno $CONN->{fh}; 469 CFPlus::lowdelay fileno $CONN->{fh};
483 470
492 $LOGIN_BUTTON->set_text ("Login"); 479 $LOGIN_BUTTON->set_text ("Login");
493 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); 480 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
494 $SETUP_DIALOG->show; 481 $SETUP_DIALOG->show;
495 $PL_WINDOW->hide; 482 $PL_WINDOW->hide;
496 $SPELL_LIST->clear_spells; 483 $SPELL_LIST->clear_spells;
497 $MESSAGE_WINDOW->clear_channels;
498 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 484 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
499 485
500 &audio_music_set ([]); 486 &audio_music_set ([]);
501 487
502 return unless $CONN; 488 return unless $CONN;
1085 text => $CFG->{profile}{default}{host}, 1071 text => $CFG->{profile}{default}{host},
1086 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", 1072 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
1087 on_changed => sub { 1073 on_changed => sub {
1088 my ($self, $value) = @_; 1074 my ($self, $value) = @_;
1089 $CFG->{profile}{default}{host} = $value; 1075 $CFG->{profile}{default}{host} = $value;
1090 0 1076 1
1091 } 1077 }
1092 ); 1078 );
1093 1079
1094 $vbox->add (new CFPlus::UI::Button 1080 $vbox->add (new CFPlus::UI::Button
1095 expand => 1, 1081 expand => 1,
1096 text => "Server List", 1082 text => "Server List",
1097 other => $METASERVER, 1083 other => $METASERVER,
1098 tooltip => "Show a list of available crossfire servers", 1084 tooltip => "Show a list of available crossfire servers",
1099 on_activate => sub { $METASERVER->toggle_visibility; 0 }, 1085 on_activate => sub { $METASERVER->toggle_visibility; 0 },
1100 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 }, 1086 on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
1101 ); 1087 );
1102 } 1088 }
1103 1089
1104 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username"); 1090 $table->add_at (0, 4, new CFPlus::UI::Label valign => 0, align => 1, text => "Username");
1105 $table->add_at (1, 4, new CFPlus::UI::Entry 1091 $table->add_at (1, 4, new CFPlus::UI::Entry
1106 text => $CFG->{profile}{default}{user}, 1092 text => $CFG->{profile}{default}{user},
1107 tooltip => "The name of your character on the server", 1093 tooltip => "The name of your character on the server",
1108 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value } 1094 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
1109 ); 1095 );
1110 1096
1111 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password"); 1097 $table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
1112 $table->add_at (1, 5, new CFPlus::UI::Entry 1098 $table->add_at (1, 5, new CFPlus::UI::Entry
1113 text => $CFG->{profile}{default}{password}, 1099 text => $CFG->{profile}{default}{password},
1114 hidden => 1, 1100 hidden => 1,
1115 tooltip => "The password for your character", 1101 tooltip => "The password for your character",
1116 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value } 1102 on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
1117 ); 1103 );
1118 1104
1119 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size"); 1105 $table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
1120 $table->add_at (1, 7, new CFPlus::UI::Slider 1106 $table->add_at (1, 7, new CFPlus::UI::Slider
1121 force_w => 100, 1107 force_w => 100,
1122 range => [$CFG->{mapsize}, 10, 100, 0, 1], 1108 range => [$CFG->{mapsize}, 10, 100, 0, 1],
1123 tooltip => "This is the size of the portion of the map update the server sends you. " 1109 tooltip => "This is the size of the portion of the map update the server sends you. "
1124 . "If you set this to a high value you will be able to see further, " 1110 . "If you set this to a high value you will be able to see further, "
1125 . "but you also increase bandwidth requirements and latency. " 1111 . "but you also increase bandwidth requirements and latency. "
1126 . "This option is only used once at log-in.", 1112 . "This option is only used once at log-in.",
1127 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 }, 1113 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
1128 ); 1114 );
1129 1115
1130 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch");
1131 $table->add_at (1, 8, new CFPlus::UI::CheckBox
1132 state => $CFG->{face_prefetch},
1133 tooltip => "<b>Background Image Prefetch</b>\n\n"
1134 . "If enabled, the client automatically pre-fetches images from the server. "
1135 . "This might increase or create lag, but increases the chances "
1136 . "of faces being ready for display when you encounter them. "
1137 . "It also uses up server bandwidth on every connect, "
1138 . "so only set it if you really need to prefetch images. "
1139 . "This option can be set and unset any time.",
1140 on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
1141 );
1142
1143 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate"); 1116 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1117 $table->add_at (1, 8, new CFPlus::UI::Entry
1118 text => $CFG->{output_rate},
1119 tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
1120 . "when sending data. When 0 or unset, the server "
1121 . "default will be used, which is usually around 100kb/s. Most servers will "
1122 . "dynamically find an optimal rate, so adjust this only when necessary.",
1123 on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
1124 );
1125
1126 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1144 $table->add_at (1, 9, new CFPlus::UI::Entry 1127 $table->add_at (1, 9, new CFPlus::UI::Entry
1145 text => $CFG->{output_rate},
1146 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
1147 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1148 . "default will be used, which is usually around 100kb/s.",
1149 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1150 );
1151
1152 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1153 $table->add_at (1, 10, new CFPlus::UI::Entry
1154 text => $CFG->{output_count}, 1128 text => $CFG->{output_count},
1155 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1129 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1156 on_changed => sub { $CFG->{output_count} = $_[1]; 0 }, 1130 on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
1157 ); 1131 );
1158 1132
1159 $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1133 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
1160 $table->add_at (1, 11, new CFPlus::UI::Entry 1134 $table->add_at (1, 10, new CFPlus::UI::Entry
1161 text => $CFG->{output_sync}, 1135 text => $CFG->{output_sync},
1162 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.", 1136 tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
1163 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 }, 1137 on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
1164 ); 1138 );
1165 1139
1166 $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button 1140 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1167 expand => 1, 1141 expand => 1,
1168 align => 0, 1142 align => 0,
1169 text => "Login", 1143 text => "Login",
1170 on_activate => sub { 1144 on_activate => sub {
1171 $CONN ? stop_game 1145 $CONN ? stop_game
1172 : start_game; 1146 : start_game;
1173 0 1147 1
1174 }, 1148 },
1175 ); 1149 );
1176 1150
1177 $vbox->add (new CFPlus::UI::FancyFrame 1151 $vbox->add (new CFPlus::UI::FancyFrame
1178 label => "Server Info", 1152 label => "Server Info",
1807 } 1781 }
1808 1782
1809 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 1783 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
1810} 1784}
1811 1785
1812sub setup_build_button {
1813 my ($enabled) = @_;
1814 if ($enabled) {
1815 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1816 $BUILD_BUTTON ||= new CFPlus::UI::Button
1817 text => "Build",
1818 tooltip => "Opens the ingame builder",
1819 on_activate => sub {
1820 if ($CONN) {
1821 $CONN->send_ext_req (builder_player_items => sub {
1822 open_ingame_editor ($_[0]) if exists $_[0]->{items};
1823 });
1824 }
1825 0
1826 };
1827 $BUTTONBAR->add ($BUILD_BUTTON);
1828 } else {
1829 $BUILD_BUTTON->hide if $BUILD_BUTTON;
1830 }
1831}
1832
1833sub open_ingame_editor {
1834 my ($msg) = @_;
1835
1836 my $win = new CFPlus::UI::Toplevel
1837 x => 0,
1838 y => 'center',
1839 z => 4,
1840 name => 'builder_window',
1841 force_w => int $WIDTH * 1/4,
1842 force_h => int $HEIGHT * 3/4,
1843 title => "In game builder",
1844 has_close_button => 1;
1845
1846 my $r = new CFPlus::UI::ScrolledWindow (
1847 expand => 1,
1848 scroll_y => 1
1849 );
1850 $r->add (my $vb = new CFPlus::UI::VBox);
1851 $win->add ($r);
1852
1853
1854 $vb->add (
1855 new CFPlus::UI::Button
1856 text => "Disable build mode",
1857 on_activate => sub { $::IN_BUILD_MODE = undef }
1858 );
1859 $vb->add (
1860 new CFPlus::UI::Button
1861 text => "ERASE",
1862 on_activate => sub { $::IN_BUILD_MODE = { do_erase => 1 } }
1863 );
1864
1865 for my $itemarchname (
1866 sort {
1867 $msg->{items}->{$a}->{build_arch_name}
1868 cmp $msg->{items}->{$b}->{build_arch_name}
1869 } keys %{$msg->{items}}
1870 ) {
1871 my $info = $msg->{items}->{$itemarchname};
1872 $vb->add (
1873 new CFPlus::UI::Button text => $info->{build_arch_name},
1874 on_activate => sub {
1875 $::IN_BUILD_MODE = { item => $itemarchname, info => $info };
1876
1877 if (grep { $msg->{items}->{$itemarchname}->{$_} } qw/has_connection has_name has_text/) {
1878 build_mode_query_arch_info ();
1879 }
1880 }
1881 );
1882 }
1883
1884 $win->show;
1885}
1886
1887sub build_mode_query_arch_info {
1888 my ($iteminfo) = $::IN_BUILD_MODE;
1889 my $itemarchname = $iteminfo->{item};
1890 my $info = $iteminfo->{info};
1891
1892 my $dialog = new CFPlus::UI::Toplevel
1893 x => "center",
1894 y => "center",
1895 z => 50,
1896 force_w => int $WIDTH * 1/2,
1897 title => "Enter information for placement of '$itemarchname'",
1898 has_close_button => 1;
1899
1900 $dialog->add (my $vb = new CFPlus::UI::VBox expand => 1);
1901
1902 $vb->add (my $table = new CFPlus::UI::Table expand => 1);
1903 my $row = 0;
1904 if ($info->{has_name}) {
1905 $table->add_at (0, $row, new CFPlus::UI::Label text => "Name:");
1906 $table->add_at (1, $row++, new CFPlus::UI::Entry expand => 1, on_changed => sub { $::IN_BUILD_MODE->{name} = $_[1]; 0 });
1907 }
1908 if ($info->{has_text}) {
1909 $table->add_at (0, $row, new CFPlus::UI::Label text => "Text:");
1910 $table->add_at (1, $row++, new CFPlus::UI::Entry expand => 1, on_changed => sub { $::IN_BUILD_MODE->{text} = $_[1]; 0 });
1911 }
1912 if ($info->{has_connection}) {
1913 $table->add_at (0, $row, new CFPlus::UI::Label text => "Connection ID:");
1914 $table->add_at (1, $row++,
1915 new CFPlus::UI::Entry
1916 expand => 1,
1917 on_changed => sub { $::IN_BUILD_MODE->{connection} = $_[1]; 0 },
1918 tooltip => "Enter the connection ID here. The connection ID connects actors like a lever to a gate or a magic ear to a gate"
1919 );
1920 }
1921
1922 $vb->add (my $hb = new CFPlus::UI::HBox expand => 1);
1923 $hb->add (new CFPlus::UI::Button
1924 text => "Close",
1925 expand => 1,
1926 on_activate => sub { $dialog->hide; 0 },
1927 );
1928 $dialog->show;
1929}
1930
1931sub video_shutdown { 1786sub video_shutdown {
1932 CFPlus::OpenGL::shutdown; 1787 CFPlus::OpenGL::shutdown;
1933 1788
1934 undef $SDL_ACTIVE; 1789 undef $SDL_ACTIVE;
1935} 1790}
1936 1791
1937sub audio_channel_finished { 1792sub audio_channel_finished {
1938 my ($channel) = @_; 1793 my ($channel) = @_;
1939 1794
1940 #warn "channel $channel finished\n";#d# 1795# warn "channel $channel finished\n";#d#
1796}
1797
1798our %AUDIO_PLAY;
1799our %AUDIO_CHUNK;
1800
1801sub audio_sound_push($) {
1802 my ($face) = @_;
1803
1804 if (my $chunk = $AUDIO_CHUNK{$face}) {
1805 for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
1806 my (undef, $dx, $dy, $vol) = @$_;
1807
1808 my $channel = $chunk->play
1809 or return;
1810
1811 $channel->volume (128 + $vol);
1812 $dx = $dx / 10 * 255;
1813 $channel->set_panning ((min 255, 255 - $dx), (min 255, 255 + $dx));
1814# my $angle = $dx ? : $dx < 0 ?
1815# my $distance = -$vol;
1816# $channel->set_position ($angle, $distance);
1817 }
1818 } else {
1819 # sound_meta not set means data is in flight either way
1820 my $meta = $CONN->{sound_meta}{$face}
1821 or return;
1822
1823 # fetch from database
1824 CFPlus::DB::get res_data => $meta->{name}, sub {
1825 my $vol = $meta->{meta}{volume} || 100;
1826 my $rwops = new CFPlus::RW $_[0];
1827 my $chunk = new CFPlus::MixChunk $rwops;
1828 $chunk->volume ($vol * 128 / 100);
1829 $AUDIO_CHUNK{$face} = $chunk;
1830
1831 audio_sound_push ($face);
1832 };
1833 }
1834}
1835
1836sub audio_sound_play {
1837 my ($face, $dx, $dy, $vol) = @_;
1838
1839 $SDL_MIXER
1840 or return;
1841
1842 my $queue = $AUDIO_PLAY{$face} ||= [];
1843 push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s
1844 audio_sound_push $face
1845 unless @$queue > 1;
1941} 1846}
1942 1847
1943sub audio_music_set { 1848sub audio_music_set {
1944 my ($songs) = @_; 1849 my ($songs) = @_;
1945 1850
1953 &audio_music_changed (); 1858 &audio_music_changed ();
1954 } 1859 }
1955} 1860}
1956 1861
1957sub audio_music_start { 1862sub audio_music_start {
1958 my $path = $MUSIC_PLAYING->{path} 1863 my $meta = $MUSIC_PLAYING_META;
1959 or return;
1960 1864
1961 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1865 CFPlus::DB::get res_data => $meta->{name}, sub {
1962 return unless $SDL_MIXER; 1866 return unless $SDL_MIXER;
1963 1867
1964 # music might have changed... 1868 # music might have changed...
1965 $path eq $MUSIC_PLAYING->{path} 1869 $meta eq $MUSIC_PLAYING_META
1966 or return &audio_music_start (); 1870 or return &audio_music_start ();
1967 1871
1872 $MUSIC_PLAYING_DATA = \$_[0];
1873
1874 my $rwops = $meta->{path}
1875 ? new_from_file CFPlus::RW $meta->{path}
1876 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1877
1968 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; 1878 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1879 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1969 1880
1970 my $NOW = time; 1881 my $NOW = time;
1971 1882
1972 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { 1883 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1973 my $pos = $MUSIC_PLAYING->{stop_pos}; 1884 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1974 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 1885 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1975 $MUSIC_START = time - $pos; 1886 $MUSIC_START = time - $pos;
1976 } else { 1887 } else {
1977 $MUSIC_PLAYER->play (0); 1888 $MUSIC_PLAYER->play (0);
1978 $MUSIC_START = time; 1889 $MUSIC_START = time;
1979 } 1890 }
1980 1891
1981 delete $MUSIC_PLAYING->{stop_time}; 1892 delete $MUSIC_PLAYING_META->{stop_time};
1982 delete $MUSIC_PLAYING->{stop_pos}; 1893 delete $MUSIC_PLAYING_META->{stop_pos};
1983 } 1894 }
1984} 1895}
1985 1896
1986sub audio_music_changed { 1897sub audio_music_changed {
1987 return unless $CFG->{bgm_enable}; 1898 return unless $CFG->{bgm_enable};
1989 1900
1990 # default MUSIC_WANT == MUSIC_DEFAULT 1901 # default MUSIC_WANT == MUSIC_DEFAULT
1991 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 1902 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1992 1903
1993 # if the currently playing song is acceptable, let it continue 1904 # if the currently playing song is acceptable, let it continue
1994 return if $MUSIC_PLAYING 1905 return if $MUSIC_PLAYING_META
1995 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 1906 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1996 1907
1997 my $NOW = time; 1908 my $NOW = time;
1998 1909
1999 if ($MUSIC_PLAYING) { 1910 if ($MUSIC_PLAYING_META) {
2000 $MUSIC_PLAYING->{stop_time} = $NOW; 1911 $MUSIC_PLAYING_META->{stop_time} = $NOW;
2001 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; 1912 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
2002 CFPlus::MixMusic::fade_out 1000; 1913 CFPlus::MixMusic::fade_out 1000;
2003 } else { 1914 } else {
2004 # sort by stop time, oldest first 1915 # sort by stop time, oldest first
2005 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 1916 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
2006 1917
2007 # if the most recently-played piece played very recently, 1918 # if the most recently-played piece played very recently,
2008 # resume it, else choose the oldest piece for rotation. 1919 # resume it, else choose the oldest piece for rotation.
2009 $MUSIC_PLAYING = 1920 $MUSIC_PLAYING_META =
2010 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 1921 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
2011 ? $MUSIC_WANT[-1] 1922 ? $MUSIC_WANT[-1]
2012 : $MUSIC_WANT[0]; 1923 : $MUSIC_WANT[0];
2013 1924
2014 audio_music_start; 1925 audio_music_start;
2015 } 1926 }
2016} 1927}
2017 1928
2018sub audio_music_finished { 1929sub audio_music_finished {
2019 $MUSIC_PLAYING = undef;
2020 undef $MUSIC_PLAYER; 1930 undef $MUSIC_PLAYER;
1931 undef $MUSIC_PLAYING_META;
1932 undef $MUSIC_PLAYING_DATA;
2021 1933
2022 audio_music_changed; 1934 audio_music_changed;
2023} 1935}
2024 1936
2025sub audio_init { 1937sub audio_init {
2026 if ($CFG->{audio_enable}) { 1938 if ($CFG->{audio_enable}) {
2027 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 1939 $ENV{MIX_EFFECTSMAXSPEED} = 1;
2028 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1940 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
2029 1941
2030 unless ($SDL_MIXER) { 1942 unless ($SDL_MIXER) {
2031 status "Unable to open sound device: there will be no sound"; 1943 status "Unable to open sound device: there will be no sound";
2032 return; 1944 return;
2033 }
2034
2035 CFPlus::Mix_AllocateChannels 8;
2036 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
2037
2038 audio_music_finished;
2039
2040 local $_;
2041 while (<$fh>) {
2042 next if /^\s*#/;
2043 next if /^\s*$/;
2044
2045 my ($file, $volume, $event) = split /\s+/, $_, 3;
2046
2047 push @SOUNDS, "$volume,$file";
2048
2049 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
2050 my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file";
2051 $chunk->volume ($volume * 128 / 100);
2052 $chunk
2053 };
2054 }
2055 } else {
2056 status "unable to open sound config: $!";
2057 } 1945 }
1946
1947 CFPlus::Mix_AllocateChannels 16;
1948 CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
1949
1950 audio_music_finished;
2058 } else { 1951 } else {
2059 undef $SDL_MIXER; 1952 undef $SDL_MIXER;
2060 } 1953 }
2061} 1954}
2062 1955
2112 2005
2113sub animation_stop { 2006sub animation_stop {
2114 my ($widget) = @_; 2007 my ($widget) = @_;
2115 delete $animate_object{$widget}; 2008 delete $animate_object{$widget};
2116} 2009}
2117
2118# check once/second for faces that need to be prefetched
2119# this should, of course, only run on demand, but
2120# SDL forces worse things on us....
2121
2122Event->timer (after => 1, interval => 0.25, cb => sub {
2123 $CONN->face_prefetch
2124 if $CONN;
2125});
2126 2010
2127%SDL_CB = ( 2011%SDL_CB = (
2128 CFPlus::SDL_QUIT => sub { 2012 CFPlus::SDL_QUIT => sub {
2129 exit; 2013 exit;
2130 }, 2014 },
2191 stat_fontsize => 0.7, 2075 stat_fontsize => 0.7,
2192 mapsize => 100, 2076 mapsize => 100,
2193 audio_enable => 1, 2077 audio_enable => 1,
2194 bgm_enable => 1, 2078 bgm_enable => 1,
2195 bgm_volume => 0.25, 2079 bgm_volume => 0.25,
2196 face_prefetch => 0,
2197 output_sync => 1, 2080 output_sync => 1,
2198 output_count => 1, 2081 output_count => 1,
2199 output_rate => "", 2082 output_rate => "",
2200 pickup => 0, 2083 pickup => 0,
2201 inv_sort => "mtime", 2084 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines