ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.96 by root, Fri Apr 6 07:45:35 2007 UTC vs.
Revision 1.104 by root, Mon Apr 23 19:22:24 2007 UTC

15use Crossfire::Protocol::Base 0.95; 15use Crossfire::Protocol::Base 0.95;
16 16
17use base 'Crossfire::Protocol::Base'; 17use base 'Crossfire::Protocol::Base';
18 18
19sub new { 19sub new {
20 my $class = shift; 20 my ($class, %arg) = @_;
21 21
22 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); 22 my $self = $class->SUPER::new (%arg,
23 setup_req => {
24 extmap => 1,
25 excmd => 1,
26 %{$arg{setup_req} || {}},
27 },
28 );
23 29
24 $self->{map_widget}->clr_commands; 30 $self->{map_widget}->clr_commands;
25 31
26 my @cmd_help = map { 32 my @cmd_help = map {
27 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 33 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
402 408
403 $self->{map}->clear; 409 $self->{map}->clear;
404 delete $self->{map_widget}{magicmap}; 410 delete $self->{map_widget}{magicmap};
405} 411}
406 412
413sub bg_fetch {
414 my ($self) = @_;
415
416 my $id;
417
418 do {
419 $id = pop @{$self->{bg_fetch}}
420 or return;
421 } while $self->{texture}[$id];
422
423 CFPlus::DB::get tilecache => $id, sub {
424 my ($data) = @_;
425
426 return unless $self->{map}; # stop when destroyed
427
428 $self->set_texture ($id => $data)
429 if defined $data;
430
431 $self->bg_fetch;
432 };
433}
407 434
408sub load_map($$$) { 435sub load_map($$$) {
409 my ($self, $hash, $x, $y) = @_; 436 my ($self, $hash, $x, $y) = @_;
410 437
438 my $gen = $self->{map_change_gen};
439
411 CFPlus::DB::get $self->{mapcache} => $hash, sub { 440 CFPlus::DB::get $self->{mapcache} => $hash, sub {
441 return unless $gen == $self->{map_change_gen};
442
412 my ($data) = @_; 443 my ($data) = @_;
413 444
414 if (defined $data) { 445 if (defined $data) {
415 $data = Compress::LZF::decompress $data; 446 $data = Compress::LZF::decompress $data;
416 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 447 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
417 for my $id ($self->{map}->set_rect ($x, $y, $data)) {
418 CFPlus::DB::get tilecache => $id, sub {
419 my ($data) = @_;
420 448
421 $self->set_texture ($id => $data) 449 my $inprogress = @{ $self->{bg_fetch} || [] };
422 if defined $data; 450 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
423 }; 451 $self->bg_fetch unless $inprogress;
424 }
425 } 452 }
426 }; 453 };
427} 454}
428 455
429# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 456# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
495 522
496 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 523 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
497 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 524 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
498 525
499 } else { 526 } else {
527 my $gen = $self->{map_change_gen};
500 $self->send_mapinfo ("spatial $path$tile", sub { 528 $self->send_mapinfo ("spatial $path$tile", sub {
529 return unless $gen == $self->{map_change_gen};
530
501 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 531 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
502 532
503 return if $mode ne "spatial"; 533 return if $mode ne "spatial";
504 534
505 $x += $self->{map}->ox; 535 $x += $self->{map}->ox;
519 549
520sub map_change { 550sub map_change {
521 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 551 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
522 552
523 $self->flush_map; 553 $self->flush_map;
554
555 ++$self->{map_change_gen};
524 556
525 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 557 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
526 558
527 my $mapmapw = $self->{mapmap}->{w}; 559 my $mapmapw = $self->{mapmap}->{w};
528 my $mapmaph = $self->{mapmap}->{h}; 560 my $mapmaph = $self->{mapmap}->{h};
568 if $changed; 600 if $changed;
569 601
570 $self->set_texture ($face->{id} => delete $face->{image}); 602 $self->set_texture ($face->{id} => delete $face->{image});
571} 603}
572 604
605sub smooth_update {
606 my ($self, $facenum, $face) = @_;
607
608 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
609}
610
573sub set_texture { 611sub set_texture {
574 my ($self, $id, $data) = @_; 612 my ($self, $id, $data) = @_;
575 613
576 $self->{texture}[$id] ||= do { 614 $self->{texture}[$id] = my $tex =
577 my $tex =
578 new_from_image CFPlus::Texture 615 new_from_image CFPlus::Texture
579 $data, minify => 1, mipmap => 1; 616 $data, minify => 1, mipmap => 1;
580 617
581 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 618 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
582 $self->{map_widget}->update; 619 $self->{map_widget}->update;
583
584 $tex
585 };
586} 620}
587 621
588sub sound_play { 622sub sound_play {
589 my ($self, $x, $y, $soundnum, $type) = @_; 623 my ($self, $x, $y, $soundnum, $type) = @_;
590 624
600 $LAST_QUERY = $prompt; 634 $LAST_QUERY = $prompt;
601 635
602 $self->{query}-> ($self, $flags, $prompt); 636 $self->{query}-> ($self, $flags, $prompt);
603} 637}
604 638
639our @CF_COLOR = (
640 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
641 [1.00, 1.00, 1.00],
642 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
643 [1.00, 0.00, 0.00],
644 [1.00, 0.54, 0.00],
645 [0.11, 0.56, 1.00],
646 [0.93, 0.46, 0.00],
647 [0.18, 0.54, 0.34],
648 [0.56, 0.73, 0.56],
649 [0.80, 0.80, 0.80],
650 [0.75, 0.61, 0.20],
651 [0.99, 0.77, 0.26],
652 [0.74, 0.65, 0.41],
653);
654
605sub drawinfo { 655sub drawinfo {
606 my ($self, $color, $text) = @_; 656 my ($self, $color, $text) = @_;
607 657
608 my @color = ( 658 my $fg = $CF_COLOR[$color % @CF_COLOR];
609 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
610 [1.00, 1.00, 1.00],
611 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
612 [1.00, 0.00, 0.00],
613 [1.00, 0.54, 0.00],
614 [0.11, 0.56, 1.00],
615 [0.93, 0.46, 0.00],
616 [0.18, 0.54, 0.34],
617 [0.56, 0.73, 0.56],
618 [0.80, 0.80, 0.80],
619 [0.75, 0.61, 0.20],
620 [0.99, 0.77, 0.26],
621 [0.74, 0.65, 0.41],
622 );
623
624 my $fg = $color[$color % @color];
625 659
626 $self->logprint ("info: ", $text); 660 $self->logprint ("info: ", $text);
627 661
628 # try to create single paragraphs of multiple lines sent by the server 662 ## try to create single paragraphs of multiple lines sent by the server
663 # no longer neecssary with TRT servers
629 $text =~ s/(?<=\S)\n(?=\w)/ /g; 664 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
630 665
631 $text = CFPlus::asxml $text; 666 $text = CFPlus::asxml $text;
632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 667 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 668 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
634 669
887 $::SERVER_INFO->set_markup ( 922 $::SERVER_INFO->set_markup (
888 "server <tt>$self->{host}:$self->{port}</tt>\n" 923 "server <tt>$self->{host}:$self->{port}</tt>\n"
889 . "protocol version <tt>$self->{version}</tt>\n" 924 . "protocol version <tt>$self->{version}</tt>\n"
890 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 925 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
891 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 926 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
927 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
892 . "editing support $yesno[!!$self->{editor_support}]\n" 928 . "editing support $yesno[!!$self->{editor_support}]\n"
893 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 929 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
930 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
894 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 931 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
895 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 932 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
896 . "map size $self->{mapw}×$self->{maph}\n" 933 . "map size $self->{mapw}×$self->{maph}\n"
897 ); 934 );
898 935

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines