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

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.148 by root, Wed Apr 19 23:37:50 2006 UTC vs.
Revision 1.153 by root, Thu Apr 20 09:13:32 2006 UTC

98 undef $CONN; 98 undef $CONN;
99} 99}
100 100
101sub client_setup { 101sub client_setup {
102 my $dialog = new CFClient::UI::FancyFrame 102 my $dialog = new CFClient::UI::FancyFrame
103 title => "Client Setup",
103 child => (my $vbox = new CFClient::UI::VBox); 104 child => (my $vbox = new CFClient::UI::VBox);
104 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
105 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 105 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
106 106
107 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); 107 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
108 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 108 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
109 109
110 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 110 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
111 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); 111 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
112 112
113 $mode_slider->connect (changed => sub { 113 $mode_slider->connect (changed => sub {
114 my ($self, $value) = @_; 114 my ($self, $value) = @_;
115 115
116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
178 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { 178 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
179 $CFG->{bgm_enable} = $_[1]; 179 $CFG->{bgm_enable} = $_[1];
180 }); 180 });
181 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { 181 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
182 $CFG->{bgm_volume} = $_[1]; 182 $CFG->{bgm_volume} = $_[1];
183 CFClient::Mix_VolumeMusic ($_[1]); 183 CFClient::MixMusic::volume $_[1] * 128;
184 }); 184 });
185 185
186 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 186 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
187 audio_shutdown (); 187 audio_shutdown ();
188 audio_init (); 188 audio_init ();
191 $dialog 191 $dialog
192} 192}
193 193
194sub metaserver_dialog { 194sub metaserver_dialog {
195 my $dialog = new CFClient::UI::FancyFrame 195 my $dialog = new CFClient::UI::FancyFrame
196 title => "Metaserver",
196 child => (my $vbox = new CFClient::UI::VBox); 197 child => (my $vbox = new CFClient::UI::VBox);
197 198
198 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 199 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
199 200
200 $dialog 201 $dialog
266 }); 267 });
267} 268}
268 269
269sub server_setup { 270sub server_setup {
270 my $dialog = new CFClient::UI::FancyFrame 271 my $dialog = new CFClient::UI::FancyFrame
272 title => "Server Setup",
271 child => (my $vbox = new CFClient::UI::VBox); 273 child => (my $vbox = new CFClient::UI::VBox);
272 274
273 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
274 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 275 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
275 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); 276 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
276 277
277 { 278 {
278 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 279 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
325 $dialog 326 $dialog
326} 327}
327 328
328sub message_window { 329sub message_window {
329 my $window = new CFClient::UI::FancyFrame 330 my $window = new CFClient::UI::FancyFrame
331 title => "Messages",
330 border_bg => [1, 1, 1, 0.5], 332 border_bg => [1, 1, 1, 0.5],
331 bg => [0.3, 0.3, 0.3, 0.8], 333 bg => [0.3, 0.3, 0.3, 0.8],
332 user_w => int $::WIDTH / 3, 334 user_w => int $::WIDTH / 3,
333 user_h => int $::HEIGHT / 5, 335 user_h => int $::HEIGHT / 5,
334 child => (my $vbox = new CFClient::UI::VBox); 336 child => (my $vbox = new CFClient::UI::VBox);
443 status "Configuration Saved"; 445 status "Configuration Saved";
444 }); 446 });
445 447
446 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 448 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
447 449
448 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); 450 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats");
449 $tgw->add (my $hbox = new CFClient::UI::HBox ()); 451 $tgw->add (my $hbox = new CFClient::UI::HBox ());
450 452
451 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); 453 $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
452 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); 454 $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
453 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); 455 $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
454 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); 456 $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
455 457
456 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 458 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
457 $CFClient::UI::ROOT->add ($tgw); 459 $CFClient::UI::ROOT->add ($tgw);
458} 460}
459 461
460sub video_shutdown { 462sub video_shutdown {
461 $CFClient::UI::ROOT->{children} = []; 463 $CFClient::UI::ROOT->{children} = [];
462 undef $SDL_ACTIVE; 464 undef $SDL_ACTIVE;
463} 465}
464 466
467my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
465my $bgmusic;#TODO#hack#d# 468my $bgmusic;#TODO#hack#d#
469
470sub audio_music_finished {
471 return unless $CFG->{bgm_enable};
472
473 # TODO: hack, do play loop and mood music
474 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
475 $bgmusic->play (0);
476
477 push @bgmusic, shift @bgmusic;
478}
466 479
467sub audio_init { 480sub audio_init {
468 if ($CFG->{audio_enable}) { 481 if ($CFG->{audio_enable}) {
469 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 482 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
470 483
471 $SDL_MIXER = !CFClient::Mix_OpenAudio; 484 $SDL_MIXER = !CFClient::Mix_OpenAudio;
472 CFClient::Mix_AllocateChannels 8; 485 CFClient::Mix_AllocateChannels 8;
473 CFClient::MixMusic::volume $CFG->{bgm_volume}; 486 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
474 487
475 # TODO: hack, do play loop and mood music 488 audio_music_finished;
476 if ($CFG->{bgm_enable}) {
477 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
478 $bgmusic->play;
479 }
480 489
481 while (<$fh>) { 490 while (<$fh>) {
482 next if /^\s*#/; 491 next if /^\s*#/;
483 next if /^\s*$/; 492 next if /^\s*$/;
484 493
569 my $hp = $stats->{1}; 578 my $hp = $stats->{1};
570 my $hp_m = $stats->{2}; 579 my $hp_m = $stats->{2};
571 my $sp = $stats->{3}; 580 my $sp = $stats->{3};
572 my $sp_m = $stats->{4}; 581 my $sp_m = $stats->{4};
573 my $fo = $stats->{18}; 582 my $fo = $stats->{18};
574 my $fo_m = 1000; 583 my $fo_m = 999;
575 my $gr = $stats->{23}; 584 my $gr = $stats->{23};
576 my $gr_m = $stats->{24}; 585 my $gr_m = $stats->{24};
577 586
578 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 587 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
579 $GAUGES->{hp}->set_value ($hp, $hp_m); 588 $GAUGES->{hp} ->set_value ($hp, $hp_m);
580 $GAUGES->{mana}->set_value ($sp, $sp_m); 589 $GAUGES->{mana} ->set_value ($sp, $sp_m);
581 $GAUGES->{food}->set_value ($fo, $fo_m); 590 $GAUGES->{food} ->set_value ($fo, $fo_m);
582 $GAUGES->{grace}->set_value ($gr, $gr_m); 591 $GAUGES->{grace}->set_value ($gr, $gr_m);
583} 592}
584 593
585sub conn::user_send { 594sub conn::user_send {
586 my ($self, $command) = @_; 595 my ($self, $command) = @_;
612 621
613 my ($hash, $x, $y, $w, $h) = @$map_info; 622 my ($hash, $x, $y, $w, $h) = @$map_info;
614 623
615 my $data = $MAP->get_rect ($x, $y, $w, $h); 624 my $data = $MAP->get_rect ($x, $y, $w, $h);
616 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 625 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
617
618 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 626 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
619
620} 627}
621 628
622sub conn::map_clear { 629sub conn::map_clear {
623 my ($self) = @_; 630 my ($self) = @_;
624 631
625 $self->flush_map; 632 $self->flush_map;
626 delete $self->{neigh}; 633 delete $self->{neigh_map};
627 634
628 $MAP->clear; 635 $MAP->clear;
629} 636}
630 637
631 638
632sub conn::load_map($$$) { 639sub conn::load_map($$$) {
633 my ($self, $hash, $x, $y) = @_; 640 my ($self, $hash, $x, $y) = @_;
634 641
635 if (defined (my $data = $MAPCACHE->get ($hash))) { 642 if (defined (my $data = $MAPCACHE->get ($hash))) {
636 $data = Compress::LZF::decompress $data; 643 $data = Compress::LZF::decompress $data;
637 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 644 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
638 for my $id ($MAP->set_rect ($x, $y, $data)) { 645 for my $id ($MAP->set_rect ($x, $y, $data)) {
639 my $data = $TILECACHE->get ($id) 646 my $data = $TILECACHE->get ($id)
640 or next; 647 or next;
641 648
642 $self->set_texture ($id => $data); 649 $self->set_texture ($id => $data);
643 } 650 }
644 } 651 }
645} 652}
646 653
654# this method does a "flood fill" into every tile direction
655# it assumes that tiles are arranged in a rectangular grid,
656# i.e. a map is the same as the left of the right map etc.
657# failure to comply are harmless and result in display errors
658# at worst.
647sub conn::flood_fill { 659sub conn::flood_fill {
648 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 660 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
649 661
650 # the server does not allow map paths > 6 662 # the server does not allow map paths > 6
651 return if 6 <= length $path; 663 return if 6 <= length $path;
652 664
653 for my $tile (1..4) { 665 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
654 next if $self->{neigh}{$hash}[$tile]; 666
667 for (
668 [1, 0, -1],
669 [2, 1, 0],
670 [3, 0, 1],
671 [4, -1, 0],
672 ) {
673 my ($tile, $dx, $dy) = @$_;
674
675 my $gx = $gx + $dx;
676 my $gy = $gy + $dy;
677
655 next unless $flags & (1 << ($tile - 1)); 678 next unless $flags & (1 << ($tile - 1));
679 next if $self->{neigh_grid}{$gx, $gy}++;
656 680
657 my $neigh = $self->{neigh}{$hash} ||= []; 681 my $neigh = $self->{neigh_map}{$hash} ||= [];
658 682 if (my $info = $neigh->[$tile]) {
659 $self->send_mapinfo ("spatial $path$tile", sub {
660 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 683 my ($flags, $x, $y, $w, $h, $hash) = @$info;
661 684
662 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
663 return if $mode ne "spatial";
664
665 $x += $MAP->ox;
666 $y += $MAP->oy;
667
668 $self->load_map ($hash, $x, $y)
669 unless $self->{neigh}{$hash}[5]++;#d#
670
671 $neigh->[$tile] = [$x, $y, $w, $h];
672
673 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 685 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
674 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 686 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
687
688 } else {
689 $self->send_mapinfo ("spatial $path$tile", sub {
690 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
691
692 return if $mode ne "spatial";
693
694 $x += $MAP->ox;
695 $y += $MAP->oy;
696
697 $self->load_map ($hash, $x, $y)
698 unless $self->{neigh_map}{$hash}[5]++;#d#
699
700 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
701
702 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
703 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
704 });
675 }); 705 }
676 } 706 }
677} 707}
678 708
679sub conn::map_change { 709sub conn::map_change {
680 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 710 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
683 713
684 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 714 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
685 715
686 my $mapmapw = 250; 716 my $mapmapw = 250;
687 my $mapmaph = 250; 717 my $mapmaph = 250;
718
719 $self->{neigh_rect} = [
720 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
721 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
722 ];
688 723
724 delete $self->{neigh_grid};
689 $self->flood_fill ("", $hash, $flags, 725 $self->flood_fill (0, 0, "", $hash, $flags);
690 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
691 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
692 726
693 $x += $ox; 727 $x += $ox;
694 $y += $oy; 728 $y += $oy;
695 729
696 $self->{map_info} = [$hash, $x, $y, $w, $h]; 730 $self->{map_info} = [$hash, $x, $y, $w, $h];
825 CFClient::SDL_QUIT => sub { 859 CFClient::SDL_QUIT => sub {
826 Event::unloop -1; 860 Event::unloop -1;
827 }, 861 },
828 CFClient::SDL_VIDEORESIZE => sub { 862 CFClient::SDL_VIDEORESIZE => sub {
829 }, 863 },
830 CFClient::SDL_VIDEOEXPOSE => sub { 864 CFClient::SDL_VIDEOEXPOSE => \&refresh,
831 refresh; 865 CFClient::SDL_ACTIVEEVENT => sub {
866# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
832 }, 867 },
833 CFClient::SDL_KEYDOWN => sub { 868 CFClient::SDL_KEYDOWN => sub {
834 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 869 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
835 # alt-enter 870 # alt-enter
836 video_shutdown; 871 video_shutdown;
838 video_init; 873 video_init;
839 } else { 874 } else {
840 CFClient::UI::feed_sdl_key_down_event ($_[0]); 875 CFClient::UI::feed_sdl_key_down_event ($_[0]);
841 } 876 }
842 }, 877 },
843 CFClient::SDL_KEYUP => sub { 878 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
844 CFClient::UI::feed_sdl_key_up_event ($_[0]); 879 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
845 }, 880 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
846 CFClient::SDL_MOUSEMOTION => sub { 881 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
847 CFClient::UI::feed_sdl_motion_event ($_[0]); 882 CFClient::SDL_USEREVENT => \&audio_music_finished,
848 },
849 CFClient::SDL_MOUSEBUTTONDOWN => sub {
850 CFClient::UI::feed_sdl_button_down_event ($_[0]);
851 },
852 CFClient::SDL_MOUSEBUTTONUP => sub {
853 CFClient::UI::feed_sdl_button_up_event ($_[0]);
854 },
855 CFClient::SDL_ACTIVEEVENT => sub {
856# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
857 },
858); 883);
859 884
860############################################################################# 885#############################################################################
861 886
862$SIG{INT} = $SIG{TERM} = sub { exit }; 887$SIG{INT} = $SIG{TERM} = sub { exit };
880 mapsize => 100, 905 mapsize => 100,
881 host => "crossfire.schmorp.de", 906 host => "crossfire.schmorp.de",
882 say_command => 'say', 907 say_command => 'say',
883 audio_enable => 1, 908 audio_enable => 1,
884 bgm_enable => 1, 909 bgm_enable => 1,
885 bgm_volume => 64, 910 bgm_volume => 0.25,
886); 911);
887 912
888while (my ($k, $v) = each %DEF_CFG) { 913while (my ($k, $v) = each %DEF_CFG) {
889 $CFG->{$k} = $v unless exists $CFG->{$k}; 914 $CFG->{$k} = $v unless exists $CFG->{$k};
890} 915}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines