… | |
… | |
1916 | |
1916 | |
1917 | $self |
1917 | $self |
1918 | } |
1918 | } |
1919 | |
1919 | |
1920 | # find and load all maps in the 3x3 area around a map |
1920 | # find and load all maps in the 3x3 area around a map |
1921 | sub load_diag { |
1921 | sub load_neighbours { |
1922 | my ($map) = @_; |
1922 | my ($map) = @_; |
1923 | |
1923 | |
1924 | my @diag; # diagonal neighbours |
1924 | my @neigh; # diagonal neighbours |
1925 | |
1925 | |
1926 | for (0 .. 3) { |
1926 | for (0 .. 3) { |
1927 | my $neigh = $map->tile_path ($_) |
1927 | my $neigh = $map->tile_path ($_) |
1928 | or next; |
1928 | or next; |
1929 | $neigh = find $neigh, $map |
1929 | $neigh = find $neigh, $map |
1930 | or next; |
1930 | or next; |
1931 | $neigh->load; |
1931 | $neigh->load; |
1932 | |
1932 | |
|
|
1933 | push @neigh, |
1933 | push @diag, [$neigh->tile_path (($_ + 3) % 4), $neigh], |
1934 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
1934 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
1935 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
1935 | } |
1936 | } |
1936 | |
1937 | |
1937 | for (@diag) { |
1938 | for (grep defined $_->[0], @neigh) { |
|
|
1939 | my ($path, $origin) = @$_; |
1938 | my $neigh = find @$_ |
1940 | my $neigh = find $path, $origin |
1939 | or next; |
1941 | or next; |
1940 | $neigh->load; |
1942 | $neigh->load; |
1941 | } |
1943 | } |
1942 | } |
1944 | } |
1943 | |
1945 | |
… | |
… | |
2312 | # use -1 or undef as default coordinates, not 0, 0 |
2314 | # use -1 or undef as default coordinates, not 0, 0 |
2313 | ($x, $y) = ($map->enter_x, $map->enter_y) |
2315 | ($x, $y) = ($map->enter_x, $map->enter_y) |
2314 | if $x <=0 && $y <= 0; |
2316 | if $x <=0 && $y <= 0; |
2315 | |
2317 | |
2316 | $map->load; |
2318 | $map->load; |
2317 | $map->load_diag; |
2319 | $map->load_neighbours; |
2318 | |
2320 | |
2319 | return unless $self->contr->active; |
2321 | return unless $self->contr->active; |
2320 | $self->activate_recursive; |
2322 | $self->activate_recursive; |
2321 | |
2323 | |
2322 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2324 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
… | |
… | |
2809 | # the server's init and main functions |
2811 | # the server's init and main functions |
2810 | |
2812 | |
2811 | sub load_facedata($) { |
2813 | sub load_facedata($) { |
2812 | my ($path) = @_; |
2814 | my ($path) = @_; |
2813 | |
2815 | |
|
|
2816 | my $enc = JSON::XS->new->utf8->canonical; |
|
|
2817 | |
2814 | warn "loading facedata from $path\n"; |
2818 | warn "loading facedata from $path\n"; |
2815 | |
2819 | |
2816 | my $facedata; |
2820 | my $facedata; |
2817 | 0 < aio_load $path, $facedata |
2821 | 0 < aio_load $path, $facedata |
2818 | or die "$path: $!"; |
2822 | or die "$path: $!"; |
2819 | |
2823 | |
2820 | $facedata = Coro::Storable::thaw $facedata; |
2824 | $facedata = Coro::Storable::thaw $facedata; |
2821 | |
2825 | |
2822 | $facedata->{version} == 2 |
2826 | $facedata->{version} == 2 |
2823 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
2827 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
|
|
2828 | |
|
|
2829 | # patch in the exptable |
|
|
2830 | cf::cede_to_tick; |
|
|
2831 | $facedata->{resource}{"res/exp_table"} = { |
|
|
2832 | type => FT_RSRC, |
|
|
2833 | data => $enc->encode ([map cf::level_to_min_exp $_, 0 .. cf::settings->max_level]), |
|
|
2834 | }; |
|
|
2835 | cf::cede_to_tick; |
2824 | |
2836 | |
2825 | { |
2837 | { |
2826 | my $faces = $facedata->{faceinfo}; |
2838 | my $faces = $facedata->{faceinfo}; |
2827 | |
2839 | |
2828 | while (my ($face, $info) = each %$faces) { |
2840 | while (my ($face, $info) = each %$faces) { |
2829 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2841 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
2830 | cf::face::set_visibility $idx, $info->{visibility}; |
2842 | cf::face::set_visibility $idx, $info->{visibility}; |
2831 | cf::face::set_magicmap $idx, $info->{magicmap}; |
2843 | cf::face::set_magicmap $idx, $info->{magicmap}; |
2832 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
2844 | cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; |
2833 | cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; |
2845 | cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64}; |
2834 | |
2846 | |
2835 | cf::cede_to_tick; |
2847 | cf::cede_to_tick; |
2836 | } |
2848 | } |
2837 | |
2849 | |
2838 | while (my ($face, $info) = each %$faces) { |
2850 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
2863 | |
2875 | |
2864 | { |
2876 | { |
2865 | # TODO: for gcfclient pleasure, we should give resources |
2877 | # TODO: for gcfclient pleasure, we should give resources |
2866 | # that gcfclient doesn't grok a >10000 face index. |
2878 | # that gcfclient doesn't grok a >10000 face index. |
2867 | my $res = $facedata->{resource}; |
2879 | my $res = $facedata->{resource}; |
2868 | my $enc = JSON::XS->new->utf8->canonical; |
|
|
2869 | |
2880 | |
2870 | my $soundconf = delete $res->{"res/sound.conf"}; |
2881 | my $soundconf = delete $res->{"res/sound.conf"}; |
2871 | |
2882 | |
2872 | while (my ($name, $info) = each %$res) { |
2883 | while (my ($name, $info) = each %$res) { |
2873 | my $meta = $enc->encode ({ |
|
|
2874 | name => $name, |
|
|
2875 | %{ $info->{meta} || {} }, |
|
|
2876 | }); |
|
|
2877 | |
|
|
2878 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
2884 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
|
|
2885 | my $data; |
2879 | |
2886 | |
2880 | if ($info->{type} & 1) { |
2887 | if ($info->{type} & 1) { |
2881 | # prepend meta info |
2888 | # prepend meta info |
2882 | |
2889 | |
|
|
2890 | my $meta = $enc->encode ({ |
|
|
2891 | name => $name, |
|
|
2892 | %{ $info->{meta} || {} }, |
|
|
2893 | }); |
|
|
2894 | |
2883 | my $data = pack "(w/a*)*", $meta, $info->{data}; |
2895 | $data = pack "(w/a*)*", $meta, $info->{data}; |
2884 | my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata |
|
|
2885 | |
|
|
2886 | cf::face::set_data $idx, 0, $data, $chk; |
|
|
2887 | } else { |
|
|
2888 | cf::face::set_data $idx, 0, $info->{data}, $info->{chksum}; |
|
|
2889 | } |
2896 | } |
2890 | |
2897 | |
|
|
2898 | cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data; |
2891 | cf::face::set_type $idx, $info->{type}; |
2899 | cf::face::set_type $idx, $info->{type}; |
2892 | |
2900 | |
2893 | cf::cede_to_tick; |
2901 | cf::cede_to_tick; |
2894 | } |
2902 | } |
2895 | |
2903 | |