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.147 by root, Thu Aug 9 03:40:01 2007 UTC vs.
Revision 1.153 by root, Mon Aug 13 14:24:17 2007 UTC

506} 506}
507 507
508sub feed_map1a { 508sub feed_map1a {
509 my ($self, $data) = @_; 509 my ($self, $data) = @_;
510 510
511 $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 511 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap});
512 my $delay;
513
514 for my $tile (@$missing) {
515 next if $self->{delay}{$tile};
516
517 $delay = 1;
518
519 if (my $tex = $::CONN->{texture}[$tile]) {
520 $tex->upload;
521 } else {
522 $self->{delay}{$tile} = 1;
523
524 # we assume the face is in-flight and will eventually come
525 push @{$self->{face_cb}{$tile}}, sub {
526 delete $self->{delay}{$tile};
527 $_[0]->upload;
528 };
529 }
530 }
531
532 if ($delay) {
533 # delay the map drawing a tiny bit in the hope of getting the missing fetched
534 Event->timer (after => 0.03, cb => sub {
535 $_[0]->w->cancel;
536 $self->{map_widget}->update;
537 });
538 } else {
512 $self->{map_widget}->update; 539 $self->{map_widget}->update;
540 }
513} 541}
514 542
515sub magicmap { 543sub magicmap {
516 my ($self, $w, $h, $x, $y, $data) = @_; 544 my ($self, $w, $h, $x, $y, $data) = @_;
517 545
524 my $map_info = delete $self->{map_info} 552 my $map_info = delete $self->{map_info}
525 or return; 553 or return;
526 554
527 my ($hash, $x, $y, $w, $h) = @$map_info; 555 my ($hash, $x, $y, $w, $h) = @$map_info;
528 556
529 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 557 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h);
558 $self->{map_cache_new}{$hash} = \$data;
530 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; 559 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { };
531 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
532} 560}
533 561
534sub map_clear { 562sub map_clear {
535 my ($self) = @_; 563 my ($self) = @_;
536 564
554 CFPlus::DB::exists tilecache => $id, sub { 582 CFPlus::DB::exists tilecache => $id, sub {
555 my ($exists) = @_; 583 my ($exists) = @_;
556 584
557 return unless $self->{map}; # stop when destroyed 585 return unless $self->{map}; # stop when destroyed
558 586
587 if ($exists) {
559 $self->have_tile ($id) 588 $self->have_tile ($id);
560 if $exists; 589 $self->{texture}[$id]->upload;
590 }
561 591
562 $self->bg_fetch; 592 $self->bg_fetch;
563 }; 593 };
564} 594}
565 595
566sub load_map($$$) { 596sub load_map($$$) {
567 my ($self, $hash, $x, $y) = @_; 597 my ($self, $hash, $x, $y) = @_;
568 598
569 my $gen = $self->{map_change_gen}; 599 my $gen = $self->{map_change_gen};
570 600
571 CFPlus::DB::get $self->{mapcache} => $hash, sub { 601 my $cb = sub {
572 return unless $gen == $self->{map_change_gen}; 602 return unless $gen == $self->{map_change_gen};
573 603
574 my ($data) = @_; 604 my ($data) = @_;
575 605
576 if (defined $data) { 606 if (defined $data) {
607 $self->{map_cache_new}{$hash} = \$data;
608
577 $data = Compress::LZF::decompress $data; 609 my $data = Compress::LZF::decompress $data;
578 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
579 610
580 my $inprogress = @{ $self->{bg_fetch} || [] }; 611 my $inprogress = @{ $self->{bg_fetch} || [] };
581 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 612 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
582 $self->bg_fetch unless $inprogress; 613 $self->bg_fetch unless $inprogress;
583 } 614 }
584 }; 615 };
616
617 if (my $rdata = $self->{map_cache_old}{$hash}) {
618 $cb->($$rdata);
619 } else {
620 CFPlus::DB::get $self->{mapcache} => $hash, $cb;
621 }
585} 622}
586 623
587# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 624# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
588# (server resource,s latency, bandwidth), so this hack is warranted. 625# (server resource,s latency, bandwidth), so this hack is warranted.
589# the right fix is to make real tiled maps with an overview file 626# the right fix is to make real tiled maps with an overview file
682 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 719 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
683 720
684 $self->flush_map; 721 $self->flush_map;
685 722
686 ++$self->{map_change_gen}; 723 ++$self->{map_change_gen};
724 $self->{map_cache_old} = delete $self->{map_cache_new};
687 725
688 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 726 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
689 727
690 my $mapmapw = $self->{mapmap}->{w}; 728 my $mapmapw = $self->{mapmap}->{w};
691 my $mapmaph = $self->{mapmap}->{h}; 729 my $mapmaph = $self->{mapmap}->{h};
721 $self->{map}->set_tileid ($facenum => $id); 759 $self->{map}->set_tileid ($facenum => $id);
722 760
723 CFPlus::DB::get tilecache => $id, $cb; 761 CFPlus::DB::get tilecache => $id, $cb;
724 762
725 } elsif ($face->{type} & 1) { # with metadata 763 } elsif ($face->{type} & 1) { # with metadata
726 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
727 CFPlus::DB::get res_meta => $face->{name}, $cb; 764 CFPlus::DB::get res_meta => $face->{name}, $cb;
728 } 765 }
729} 766}
730 767
731sub face_update { 768sub face_update {
778sub have_tile { 815sub have_tile {
779 my ($self, $tile) = @_; 816 my ($self, $tile) = @_;
780 817
781 return unless $self->{map}; 818 return unless $self->{map};
782 819
783 $self->{texture}[$tile] ||= my $tex = 820 my $tex = $self->{texture}[$tile] ||=
784 new CFPlus::Texture 821 new CFPlus::Texture
785 tile => $tile, minify => 1, mipmap => 1, delay => 1; 822 tile => $tile, minify => 1, mipmap => 1, delay => 1;
786 823
787 $_->() for @{(delete $self->{face_cb}{$tile}) || []}; 824 $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []};
788} 825}
789 826
790sub connect_face_update { 827sub connect_face_update {
791 my ($self, $id, $cb) = @_; 828 my ($self, $id, $cb) = @_;
792 829
987 } 1024 }
988 1025
989 $::FLOORBOX->add_at (@add); 1026 $::FLOORBOX->add_at (@add);
990 }); 1027 });
991 1028
992 $::WANT_REFRESH++; 1029 $::WANT_REFRESH->start;
993} 1030}
994 1031
995sub set_opencont { 1032sub set_opencont {
996 my ($conn, $tag, $name) = @_; 1033 my ($conn, $tag, $name) = @_;
997 $conn->{open_container} = $tag; 1034 $conn->{open_container} = $tag;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines