… | |
… | |
1619 | $self->init; # pass $1 etc. |
1619 | $self->init; # pass $1 etc. |
1620 | return $self; |
1620 | return $self; |
1621 | } |
1621 | } |
1622 | } |
1622 | } |
1623 | |
1623 | |
1624 | Carp::carp "unable to resolve path '$path' (base '$base')."; |
1624 | Carp::cluck "unable to resolve path '$path' (base '$base')."; |
1625 | () |
1625 | () |
1626 | } |
1626 | } |
1627 | |
1627 | |
1628 | sub init { |
1628 | sub init { |
1629 | my ($self) = @_; |
1629 | my ($self) = @_; |
… | |
… | |
1907 | |
1907 | |
1908 | undef $MAP_PREFETCH{$path}; |
1908 | undef $MAP_PREFETCH{$path}; |
1909 | $MAP_PREFETCHER ||= cf::async { |
1909 | $MAP_PREFETCHER ||= cf::async { |
1910 | while (%MAP_PREFETCH) { |
1910 | while (%MAP_PREFETCH) { |
1911 | for my $path (keys %MAP_PREFETCH) { |
1911 | for my $path (keys %MAP_PREFETCH) { |
1912 | my $map = find $path |
1912 | if (my $map = find $path) { |
1913 | or next; |
|
|
1914 | $map->load; |
1913 | $map->load; |
|
|
1914 | } |
1915 | |
1915 | |
1916 | delete $MAP_PREFETCH{$path}; |
1916 | delete $MAP_PREFETCH{$path}; |
1917 | } |
1917 | } |
1918 | } |
1918 | } |
1919 | undef $MAP_PREFETCHER; |
1919 | undef $MAP_PREFETCHER; |
… | |
… | |
2256 | |
2256 | |
2257 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2257 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2258 | $self->enter_map ($map, $x, $y); |
2258 | $self->enter_map ($map, $x, $y); |
2259 | } |
2259 | } |
2260 | |
2260 | |
2261 | =item $player_object->goto ($path, $x, $y[, $check->($map)]) |
2261 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2262 | |
2262 | |
2263 | Moves the player to the given map-path and coordinates by first freezing |
2263 | Moves the player to the given map-path and coordinates by first freezing |
2264 | her, loading and preparing them map, calling the provided $check callback |
2264 | her, loading and preparing them map, calling the provided $check callback |
2265 | that has to return the map if sucecssful, and then unfreezes the player on |
2265 | that has to return the map if sucecssful, and then unfreezes the player on |
2266 | the new (success) or old (failed) map position. |
2266 | the new (success) or old (failed) map position. In either case, $done will |
|
|
2267 | be called at the end of this process. |
2267 | |
2268 | |
2268 | =cut |
2269 | =cut |
2269 | |
2270 | |
2270 | our $GOTOGEN; |
2271 | our $GOTOGEN; |
2271 | |
2272 | |
2272 | sub cf::object::player::goto { |
2273 | sub cf::object::player::goto { |
2273 | my ($self, $path, $x, $y, $check) = @_; |
2274 | my ($self, $path, $x, $y, $check, $done) = @_; |
2274 | |
2275 | |
2275 | # do generation counting so two concurrent goto's will be executed in-order |
2276 | # do generation counting so two concurrent goto's will be executed in-order |
2276 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2277 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2277 | |
2278 | |
2278 | $self->enter_link; |
2279 | $self->enter_link; |
… | |
… | |
2298 | |
2299 | |
2299 | if ($gen == $self->{_goto_generation}) { |
2300 | if ($gen == $self->{_goto_generation}) { |
2300 | delete $self->{_goto_generation}; |
2301 | delete $self->{_goto_generation}; |
2301 | $self->leave_link ($map, $x, $y); |
2302 | $self->leave_link ($map, $x, $y); |
2302 | } |
2303 | } |
|
|
2304 | |
|
|
2305 | $done->() if $done; |
2303 | })->prio (1); |
2306 | })->prio (1); |
2304 | } |
2307 | } |
2305 | |
2308 | |
2306 | =item $player_object->enter_exit ($exit_object) |
2309 | =item $player_object->enter_exit ($exit_object) |
2307 | |
2310 | |
… | |
… | |
2768 | my $meta = $enc->encode ({ |
2771 | my $meta = $enc->encode ({ |
2769 | name => $name, |
2772 | name => $name, |
2770 | type => $info->{type}, |
2773 | type => $info->{type}, |
2771 | copyright => $info->{copyright}, #TODO# |
2774 | copyright => $info->{copyright}, #TODO# |
2772 | }); |
2775 | }); |
2773 | my $data = pack "(w/a*)*", $meta, $info->{data}; |
|
|
2774 | my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata |
|
|
2775 | |
2776 | |
2776 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
2777 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
|
|
2778 | |
|
|
2779 | if ($name =~ /\.jpg$/) { |
|
|
2780 | cf::face::set_data $idx, 0, $info->{data}, $info->{chksum};#d# temp hack |
|
|
2781 | cf::face::set_data $idx, 1, $info->{data}, $info->{chksum};#d# temp hack |
|
|
2782 | } else { |
|
|
2783 | my $data = pack "(w/a*)*", $meta, $info->{data}; |
|
|
2784 | my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata |
|
|
2785 | |
2777 | cf::face::set_type $idx, 1; |
2786 | cf::face::set_type $idx, 1; |
2778 | cf::face::set_data $idx, 0, $data, $chk; |
2787 | cf::face::set_data $idx, 0, $data, $chk; |
|
|
2788 | } |
2779 | |
2789 | |
2780 | cf::cede_to_tick; |
2790 | cf::cede_to_tick; |
2781 | } |
2791 | } |
2782 | } |
2792 | } |
2783 | |
2793 | |