… | |
… | |
1439 | Coro::cede; |
1439 | Coro::cede; |
1440 | |
1440 | |
1441 | $self->in_memory (cf::MAP_IN_MEMORY); |
1441 | $self->in_memory (cf::MAP_IN_MEMORY); |
1442 | } |
1442 | } |
1443 | |
1443 | |
|
|
1444 | # find and load all maps in the 3x3 area around a map |
|
|
1445 | sub load_diag { |
|
|
1446 | my ($map) = @_; |
|
|
1447 | |
|
|
1448 | my @diag; # diagonal neighbours |
|
|
1449 | |
|
|
1450 | for (0 .. 3) { |
|
|
1451 | my $neigh = $map->tile_path ($_) |
|
|
1452 | or next; |
|
|
1453 | $neigh = find $neigh, $map |
|
|
1454 | or next; |
|
|
1455 | $neigh->load; |
|
|
1456 | |
|
|
1457 | push @diag, [$neigh->tile_path (($_ + 3) % 4), $neigh], |
|
|
1458 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
|
|
1459 | } |
|
|
1460 | |
|
|
1461 | for (@diag) { |
|
|
1462 | my $neigh = find @$_ |
|
|
1463 | or next; |
|
|
1464 | $neigh->load; |
|
|
1465 | } |
|
|
1466 | } |
|
|
1467 | |
1444 | sub find_sync { |
1468 | sub find_sync { |
1445 | my ($path, $origin) = @_; |
1469 | my ($path, $origin) = @_; |
1446 | |
1470 | |
1447 | cf::sync_job { cf::map::find $path, $origin } |
1471 | cf::sync_job { find $path, $origin } |
1448 | } |
1472 | } |
1449 | |
1473 | |
1450 | sub do_load_sync { |
1474 | sub do_load_sync { |
1451 | my ($map) = @_; |
1475 | my ($map) = @_; |
1452 | |
1476 | |
1453 | cf::sync_job { $map->load }; |
1477 | cf::sync_job { $map->load }; |
|
|
1478 | } |
|
|
1479 | |
|
|
1480 | our %MAP_PREFETCH; |
|
|
1481 | our $MAP_PREFETCHER = Coro::async { |
|
|
1482 | while () { |
|
|
1483 | while (%MAP_PREFETCH) { |
|
|
1484 | my $key = each %MAP_PREFETCH |
|
|
1485 | or next; |
|
|
1486 | my $path = delete $MAP_PREFETCH{$key}; |
|
|
1487 | |
|
|
1488 | my $map = find $path |
|
|
1489 | or next; |
|
|
1490 | $map->load; |
|
|
1491 | } |
|
|
1492 | Coro::schedule; |
|
|
1493 | } |
|
|
1494 | }; |
|
|
1495 | |
|
|
1496 | sub find_async { |
|
|
1497 | my ($path, $origin) = @_; |
|
|
1498 | |
|
|
1499 | $path = new cf::path $path, $origin && $origin->path; |
|
|
1500 | my $key = $path->as_string; |
|
|
1501 | |
|
|
1502 | if (my $map = $cf::MAP{$key}) { |
|
|
1503 | return $map if $map->in_memory == cf::MAP_IN_MEMORY; |
|
|
1504 | } |
|
|
1505 | |
|
|
1506 | $MAP_PREFETCH{$key} = $path; |
|
|
1507 | $MAP_PREFETCHER->ready; |
|
|
1508 | |
|
|
1509 | () |
1454 | } |
1510 | } |
1455 | |
1511 | |
1456 | sub save { |
1512 | sub save { |
1457 | my ($self) = @_; |
1513 | my ($self) = @_; |
1458 | |
1514 | |
… | |
… | |
1707 | # use -1 or undef as default coordinates, not 0, 0 |
1763 | # use -1 or undef as default coordinates, not 0, 0 |
1708 | ($x, $y) = ($map->enter_x, $map->enter_y) |
1764 | ($x, $y) = ($map->enter_x, $map->enter_y) |
1709 | if $x <=0 && $y <= 0; |
1765 | if $x <=0 && $y <= 0; |
1710 | |
1766 | |
1711 | $map->load; |
1767 | $map->load; |
|
|
1768 | $map->load_diag; |
1712 | |
1769 | |
1713 | return unless $self->contr->active; |
1770 | return unless $self->contr->active; |
1714 | $self->activate_recursive; |
1771 | $self->activate_recursive; |
1715 | $self->enter_map ($map, $x, $y); |
1772 | $self->enter_map ($map, $x, $y); |
1716 | } |
1773 | } |