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.97 by root, Fri Apr 6 08:09:43 2007 UTC vs.
Revision 1.102 by root, Wed Apr 18 18:16:16 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 %{$arg{setup_req} || {}},
26 },
27 );
23 28
24 $self->{map_widget}->clr_commands; 29 $self->{map_widget}->clr_commands;
25 30
26 my @cmd_help = map { 31 my @cmd_help = map {
27 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 32 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
415 } while $self->{texture}[$id]; 420 } while $self->{texture}[$id];
416 421
417 CFPlus::DB::get tilecache => $id, sub { 422 CFPlus::DB::get tilecache => $id, sub {
418 my ($data) = @_; 423 my ($data) = @_;
419 424
425 return unless $self->{map}; # stop when destroyed
426
420 $self->set_texture ($id => $data) 427 $self->set_texture ($id => $data)
421 if defined $data; 428 if defined $data;
422 429
423 $self->bg_fetch; 430 $self->bg_fetch;
424 }; 431 };
425} 432}
426 433
427sub load_map($$$) { 434sub load_map($$$) {
428 my ($self, $hash, $x, $y) = @_; 435 my ($self, $hash, $x, $y) = @_;
429 436
437 my $gen = $self->{map_change_gen};
438
430 CFPlus::DB::get $self->{mapcache} => $hash, sub { 439 CFPlus::DB::get $self->{mapcache} => $hash, sub {
440 return unless $gen == $self->{map_change_gen};
441
431 my ($data) = @_; 442 my ($data) = @_;
432 443
433 if (defined $data) { 444 if (defined $data) {
434 $data = Compress::LZF::decompress $data; 445 $data = Compress::LZF::decompress $data;
435 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 446 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
436 447
437 my $inprogress = @{ $self->{bg_fetch} || [] }; 448 my $inprogress = @{ $self->{bg_fetch} || [] };
438 push @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 449 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
439 $self->bg_fetch unless $inprogress; 450 $self->bg_fetch unless $inprogress;
440 } 451 }
441 }; 452 };
442} 453}
443 454
510 521
511 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 522 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
512 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 523 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
513 524
514 } else { 525 } else {
526 my $gen = $self->{map_change_gen};
515 $self->send_mapinfo ("spatial $path$tile", sub { 527 $self->send_mapinfo ("spatial $path$tile", sub {
528 return unless $gen == $self->{map_change_gen};
529
516 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 530 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
517 531
518 return if $mode ne "spatial"; 532 return if $mode ne "spatial";
519 533
520 $x += $self->{map}->ox; 534 $x += $self->{map}->ox;
534 548
535sub map_change { 549sub map_change {
536 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 550 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
537 551
538 $self->flush_map; 552 $self->flush_map;
553
554 ++$self->{map_change_gen};
539 555
540 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 556 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
541 557
542 my $mapmapw = $self->{mapmap}->{w}; 558 my $mapmapw = $self->{mapmap}->{w};
543 my $mapmaph = $self->{mapmap}->{h}; 559 my $mapmaph = $self->{mapmap}->{h};
583 if $changed; 599 if $changed;
584 600
585 $self->set_texture ($face->{id} => delete $face->{image}); 601 $self->set_texture ($face->{id} => delete $face->{image});
586} 602}
587 603
604sub smooth_update {
605 my ($self, $facenum, $face) = @_;
606
607 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
608}
609
588sub set_texture { 610sub set_texture {
589 my ($self, $id, $data) = @_; 611 my ($self, $id, $data) = @_;
590 612
591 $self->{texture}[$id] ||= do { 613 $self->{texture}[$id] = my $tex =
592 my $tex =
593 new_from_image CFPlus::Texture 614 new_from_image CFPlus::Texture
594 $data, minify => 1, mipmap => 1; 615 $data, minify => 1, mipmap => 1;
595 616
596 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 617 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
597 $self->{map_widget}->update; 618 $self->{map_widget}->update;
598
599 $tex
600 };
601} 619}
602 620
603sub sound_play { 621sub sound_play {
604 my ($self, $x, $y, $soundnum, $type) = @_; 622 my ($self, $x, $y, $soundnum, $type) = @_;
605 623
638 656
639 my $fg = $color[$color % @color]; 657 my $fg = $color[$color % @color];
640 658
641 $self->logprint ("info: ", $text); 659 $self->logprint ("info: ", $text);
642 660
643 # try to create single paragraphs of multiple lines sent by the server 661 ## try to create single paragraphs of multiple lines sent by the server
662 # no longer neecssary with TRT servers
644 $text =~ s/(?<=\S)\n(?=\w)/ /g; 663 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
645 664
646 $text = CFPlus::asxml $text; 665 $text = CFPlus::asxml $text;
647 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 666 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
648 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 667 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
649 668

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines