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.140 by root, Wed Apr 19 06:06:46 2006 UTC vs.
Revision 1.145 by root, Wed Apr 19 20:46:45 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event; 9use SDL::Event;
12use SDL::Surface;
13 10
14use SDL::Mixer; 11use SDL::Mixer;
15use SDL::Sound; 12use SDL::Sound;
16use SDL::Music; 13use SDL::Music;
17 14
22 19
23use Compress::LZF; 20use Compress::LZF;
24 21
25use CFClient; 22use CFClient;
26use CFClient::UI; 23use CFClient::UI;
24use CFClient::MapWidget;
27 25
28our $VERSION = '0.1'; 26our $VERSION = '0.1';
29 27
30my $MAX_FPS = 60; 28my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 29my $MIN_FPS = 5; # unused as of yet
158 my ($self, $value) = @_; 156 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 157 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 158 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
161 }); 159 });
162 160
163 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize"); 161 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.5, 1.5, 0.1], connect_changed => sub { 162 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
165 $CFG->{gui_fontsize} = 0.1 * int $_[0] * 10; 163 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
166# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 164# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
167 }); 165 });
168 166
169 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize"); 167 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
170 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.5, 0.1], connect_changed => sub { 168 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
171 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[0] * 10); 169 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
172 }); 170 });
173 171
174 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 172 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
175 video_shutdown (); 173 video_shutdown ();
176 video_init (); 174 video_init ();
182 }); 180 });
183# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); 181# $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 { 182# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
185# $CFG->{effects_volume} = $_[1]; 183# $CFG->{effects_volume} = $_[1];
186# }); 184# });
187 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Bg. Music"); 185 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
188 $table->add (1, 10, my $hbox = new CFClient::UI::HBox); 186 $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 { 187 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
190 $CFG->{bgm_enable} = $_[1]; 188 $CFG->{bgm_enable} = $_[1];
191 }); 189 });
192 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { 190 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub {
279 277
280sub server_setup { 278sub server_setup {
281 my $dialog = new CFClient::UI::FancyFrame 279 my $dialog = new CFClient::UI::FancyFrame
282 child => (my $vbox = new CFClient::UI::VBox); 280 child => (my $vbox = new CFClient::UI::VBox);
283 281
284 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 282 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
285 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 283 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
286 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 284 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
287 285
288 { 286 {
289 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 287 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
290 288
291 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 289 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
292 my ($self, $value) = @_; 290 my ($self, $value) = @_;
293 $CFG->{host} = $value; 291 $CFG->{host} = $value;
294 }); 292 });
295 293
296 $METASERVER = metaserver_dialog; 294 $METASERVER = metaserver_dialog;
297 295
298 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 296 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
299 update_metaserver $HOST; 297 update_metaserver $HOST;
300 }); 298 });
301 } 299 }
302 300
303 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 301 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
304 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 302 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
305 my ($self, $value) = @_; 303 my ($self, $value) = @_;
306 $CFG->{user} = $value; 304 $CFG->{user} = $value;
307 }); 305 });
308 306
309 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 307 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
310 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 308 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
311 my ($self, $value) = @_; 309 my ($self, $value) = @_;
312 $CFG->{password} = $value; 310 $CFG->{password} = $value;
313 }); 311 });
314 312
315 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 313 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
316 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 314 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
317 my ($self, $value) = @_; 315 my ($self, $value) = @_;
318 $CFG->{say_command} = $value; 316 $CFG->{say_command} = $value;
319 }); 317 });
320 318
321 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 319 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
322 $table->add (1, 7, new CFClient::UI::Slider 320 $table->add (1, 7, new CFClient::UI::Slider
323 req_w => 100, 321 req_w => 100,
324 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 322 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
325 connect_changed => sub { 323 connect_changed => sub {
326 my ($self, $value) = @_; 324 my ($self, $value) = @_;
387 385
388 $window 386 $window
389} 387}
390 388
391sub sdl_init { 389sub sdl_init {
392 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 390 CFClient::SDL_Init
393 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
394 and die "SDL::Init failed!\n"; 391 and die "SDL::Init failed!\n";
395} 392}
396 393
397sub video_init { 394sub video_init {
398 sdl_init; 395 sdl_init;
399 396
400 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 397 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
401 $FULLSCREEN = $CFG->{fullscreen}; 398 $FULLSCREEN = $CFG->{fullscreen};
402 $FAST = $CFG->{fast}; 399 $FAST = $CFG->{fast};
403 400
404 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 401 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
405 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
406 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
407 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
408
409 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
410 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
411 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
412 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
413
414 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
415 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
416 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
417
418 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
419 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
420 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
421 or die "SDL::SetVideoMode failed!\n"; 402 or die "SDL_SetVideoMode failed!\n";
422
423 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
424 403
425 $SDL_EV = new SDL::Event; 404 $SDL_EV = new SDL::Event;
426 $SDL_EV->set_unicode (1); 405 $SDL_EV->set_unicode (1);
427 406
428 $SDL_ACTIVE = 1; 407 $SDL_ACTIVE = 1;
448 fontsize => 0.8, 427 fontsize => 0.8,
449 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 428 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
450 $ALT_ENTER_MESSAGE->show; 429 $ALT_ENTER_MESSAGE->show;
451 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 430 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
452 431
453 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 432 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
454 $MAPWIDGET->focus_in; 433 $MAPWIDGET->focus_in;
455 $MAPWIDGET->connect (activate_console => sub { 434 $MAPWIDGET->connect (activate_console => sub {
456 my ($mapwidget, $preset) = @_; 435 my ($mapwidget, $preset) = @_;
457 436
458 if ($CONSOLE) { 437 if ($CONSOLE) {
499my $bgmusic;#TODO#hack#d# 478my $bgmusic;#TODO#hack#d#
500 479
501sub audio_init { 480sub audio_init {
502 if ($CFG->{audio_enable}) { 481 if ($CFG->{audio_enable}) {
503 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 482 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
483
504 $SDL_MIXER = new SDL::Mixer; 484 $SDL_MIXER = new SDL::Mixer
485 -rate => 22050,
486 -channels => 1, # mono
487 -size => 512;
488
505 $SDL_MIXER->allocate_channels (8); 489 $SDL_MIXER->allocate_channels (8);
506 490
507 # TODO: hack, do play loop and mood music 491 # TODO: hack, do play loop and mood music
508 if ($CFG->{bgm_enable}) { 492 if ($CFG->{bgm_enable}) {
509 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 493 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
795 779
796 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 780 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
797 or return; 781 or return;
798 782
799 $SDL_MIXER->play_channel (-1, $chunk); 783 $SDL_MIXER->play_channel (-1, $chunk);
800 warn "sound $x,$y,$soundnum,$type\n";#d# 784# warn "sound $x,$y,$soundnum,$type\n";#d#
801} 785}
802 786
803sub conn::query { 787sub conn::query {
804 my ($self, $flags, $prompt) = @_; 788 my ($self, $flags, $prompt) = @_;
805 789
806 #TODO 790 #TODO, display dialog with relevant information
807 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 791 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
808} 792}
809 793
810sub conn::drawinfo { 794sub conn::drawinfo {
811 my ($self, $color, $text) = @_; 795 my ($self, $color, $text) = @_;
827 ); 811 );
828 812
829 $LOGVIEW->add_paragraph ($color[$color], $text); 813 $LOGVIEW->add_paragraph ($color[$color], $text);
830} 814}
831 815
816sub conn::spell_add {
817 my ($self, $spell) = @_;
818
819 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
820 });
821 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
822 });
823}
824
825sub conn::spell_delete {
826 my ($self, $spell) = @_;
827}
828
829sub conn::addme_success {
830 my ($self) = @_;
831
832 for my $skill (values %{$self->{skill_info}}) {
833 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
834 });
835 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
836 });
837 }
838}
839
832%SDL_CB = ( 840%SDL_CB = (
833 SDL_QUIT() => sub { 841 CFClient::SDL_QUIT => sub {
834 Event::unloop -1; 842 Event::unloop -1;
835 }, 843 },
836 SDL_VIDEORESIZE() => sub { 844 CFClient::SDL_VIDEORESIZE => sub {
837 }, 845 },
838 SDL_VIDEOEXPOSE() => sub { 846 CFClient::SDL_VIDEOEXPOSE => sub {
839 refresh; 847 refresh;
840 }, 848 },
841 SDL_KEYDOWN() => sub { 849 CFClient::SDL_KEYDOWN => sub {
842 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 850 if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) {
843 # alt-enter 851 # alt-enter
844 video_shutdown; 852 video_shutdown;
845 $CFG->{fullscreen} = !$CFG->{fullscreen}; 853 $CFG->{fullscreen} = !$CFG->{fullscreen};
846 video_init; 854 video_init;
847 } else { 855 } else {
848 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 856 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
849 } 857 }
850 }, 858 },
851 SDL_KEYUP() => sub { 859 CFClient::SDL_KEYUP => sub {
852 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 860 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
853 }, 861 },
854 SDL_MOUSEMOTION() => sub { 862 CFClient::SDL_MOUSEMOTION => sub {
855 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 863 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
856 }, 864 },
857 SDL_MOUSEBUTTONDOWN() => sub { 865 CFClient::SDL_MOUSEBUTTONDOWN => sub {
858 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 866 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
859 }, 867 },
860 SDL_MOUSEBUTTONUP() => sub { 868 CFClient::SDL_MOUSEBUTTONUP => sub {
861 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 869 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
862 }, 870 },
863 SDL_ACTIVEEVENT() => sub { 871 CFClient::SDL_ACTIVEEVENT => sub {
864# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 872# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
865 }, 873 },
866); 874);
867 875
868############################################################################# 876#############################################################################
899 907
900sdl_init; 908sdl_init;
901 909
902@SDL_MODES = reverse 910@SDL_MODES = reverse
903 grep $_->[0] >= 640 && $_->[1] >= 480, 911 grep $_->[0] >= 640 && $_->[1] >= 480,
904 map [SDL::RectW ($_), SDL::RectH ($_)], 912 CFClient::SDL_ListModes;
905 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
906 913
907@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 914@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
908 915
909$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 916$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
910 917

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines