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.216 by root, Sun Aug 19 12:56:24 2007 UTC vs.
Revision 1.224 by root, Thu Aug 30 07:57:59 2007 UTC

126our $FONT_FIXED; 126our $FONT_FIXED;
127 127
128our $MAP; 128our $MAP;
129our $MAPMAP; 129our $MAPMAP;
130our $MAPWIDGET; 130our $MAPWIDGET;
131our $COMPLETER;
131our $BUTTONBAR; 132our $BUTTONBAR;
132our $METASERVER; 133our $METASERVER;
133our $LOGIN_BUTTON; 134our $LOGIN_BUTTON;
134our $QUIT_DIALOG; 135our $QUIT_DIALOG;
135our $HOST_ENTRY; 136our $HOST_ENTRY;
146our $PL_WINDOW; 147our $PL_WINDOW;
147 148
148our $MUSIC_PLAYING_WIDGET; 149our $MUSIC_PLAYING_WIDGET;
149our $LICENSE_WIDGET; 150our $LICENSE_WIDGET;
150 151
152our $PICKUP_PAGE;
151our $INVENTORY_PAGE; 153our $INVENTORY_PAGE;
152our $STATS_PAGE; 154our $STATS_PAGE;
153our $SKILL_PAGE; 155our $SKILL_PAGE;
154our $SPELL_PAGE; 156our $SPELL_PAGE;
155our $SPELL_LIST; 157our $SPELL_LIST;
228 $channel->set_position_r ($dx, $dy, 20); 230 $channel->set_position_r ($dx, $dy, 20);
229 $chunk->play ($channel); 231 $chunk->play ($channel);
230 } 232 }
231 } else { 233 } else {
232 # sound_meta not set means data is in flight either way 234 # sound_meta not set means data is in flight either way
233 my $meta = $CONN->{sound_meta}{$face} 235 my $meta = $CONN->{face}[$face]
234 or return; 236 or return;
235 237
238 $meta->{data}
239 or return;
240
236 # if its a jingle, play it as ambient music 241 # if its a jingle, play it as ambient music
237 if ($meta->{meta}{jingle}) { 242 if ($meta->{data}{jingle}) {
238 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue 243 if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
239 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue 244 push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
240 &audio_music_push ($face); 245 &audio_music_push ($face);
241 } 246 }
242 } else { 247 } else {
243 # fetch from database 248 # fetch from database
244 CFPlus::DB::get res_data => $meta->{name}, sub { 249 CFPlus::DB::get res_data => $meta->{name}, sub {
245 my $rwops = new CFPlus::RW $_[0]; 250 my $rwops = new CFPlus::RW $_[0];
246 my $chunk = new CFPlus::MixChunk $rwops 251 my $chunk = new CFPlus::MixChunk $rwops
247 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; 252 or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
248 $chunk->volume (($meta->{meta}{volume} || 1) * 128); 253 $chunk->volume (($meta->{data}{volume} || 1) * 128);
249 $AUDIO_CHUNK{$face} = $chunk; 254 $AUDIO_CHUNK{$face} = $chunk;
250 255
251 audio_sound_push ($face); 256 audio_sound_push ($face);
252 }; 257 };
253 } 258 }
271sub audio_music_set_meta { 276sub audio_music_set_meta {
272 my ($meta) = @_; 277 my ($meta) = @_;
273 278
274 $MUSIC_PLAYING_META = $meta; 279 $MUSIC_PLAYING_META = $meta;
275 $MUSIC_PLAYING_WIDGET->set_markup ( 280 $MUSIC_PLAYING_WIDGET->set_markup (
276 "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" 281 "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
277 . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" 282 . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
278 . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" 283 . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
279 . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) 284 . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license})
280 ); 285 );
281} 286}
282 287
283sub audio_music_update_volume { 288sub audio_music_update_volume {
284 return unless $MUSIC_PLAYING_META; 289 return unless $MUSIC_PLAYING_META;
285 my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; 290 my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
286 my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; 291 my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
287 CFPlus::MixMusic::volume $base * $volume * 128; 292 CFPlus::MixMusic::volume $base * $volume * 128;
288} 293}
289 294
290sub audio_music_start { 295sub audio_music_start {
291 my $meta = $MUSIC_PLAYING_META; 296 my $meta = $MUSIC_PLAYING_META;
310 315
311 my $NOW = time; 316 my $NOW = time;
312 317
313 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { 318 if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
314 my $pos = $MUSIC_PLAYING_META->{stop_pos}; 319 my $pos = $MUSIC_PLAYING_META->{stop_pos};
315 $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos); 320 $MUSIC_PLAYER->fade_in_pos (0, 700, $pos);
316 $MUSIC_START = time - $pos; 321 $MUSIC_START = time - $pos;
317 } else { 322 } else {
318 $MUSIC_PLAYER->play (0); 323 $MUSIC_PLAYER->play (0);
319 $MUSIC_START = time; 324 $MUSIC_START = time;
320 } 325 }
334 $fade_out = 333; 339 $fade_out = 333;
335 } else { 340 } else {
336 return unless $CFG->{bgm_enable}; 341 return unless $CFG->{bgm_enable};
337 342
338 my @have = 343 my @have =
339 grep $_, 344 grep $_ && $_->{data},
340 map $CONN->{music_meta}{$_}, 345 map $CONN->{face}[$_],
341 @$MUSIC_WANT; 346 @$MUSIC_WANT;
347
348 # randomize music a bit so that the order is not always the same
349 $_->{stop_time} ||= rand for @have;
342 350
343 @MUSIC_HAVE = @have 351 @MUSIC_HAVE = @have
344 if @have; 352 if @have;
345 353
346 # default MUSIC_HAVE == MUSIC_DEFAULT 354 # default MUSIC_HAVE == MUSIC_DEFAULT
347 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; 355 @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
348 $fade_out = 1000; 356 $fade_out = 700;
349 } 357 }
350 358
351 # if the currently playing song is acceptable, let it continue 359 # if the currently playing song is acceptable, let it continue
352 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; 360 return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
353 361
362 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; 370 @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
363 371
364 # if the most recently-played piece played very recently, 372 # if the most recently-played piece played very recently,
365 # resume it, else choose the oldest piece for rotation. 373 # resume it, else choose the oldest piece for rotation.
366 audio_music_set_meta 374 audio_music_set_meta
367 $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME 375 $MUSIC_HAVE[-1]{stop_pos} && $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
368 ? $MUSIC_HAVE[-1] 376 ? $MUSIC_HAVE[-1]
369 : $MUSIC_HAVE[0]; 377 : $MUSIC_HAVE[0];
370 378
371 audio_music_start; 379 audio_music_start;
372 } 380 }
378 $MUSIC_WANT = $songs; 386 $MUSIC_WANT = $songs;
379 audio_music_push; 387 audio_music_push;
380} 388}
381 389
382sub audio_music_finished { 390sub audio_music_finished {
391 if ($MUSIC_PLAYING_META) {
392 $MUSIC_PLAYING_META->{stop_time} = time;
393 }
394
383 # we compress multiple jingles of the same type 395 # we compress multiple jingles of the same type
384 shift @MUSIC_JINGLE 396 shift @MUSIC_JINGLE
385 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; 397 while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
386 398
387 $MUSIC_PLAYING_WIDGET->clear; 399 $MUSIC_PLAYING_WIDGET->clear;
784 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); 796 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
785 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 797 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
786 state => $CFG->{texture_compression}, 798 state => $CFG->{texture_compression},
787 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " 799 tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
788 . "will save a lot of memory and increase performance. The compression algorithm " 800 . "will save a lot of memory and increase performance. The compression algorithm "
789 . "can differ form card to card, so your mileage may vary.", 801 . "can differ form card to card, so your mileage may vary. This setting is ignored in "
802 . "forced OpenGL 1.1 mode.",
790 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } 803 on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
791 ); 804 );
792 805
793 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); 806 $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
794 $table->add_at (1, $row++, new CFPlus::UI::CheckBox 807 $table->add_at (1, $row++, new CFPlus::UI::CheckBox
917 expand => 1, state => $CFG->{bgm_enable}, 930 expand => 1, state => $CFG->{bgm_enable},
918 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", 931 tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
919 on_changed => sub { 932 on_changed => sub {
920 $CFG->{bgm_enable} = $_[1]; 933 $CFG->{bgm_enable} = $_[1];
921 $CONN->update_fx_want if $CONN; 934 $CONN->update_fx_want if $CONN;
935 audio_music_push;
922 0 936 0
923 } 937 }
924 ); 938 );
925 $table->add_at (2, $row++, new CFPlus::UI::Slider 939 $table->add_at (2, $row++, new CFPlus::UI::Slider
926 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], 940 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
979 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); 993 $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health");
980 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); 994 $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana");
981 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); 995 $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace");
982 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); 996 $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
983 997
984 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); 998 $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
999 $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
1000 $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress);
985 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); 1001 $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
986 1002
987 $GAUGES = { 1003 $GAUGES = {
1004 exp => $exp, prg => $prg, sklprg => $sklprg,
988 exp => $exp, win => $win, range => $rng, 1005 win => $win, range => $rng,
989 food => $fg, mana => $mg, hp => $hg, grace => $gg 1006 hp => $hg, mana => $mg, grace => $gg, food => $fg,
990 }; 1007 };
991 1008
992 &set_gauge_window_fontsize; 1009 &set_gauge_window_fontsize;
993 1010
994 $win 1011 $win
1195 $r 1212 $r
1196} 1213}
1197 1214
1198sub skill_window { 1215sub skill_window {
1199 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); 1216 my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
1217
1200 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); 1218 $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
1219
1201 $sw 1220 $sw
1202} 1221}
1203 1222
1204sub formsep($) { 1223sub formsep($) {
1205 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 1224 scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1
1650} 1669}
1651 1670
1652sub add_license { 1671sub add_license {
1653 my ($meta) = @_; 1672 my ($meta) = @_;
1654 1673
1655 $meta = $meta->{meta} 1674 $meta = $meta->{data}
1656 or return; 1675 or return;
1657 1676
1658 $meta->{license} || $meta->{author} || $meta->{source} 1677 $meta->{license} || $meta->{author} || $meta->{source}
1659 or return; 1678 or return;
1660 1679
1714 $ntb->add_tab ( 1733 $ntb->add_tab (
1715 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, 1734 "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget,
1716 "Toggles the inventory window, where you can manage your loot (or treasures :). " 1735 "Toggles the inventory window, where you can manage your loot (or treasures :). "
1717 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." 1736 . "You can also hit the <b>Tab</b>-key to show/hide the Inventory."
1718 ); 1737 );
1719 $ntb->add_tab (Pickup => autopickup_setup, 1738 $ntb->add_tab (Pickup => $PICKUP_PAGE = autopickup_setup,
1720 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); 1739 "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
1721 1740
1722 $ntb->add_tab (Media => media_window, 1741 $ntb->add_tab (Media => media_window,
1723 "License, Author and Source info for media sent by the server."); 1742 "License, Author and Source info for media sent by the server.");
1724 1743
1965 1984
1966 $SDL_ACTIVE = 1; 1985 $SDL_ACTIVE = 1;
1967 $LAST_REFRESH = time - 0.01; 1986 $LAST_REFRESH = time - 0.01;
1968 1987
1969 CFPlus::OpenGL::init; 1988 CFPlus::OpenGL::init;
1989 CFPlus::Macro::init;
1970 1990
1971 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 1991 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
1972 1992
1973 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d# 1993 $CFPlus::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
1974 1994
1975 ############################################################################# 1995 #############################################################################
1976 1996
1977 if ($DEBUG_STATUS) { 1997 if ($DEBUG_STATUS) {
1978 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h; 1998 CFPlus::UI::rescale_widgets $WIDTH / $old_w, $HEIGHT / $old_h;
1979 } else { 1999 } else {
1980 # create the widgets 2000 # create/configure the widgets
2001
2002 $CFPlus::UI::ROOT->connect (key_down => sub {
2003 my (undef, $ev) = @_;
2004
2005 if (my @macros = CFPlus::Macro::find $ev) {
2006 CFPlus::Macro::execute $_ for @macros;
2007
2008 return 1;
2009 }
2010
2011 0
2012 });
1981 2013
1982 $DEBUG_STATUS = new CFPlus::UI::Label 2014 $DEBUG_STATUS = new CFPlus::UI::Label
1983 padding => 0, 2015 padding => 0,
1984 z => 100, 2016 z => 100,
1985 force_x => "max", 2017 force_x => "max",
2015 $MESSAGE_WINDOW->activate_console ($preset) 2047 $MESSAGE_WINDOW->activate_console ($preset)
2016 if $MESSAGE_WINDOW; 2048 if $MESSAGE_WINDOW;
2017 }); 2049 });
2018 $MAPWIDGET->show; 2050 $MAPWIDGET->show;
2019 $MAPWIDGET->grab_focus; 2051 $MAPWIDGET->grab_focus;
2052
2053 $COMPLETER = new CFPlus::MapWidget::Command::
2054 command => { },
2055 tooltip => "#completer_help",
2056 ;
2020 2057
2021 $SETUP_DIALOG = new CFPlus::UI::Toplevel 2058 $SETUP_DIALOG = new CFPlus::UI::Toplevel
2022 title => "Setup", 2059 title => "Setup",
2023 name => "setup_dialog", 2060 name => "setup_dialog",
2024 x => 'center', 2061 x => 'center',
2149 delete $animate_object{$widget}; 2186 delete $animate_object{$widget};
2150} 2187}
2151 2188
2152%SDL_CB = ( 2189%SDL_CB = (
2153 CFPlus::SDL_QUIT => sub { 2190 CFPlus::SDL_QUIT => sub {
2154 exit; 2191 Event::unloop_all;
2155 }, 2192 },
2156 CFPlus::SDL_VIDEORESIZE => sub { 2193 CFPlus::SDL_VIDEORESIZE => sub {
2157 }, 2194 },
2158 CFPlus::SDL_VIDEOEXPOSE => sub { 2195 CFPlus::SDL_VIDEOEXPOSE => sub {
2159 CFPlus::UI::full_refresh; 2196 CFPlus::UI::full_refresh;
2201 2238
2202 my %DEF_CFG = ( 2239 my %DEF_CFG = (
2203 sdl_mode => 0, 2240 sdl_mode => 0,
2204 fullscreen => 0, 2241 fullscreen => 0,
2205 fast => 0, 2242 fast => 0,
2206 force_opengl11 => 0, 2243 force_opengl11 => undef,
2207 texture_compression => 1, 2244 texture_compression => 1,
2208 map_scale => 1, 2245 map_scale => 1,
2209 fow_enable => 1, 2246 fow_enable => 1,
2210 fow_intensity => 0, 2247 fow_intensity => 0,
2211 map_smoothing => 1, 2248 map_smoothing => 1,
2292# } 2329# }
2293# my $t2 = Time::HiRes::time; 2330# my $t2 = Time::HiRes::time;
2294# warn $t2-$t1; 2331# warn $t2-$t1;
2295# } 2332# }
2296 2333
2297 $startup_done->();
2298
2299 video_init; 2334 video_init;
2300 audio_init; 2335 audio_init;
2301} 2336}
2302 2337
2303show_tip_of_the_day if $CFG->{show_tips}; 2338show_tip_of_the_day if $CFG->{show_tips};
2339
2340Event->idle (cb => sub {
2341 $_[0]->w->cancel;
2342 $startup_done->();
2343});
2304 2344
2305Event::loop; 2345Event::loop;
2306 2346
2307#video_shutdown; 2347#video_shutdown;
2308#audio_shutdown; 2348#audio_shutdown;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines