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.128 by root, Mon Apr 17 21:21:30 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
54our $GAUGES; 58our $GAUGES;
55 59
56our $SDL_ACTIVE; 60our $SDL_ACTIVE;
57our $SDL_EV; 61our $SDL_EV;
58our %SDL_CB; 62our %SDL_CB;
63
64our $SDL_MIXER;
65our @SOUNDS; # event => file mapping
66our %AUDIO_CHUNKS; # audio files
59 67
60our $ALT_ENTER_MESSAGE; 68our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 69our $STATUS_LINE;
62our $DEBUG_STATUS; 70our $DEBUG_STATUS;
63 71
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
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};
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 450 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442 451
443 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); 452 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
444 $tgw->add (my $hbox = new CFClient::UI::HBox ()); 453 $tgw->add (my $hbox = new CFClient::UI::HBox ());
445 454
446 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food', expand => 1)); 455 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
447 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana', expand => 1)); 456 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
448 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp', expand => 1));
449 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace', expand => 1)); 457 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
458 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
450 459
451 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 460 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
452 $CFClient::UI::ROOT->add ($tgw); 461 $CFClient::UI::ROOT->add ($tgw);
453} 462}
454 463
455sub destroy_screen { 464sub video_shutdown {
456 $CFClient::UI::ROOT->{children} = []; 465 $CFClient::UI::ROOT->{children} = [];
457 undef $SDL_ACTIVE; 466 undef $SDL_ACTIVE;
458 undef $SDL_EV; 467 undef $SDL_EV;
459 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 = ();
460} 500}
461 501
462my %animate_object; 502my %animate_object;
463my $animate_timer; 503my $animate_timer;
464 504
634 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 674 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
635 675
636 $self->flush_map; 676 $self->flush_map;
637 677
638 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 678 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
639
640 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
641 679
642 my $mapmapw = 250; 680 my $mapmapw = 250;
643 my $mapmaph = 250; 681 my $mapmaph = 250;
644 682
645 $self->flood_fill ("", $hash, $flags, 683 $self->flood_fill ("", $hash, $flags,
707 $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}});
708 $MAPWIDGET->update; 746 $MAPWIDGET->update;
709 747
710 $tex 748 $tex
711 }; 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#
712} 760}
713 761
714sub conn::query { 762sub conn::query {
715 my ($self, $flags, $prompt) = @_; 763 my ($self, $flags, $prompt) = @_;
716 764
750 refresh; 798 refresh;
751 }, 799 },
752 SDL_KEYDOWN() => sub { 800 SDL_KEYDOWN() => sub {
753 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) {
754 # alt-enter 802 # alt-enter
755 destroy_screen; 803 video_shutdown;
756 $CFG->{fullscreen} = !$CFG->{fullscreen}; 804 $CFG->{fullscreen} = !$CFG->{fullscreen};
757 init_screen; 805 video_init;
758 } else { 806 } else {
759 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 807 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
760 } 808 }
761 }, 809 },
762 SDL_KEYUP() => sub { 810 SDL_KEYUP() => sub {
776 }, 824 },
777); 825);
778 826
779############################################################################# 827#############################################################################
780 828
829$SIG{INT} = $SIG{TERM} = sub { exit };
830
781$TILECACHE = CFClient::db_table "tilecache"; 831$TILECACHE = CFClient::db_table "tilecache";
782$FACEMAP = CFClient::db_table "facemap"; 832$FACEMAP = CFClient::db_table "facemap";
783 833
784CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 834CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
785 835
818 868
819 CFClient::add_font $_ for @fonts; 869 CFClient::add_font $_ for @fonts;
820 CFClient::set_font $fonts[0]; 870 CFClient::set_font $fonts[0];
821} 871}
822 872
823init_screen; 873video_init;
874audio_init;
824 875
825Event::loop; 876Event::loop;
826 877
878END { SDL::Quit }
827 879
880

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines