… | |
… | |
552 | my $map_info = delete $self->{map_info} |
552 | my $map_info = delete $self->{map_info} |
553 | or return; |
553 | or return; |
554 | |
554 | |
555 | my ($hash, $x, $y, $w, $h) = @$map_info; |
555 | my ($hash, $x, $y, $w, $h) = @$map_info; |
556 | |
556 | |
557 | 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; |
558 | CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; |
559 | CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; |
559 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
560 | } |
560 | } |
561 | |
561 | |
562 | sub map_clear { |
562 | sub map_clear { |
563 | my ($self) = @_; |
563 | my ($self) = @_; |
564 | |
564 | |
… | |
… | |
583 | my ($exists) = @_; |
583 | my ($exists) = @_; |
584 | |
584 | |
585 | return unless $self->{map}; # stop when destroyed |
585 | return unless $self->{map}; # stop when destroyed |
586 | |
586 | |
587 | if ($exists) { |
587 | if ($exists) { |
588 | $self->have_tile ($id) |
588 | $self->have_tile ($id); |
589 | $self->{texture}[$id]->upload; |
589 | $self->{texture}[$id]->upload; |
590 | } |
590 | } |
591 | |
591 | |
592 | $self->bg_fetch; |
592 | $self->bg_fetch; |
593 | }; |
593 | }; |
… | |
… | |
596 | sub load_map($$$) { |
596 | sub load_map($$$) { |
597 | my ($self, $hash, $x, $y) = @_; |
597 | my ($self, $hash, $x, $y) = @_; |
598 | |
598 | |
599 | my $gen = $self->{map_change_gen}; |
599 | my $gen = $self->{map_change_gen}; |
600 | |
600 | |
601 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
601 | my $cb = sub { |
602 | return unless $gen == $self->{map_change_gen}; |
602 | return unless $gen == $self->{map_change_gen}; |
603 | |
603 | |
604 | my ($data) = @_; |
604 | my ($data) = @_; |
605 | |
605 | |
606 | if (defined $data) { |
606 | if (defined $data) { |
|
|
607 | $self->{map_cache_new}{$hash} = \$data; |
|
|
608 | |
607 | $data = Compress::LZF::decompress $data; |
609 | my $data = Compress::LZF::decompress $data; |
608 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
609 | |
610 | |
610 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
611 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
611 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
612 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
612 | $self->bg_fetch unless $inprogress; |
613 | $self->bg_fetch unless $inprogress; |
613 | } |
614 | } |
614 | }; |
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 | } |
615 | } |
622 | } |
616 | |
623 | |
617 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
624 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
618 | # (server resource,s latency, bandwidth), so this hack is warranted. |
625 | # (server resource,s latency, bandwidth), so this hack is warranted. |
619 | # 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 |
… | |
… | |
712 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
719 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
713 | |
720 | |
714 | $self->flush_map; |
721 | $self->flush_map; |
715 | |
722 | |
716 | ++$self->{map_change_gen}; |
723 | ++$self->{map_change_gen}; |
|
|
724 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
717 | |
725 | |
718 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
726 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
719 | |
727 | |
720 | my $mapmapw = $self->{mapmap}->{w}; |
728 | my $mapmapw = $self->{mapmap}->{w}; |
721 | my $mapmaph = $self->{mapmap}->{h}; |
729 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
905 | $self->{$type} = $text; |
913 | $self->{$type} = $text; |
906 | } else { |
914 | } else { |
907 | $self->logprint ("msg: ", $text); |
915 | $self->logprint ("msg: ", $text); |
908 | return if $color < 0; # negative color == ignore if not understood |
916 | return if $color < 0; # negative color == ignore if not understood |
909 | |
917 | |
910 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
918 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
911 | |
919 | |
912 | ## try to create single paragraphs of multiple lines sent by the server |
920 | ## try to create single paragraphs of multiple lines sent by the server |
913 | # no longer neecssary with TRT servers |
921 | # no longer neecssary with TRT servers |
914 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
922 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
915 | |
923 | |
916 | ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) |
924 | ::message ({ |
|
|
925 | fg => $fg, |
|
|
926 | markup => $_, |
|
|
927 | type => $type, |
|
|
928 | extra => [@extra], |
|
|
929 | color_flags => $color |
917 | for split /\n/, $text; |
930 | }) for split /\n/, $text; |
918 | |
931 | |
919 | $self->{statusbox}->add ($text, |
932 | $self->{statusbox}->add ($text, |
920 | group => $text, |
933 | group => $text, |
921 | fg => $fg, |
934 | fg => $fg, |
922 | timeout => $color >= 2 ? 180 : 10, |
935 | timeout => $color >= 2 ? 180 : 10, |