ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.332 by root, Sat Aug 18 17:33:53 2007 UTC vs.
Revision 1.335 by root, Mon Aug 20 22:21:48 2007 UTC

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
1921sub load_diag { 1921sub 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
2811sub load_facedata($) { 2813sub 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 $facedata->{resource}{"res/exp_table"} = {
2831 type => FT_RSRC,
2832 data => $enc->encode ([map cf::level_to_min_exp $_, 0 .. cf::settings->max_level]),
2833 };
2834 cf::cede_to_tick;
2824 2835
2825 { 2836 {
2826 my $faces = $facedata->{faceinfo}; 2837 my $faces = $facedata->{faceinfo};
2827 2838
2828 while (my ($face, $info) = each %$faces) { 2839 while (my ($face, $info) = each %$faces) {
2829 my $idx = (cf::face::find $face) || cf::face::alloc $face; 2840 my $idx = (cf::face::find $face) || cf::face::alloc $face;
2830 cf::face::set_visibility $idx, $info->{visibility}; 2841 cf::face::set_visibility $idx, $info->{visibility};
2831 cf::face::set_magicmap $idx, $info->{magicmap}; 2842 cf::face::set_magicmap $idx, $info->{magicmap};
2832 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; 2843 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32};
2833 cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; 2844 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64};
2834 2845
2835 cf::cede_to_tick; 2846 cf::cede_to_tick;
2836 } 2847 }
2837 2848
2838 while (my ($face, $info) = each %$faces) { 2849 while (my ($face, $info) = each %$faces) {
2863 2874
2864 { 2875 {
2865 # TODO: for gcfclient pleasure, we should give resources 2876 # TODO: for gcfclient pleasure, we should give resources
2866 # that gcfclient doesn't grok a >10000 face index. 2877 # that gcfclient doesn't grok a >10000 face index.
2867 my $res = $facedata->{resource}; 2878 my $res = $facedata->{resource};
2868 my $enc = JSON::XS->new->utf8->canonical;
2869 2879
2870 my $soundconf = delete $res->{"res/sound.conf"}; 2880 my $soundconf = delete $res->{"res/sound.conf"};
2871 2881
2872 while (my ($name, $info) = each %$res) { 2882 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; 2883 my $idx = (cf::face::find $name) || cf::face::alloc $name;
2884 my $data;
2879 2885
2880 if ($info->{type} & 1) { 2886 if ($info->{type} & 1) {
2881 # prepend meta info 2887 # prepend meta info
2882 2888
2889 my $meta = $enc->encode ({
2890 name => $name,
2891 %{ $info->{meta} || {} },
2892 });
2893
2883 my $data = pack "(w/a*)*", $meta, $info->{data}; 2894 $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 } 2895 }
2890 2896
2897 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
2891 cf::face::set_type $idx, $info->{type}; 2898 cf::face::set_type $idx, $info->{type};
2892 2899
2893 cf::cede_to_tick; 2900 cf::cede_to_tick;
2894 } 2901 }
2895 2902

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines