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.131 by root, Tue Apr 18 02:04:23 2006 UTC vs.
Revision 1.140 by root, Wed Apr 19 06:06:46 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::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
13use SDL::OpenGL; 18use SDL::OpenGL;
14 19
15use Crossfire; 20use Crossfire;
16use Crossfire::Protocol; 21use Crossfire::Protocol;
17 22
54our $GAUGES; 59our $GAUGES;
55 60
56our $SDL_ACTIVE; 61our $SDL_ACTIVE;
57our $SDL_EV; 62our $SDL_EV;
58our %SDL_CB; 63our %SDL_CB;
64
65our $SDL_MIXER;
66our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files
59 68
60our $ALT_ENTER_MESSAGE; 69our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 70our $STATUS_LINE;
62our $DEBUG_STATUS; 71our $DEBUG_STATUS;
63 72
101} 110}
102 111
103sub client_setup { 112sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 113 my $dialog = new CFClient::UI::FancyFrame
105 child => (my $vbox = new CFClient::UI::VBox); 114 child => (my $vbox = new CFClient::UI::VBox);
106 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 115 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
107 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 116 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
108 117
109 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 118 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 120
112 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 121 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
113 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 122 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
114 123
115 $mode_slider->connect (changed => sub { 124 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 125 my ($self, $value) = @_;
117 126
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 129 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 130 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 131
123 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 132 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
124 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
125 my ($self, $value) = @_; 134 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 135 $CFG->{fullscreen} = $value;
127 }); 136 });
128 137
129 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 138 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
130 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
131 my ($self, $value) = @_; 140 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 141 $CFG->{fast} = $value;
133 }); 142 });
134 143
135 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 144 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
136 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
137 my ($self, $value) = @_; 146 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 147 $CFG->{fow_enable} = $value;
139 }); 148 });
140 149
141 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 150 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
142 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
143 my ($self, $value) = @_; 152 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 153 $CFG->{fow_intensity} = $value;
145 }); 154 });
146 155
147 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 156 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
148 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 157 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
149 my ($self, $value) = @_; 158 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 159 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 161 });
152 162
153 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 163 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.5, 1.5, 0.1], connect_changed => sub {
165 $CFG->{gui_fontsize} = 0.1 * int $_[0] * 10;
166# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
167 });
168
169 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 170 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.5, 0.1], connect_changed => sub {
155 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 171 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[0] * 10);
157 }); 172 });
158 173
159 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 174 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
160 destroy_screen (); 175 video_shutdown ();
161 init_screen (); 176 video_init ();
177 });
178
179 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
181 $CFG->{audio_enable} = $_[1];
182 });
183# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
184# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
185# $CFG->{effects_volume} = $_[1];
186# });
187 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Bg. Music");
188 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
189 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
190 $CFG->{bgm_enable} = $_[1];
191 });
192 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub {
193 $CFG->{bgm_volume} = $_[1];
194 $SDL_MIXER->music_volume ($_[1]);
195 });
196
197 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
198 audio_shutdown ();
199 audio_init ();
162 }); 200 });
163 201
164 $dialog 202 $dialog
165} 203}
166 204
230 $HOST->set_text ($CFG->{host} = $host); 268 $HOST->set_text ($CFG->{host} = $host);
231 }), 269 }),
232 (new CFClient::UI::Empty expand => 1), 270 (new CFClient::UI::Empty expand => 1),
233 ]); 271 ]);
234 272
235 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 273 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
236 for 0 .. $#$m; 274 for 0 .. $#$m;
237 } 275 }
238 } 276 }
239 }); 277 });
240} 278}
349 387
350 $window 388 $window
351} 389}
352 390
353sub sdl_init { 391sub sdl_init {
354 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 392 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
355 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 393 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 394 and die "SDL::Init failed!\n";
357} 395}
358 396
359sub init_screen { 397sub video_init {
360 sdl_init; 398 sdl_init;
361 399
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 400 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 401 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 402 $FAST = $CFG->{fast};
391 429
392 $LAST_REFRESH = time - 0.01; 430 $LAST_REFRESH = time - 0.01;
393 431
394 CFClient::gl_init; 432 CFClient::gl_init;
395 433
396 $FONTSIZE = int $HEIGHT / 40; 434 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
397 435
398 ############################################################################# 436 #############################################################################
399 437
400 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 438 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
401 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 439 $DEBUG_STATUS->show;
402 440
403 $STATUS_LINE = new CFClient::UI::Label 441 $STATUS_LINE = new CFClient::UI::Label
404 padding => 0, 442 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 443 y => $HEIGHT - $FONTSIZE * 1.8;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 444 $STATUS_LINE->show;
407 445
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 446 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 447 padding => 0,
410 y => $HEIGHT * 44 / 45,
411 fontsize => $HEIGHT / 45, 448 fontsize => 0.8,
412 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 449 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 450 $ALT_ENTER_MESSAGE->show;
451 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
414 452
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 453 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
416 $MAPWIDGET->focus_in; 454 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 455 $MAPWIDGET->connect (activate_console => sub {
418 my ($mapwidget, $preset) = @_; 456 my ($mapwidget, $preset) = @_;
450 488
451 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 489 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
452 $CFClient::UI::ROOT->add ($tgw); 490 $CFClient::UI::ROOT->add ($tgw);
453} 491}
454 492
455sub destroy_screen { 493sub video_shutdown {
456 $CFClient::UI::ROOT->{children} = []; 494 $CFClient::UI::ROOT->{children} = [];
457 undef $SDL_ACTIVE; 495 undef $SDL_ACTIVE;
458 undef $SDL_EV; 496 undef $SDL_EV;
459 SDL::Quit; 497}
498
499my $bgmusic;#TODO#hack#d#
500
501sub audio_init {
502 if ($CFG->{audio_enable}) {
503 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
504 $SDL_MIXER = new SDL::Mixer;
505 $SDL_MIXER->allocate_channels (8);
506
507 # TODO: hack, do play loop and mood music
508 if ($CFG->{bgm_enable}) {
509 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
510 $SDL_MIXER->play_music ($bgmusic, -1);
511 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
512 }
513
514 while (<$fh>) {
515 next if /^\s*#/;
516 next if /^\s*$/;
517
518 my ($file, $volume, $event) = split /\s+/, $_, 3;
519
520 push @SOUNDS, "$volume,$file";
521
522 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
523 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
524 $chunk->volume ($volume * 128 / 100);
525 $chunk
526 };
527 }
528 } else {
529 status "unable to open sound config: $!";
530 }
531 }
532}
533
534sub audio_shutdown {
535 undef $SDL_MIXER;
536 @SOUNDS = ();
537 %AUDIO_CHUNKS = ();
460} 538}
461 539
462my %animate_object; 540my %animate_object;
463my $animate_timer; 541my $animate_timer;
464 542
705 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 783 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
706 $MAPWIDGET->update; 784 $MAPWIDGET->update;
707 785
708 $tex 786 $tex
709 }; 787 };
788}
789
790sub conn::sound_play {
791 my ($self, $x, $y, $soundnum, $type) = @_;
792
793 $SDL_MIXER
794 or return;
795
796 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
797 or return;
798
799 $SDL_MIXER->play_channel (-1, $chunk);
800 warn "sound $x,$y,$soundnum,$type\n";#d#
710} 801}
711 802
712sub conn::query { 803sub conn::query {
713 my ($self, $flags, $prompt) = @_; 804 my ($self, $flags, $prompt) = @_;
714 805
748 refresh; 839 refresh;
749 }, 840 },
750 SDL_KEYDOWN() => sub { 841 SDL_KEYDOWN() => sub {
751 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 842 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
752 # alt-enter 843 # alt-enter
753 destroy_screen; 844 video_shutdown;
754 $CFG->{fullscreen} = !$CFG->{fullscreen}; 845 $CFG->{fullscreen} = !$CFG->{fullscreen};
755 init_screen; 846 video_init;
756 } else { 847 } else {
757 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 848 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
758 } 849 }
759 }, 850 },
760 SDL_KEYUP() => sub { 851 SDL_KEYUP() => sub {
790 fullscreen => 0, 881 fullscreen => 0,
791 fast => 0, 882 fast => 0,
792 fow_enable => 1, 883 fow_enable => 1,
793 fow_intensity => 0.45, 884 fow_intensity => 0.45,
794 fow_smooth => 0, 885 fow_smooth => 0,
886 gui_fontsize => 1,
795 log_fontsize => 14, 887 log_fontsize => 14,
796 mapsize => 100, 888 mapsize => 100,
797 host => "crossfire.schmorp.de", 889 host => "crossfire.schmorp.de",
798 say_command => 'say', 890 say_command => 'say',
891 audio_enable => 1,
892 bgm_enable => 1,
893 bgm_volume => 64,
799); 894);
800 895
801while (my ($k, $v) = each %DEF_CFG) { 896while (my ($k, $v) = each %DEF_CFG) {
802 $CFG->{$k} = $v unless exists $CFG->{$k}; 897 $CFG->{$k} = $v unless exists $CFG->{$k};
803} 898}
818 913
819 CFClient::add_font $_ for @fonts; 914 CFClient::add_font $_ for @fonts;
820 CFClient::set_font $fonts[0]; 915 CFClient::set_font $fonts[0];
821} 916}
822 917
823init_screen; 918video_init;
919audio_init;
824 920
825Event::loop; 921Event::loop;
826 922
827END { SDL::Quit } 923END { SDL::Quit }
828 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines