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.155 by root, Thu Apr 20 21:28:51 2006 UTC

45our $LOGVIEW; 45our $LOGVIEW;
46our $CONSOLE; 46our $CONSOLE;
47our $METASERVER; 47our $METASERVER;
48 48
49our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
50 51
51our $SDL_ACTIVE; 52our $SDL_ACTIVE;
52our %SDL_CB; 53our %SDL_CB;
53 54
54our $SDL_MIXER; 55our $SDL_MIXER;
98 undef $CONN; 99 undef $CONN;
99} 100}
100 101
101sub client_setup { 102sub client_setup {
102 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
103 child => (my $vbox = new CFClient::UI::VBox); 105 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]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
106 107
107 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); 108 $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); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
109 110
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_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); 112 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
112 113
113 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
114 my ($self, $value) = @_; 115 my ($self, $value) = @_;
115 116
116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $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 { 179 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
179 $CFG->{bgm_enable} = $_[1]; 180 $CFG->{bgm_enable} = $_[1];
180 }); 181 });
181 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { 182 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
182 $CFG->{bgm_volume} = $_[1]; 183 $CFG->{bgm_volume} = $_[1];
183 CFClient::Mix_VolumeMusic ($_[1]); 184 CFClient::MixMusic::volume $_[1] * 128;
184 }); 185 });
185 186
186 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 187 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
187 audio_shutdown (); 188 audio_shutdown ();
188 audio_init (); 189 audio_init ();
189 }); 190 });
190 191
191 $dialog 192 $dialog
192} 193}
193 194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats");
197
198 $tgw->add (my $vb = new CFClient::UI::VBox);
199
200 $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1);
201
202 $vb->add (my $hb2 = new CFClient::UI::HBox expand => 1);
203
204 $hb2->add (my $hg = new CFClient::UI::Gauge type => 'hp', expand => 1);
205 $hb2->add (my $mg = new CFClient::UI::Gauge type => 'mana', expand => 1);
206 $hb2->add (my $gg = new CFClient::UI::Gauge type => 'grace', expand => 1);
207 $hb2->add (my $fg = new CFClient::UI::Gauge type => 'food', expand => 1);
208 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
209
210 $tgw
211}
212
213sub update_stats_window {
214 my ($stats) = @_;
215
216 $STATWIDS->{stat}->set_text (
217 "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28})
218 . " Level: $stats->{12}\n"
219 . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n",
220 @$stats{5,8,9,6,7,22,10, 13, 14})
221 . (sprintf "Dam %d Arm %d Speed %.2f/%.2f",
222 @$stats{15,16,17,19})
223 );
224}
225
194sub metaserver_dialog { 226sub metaserver_dialog {
195 my $dialog = new CFClient::UI::FancyFrame 227 my $dialog = new CFClient::UI::FancyFrame
228 title => "Metaserver",
196 child => (my $vbox = new CFClient::UI::VBox); 229 child => (my $vbox = new CFClient::UI::VBox);
197 230
198 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 231 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
199 232
200 $dialog 233 $dialog
266 }); 299 });
267} 300}
268 301
269sub server_setup { 302sub server_setup {
270 my $dialog = new CFClient::UI::FancyFrame 303 my $dialog = new CFClient::UI::FancyFrame
304 title => "Server Setup",
271 child => (my $vbox = new CFClient::UI::VBox); 305 child => (my $vbox = new CFClient::UI::VBox);
272 306
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]); 307 $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"); 308 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
276 309
277 { 310 {
278 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 311 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
325 $dialog 358 $dialog
326} 359}
327 360
328sub message_window { 361sub message_window {
329 my $window = new CFClient::UI::FancyFrame 362 my $window = new CFClient::UI::FancyFrame
363 title => "Messages",
330 border_bg => [1, 1, 1, 0.5], 364 border_bg => [1, 1, 1, 0.5],
331 bg => [0.3, 0.3, 0.3, 0.8], 365 bg => [0.3, 0.3, 0.3, 0.8],
332 user_w => int $::WIDTH / 3, 366 user_w => int $::WIDTH / 3,
333 user_h => int $::HEIGHT / 5, 367 user_h => int $::HEIGHT / 5,
334 child => (my $vbox = new CFClient::UI::VBox); 368 child => (my $vbox = new CFClient::UI::VBox);
443 status "Configuration Saved"; 477 status "Configuration Saved";
444 }); 478 });
445 479
446 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 480 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
447 481
448 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
449 $tgw->add (my $hbox = new CFClient::UI::HBox ());
450 482
451 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
452 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
453 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
454 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
455
456 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
457 $CFClient::UI::ROOT->add ($tgw); 483 $CFClient::UI::ROOT->add (make_stats_window);
458} 484}
459 485
460sub video_shutdown { 486sub video_shutdown {
461 $CFClient::UI::ROOT->{children} = []; 487 $CFClient::UI::ROOT->{children} = [];
462 undef $SDL_ACTIVE; 488 undef $SDL_ACTIVE;
463} 489}
464 490
491my @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# 492my $bgmusic;#TODO#hack#d#
493
494sub audio_music_finished {
495 return unless $CFG->{bgm_enable};
496
497 # TODO: hack, do play loop and mood music
498 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
499 $bgmusic->play (0);
500
501 push @bgmusic, shift @bgmusic;
502}
466 503
467sub audio_init { 504sub audio_init {
468 if ($CFG->{audio_enable}) { 505 if ($CFG->{audio_enable}) {
469 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 506 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
470
471 $SDL_MIXER = !CFClient::Mix_OpenAudio; 507 $SDL_MIXER = !CFClient::Mix_OpenAudio;
472 CFClient::Mix_AllocateChannels 8; 508 CFClient::Mix_AllocateChannels 8;
473 CFClient::MixMusic::volume $CFG->{bgm_volume}; 509 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
474 510
475 # TODO: hack, do play loop and mood music 511 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 512
481 while (<$fh>) { 513 while (<$fh>) {
482 next if /^\s*#/; 514 next if /^\s*#/;
483 next if /^\s*$/; 515 next if /^\s*$/;
484 516
569 my $hp = $stats->{1}; 601 my $hp = $stats->{1};
570 my $hp_m = $stats->{2}; 602 my $hp_m = $stats->{2};
571 my $sp = $stats->{3}; 603 my $sp = $stats->{3};
572 my $sp_m = $stats->{4}; 604 my $sp_m = $stats->{4};
573 my $fo = $stats->{18}; 605 my $fo = $stats->{18};
574 my $fo_m = 1000; 606 my $fo_m = 999;
575 my $gr = $stats->{23}; 607 my $gr = $stats->{23};
576 my $gr_m = $stats->{24}; 608 my $gr_m = $stats->{24};
577 609
578 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 610 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
579 $GAUGES->{hp}->set_value ($hp, $hp_m); 611 $GAUGES->{hp} ->set_value ($hp, $hp_m);
580 $GAUGES->{mana}->set_value ($sp, $sp_m); 612 $GAUGES->{mana} ->set_value ($sp, $sp_m);
581 $GAUGES->{food}->set_value ($fo, $fo_m); 613 $GAUGES->{food} ->set_value ($fo, $fo_m);
582 $GAUGES->{grace}->set_value ($gr, $gr_m); 614 $GAUGES->{grace}->set_value ($gr, $gr_m);
615
616 update_stats_window ($stats);
583} 617}
584 618
585sub conn::user_send { 619sub conn::user_send {
586 my ($self, $command) = @_; 620 my ($self, $command) = @_;
587 621
612 646
613 my ($hash, $x, $y, $w, $h) = @$map_info; 647 my ($hash, $x, $y, $w, $h) = @$map_info;
614 648
615 my $data = $MAP->get_rect ($x, $y, $w, $h); 649 my $data = $MAP->get_rect ($x, $y, $w, $h);
616 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 650 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
617
618 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 651 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
619
620} 652}
621 653
622sub conn::map_clear { 654sub conn::map_clear {
623 my ($self) = @_; 655 my ($self) = @_;
624 656
625 $self->flush_map; 657 $self->flush_map;
626 delete $self->{neigh}; 658 delete $self->{neigh_map};
627 659
628 $MAP->clear; 660 $MAP->clear;
629} 661}
630 662
631 663
632sub conn::load_map($$$) { 664sub conn::load_map($$$) {
633 my ($self, $hash, $x, $y) = @_; 665 my ($self, $hash, $x, $y) = @_;
634 666
635 if (defined (my $data = $MAPCACHE->get ($hash))) { 667 if (defined (my $data = $MAPCACHE->get ($hash))) {
636 $data = Compress::LZF::decompress $data; 668 $data = Compress::LZF::decompress $data;
637 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 669 #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)) { 670 for my $id ($MAP->set_rect ($x, $y, $data)) {
639 my $data = $TILECACHE->get ($id) 671 my $data = $TILECACHE->get ($id)
640 or next; 672 or next;
641 673
642 $self->set_texture ($id => $data); 674 $self->set_texture ($id => $data);
643 } 675 }
644 } 676 }
645} 677}
646 678
679# this method does a "flood fill" into every tile direction
680# it assumes that tiles are arranged in a rectangular grid,
681# i.e. a map is the same as the left of the right map etc.
682# failure to comply are harmless and result in display errors
683# at worst.
647sub conn::flood_fill { 684sub conn::flood_fill {
648 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 685 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
649 686
650 # the server does not allow map paths > 6 687 # the server does not allow map paths > 6
651 return if 6 <= length $path; 688 return if 6 <= length $path;
652 689
653 for my $tile (1..4) { 690 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
654 next if $self->{neigh}{$hash}[$tile]; 691
692 for (
693 [1, 0, -1],
694 [2, 1, 0],
695 [3, 0, 1],
696 [4, -1, 0],
697 ) {
698 my ($tile, $dx, $dy) = @$_;
699
700 my $gx = $gx + $dx;
701 my $gy = $gy + $dy;
702
655 next unless $flags & (1 << ($tile - 1)); 703 next unless $flags & (1 << ($tile - 1));
704 next if $self->{neigh_grid}{$gx, $gy}++;
656 705
657 my $neigh = $self->{neigh}{$hash} ||= []; 706 my $neigh = $self->{neigh_map}{$hash} ||= [];
658 707 if (my $info = $neigh->[$tile]) {
659 $self->send_mapinfo ("spatial $path$tile", sub {
660 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 708 my ($flags, $x, $y, $w, $h, $hash) = @$info;
661 709
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) 710 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
674 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 711 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
712
713 } else {
714 $self->send_mapinfo ("spatial $path$tile", sub {
715 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
716
717 return if $mode ne "spatial";
718
719 $x += $MAP->ox;
720 $y += $MAP->oy;
721
722 $self->load_map ($hash, $x, $y)
723 unless $self->{neigh_map}{$hash}[5]++;#d#
724
725 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
726
727 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
728 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
729 });
675 }); 730 }
676 } 731 }
677} 732}
678 733
679sub conn::map_change { 734sub conn::map_change {
680 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 735 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
683 738
684 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 739 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
685 740
686 my $mapmapw = 250; 741 my $mapmapw = 250;
687 my $mapmaph = 250; 742 my $mapmaph = 250;
743
744 $self->{neigh_rect} = [
745 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
746 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
747 ];
688 748
749 delete $self->{neigh_grid};
689 $self->flood_fill ("", $hash, $flags, 750 $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 751
693 $x += $ox; 752 $x += $ox;
694 $y += $oy; 753 $y += $oy;
695 754
696 $self->{map_info} = [$hash, $x, $y, $w, $h]; 755 $self->{map_info} = [$hash, $x, $y, $w, $h];
825 CFClient::SDL_QUIT => sub { 884 CFClient::SDL_QUIT => sub {
826 Event::unloop -1; 885 Event::unloop -1;
827 }, 886 },
828 CFClient::SDL_VIDEORESIZE => sub { 887 CFClient::SDL_VIDEORESIZE => sub {
829 }, 888 },
830 CFClient::SDL_VIDEOEXPOSE => sub { 889 CFClient::SDL_VIDEOEXPOSE => \&refresh,
831 refresh; 890 CFClient::SDL_ACTIVEEVENT => sub {
891# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
832 }, 892 },
833 CFClient::SDL_KEYDOWN => sub { 893 CFClient::SDL_KEYDOWN => sub {
834 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 894 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
835 # alt-enter 895 # alt-enter
836 video_shutdown; 896 video_shutdown;
838 video_init; 898 video_init;
839 } else { 899 } else {
840 CFClient::UI::feed_sdl_key_down_event ($_[0]); 900 CFClient::UI::feed_sdl_key_down_event ($_[0]);
841 } 901 }
842 }, 902 },
843 CFClient::SDL_KEYUP => sub { 903 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
844 CFClient::UI::feed_sdl_key_up_event ($_[0]); 904 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
845 }, 905 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
846 CFClient::SDL_MOUSEMOTION => sub { 906 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
847 CFClient::UI::feed_sdl_motion_event ($_[0]); 907 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); 908);
859 909
860############################################################################# 910#############################################################################
861 911
862$SIG{INT} = $SIG{TERM} = sub { exit }; 912$SIG{INT} = $SIG{TERM} = sub { exit };
880 mapsize => 100, 930 mapsize => 100,
881 host => "crossfire.schmorp.de", 931 host => "crossfire.schmorp.de",
882 say_command => 'say', 932 say_command => 'say',
883 audio_enable => 1, 933 audio_enable => 1,
884 bgm_enable => 1, 934 bgm_enable => 1,
885 bgm_volume => 64, 935 bgm_volume => 0.25,
886); 936);
887 937
888while (my ($k, $v) = each %DEF_CFG) { 938while (my ($k, $v) = each %DEF_CFG) {
889 $CFG->{$k} = $v unless exists $CFG->{$k}; 939 $CFG->{$k} = $v unless exists $CFG->{$k};
890} 940}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines