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.119 by root, Mon Apr 17 06:50:26 2006 UTC vs.
Revision 1.134 by root, Tue Apr 18 05:13:15 2006 UTC

8 8
9use SDL; 9use SDL;
10use SDL::App; 10use SDL::App;
11use SDL::Event; 11use SDL::Event;
12use SDL::Surface; 12use SDL::Surface;
13
14use SDL::Sound;
15use SDL::Mixer;
16
13use SDL::OpenGL; 17use SDL::OpenGL;
14 18
15use Crossfire; 19use Crossfire;
16use Crossfire::Protocol; 20use Crossfire::Protocol;
17 21
49our $BUTTONBAR; 53our $BUTTONBAR;
50our $LOGVIEW; 54our $LOGVIEW;
51our $CONSOLE; 55our $CONSOLE;
52our $METASERVER; 56our $METASERVER;
53 57
58our $GAUGES;
59
54our $SDL_ACTIVE; 60our $SDL_ACTIVE;
55our $SDL_EV; 61our $SDL_EV;
56our %SDL_CB; 62our %SDL_CB;
57 63
64our $SDL_MIXER;
65our @SOUNDS; # event => file mapping
66our %AUDIO_CHUNKS; # audio files
67
58our $ALT_ENTER_MESSAGE; 68our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 69our $STATUS_LINE;
60our $DEBUG_STATUS; 70our $DEBUG_STATUS;
61 71
62sub status { 72sub status {
63 $STATUS_LINE->set_text ($_[0]); 73 $STATUS_LINE->set_text ($_[0]);
64 my ($w, $h) = $STATUS_LINE->size_request;
65 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 74 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
66} 75}
67 76
68sub debug { 77sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 78 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 79 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
71 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
72} 80}
73 81
74sub start_game { 82sub start_game {
75 status "logging in..."; 83 status "logging in...";
76 84
146 154
147 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 155 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth");
148 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 156 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
149 my ($self, $value) = @_; 157 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 158 $CFG->{fow_smooth} = $value;
159 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 160 });
152 161
153 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 162 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 163 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub {
155 my ($self, $value) = @_; 164 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 165 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value);
157 }); 166 });
158 167
159 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 168 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
160 destroy_screen (); 169 video_shutdown ();
161 init_screen (); 170 video_init ();
162 }); 171 });
163 172
164 $dialog 173 $dialog
165} 174}
166 175
300 309
301sub message_window { 310sub message_window {
302 my $window = new CFClient::UI::FancyFrame 311 my $window = new CFClient::UI::FancyFrame
303 border_bg => [1, 1, 1, 0.5], 312 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 313 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => $::WIDTH/4, 314 user_w => int $::WIDTH / 3,
306 user_h => $::HEIGHT, 315 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 316 child => (my $vbox = new CFClient::UI::VBox);
308 317
309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 318 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
310 expand => 1, 319 expand => 1,
311 fontsize => $::CFG->{log_fontsize}, 320 fontsize => $::CFG->{log_fontsize},
312 ); 321 );
313 322
314 $vbox->add (my $input = new CFClient::UI::LineEntry 323 $vbox->add (my $input = new CFClient::UI::Entry
315 connect_focus_in => sub { 324 connect_focus_in => sub {
316 my ($input, $prev_focus) = @_; 325 my ($input, $prev_focus) = @_;
317 326
318 delete $input->{refocus_map}; 327 delete $input->{refocus_map};
319 328
325 connect_activate => sub { 334 connect_activate => sub {
326 my ($input, $text) = @_; 335 my ($input, $text) = @_;
327 $input->set_text (''); 336 $input->set_text ('');
328 337
329 if ($text =~ /^\/(.*)/) { 338 if ($text =~ /^\/(.*)/) {
330 $::CONN->user_send ("command $1"); 339 $::CONN->user_send ($1);
331 } else { 340 } else {
332 my $say_cmd = $::CFG->{say_command} || 'say'; 341 my $say_cmd = $::CFG->{say_command} || 'say';
333 $::CONN->user_send ("command $say_cmd $text"); 342 $::CONN->user_send ("$say_cmd $text");
334 } 343 }
335 if ($input->{refocus_map}) { 344 if ($input->{refocus_map}) {
336 delete $input->{refocus_map}; 345 delete $input->{refocus_map};
337 $MAPWIDGET->focus_in 346 $MAPWIDGET->focus_in
338 } 347 }
354 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 363 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
355 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 364 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 365 and die "SDL::Init failed!\n";
357} 366}
358 367
359sub init_screen { 368sub video_init {
360 sdl_init; 369 sdl_init;
361 370
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 371 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 372 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 373 $FAST = $CFG->{fast};
404 padding => 0, 413 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 414 y => $HEIGHT * 44 / 45 - $FONTSIZE;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 415 $CFClient::UI::ROOT->add ($STATUS_LINE);
407 416
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 417 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 418 padding => 0,
410 y => $HEIGHT * 44 / 45, 419 y => $HEIGHT * 44 / 45,
411 height => $HEIGHT / 45, 420 fontsize => $HEIGHT / 45,
412 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 421 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 422 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE);
414 423
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 424 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
416 $MAPWIDGET->focus_in; 425 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 426 $MAPWIDGET->connect (activate_console => sub {
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 446 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 447 status "Configuration Saved";
439 }); 448 });
440 449
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 450 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 451
444sub destroy_screen { 452 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
453 $tgw->add (my $hbox = new CFClient::UI::HBox ());
454
455 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
456 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
457 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
458 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
459
460 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
461 $CFClient::UI::ROOT->add ($tgw);
462}
463
464sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 465 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 466 undef $SDL_ACTIVE;
447 undef $SDL_EV; 467 undef $SDL_EV;
448 SDL::Quit; 468}
469
470sub audio_init {
471 if ($CFG->{sound} || 1) {
472 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
473 $SDL_MIXER = new SDL::Mixer;
474 $SDL_MIXER->allocate_channels (8);
475
476 while (<$fh>) {
477 next if /^\s*#/;
478 next if /^\s*$/;
479
480 my ($file, $volume, $event) = split /\s+/, $_, 3;
481
482 push @SOUNDS, "$volume,$file";
483
484 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
485 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
486 $chunk->volume ($volume * 128 / 100);
487 $chunk
488 };
489 }
490 } else {
491 status "unable to open sound config: $!";
492 }
493 }
494}
495
496sub audio_shutdown {
497 undef $SDL_MIXER;
498 @SOUNDS = ();
499 %AUDIO_CHUNKS = ();
449} 500}
450 501
451my %animate_object; 502my %animate_object;
452my $animate_timer; 503my $animate_timer;
453 504
502 delete $animate_object{$widget}; 553 delete $animate_object{$widget};
503} 554}
504 555
505@conn::ISA = Crossfire::Protocol::; 556@conn::ISA = Crossfire::Protocol::;
506 557
558sub conn::stats_update {
559 my ($self, $stats) = @_;
560
561 # i love text protocols!!!
562 # FIXME: the stats are somehow weird
563 my $hp = $stats->{1};
564 my $hp_m = $stats->{2};
565 my $sp = $stats->{3};
566 my $sp_m = $stats->{4};
567 my $fo = $stats->{18};
568 my $fo_m = 1000;
569 my $gr = $stats->{23};
570 my $gr_m = $stats->{24};
571
572 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
573 $GAUGES->{hp}->set_value ($hp, $hp_m);
574 $GAUGES->{mana}->set_value ($sp, $sp_m);
575 $GAUGES->{food}->set_value ($fo, $fo_m);
576 $GAUGES->{grace}->set_value ($gr, $gr_m);
577}
578
507sub conn::user_send { 579sub conn::user_send {
508 my ($self, $command) = @_; 580 my ($self, $command) = @_;
509 581
510 $self->send ($command); 582 $self->send_command ($command);
511 status $command; 583 status $command;
512} 584}
513 585
514sub conn::map_scroll { 586sub conn::map_scroll {
515 my ($self, $dx, $dy) = @_; 587 my ($self, $dx, $dy) = @_;
567} 639}
568 640
569sub conn::flood_fill { 641sub conn::flood_fill {
570 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 642 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_;
571 643
644 # the server does not allow map paths > 6
645 return if 6 <= length $path;
646
572 for my $tile (1..4) { 647 for my $tile (1..4) {
573 next if $self->{neigh}{$hash}[$tile]; 648 next if $self->{neigh}{$hash}[$tile];
574 next unless $flags & (1 << ($tile - 1)); 649 next unless $flags & (1 << ($tile - 1));
575 650
576 my $neigh = $self->{neigh}{$hash} ||= []; 651 my $neigh = $self->{neigh}{$hash} ||= [];
577 652
578 $self->send_mapinfo ("spatial $path$tile", sub { 653 $self->send_mapinfo ("spatial $path$tile", sub {
579 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 654 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
580 655
581 warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# 656 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
582 return if $mode ne "spatial"; 657 return if $mode ne "spatial";
583 658
584 $x += $MAP->ox; 659 $x += $MAP->ox;
585 $y += $MAP->oy; 660 $y += $MAP->oy;
586 661
587 $self->load_map ($hash, $x, $y); 662 $self->load_map ($hash, $x, $y)
663 unless $self->{neigh}{$hash}[5]++;#d#
588 664
589 $neigh->[$tile] = [$x, $y, $w, $h]; 665 $neigh->[$tile] = [$x, $y, $w, $h];
590 666
591 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 667 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1)
592 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 668 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
598 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 674 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
599 675
600 $self->flush_map; 676 $self->flush_map;
601 677
602 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 678 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
603
604 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
605 679
606 my $mapmapw = 250; 680 my $mapmapw = 250;
607 my $mapmaph = 250; 681 my $mapmaph = 250;
608 682
609 $self->flood_fill ("", $hash, $flags, 683 $self->flood_fill ("", $hash, $flags,
671 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 745 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
672 $MAPWIDGET->update; 746 $MAPWIDGET->update;
673 747
674 $tex 748 $tex
675 }; 749 };
750}
751
752sub conn::sound_play {
753 my ($self, $x, $y, $soundnum, $type) = @_;
754
755 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
756 or return;
757
758 $SDL_MIXER->play_channel (-1, $chunk);
759 warn "sound $x,$y,$soundnum,$type\n";#d#
676} 760}
677 761
678sub conn::query { 762sub conn::query {
679 my ($self, $flags, $prompt) = @_; 763 my ($self, $flags, $prompt) = @_;
680 764
714 refresh; 798 refresh;
715 }, 799 },
716 SDL_KEYDOWN() => sub { 800 SDL_KEYDOWN() => sub {
717 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 801 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
718 # alt-enter 802 # alt-enter
719 destroy_screen; 803 video_shutdown;
720 $CFG->{fullscreen} = !$CFG->{fullscreen}; 804 $CFG->{fullscreen} = !$CFG->{fullscreen};
721 init_screen; 805 video_init;
722 } else { 806 } else {
723 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 807 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
724 } 808 }
725 }, 809 },
726 SDL_KEYUP() => sub { 810 SDL_KEYUP() => sub {
740 }, 824 },
741); 825);
742 826
743############################################################################# 827#############################################################################
744 828
829$SIG{INT} = $SIG{TERM} = sub { exit };
830
745$TILECACHE = CFClient::db_table "tilecache"; 831$TILECACHE = CFClient::db_table "tilecache";
746$FACEMAP = CFClient::db_table "facemap"; 832$FACEMAP = CFClient::db_table "facemap";
747 833
748CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 834CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
749 835
775 861
776@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 862@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
777 863
778$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 864$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
779 865
780init_screen;
781
782{ 866{
783 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 867 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
784 868
785 CFClient::add_font $_ for @fonts; 869 CFClient::add_font $_ for @fonts;
786 CFClient::set_font $fonts[0]; 870 CFClient::set_font $fonts[0];
787} 871}
788 872
873video_init;
874audio_init;
875
789Event::loop; 876Event::loop;
790 877
878END { SDL::Quit }
791 879
880

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines