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.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
402 407
403 $self->{map}->clear; 408 $self->{map}->clear;
404 delete $self->{map_widget}{magicmap}; 409 delete $self->{map_widget}{magicmap};
405} 410}
406 411
412sub bg_fetch {
413 my ($self) = @_;
414
415 my $id;
416
417 do {
418 $id = pop @{$self->{bg_fetch}}
419 or return;
420 } while $self->{texture}[$id];
421
422 CFPlus::DB::get tilecache => $id, sub {
423 my ($data) = @_;
424
425 return unless $self->{map}; # stop when destroyed
426
427 $self->set_texture ($id => $data)
428 if defined $data;
429
430 $self->bg_fetch;
431 };
432}
407 433
408sub load_map($$$) { 434sub load_map($$$) {
409 my ($self, $hash, $x, $y) = @_; 435 my ($self, $hash, $x, $y) = @_;
410 436
437 my $gen = $self->{map_change_gen};
438
411 CFPlus::DB::get $self->{mapcache} => $hash, sub { 439 CFPlus::DB::get $self->{mapcache} => $hash, sub {
440 return unless $gen == $self->{map_change_gen};
441
412 my ($data) = @_; 442 my ($data) = @_;
413 443
414 if (defined $data) { 444 if (defined $data) {
415 $data = Compress::LZF::decompress $data; 445 $data = Compress::LZF::decompress $data;
416 #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#
417 for my $id ($self->{map}->set_rect ($x, $y, $data)) {
418 CFPlus::DB::get tilecache => $id, sub {
419 my ($data) = @_;
420 447
421 $self->set_texture ($id => $data) 448 my $inprogress = @{ $self->{bg_fetch} || [] };
422 if defined $data; 449 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
423 }; 450 $self->bg_fetch unless $inprogress;
424 }
425 } 451 }
426 }; 452 };
427} 453}
428 454
429# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 455# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
495 521
496 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 522 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
497 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 523 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
498 524
499 } else { 525 } else {
526 my $gen = $self->{map_change_gen};
500 $self->send_mapinfo ("spatial $path$tile", sub { 527 $self->send_mapinfo ("spatial $path$tile", sub {
528 return unless $gen == $self->{map_change_gen};
529
501 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 530 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
502 531
503 return if $mode ne "spatial"; 532 return if $mode ne "spatial";
504 533
505 $x += $self->{map}->ox; 534 $x += $self->{map}->ox;
519 548
520sub map_change { 549sub map_change {
521 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 550 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
522 551
523 $self->flush_map; 552 $self->flush_map;
553
554 ++$self->{map_change_gen};
524 555
525 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 556 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
526 557
527 my $mapmapw = $self->{mapmap}->{w}; 558 my $mapmapw = $self->{mapmap}->{w};
528 my $mapmaph = $self->{mapmap}->{h}; 559 my $mapmaph = $self->{mapmap}->{h};
568 if $changed; 599 if $changed;
569 600
570 $self->set_texture ($face->{id} => delete $face->{image}); 601 $self->set_texture ($face->{id} => delete $face->{image});
571} 602}
572 603
604sub smooth_update {
605 my ($self, $facenum, $face) = @_;
606
607 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
608}
609
573sub set_texture { 610sub set_texture {
574 my ($self, $id, $data) = @_; 611 my ($self, $id, $data) = @_;
575 612
576 $self->{texture}[$id] ||= do { 613 $self->{texture}[$id] = my $tex =
577 my $tex =
578 new_from_image CFPlus::Texture 614 new_from_image CFPlus::Texture
579 $data, minify => 1, mipmap => 1; 615 $data, minify => 1, mipmap => 1;
580 616
581 $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}});
582 $self->{map_widget}->update; 618 $self->{map_widget}->update;
583
584 $tex
585 };
586} 619}
587 620
588sub sound_play { 621sub sound_play {
589 my ($self, $x, $y, $soundnum, $type) = @_; 622 my ($self, $x, $y, $soundnum, $type) = @_;
590 623
623 656
624 my $fg = $color[$color % @color]; 657 my $fg = $color[$color % @color];
625 658
626 $self->logprint ("info: ", $text); 659 $self->logprint ("info: ", $text);
627 660
628 # 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
629 $text =~ s/(?<=\S)\n(?=\w)/ /g; 663 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
630 664
631 $text = CFPlus::asxml $text; 665 $text = CFPlus::asxml $text;
632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 666 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 667 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
634 668

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines