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.114 by root, Sat Apr 15 21:16:51 2006 UTC vs.
Revision 1.139 by root, Wed Apr 19 00:47:35 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
23use Compress::LZF;
24
18use CFClient; 25use CFClient;
19use CFClient::UI; 26use CFClient::UI;
20 27
21our $VERSION = '0.1'; 28our $VERSION = '0.1';
22 29
23my $MAX_FPS = 60; 30my $MAX_FPS = 60;
24my $MIN_FPS = 5; # unused as of yet 31my $MIN_FPS = 5; # unused as of yet
25 32
26our $META_SERVER = "crossfire.real-time.com:13326"; 33our $META_SERVER = "crossfire.real-time.com:13326";
27 34
35our $FACEMAP;
36our $TILECACHE;
28our $FACECACHE; 37our $MAPCACHE;
29 38
30our $LAST_REFRESH; 39our $LAST_REFRESH;
31our $NOW; 40our $NOW;
32 41
33our $CFG; 42our $CFG;
45our $BUTTONBAR; 54our $BUTTONBAR;
46our $LOGVIEW; 55our $LOGVIEW;
47our $CONSOLE; 56our $CONSOLE;
48our $METASERVER; 57our $METASERVER;
49 58
59our $GAUGES;
60
50our $SDL_ACTIVE; 61our $SDL_ACTIVE;
51our $SDL_EV; 62our $SDL_EV;
52our %SDL_CB; 63our %SDL_CB;
53 64
65our $SDL_MIXER;
66our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files
68
54our $ALT_ENTER_MESSAGE; 69our $ALT_ENTER_MESSAGE;
55our $STATUS_LINE; 70our $STATUS_LINE;
56our $DEBUG_STATUS; 71our $DEBUG_STATUS;
57 72
58sub status { 73sub status {
59 $STATUS_LINE->set_text ($_[0]); 74 $STATUS_LINE->set_text ($_[0]);
60 my ($w, $h) = $STATUS_LINE->size_request;
61 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 75 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
62} 76}
63 77
64sub debug { 78sub debug {
65 $DEBUG_STATUS->set_text ($_[0]); 79 $DEBUG_STATUS->set_text ($_[0]);
66 my ($w, $h) = $DEBUG_STATUS->size_request; 80 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
67 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
68} 81}
69 82
70sub start_game { 83sub start_game {
71 status "logging in..."; 84 status "logging in...";
72 85
73 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 86 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
87
88 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
74 89
75 $MAP = new CFClient::Map $mapsize, $mapsize; 90 $MAP = new CFClient::Map $mapsize, $mapsize;
76 91
77 my ($host, $port) = split /:/, $CFG->{host}; 92 my ($host, $port) = split /:/, $CFG->{host};
78 93
140 155
141 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth");
142 $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 {
143 my ($self, $value) = @_; 158 my ($self, $value) = @_;
144 $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;
145 }); 161 });
146 162
147 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 163 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize");
148 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub {
149 my ($self, $value) = @_; 165 my ($self, $value) = @_;
150 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value);
151 }); 167 });
152 168
153 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 169 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
154 destroy_screen (); 170 video_shutdown ();
155 init_screen (); 171 video_init ();
172 });
173
174 $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound");
175 $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{audio_enable} = $value;
178 });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bgm_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bgm_enable} = $value;
183 });
184 $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
185 audio_shutdown ();
186 audio_init ();
156 }); 187 });
157 188
158 $dialog 189 $dialog
159} 190}
160 191
294 325
295sub message_window { 326sub message_window {
296 my $window = new CFClient::UI::FancyFrame 327 my $window = new CFClient::UI::FancyFrame
297 border_bg => [1, 1, 1, 0.5], 328 border_bg => [1, 1, 1, 0.5],
298 bg => [0.3, 0.3, 0.3, 0.8], 329 bg => [0.3, 0.3, 0.3, 0.8],
299 user_w => $::WIDTH/4, 330 user_w => int $::WIDTH / 3,
300 user_h => $::HEIGHT, 331 user_h => int $::HEIGHT / 5,
301 child => (my $vbox = new CFClient::UI::VBox); 332 child => (my $vbox = new CFClient::UI::VBox);
302 333
303 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 334 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
304 expand => 1, 335 expand => 1,
305 fontsize => $::CFG->{log_fontsize}, 336 fontsize => $::CFG->{log_fontsize},
306 ); 337 );
307 338
308 $vbox->add (my $input = new CFClient::UI::LineEntry); 339 $vbox->add (my $input = new CFClient::UI::Entry
340 connect_focus_in => sub {
341 my ($input, $prev_focus) = @_;
342
343 delete $input->{refocus_map};
344
345 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
346 $input->{refocus_map} = 1;
347 }
348 delete $input->{auto_activated};
349 },
309 $input->connect (activate => sub { 350 connect_activate => sub {
310 my ($input, $text) = @_; 351 my ($input, $text) = @_;
311 $input->set_text (''); 352 $input->set_text ('');
312 353
313 if ($text =~ /^\/(.*)/) { 354 if ($text =~ /^\/(.*)/) {
314 $::CONN->user_send ("command $1"); 355 $::CONN->user_send ($1);
315 } else { 356 } else {
316 my $say_cmd = $::CFG->{say_command} || 'say'; 357 my $say_cmd = $::CFG->{say_command} || 'say';
317 $::CONN->user_send ("command $say_cmd $text"); 358 $::CONN->user_send ("$say_cmd $text");
318 } 359 }
360 if ($input->{refocus_map}) {
361 delete $input->{refocus_map};
362 $MAPWIDGET->focus_in
319 1 363 }
320 }); 364 },
321 $input->connect (escape => sub { 365 connect_escape => sub {
322 $MAPWIDGET->focus_in 366 $MAPWIDGET->focus_in
323 }); 367 },
324 $input->focus_in; 368 );
325 369
326 $CONSOLE = { 370 $CONSOLE = {
327 window => $window, 371 window => $window,
328 input => $input 372 input => $input
329 }; 373 };
335 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 379 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE
336 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 380 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
337 and die "SDL::Init failed!\n"; 381 and die "SDL::Init failed!\n";
338} 382}
339 383
340sub init_screen { 384sub video_init {
341 sdl_init; 385 sdl_init;
342 386
343 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 387 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
344 $FULLSCREEN = $CFG->{fullscreen}; 388 $FULLSCREEN = $CFG->{fullscreen};
345 $FAST = $CFG->{fast}; 389 $FAST = $CFG->{fast};
385 padding => 0, 429 padding => 0,
386 y => $HEIGHT * 44 / 45 - $FONTSIZE; 430 y => $HEIGHT * 44 / 45 - $FONTSIZE;
387 $CFClient::UI::ROOT->add ($STATUS_LINE); 431 $CFClient::UI::ROOT->add ($STATUS_LINE);
388 432
389 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 433 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
390 padding => 0, 434 padding => 0,
391 y => $HEIGHT * 44 / 45, 435 y => $HEIGHT * 44 / 45,
392 height => $HEIGHT / 45, 436 fontsize => $HEIGHT / 45,
393 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 437 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
394 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 438 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE);
395 439
396 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 440 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget);
397 $MAPWIDGET->focus_in; 441 $MAPWIDGET->focus_in;
398 $MAPWIDGET->connect (activate_console => sub { 442 $MAPWIDGET->connect (activate_console => sub {
399 my ($mapwidget, $preset) = @_; 443 my ($mapwidget, $preset) = @_;
400 444
401 if ($CONSOLE) { 445 if ($CONSOLE) {
446 $CONSOLE->{input}->{auto_activated} = 1;
402 $CONSOLE->{input}->focus_in; 447 $CONSOLE->{input}->focus_in;
403 448
404 if ($preset && $CONSOLE->{input}->get_text eq '') { 449 if ($preset && $CONSOLE->{input}->get_text eq '') {
405 $CONSOLE->{input}->set_text ($preset); 450 $CONSOLE->{input}->set_text ($preset);
406 } 451 }
416 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 461 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
417 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 462 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
418 status "Configuration Saved"; 463 status "Configuration Saved";
419 }); 464 });
420 465
421 $BUTTONBAR->{children}[0]->emit ("activate"); 466 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
422}
423 467
424sub destroy_screen { 468 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
469 $tgw->add (my $hbox = new CFClient::UI::HBox ());
470
471 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
472 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
473 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
474 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
475
476 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
477 $CFClient::UI::ROOT->add ($tgw);
478}
479
480sub video_shutdown {
425 $CFClient::UI::ROOT->{children} = []; 481 $CFClient::UI::ROOT->{children} = [];
426 undef $SDL_ACTIVE; 482 undef $SDL_ACTIVE;
427 undef $SDL_EV; 483 undef $SDL_EV;
428 SDL::Quit; 484}
485
486my $bgmusic;#TODO#hack#d#
487
488sub audio_init {
489 if ($CFG->{audio_enable}) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer;
492 $SDL_MIXER->allocate_channels (8);
493
494 # TODO: hack, do play loop and mood music
495 if ($CFG->{bgm_enable}) {
496 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
497 $SDL_MIXER->play_music ($bgmusic, -1);
498 }
499
500 while (<$fh>) {
501 next if /^\s*#/;
502 next if /^\s*$/;
503
504 my ($file, $volume, $event) = split /\s+/, $_, 3;
505
506 push @SOUNDS, "$volume,$file";
507
508 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
509 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file";
510 $chunk->volume ($volume * 128 / 100);
511 $chunk
512 };
513 }
514 } else {
515 status "unable to open sound config: $!";
516 }
517 }
518}
519
520sub audio_shutdown {
521 undef $SDL_MIXER;
522 @SOUNDS = ();
523 %AUDIO_CHUNKS = ();
429} 524}
430 525
431my %animate_object; 526my %animate_object;
432my $animate_timer; 527my $animate_timer;
433 528
482 delete $animate_object{$widget}; 577 delete $animate_object{$widget};
483} 578}
484 579
485@conn::ISA = Crossfire::Protocol::; 580@conn::ISA = Crossfire::Protocol::;
486 581
582sub conn::stats_update {
583 my ($self, $stats) = @_;
584
585 # i love text protocols!!!
586 # FIXME: the stats are somehow weird
587 my $hp = $stats->{1};
588 my $hp_m = $stats->{2};
589 my $sp = $stats->{3};
590 my $sp_m = $stats->{4};
591 my $fo = $stats->{18};
592 my $fo_m = 1000;
593 my $gr = $stats->{23};
594 my $gr_m = $stats->{24};
595
596 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
597 $GAUGES->{hp}->set_value ($hp, $hp_m);
598 $GAUGES->{mana}->set_value ($sp, $sp_m);
599 $GAUGES->{food}->set_value ($fo, $fo_m);
600 $GAUGES->{grace}->set_value ($gr, $gr_m);
601}
602
487sub conn::user_send { 603sub conn::user_send {
488 my ($self, $command) = @_; 604 my ($self, $command) = @_;
489 605
490 $self->send ($command); 606 $self->send_command ($command);
491 status $command; 607 status $command;
608}
609
610sub conn::map_scroll {
611 my ($self, $dx, $dy) = @_;
612
613 $MAP->scroll ($dx, $dy);
492} 614}
493 615
494sub conn::feed_map1a { 616sub conn::feed_map1a {
495 my ($self, $data) = @_; 617 my ($self, $data) = @_;
496 618
497# $self->Crossfire::Protocol::feed_map1a ($data); 619# $self->Crossfire::Protocol::feed_map1a ($data);
498 620
499 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
500 $MAP->map1a_update ($data); 621 $MAP->map1a_update ($data);
501 $MAPWIDGET->update; 622 $MAPWIDGET->update;
502} 623}
503 624
504#sub conn::map_update { 625sub conn::flush_map {
505# my ($self, $dirty) = @_; 626 my ($self) = @_;
506# 627
507# $MAPWIDGET->update; 628 my $map_info = delete $self->{map_info}
508#} 629 or return;
630
631 my ($hash, $x, $y, $w, $h) = @$map_info;
632
633 my $data = $MAP->get_rect ($x, $y, $w, $h);
634 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
635
636 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
637
638}
509 639
510sub conn::map_clear { 640sub conn::map_clear {
511 my ($self) = @_; 641 my ($self) = @_;
512 642
643 $self->flush_map;
644 delete $self->{neigh};
645
513 $MAP->clear; 646 $MAP->clear;
647}
514 648
515# refresh; 649
650sub conn::load_map($$$) {
651 my ($self, $hash, $x, $y) = @_;
652
653 if (defined (my $data = $MAPCACHE->get ($hash))) {
654 $data = Compress::LZF::decompress $data;
655 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
656 for my $id ($MAP->set_rect ($x, $y, $data)) {
657 my $data = $TILECACHE->get ($id)
658 or next;
659
660 $self->set_texture ($id => $data);
661 }
662 }
663}
664
665sub conn::flood_fill {
666 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_;
667
668 # the server does not allow map paths > 6
669 return if 6 <= length $path;
670
671 for my $tile (1..4) {
672 next if $self->{neigh}{$hash}[$tile];
673 next unless $flags & (1 << ($tile - 1));
674
675 my $neigh = $self->{neigh}{$hash} ||= [];
676
677 $self->send_mapinfo ("spatial $path$tile", sub {
678 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
679
680 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
681 return if $mode ne "spatial";
682
683 $x += $MAP->ox;
684 $y += $MAP->oy;
685
686 $self->load_map ($hash, $x, $y)
687 unless $self->{neigh}{$hash}[5]++;#d#
688
689 $neigh->[$tile] = [$x, $y, $w, $h];
690
691 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1)
692 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
693 });
694 }
695}
696
697sub conn::map_change {
698 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
699
700 $self->flush_map;
701
702 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
703
704 my $mapmapw = 250;
705 my $mapmaph = 250;
706
707 $self->flood_fill ("", $hash, $flags,
708 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
709 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
710
711 $x += $ox;
712 $y += $oy;
713
714 $self->{map_info} = [$hash, $x, $y, $w, $h];
715
716 $self->load_map ($hash, $x, $y);
516} 717}
517 718
518sub conn::face_find { 719sub conn::face_find {
519 my ($self, $face) = @_; 720 my ($self, $facenum, $face) = @_;
520 721
521 my $data; 722 my $hash = "$face->{chksum},$face->{name}";
522 723
523 $FACECACHE->get ("$face->{chksum},$face->{name}") 724 my $id = $FACEMAP->get ($hash);
725
726 unless ($id) {
727 # create new id for face
728 # i love transactions
729 for (1..100) {
730 my $txn = $CFClient::DB_ENV->txn_begin;
731 my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
732 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
733 $id++;
734 if ($FACEMAP->put (id => $id) == 0
735 && $FACEMAP->put ($hash => $id) == 0) {
736 $txn->txn_commit;
737
738 goto gotid;
739 }
740 }
741 $txn->abort;
742 }
743
744 CFClient::fatal "maximum number of transaction retries reached - database problems?";
745 }
746
747gotid:
748 $face->{id} = $id;
749 $MAP->set_face ($facenum => $id);
750 $TILECACHE->get ($id)
524} 751}
525 752
526sub conn::face_update { 753sub conn::face_update {
527 my ($self, $facenum, $face) = @_; 754 my ($self, $facenum, $face) = @_;
528 755
529 $FACECACHE->put ("$face->{chksum},$face->{name}" => $face->{image}); 756 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
530 757
531 my $tex = $face->{texture} = 758 $self->set_texture ($face->{id} => delete $face->{image});
759}
760
761sub conn::set_texture {
762 my ($self, $id, $data) = @_;
763
764 $self->{texture}[$id] ||= do {
765 my $tex =
532 new_from_image CFClient::Texture 766 new_from_image CFClient::Texture
533 delete $face->{image}, minify => 1; 767 $data, minify => 1;
534 768
535 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 769 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
536 $MAPWIDGET->update; 770 $MAPWIDGET->update;
771
772 $tex
773 };
774}
775
776sub conn::sound_play {
777 my ($self, $x, $y, $soundnum, $type) = @_;
778
779 $SDL_MIXER
780 or return;
781
782 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
783 or return;
784
785 $SDL_MIXER->play_channel (-1, $chunk);
786 warn "sound $x,$y,$soundnum,$type\n";#d#
537} 787}
538 788
539sub conn::query { 789sub conn::query {
540 my ($self, $flags, $prompt) = @_; 790 my ($self, $flags, $prompt) = @_;
541 791
547 my ($self, $color, $text) = @_; 797 my ($self, $color, $text) = @_;
548 798
549 my @color = ( 799 my @color = (
550 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 800 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
551 [1.00, 1.00, 1.00], 801 [1.00, 1.00, 1.00],
552 [0.00, 0.00, 0.55], 802 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
553 [1.00, 0.00, 0.00], 803 [1.00, 0.00, 0.00],
554 [1.00, 0.54, 0.00], 804 [1.00, 0.54, 0.00],
555 [0.11, 0.56, 1.00], 805 [0.11, 0.56, 1.00],
556 [0.93, 0.46, 0.00], 806 [0.93, 0.46, 0.00],
557 [0.18, 0.54, 0.34], 807 [0.18, 0.54, 0.34],
575 refresh; 825 refresh;
576 }, 826 },
577 SDL_KEYDOWN() => sub { 827 SDL_KEYDOWN() => sub {
578 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 828 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
579 # alt-enter 829 # alt-enter
580 destroy_screen; 830 video_shutdown;
581 $CFG->{fullscreen} = !$CFG->{fullscreen}; 831 $CFG->{fullscreen} = !$CFG->{fullscreen};
582 init_screen; 832 video_init;
583 } else { 833 } else {
584 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 834 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
585 } 835 }
586 }, 836 },
587 SDL_KEYUP() => sub { 837 SDL_KEYUP() => sub {
601 }, 851 },
602); 852);
603 853
604############################################################################# 854#############################################################################
605 855
856$SIG{INT} = $SIG{TERM} = sub { exit };
857
606$FACECACHE = CFClient::db_table "facecache"; 858$TILECACHE = CFClient::db_table "tilecache";
859$FACEMAP = CFClient::db_table "facemap";
607 860
608CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 861CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
609 862
610my %DEF_CFG = ( 863my %DEF_CFG = (
611 sdl_mode => 0, 864 sdl_mode => 0,
618 fow_smooth => 0, 871 fow_smooth => 0,
619 log_fontsize => 14, 872 log_fontsize => 14,
620 mapsize => 100, 873 mapsize => 100,
621 host => "crossfire.schmorp.de", 874 host => "crossfire.schmorp.de",
622 say_command => 'say', 875 say_command => 'say',
876 audio_enable => 1,
877 bgm_enable => 1,
623); 878);
624 879
625while (my ($k, $v) = each %DEF_CFG) { 880while (my ($k, $v) = each %DEF_CFG) {
626 $CFG->{$k} = $v unless exists $CFG->{$k}; 881 $CFG->{$k} = $v unless exists $CFG->{$k};
627} 882}
635 890
636@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 891@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
637 892
638$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 893$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
639 894
640init_screen;
641
642{ 895{
643 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 896 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
644 897
645 CFClient::add_font $_ for @fonts; 898 CFClient::add_font $_ for @fonts;
646 CFClient::set_font $fonts[0]; 899 CFClient::set_font $fonts[0];
647} 900}
648 901
902video_init;
903audio_init;
904
649Event::loop; 905Event::loop;
650 906
907END { SDL::Quit }
651 908
909

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines