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.190 by root, Sun Jul 29 18:56:03 2007 UTC

162 162
163our $SDL_MIXER; 163our $SDL_MIXER;
164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; 164our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
165our @MUSIC_WANT; 165our @MUSIC_WANT;
166our $MUSIC_START; 166our $MUSIC_START;
167our $MUSIC_PLAYING; 167our $MUSIC_PLAYING_DATA;
168our $MUSIC_PLAYING_META;
168our $MUSIC_PLAYER; 169our $MUSIC_PLAYER;
169our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before 170our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
170our @SOUNDS; # event => file mapping 171our @SOUNDS; # event => file mapping
171our %AUDIO_CHUNKS; # audio files 172our %AUDIO_CHUNKS; # audio files
172 173
177our $INV; 178our $INV;
178our $INVR; 179our $INVR;
179our $INV_RIGHT_HB; 180our $INV_RIGHT_HB;
180 181
181our $PICKUP_CFG; 182our $PICKUP_CFG;
182
183our $IN_BUILD_MODE;
184our $BUILD_BUTTON;
185 183
186sub status { 184sub status {
187 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); 185 $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
188} 186}
189 187
492 $LOGIN_BUTTON->set_text ("Login"); 490 $LOGIN_BUTTON->set_text ("Login");
493 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER); 491 $SETUP_NOTEBOOK->set_current_page ($SETUP_SERVER);
494 $SETUP_DIALOG->show; 492 $SETUP_DIALOG->show;
495 $PL_WINDOW->hide; 493 $PL_WINDOW->hide;
496 $SPELL_LIST->clear_spells; 494 $SPELL_LIST->clear_spells;
497 $MESSAGE_WINDOW->clear_channels;
498 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN); 495 $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
499 496
500 &audio_music_set ([]); 497 &audio_music_set ([]);
501 498
502 return unless $CONN; 499 return unless $CONN;
1125 . "but you also increase bandwidth requirements and latency. " 1122 . "but you also increase bandwidth requirements and latency. "
1126 . "This option is only used once at log-in.", 1123 . "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 }, 1124 on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 },
1128 ); 1125 );
1129 1126
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"); 1127 $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
1144 $table->add_at (1, 9, new CFPlus::UI::Entry 1128 $table->add_at (1, 8, new CFPlus::UI::Entry
1145 text => $CFG->{output_rate}, 1129 text => $CFG->{output_rate},
1146 tooltip => "The approximate bandwidth in bytes per second that the server should not exceed " 1130 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 " 1131 . "when sending images, to ensure interactiveness. When 0 or unset, the server "
1148 . "default will be used, which is usually around 100kb/s.", 1132 . "default will be used, which is usually around 100kb/s.",
1149 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 }, 1133 on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
1150 ); 1134 );
1151 1135
1152 $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count"); 1136 $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
1153 $table->add_at (1, 10, new CFPlus::UI::Entry 1137 $table->add_at (1, 9, new CFPlus::UI::Entry
1154 text => $CFG->{output_count}, 1138 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.", 1139 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 }, 1140 on_changed => sub { $CFG->{output_count} = $_[1]; 0 },
1157 ); 1141 );
1158 1142
1159 $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync"); 1143 $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 1144 $table->add_at (1, 10, new CFPlus::UI::Entry
1161 text => $CFG->{output_sync}, 1145 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.", 1146 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 }, 1147 on_changed => sub { $CFG->{output_sync} = $_[1]; 0 },
1164 ); 1148 );
1165 1149
1166 $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button 1150 $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
1167 expand => 1, 1151 expand => 1,
1168 align => 0, 1152 align => 0,
1169 text => "Login", 1153 text => "Login",
1170 on_activate => sub { 1154 on_activate => sub {
1171 $CONN ? stop_game 1155 $CONN ? stop_game
1807 } 1791 }
1808 1792
1809 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); 1793 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
1810} 1794}
1811 1795
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 { 1796sub video_shutdown {
1932 CFPlus::OpenGL::shutdown; 1797 CFPlus::OpenGL::shutdown;
1933 1798
1934 undef $SDL_ACTIVE; 1799 undef $SDL_ACTIVE;
1935} 1800}
1953 &audio_music_changed (); 1818 &audio_music_changed ();
1954 } 1819 }
1955} 1820}
1956 1821
1957sub audio_music_start { 1822sub audio_music_start {
1958 my $path = $MUSIC_PLAYING->{path} 1823 my $meta = $MUSIC_PLAYING_META;
1959 or return;
1960 1824
1961 CFPlus::DB::prefetch_file $path, 1024_000, sub { 1825 CFPlus::DB::get res_data => $meta->{name}, sub {
1962 return unless $SDL_MIXER; 1826 return unless $SDL_MIXER;
1963 1827
1964 # music might have changed... 1828 # music might have changed...
1965 $path eq $MUSIC_PLAYING->{path} 1829 $meta eq $MUSIC_PLAYING_META
1966 or return &audio_music_start (); 1830 or return &audio_music_start ();
1967 1831
1832 $MUSIC_PLAYING_DATA = \$_[0];
1833
1834 my $rwops = $meta->{path}
1835 ? new_from_file CFPlus::RW $meta->{path}
1836 : new CFPlus::RW $$MUSIC_PLAYING_DATA;
1837
1968 $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path; 1838 $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
1839 or ((warn CFPlus::Mix_GetError), return); # pretty fatal error
1969 1840
1970 my $NOW = time; 1841 my $NOW = time;
1971 1842
1972 if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) { 1843 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
1973 my $pos = $MUSIC_PLAYING->{stop_pos}; 1844 my $pos = $MUSIC_PLAYING_META->{stop_pos};
1974 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 1845 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
1975 $MUSIC_START = time - $pos; 1846 $MUSIC_START = time - $pos;
1976 } else { 1847 } else {
1977 $MUSIC_PLAYER->play (0); 1848 $MUSIC_PLAYER->play (0);
1978 $MUSIC_START = time; 1849 $MUSIC_START = time;
1979 } 1850 }
1980 1851
1981 delete $MUSIC_PLAYING->{stop_time}; 1852 delete $MUSIC_PLAYING_META->{stop_time};
1982 delete $MUSIC_PLAYING->{stop_pos}; 1853 delete $MUSIC_PLAYING_META->{stop_pos};
1983 } 1854 }
1984} 1855}
1985 1856
1986sub audio_music_changed { 1857sub audio_music_changed {
1987 return unless $CFG->{bgm_enable}; 1858 return unless $CFG->{bgm_enable};
1989 1860
1990 # default MUSIC_WANT == MUSIC_DEFAULT 1861 # default MUSIC_WANT == MUSIC_DEFAULT
1991 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; 1862 @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
1992 1863
1993 # if the currently playing song is acceptable, let it continue 1864 # if the currently playing song is acceptable, let it continue
1994 return if $MUSIC_PLAYING 1865 return if $MUSIC_PLAYING_META
1995 && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT; 1866 && grep $MUSIC_PLAYING_META == $_, @MUSIC_WANT;
1996 1867
1997 my $NOW = time; 1868 my $NOW = time;
1998 1869
1999 if ($MUSIC_PLAYING) { 1870 if ($MUSIC_PLAYING_META) {
2000 $MUSIC_PLAYING->{stop_time} = $NOW; 1871 $MUSIC_PLAYING_META->{stop_time} = $NOW;
2001 $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START; 1872 $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
2002 CFPlus::MixMusic::fade_out 1000; 1873 CFPlus::MixMusic::fade_out 1000;
2003 } else { 1874 } else {
2004 # sort by stop time, oldest first 1875 # sort by stop time, oldest first
2005 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT; 1876 @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
2006 1877
2007 # if the most recently-played piece played very recently, 1878 # if the most recently-played piece played very recently,
2008 # resume it, else choose the oldest piece for rotation. 1879 # resume it, else choose the oldest piece for rotation.
2009 $MUSIC_PLAYING = 1880 $MUSIC_PLAYING_META =
2010 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME 1881 $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
2011 ? $MUSIC_WANT[-1] 1882 ? $MUSIC_WANT[-1]
2012 : $MUSIC_WANT[0]; 1883 : $MUSIC_WANT[0];
2013 1884
2014 audio_music_start; 1885 audio_music_start;
2015 } 1886 }
2016} 1887}
2017 1888
2018sub audio_music_finished { 1889sub audio_music_finished {
2019 $MUSIC_PLAYING = undef;
2020 undef $MUSIC_PLAYER; 1890 undef $MUSIC_PLAYER;
1891 undef $MUSIC_PLAYING_META;
1892 undef $MUSIC_PLAYING_DATA;
2021 1893
2022 audio_music_changed; 1894 audio_music_changed;
2023} 1895}
2024 1896
2025sub audio_init { 1897sub audio_init {
2026 if ($CFG->{audio_enable}) { 1898 if ($CFG->{audio_enable}) {
2027 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") { 1899 if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
1900 $ENV{MIX_EFFECTSMAXSPEED} = 1;
2028 $SDL_MIXER = !CFPlus::Mix_OpenAudio; 1901 $SDL_MIXER = !CFPlus::Mix_OpenAudio;
2029 1902
2030 unless ($SDL_MIXER) { 1903 unless ($SDL_MIXER) {
2031 status "Unable to open sound device: there will be no sound"; 1904 status "Unable to open sound device: there will be no sound";
2032 return; 1905 return;
2045 my ($file, $volume, $event) = split /\s+/, $_, 3; 1918 my ($file, $volume, $event) = split /\s+/, $_, 3;
2046 1919
2047 push @SOUNDS, "$volume,$file"; 1920 push @SOUNDS, "$volume,$file";
2048 1921
2049 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 1922 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
2050 my $chunk = new_from_file CFPlus::MixChunk CFPlus::find_rcfile "sounds/$file"; 1923 my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file";
1924 my $chunk = new CFPlus::MixChunk $rwops;
2051 $chunk->volume ($volume * 128 / 100); 1925 $chunk->volume ($volume * 128 / 100);
2052 $chunk 1926 $chunk
2053 }; 1927 };
2054 } 1928 }
2055 } else { 1929 } else {
2112 1986
2113sub animation_stop { 1987sub animation_stop {
2114 my ($widget) = @_; 1988 my ($widget) = @_;
2115 delete $animate_object{$widget}; 1989 delete $animate_object{$widget};
2116} 1990}
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 1991
2127%SDL_CB = ( 1992%SDL_CB = (
2128 CFPlus::SDL_QUIT => sub { 1993 CFPlus::SDL_QUIT => sub {
2129 exit; 1994 exit;
2130 }, 1995 },
2191 stat_fontsize => 0.7, 2056 stat_fontsize => 0.7,
2192 mapsize => 100, 2057 mapsize => 100,
2193 audio_enable => 1, 2058 audio_enable => 1,
2194 bgm_enable => 1, 2059 bgm_enable => 1,
2195 bgm_volume => 0.25, 2060 bgm_volume => 0.25,
2196 face_prefetch => 0,
2197 output_sync => 1, 2061 output_sync => 1,
2198 output_count => 1, 2062 output_count => 1,
2199 output_rate => "", 2063 output_rate => "",
2200 pickup => 0, 2064 pickup => 0,
2201 inv_sort => "mtime", 2065 inv_sort => "mtime",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines