… | |
… | |
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 | |
… | |
… | |
582 | CFPlus::DB::exists tilecache => $id, sub { |
582 | CFPlus::DB::exists tilecache => $id, sub { |
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 | $self->have_tile ($id) |
588 | $self->have_tile ($id); |
588 | if $exists; |
589 | $self->{texture}[$id]->upload; |
|
|
590 | } |
589 | |
591 | |
590 | $self->bg_fetch; |
592 | $self->bg_fetch; |
591 | }; |
593 | }; |
592 | } |
594 | } |
593 | |
595 | |
594 | sub load_map($$$) { |
596 | sub load_map($$$) { |
595 | my ($self, $hash, $x, $y) = @_; |
597 | my ($self, $hash, $x, $y) = @_; |
596 | |
598 | |
597 | my $gen = $self->{map_change_gen}; |
599 | my $gen = $self->{map_change_gen}; |
598 | |
600 | |
599 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
601 | my $cb = sub { |
600 | return unless $gen == $self->{map_change_gen}; |
602 | return unless $gen == $self->{map_change_gen}; |
601 | |
603 | |
602 | my ($data) = @_; |
604 | my ($data) = @_; |
603 | |
605 | |
604 | if (defined $data) { |
606 | if (defined $data) { |
|
|
607 | $self->{map_cache_new}{$hash} = \$data; |
|
|
608 | |
605 | $data = Compress::LZF::decompress $data; |
609 | my $data = Compress::LZF::decompress $data; |
606 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
607 | |
610 | |
608 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
611 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
609 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
612 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
610 | $self->bg_fetch unless $inprogress; |
613 | $self->bg_fetch unless $inprogress; |
611 | } |
614 | } |
612 | }; |
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 | } |
613 | } |
622 | } |
614 | |
623 | |
615 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
624 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
616 | # (server resource,s latency, bandwidth), so this hack is warranted. |
625 | # (server resource,s latency, bandwidth), so this hack is warranted. |
617 | # 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 |
… | |
… | |
710 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
719 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
711 | |
720 | |
712 | $self->flush_map; |
721 | $self->flush_map; |
713 | |
722 | |
714 | ++$self->{map_change_gen}; |
723 | ++$self->{map_change_gen}; |
|
|
724 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
715 | |
725 | |
716 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
726 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
717 | |
727 | |
718 | my $mapmapw = $self->{mapmap}->{w}; |
728 | my $mapmapw = $self->{mapmap}->{w}; |
719 | my $mapmaph = $self->{mapmap}->{h}; |
729 | my $mapmaph = $self->{mapmap}->{h}; |