1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
|
|
3 | # do splash-screen thingy on win32 |
3 | my $startup_done = sub { }; |
4 | my $startup_done = sub { }; |
4 | our $PANGO = "1.5.0"; |
|
|
5 | |
|
|
6 | # do splash-screen thingy on win32 |
|
|
7 | BEGIN { |
5 | BEGIN { |
8 | if (%PAR::LibCache && $^O eq "MSWin32") { |
6 | if (%PAR::LibCache && $^O eq "MSWin32") { |
9 | while (my ($filename, $zip) = each %PAR::LibCache) { |
7 | while (my ($filename, $zip) = each %PAR::LibCache) { |
10 | $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp"); |
8 | $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp"); |
11 | } |
9 | } |
… | |
… | |
30 | # do things only needed for single-binary version (par) |
28 | # do things only needed for single-binary version (par) |
31 | BEGIN { |
29 | BEGIN { |
32 | if (%PAR::LibCache) { |
30 | if (%PAR::LibCache) { |
33 | @INC = grep ref, @INC; # weed out all paths except pars loader refs |
31 | @INC = grep ref, @INC; # weed out all paths except pars loader refs |
34 | |
32 | |
35 | my $tmp = $ENV{PAR_TEMP}; |
33 | my $root = $ENV{PAR_TEMP}; |
36 | |
34 | |
37 | while (my ($filename, $zip) = each %PAR::LibCache) { |
35 | while (my ($filename, $zip) = each %PAR::LibCache) { |
38 | for ($zip->memberNames) { |
36 | for ($zip->memberNames) { |
39 | next unless /^root\/(.*)/; |
37 | next unless /^root\/(.*)/; |
40 | $zip->extractMember ($_, "$tmp/$1") |
38 | $zip->extractMember ($_, "$root/$1") |
41 | unless -e "$tmp/$1"; |
39 | unless -e "$root/$1"; |
42 | } |
40 | } |
43 | } |
41 | } |
44 | |
42 | |
45 | if ($^O eq "MSWin32") { |
43 | if ($^O eq "MSWin32") { |
46 | # relocatable |
44 | # pango is relocatable on win32 |
47 | } else { |
45 | } else { |
|
|
46 | open my $fh, "<:perlio", "$root/pangoversion" |
|
|
47 | or die "pangoversion: $!"; |
|
|
48 | my $PANGO = <$fh>; |
48 | # unix, need to patch pango rc file |
49 | # unix, need to patch pango rc file |
49 | open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules" |
50 | open my $fh, "<:perlio", "$root/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules" |
50 | or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!"; |
51 | or die "$root/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!"; |
51 | local $/; |
52 | local $/; |
52 | my $rc = <$fh>; |
53 | my $rc = <$fh>; |
53 | $rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones |
54 | $rc =~ s/^\//$root\//gm; # replace abs paths by relative ones |
54 | |
55 | |
55 | mkdir "$tmp/pango-modules"; |
56 | mkdir "$root/pango-modules"; |
56 | open my $fh, ">:perlio", "$tmp/pango-modules/pango.modules" |
57 | open my $fh, ">:perlio", "$root/pango-modules/pango.modules" |
57 | or die "$tmp/pango-modules/pango.modules: $!"; |
58 | or die "$root/pango-modules/pango.modules: $!"; |
58 | print $fh $rc; |
59 | print $fh $rc; |
59 | |
60 | |
60 | $ENV{PANGO_RC_FILE} = "$tmp/pango.rc"; |
61 | $ENV{PANGO_RC_FILE} = "$root/pango.rc"; |
61 | open my $fh, ">:perlio", $ENV{PANGO_RC_FILE} |
62 | open my $fh, ">:perlio", $ENV{PANGO_RC_FILE} |
62 | or die "$ENV{PANGO_RC_FILE}: $!"; |
63 | or die "$ENV{PANGO_RC_FILE}: $!"; |
63 | print $fh "[Pango]\nModuleFiles = $tmp/pango-modules\n"; |
64 | print $fh "[Pango]\nModuleFiles = $root/pango-modules\n"; |
64 | } |
65 | } |
65 | |
66 | |
66 | unshift @INC, $tmp; |
67 | unshift @INC, $root; |
67 | } |
68 | } |
68 | } |
69 | } |
69 | |
70 | |
70 | # need to do it again because that pile of garbage called PAR nukes it before main |
71 | # need to do it again because that pile of garbage called PAR nukes it before main |
71 | unshift @INC, $ENV{PAR_TEMP} |
72 | unshift @INC, $ENV{PAR_TEMP} |
… | |
… | |
86 | use CFPlus::DB; |
87 | use CFPlus::DB; |
87 | use CFPlus::UI; |
88 | use CFPlus::UI; |
88 | use CFPlus::UI::Canvas; |
89 | use CFPlus::UI::Canvas; |
89 | use CFPlus::UI::Inventory; |
90 | use CFPlus::UI::Inventory; |
90 | use CFPlus::UI::SpellList; |
91 | use CFPlus::UI::SpellList; |
|
|
92 | use CFPlus::UI::Dockable; |
91 | use CFPlus::UI::MessageWindow; |
93 | use CFPlus::UI::MessageWindow; |
|
|
94 | use CFPlus::UI::ChatView; |
92 | use CFPlus::Pod; |
95 | use CFPlus::Pod; |
93 | use CFPlus::MapWidget; |
96 | use CFPlus::MapWidget; |
94 | use CFPlus::Macro; |
97 | use CFPlus::Macro; |
95 | |
98 | |
96 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
99 | $SIG{QUIT} = sub { Carp::cluck "QUIT" }; |
… | |
… | |
182 | sub debug { |
185 | sub debug { |
183 | $DEBUG_STATUS->set_text ($_[0]); |
186 | $DEBUG_STATUS->set_text ($_[0]); |
184 | } |
187 | } |
185 | |
188 | |
186 | sub message { |
189 | sub message { |
187 | my ($para) = @_; |
|
|
188 | $MESSAGE_WINDOW->message ($para); |
190 | $MESSAGE_WINDOW->message (@_); |
189 | } |
191 | } |
190 | |
192 | |
191 | ############################################################################# |
193 | ############################################################################# |
192 | #TODO: maybe move into own audio module... |
194 | #TODO: maybe move into own audio module... |
193 | |
195 | |
… | |
… | |
406 | } |
408 | } |
407 | |
409 | |
408 | sub audio_init { |
410 | sub audio_init { |
409 | if ($CFG->{audio_enable}) { |
411 | if ($CFG->{audio_enable}) { |
410 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
412 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
411 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
413 | $SDL_MIXER = !CFPlus::Mix_OpenAudio |
|
|
414 | $CFG->{audio_hw_frequency}, |
|
|
415 | CFPlus::MIX_DEFAULT_FORMAT, |
|
|
416 | $CFG->{audio_hw_channels}, |
|
|
417 | $CFG->{audio_hw_chunksize}; |
412 | |
418 | |
413 | unless ($SDL_MIXER) { |
419 | if ($SDL_MIXER) { |
|
|
420 | CFPlus::Mix_AllocateChannels $CFG->{audio_mix_channels}; |
|
|
421 | |
|
|
422 | audio_music_finished; |
|
|
423 | } else { |
414 | status "Unable to open sound device: there will be no sound"; |
424 | status "Unable to open sound device: there will be no sound"; |
415 | return; |
|
|
416 | } |
425 | } |
417 | |
|
|
418 | CFPlus::Mix_AllocateChannels 16; |
|
|
419 | |
|
|
420 | audio_music_finished; |
|
|
421 | } else { |
426 | } else { |
422 | undef $SDL_MIXER; |
427 | undef $SDL_MIXER; |
423 | } |
428 | } |
|
|
429 | |
|
|
430 | sub audio_tab_update; |
|
|
431 | audio_tab_update; |
424 | } |
432 | } |
425 | |
433 | |
426 | sub audio_shutdown { |
434 | sub audio_shutdown { |
427 | undef $MUSIC_PLAYER; |
435 | undef $MUSIC_PLAYER; |
428 | undef $MUSIC_PLAYING_META; |
436 | undef $MUSIC_PLAYING_META; |
… | |
… | |
888 | ); |
896 | ); |
889 | |
897 | |
890 | $vbox |
898 | $vbox |
891 | } |
899 | } |
892 | |
900 | |
|
|
901 | our $AUDIO_HW_CHUNKSIZE; |
|
|
902 | our $AUDIO_INFO; |
|
|
903 | |
|
|
904 | sub audio_tab_update { |
|
|
905 | my ($freq, $format, $chans) = CFPlus::Mix_QuerySpec; |
|
|
906 | |
|
|
907 | $AUDIO_HW_CHUNKSIZE->set_options ([ |
|
|
908 | [0, "default", "system default"], |
|
|
909 | map { |
|
|
910 | my $ms = sprintf "%dms", 1000 * $_ / $CFG->{audio_hw_frequency}; |
|
|
911 | [$_, $ms, "$ms ($_ samples)"], |
|
|
912 | } 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 |
|
|
913 | ]); |
|
|
914 | |
|
|
915 | my $text = !$freq |
|
|
916 | ? "audio is off" |
|
|
917 | : "Frequency (Hz): $freq\n" |
|
|
918 | . "Channels: $chans"; |
|
|
919 | |
|
|
920 | $AUDIO_INFO->set_text ($text); |
|
|
921 | } |
|
|
922 | |
893 | sub audio_setup { |
923 | sub audio_setup { |
894 | my $vbox = new CFPlus::UI::VBox; |
924 | my $vbox = new CFPlus::UI::VBox; |
895 | |
925 | |
896 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]); |
926 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]); |
897 | |
927 | |
… | |
… | |
899 | |
929 | |
900 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
930 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
901 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
931 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
902 | state => $CFG->{audio_enable}, |
932 | state => $CFG->{audio_enable}, |
903 | tooltip => "<b>Master Audio Enable.</b> If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", |
933 | tooltip => "<b>Master Audio Enable.</b> If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", |
904 | on_changed => sub { $CFG->{audio_enable} = $_[1]; 0 } |
934 | on_changed => sub { $CFG->{audio_enable} = $_[1]; 1 } |
905 | ); |
935 | ); |
906 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
907 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
|
|
908 | # $CFG->{effects_volume} = $_[1]; |
|
|
909 | # }); |
|
|
910 | |
936 | |
911 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); |
937 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); |
912 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
938 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
913 | expand => 1, state => $CFG->{effects_enable}, |
939 | expand => 1, state => $CFG->{effects_enable}, |
914 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
940 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
915 | on_changed => sub { |
941 | on_changed => sub { |
916 | $CFG->{effects_enable} = $_[1]; |
942 | $CFG->{effects_enable} = $_[1]; |
917 | $CONN->update_fx_want if $CONN; |
943 | $CONN->update_fx_want if $CONN; |
918 | 0 |
944 | 1 |
919 | } |
945 | } |
920 | ); |
946 | ); |
921 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
947 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
922 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
948 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
923 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
949 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
924 | . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", |
950 | . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", |
925 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
951 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 1 } |
926 | ); |
952 | ); |
927 | |
953 | |
928 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
954 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
929 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
955 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
930 | expand => 1, state => $CFG->{bgm_enable}, |
956 | expand => 1, state => $CFG->{bgm_enable}, |
931 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
957 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
932 | on_changed => sub { |
958 | on_changed => sub { |
933 | $CFG->{bgm_enable} = $_[1]; |
959 | $CFG->{bgm_enable} = $_[1]; |
934 | $CONN->update_fx_want if $CONN; |
960 | $CONN->update_fx_want if $CONN; |
935 | audio_music_push; |
961 | audio_music_push; |
936 | 0 |
962 | 1 |
937 | } |
963 | } |
938 | ); |
964 | ); |
939 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
965 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
940 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
966 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
941 | tooltip => "The volume of the background music. Changes are instant.", |
967 | tooltip => "The volume of the background music. Changes are instant.", |
942 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
968 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
|
|
969 | ); |
|
|
970 | |
|
|
971 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Frequency"); |
|
|
972 | $table->add_at (1, $row++, new CFPlus::UI::Selector |
|
|
973 | c_colspan => 2, expand => 1, |
|
|
974 | value => $CFG->{audio_hw_frequency}, |
|
|
975 | options => [ |
|
|
976 | [11025, "11 kHz" , "11kHz (low quality)"], |
|
|
977 | [22050, "22 kHz" , "22kHz (reduced quality)"], |
|
|
978 | [44100, "44.1 kHz", "44.1kHz (cd quality)"], |
|
|
979 | [48000, "48 kHz" , "48kHz (studio quality)"], |
|
|
980 | ], |
|
|
981 | tooltip => "The sampling frequency to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", |
|
|
982 | on_changed => sub { |
|
|
983 | $CFG->{audio_hw_frequency} = $_[1]; |
|
|
984 | audio_tab_update; |
|
|
985 | 1 |
|
|
986 | } |
|
|
987 | ); |
|
|
988 | |
|
|
989 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Channels"); |
|
|
990 | $table->add_at (1, $row++, new CFPlus::UI::Selector |
|
|
991 | c_colspan => 2, expand => 1, |
|
|
992 | value => $CFG->{audio_hw_channels}, |
|
|
993 | options => [ |
|
|
994 | [1, "Mono" , "Mono (single channel, low quality)"], |
|
|
995 | [2, "Stereo" , "Stereo (dual channe, standard quality)"], |
|
|
996 | [4, "4 Ch Surround", "4 Channel Surround Sound (3d sound, high quality)"], |
|
|
997 | [6, "6 Ch Surround", "6 Channel Surround Sound (3d sound + center + lfe)"], |
|
|
998 | ], |
|
|
999 | tooltip => "The number of independent sound channels to use. Higher sounds better, but also more cpu-intensive and might cause stuttering.", |
|
|
1000 | on_changed => sub { |
|
|
1001 | $CFG->{audio_hw_channels} = $_[1]; |
|
|
1002 | audio_tab_update; |
|
|
1003 | 1 |
|
|
1004 | } |
|
|
1005 | ); |
|
|
1006 | |
|
|
1007 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Latency"); |
|
|
1008 | $table->add_at (1, $row++, $AUDIO_HW_CHUNKSIZE = new CFPlus::UI::Selector |
|
|
1009 | c_colspan => 2, expand => 1, |
|
|
1010 | value => $CFG->{audio_hw_chunksize}, |
|
|
1011 | tooltip => "The guarenteed latency. Lower is better, but also more cpu-intensive and might cause stuttering. If music playback " |
|
|
1012 | . "is stuttering, increase this value. Values of 50-100ms are optimal.", |
|
|
1013 | on_changed => sub { |
|
|
1014 | $CFG->{audio_hw_chunksize} = $_[1] |
|
|
1015 | if $_[1]; |
|
|
1016 | audio_tab_update; |
|
|
1017 | 1 |
|
|
1018 | } |
|
|
1019 | ); |
|
|
1020 | |
|
|
1021 | # should really be a slider |
|
|
1022 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Mixer Voices"); |
|
|
1023 | $table->add_at (1, $row++, new CFPlus::UI::ValSlider |
|
|
1024 | c_colspan => 2, expand => 1, |
|
|
1025 | tooltip => "The number of simultaneous sound effects possible. Higher is better, but also more cpu-intensive and might cause stuttering.", |
|
|
1026 | range => [$::CFG->{audio_mix_channels}, 4, 32, 0, 1], |
|
|
1027 | template => ">= 99", |
|
|
1028 | on_changed => sub { |
|
|
1029 | my ($slider, $value) = @_; |
|
|
1030 | |
|
|
1031 | $CFG->{audio_mix_channels} = $value |
|
|
1032 | if $value; |
|
|
1033 | 1; |
|
|
1034 | } |
943 | ); |
1035 | ); |
944 | |
1036 | |
945 | $table->add_at (1, $row++, new CFPlus::UI::Button |
1037 | $table->add_at (1, $row++, new CFPlus::UI::Button |
946 | c_colspan => 2, expand => 1, align => 0, text => "Apply", |
1038 | c_colspan => 2, expand => 1, align => 0, text => "Apply", |
947 | tooltip => "Apply the audio settings", |
1039 | tooltip => "Apply the audio settings", |
… | |
… | |
949 | audio_shutdown (); |
1041 | audio_shutdown (); |
950 | audio_init (); |
1042 | audio_init (); |
951 | 0 |
1043 | 0 |
952 | } |
1044 | } |
953 | ); |
1045 | ); |
|
|
1046 | |
|
|
1047 | $vbox->add (new CFPlus::UI::FancyFrame |
|
|
1048 | expand => 1, |
|
|
1049 | label => "Audio Info", |
|
|
1050 | child => ($AUDIO_INFO = new CFPlus::UI::Label ellipsise => 0), |
|
|
1051 | ); |
|
|
1052 | |
|
|
1053 | audio_tab_update; |
954 | |
1054 | |
955 | $vbox |
1055 | $vbox |
956 | } |
1056 | } |
957 | |
1057 | |
958 | sub set_gauge_window_fontsize { |
1058 | sub set_gauge_window_fontsize { |
… | |
… | |
2251 | gauge_fontsize => 1, |
2351 | gauge_fontsize => 1, |
2252 | gauge_size => 0.35, |
2352 | gauge_size => 0.35, |
2253 | stat_fontsize => 0.7, |
2353 | stat_fontsize => 0.7, |
2254 | mapsize => 100, |
2354 | mapsize => 100, |
2255 | audio_enable => 1, |
2355 | audio_enable => 1, |
|
|
2356 | audio_hw_channels => 2, |
|
|
2357 | audio_hw_frequency => 22050, |
|
|
2358 | audio_hw_chunksize => 0, |
|
|
2359 | audio_mix_channels => 8, |
2256 | effects_enable => 1, |
2360 | effects_enable => 1, |
2257 | effects_volume => 1, |
2361 | effects_volume => 1, |
2258 | bgm_enable => 1, |
2362 | bgm_enable => 1, |
2259 | bgm_volume => 0.5, |
2363 | bgm_volume => 0.5, |
2260 | output_sync => 1, |
2364 | output_sync => 1, |